Index: firmware/App/Controllers/BPModule.c =================================================================== diff -u -r18e59a9564adbb5a6a6a64a18460bdb5bf4d293e -r3e6b89e98c3725c7afd94a3c37fe3efce3fde65f --- firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 18e59a9564adbb5a6a6a64a18460bdb5bf4d293e) +++ firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 3e6b89e98c3725c7afd94a3c37fe3efce3fde65f) @@ -28,6 +28,7 @@ // ********** private definitions ********** +// TODO remove these when institutional settings are available #define BP_SYSTOLIC_LOW_LIMIT 90 ///< Low systolic blood pressure threshold in mmHg #define BP_SYSTOLIC_HIGH_LIMIT 180 ///< High systolic blood pressure threshold in mmHG #define BP_HEART_RATE_LOW_LIMIT 40 ///< Low heart rate threshold in BPM @@ -46,88 +47,69 @@ // ********** private data ********** static BP_MODULE_STATE_T bpModuleState = BP_MODULE_IDLE_STATE; ///< Current blood pressure module state -static BP_RESULTS_T bpModuleResults; ///< Latest blood pressure measurement results static U08 lowSystolicCount; ///< Consecutive low systolic pressure counter -static BOOL bpSystolicLowDetected; ///< Low systolic blood pressure detection -static BOOL bpSystolicLowTooManyDetected; ///< Consecutive low systolic detection -static BOOL bpSystolicHighDetected; ///< High systolic blood pressure detection -static BOOL bpHeartRateLowDetected; ///< Low heart rate detection -static BOOL bpHeartRateHighDetected; ///< High heart rate detection -static BOOL bpModuleErrorDetected; ///< Blood pressure module error detection flag. +static BOOL requestAdultBPReading; ///< Adult BP reading request +static BOOL requestPedsBPReading; ///< Pediatric BP reading request +static BOOL requestAbortBPReading; ///< Abort BP reading request // ********** private function prototypes ********** -static void resetBPAlarmFlags( void ); static void checkBloodPressureReading( void ); -static void handleBPModuleIdleState( void ); -static void handleBPModuleMeasureState( void ); -static void handleBPModuleCheckState( void ); +static BP_MODULE_STATE_T handleBPModuleIdleState( void ); +static BP_MODULE_STATE_T handleBPModuleMeasureState( void ); +static BP_MODULE_STATE_T handleBPModuleCheckState( void ); /*********************************************************************//** * @brief * The initBPModule function initializes the blood pressure module. * @details \b Inputs: none -* @details \b Outputs: bpModuleState +* @details \b Outputs: BPModule variables initialized * @return none ***************************************************************************/ void initBPModule( void ) { initBPDriver(); - bpModuleState = BP_MODULE_IDLE_STATE; - resetBPAlarmFlags(); + bpModuleState = BP_MODULE_IDLE_STATE; + lowSystolicCount = 0; + requestAdultBPReading = FALSE; + requestPedsBPReading = FALSE; + requestAbortBPReading = FALSE; } /*********************************************************************//** * @brief - * The resetBPAlarmFlags function clears all blood pressure alarm - * detection flags. - * @details \b Inputs: none - * @details \b Outputs: BP alarm detection flags - * @return none - ***************************************************************************/ -static void resetBPAlarmFlags( void ) -{ - bpSystolicLowDetected = FALSE; - bpSystolicLowTooManyDetected = FALSE; - bpSystolicHighDetected = FALSE; - bpHeartRateLowDetected = FALSE; - bpHeartRateHighDetected = FALSE; - bpModuleErrorDetected = FALSE; -} - -/*********************************************************************//** - * @brief * The execBPModule function executes the blood pressure module state * machine. * @details \b Inputs: bpModuleState - * @details \b Outputs: bpModuleState, bpModuleResults + * @details \b Outputs: bpModuleState * @return none ***************************************************************************/ void execBPModule( void ) { + execBPDriver(); switch ( bpModuleState ) { case BP_MODULE_IDLE_STATE: { - handleBPModuleIdleState(); + bpModuleState = handleBPModuleIdleState(); break; } case BP_MODULE_MEASURE_STATE: { - handleBPModuleMeasureState(); + bpModuleState = handleBPModuleMeasureState(); break; } case BP_MODULE_CHECK_STATE: { - handleBPModuleCheckState(); + bpModuleState = handleBPModuleCheckState(); break; } default: { - activateAlarm( ALARM_ID_TD_SOFTWARE_FAULT ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_BP_MODULE_STATE, bpModuleState ); bpModuleState = BP_MODULE_IDLE_STATE; break; } @@ -144,8 +126,7 @@ ***************************************************************************/ void initiateAdultBPReading( void ) { - startAdultBPMeasurement(); - bpModuleState = BP_MODULE_MEASURE_STATE; + requestAdultBPReading = TRUE; } /*********************************************************************//** @@ -158,8 +139,7 @@ ***************************************************************************/ void initiatePedsBPReading( void ) { - startPedsBPMeasurement(); - bpModuleState = BP_MODULE_MEASURE_STATE; + requestPedsBPReading = TRUE; } /*********************************************************************//** @@ -172,135 +152,45 @@ ***************************************************************************/ void abortBPReading( void ) { - abortBPMeasurement(); - bpModuleState = BP_MODULE_IDLE_STATE; + requestAbortBPReading = TRUE; } /*********************************************************************//** * @brief - * The isBPSystolicLowDetected function returns the systolic low - * detection state. - * @details \b Inputs: bpSystolicLowDetected - * @details \b Outputs: none - * @return TRUE if detected, FALSE otherwise. - ***************************************************************************/ -BOOL isBPSystolicLowDetected( void ) -{ - return bpSystolicLowDetected; -} - -/*********************************************************************//** - * @brief - * The isBPSystolicLowTooManyDetected function returns the consecutive - * systolic low detection state. - * @details \b Inputs: bpSystolicLowTooManyDetected - * @details \b Outputs: none - * @return TRUE if detected, FALSE otherwise. - ***************************************************************************/ -BOOL isBPSystolicLowTooManyDetected( void ) -{ - return bpSystolicLowTooManyDetected; -} - -/*********************************************************************//** - * @brief - * The isBPSystolicHighDetected function returns the systolic high - * detection state. - * @details \b Inputs: bpSystolicHighDetected - * @details \b Outputs: none - * @return TRUE if detected, FALSE otherwise. - ***************************************************************************/ -BOOL isBPSystolicHighDetected( void ) -{ - return bpSystolicHighDetected; -} - -/*********************************************************************//** - * @brief - * The isBPHeartRateLowDetected function returns the heart rate low - * detection state. - * @details \b Inputs: bpHeartRateLowDetected - * @details \b Outputs: none - * @return TRUE if detected, FALSE otherwise. - ***************************************************************************/ -BOOL isBPHeartRateLowDetected( void ) -{ - return bpHeartRateLowDetected; -} - -/*********************************************************************//** - * @brief - * The isBPHeartRateHighDetected function returns the heart rate high - * detection state. - * @details \b Inputs: bpHeartRateHighDetected - * @details \b Outputs: none - * @return TRUE if detected, FALSE otherwise. - ***************************************************************************/ -BOOL isBPHeartRateHighDetected( void ) -{ - return bpHeartRateHighDetected; -} - -/*********************************************************************//** - * @brief - * The hasBPModuleError function returns the blood pressure module - * error detection state. - * @details \b Inputs: bpModuleErrorDetected - * @details \b Outputs: none - * @return TRUE if error detected, FALSE otherwise. - ***************************************************************************/ -BOOL hasBPModuleError( void ) -{ - return bpModuleErrorDetected; -} - -/*********************************************************************//** - * @brief * The checkBloodPressureReading function validates blood pressure * measurement results against configured thresholds and activates * corresponding blood pressure alarms. - * @details \b Inputs: bpModuleResults - * @details \b Outputs: bpSystolicLowDetected, bpSystolicLowTooManyDetected - * bpSystolicHighDetected, bpHeartRateLowDetected, bpHeartRateHighDetected + * @details \b Inputs: systolicPressure, heartRate + * @details \b Outputs: activate BP alarms * @return none ***************************************************************************/ static void checkBloodPressureReading( void ) { - resetBPAlarmFlags(); + U16 systolicPressure = getBPSystolicPressure(); + U16 heartRate = getBPHeartRate(); - if ( bpModuleResults.systolic <= BP_SYSTOLIC_LOW_LIMIT ) + if ( systolicPressure <= BP_SYSTOLIC_LOW_LIMIT ) { - bpSystolicLowDetected = TRUE; lowSystolicCount++; - if ( lowSystolicCount >= BP_LOW_SYSTOLIC_MAX_COUNT ) { - bpSystolicLowTooManyDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_LOW_TOO_MANY ); } else { activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_LOW ); } } - - else + if ( systolicPressure >= BP_SYSTOLIC_HIGH_LIMIT ) { - lowSystolicCount = 0; - } - if ( bpModuleResults.systolic >= BP_SYSTOLIC_HIGH_LIMIT ) - { - bpSystolicHighDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_HIGH ); } - if ( bpModuleResults.heartRate <= BP_HEART_RATE_LOW_LIMIT ) + if ( heartRate <= BP_HEART_RATE_LOW_LIMIT ) { - bpHeartRateLowDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_HEART_RATE_LOW ); } - if ( bpModuleResults.heartRate >= BP_HEART_RATE_HIGH_LIMIT ) + if ( heartRate >= BP_HEART_RATE_HIGH_LIMIT ) { - bpHeartRateHighDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_HEART_RATE_HIGH ); } } @@ -309,53 +199,80 @@ * @brief * The handleBPModuleIdleState function executes the BP module idle * state handling. - * @details \b Inputs: none - * @details \b Outputs: none - * @return none + * @details \b Inputs: requestAdultBPReading, requestPedsBPReading, + * requestAbortBPReading + * @details \b Outputs: flags + * @return next BP module state ***************************************************************************/ -static void handleBPModuleIdleState( void ) +static BP_MODULE_STATE_T handleBPModuleIdleState( void ) { - // TODO + BP_MODULE_STATE_T nextState = BP_MODULE_IDLE_STATE; + + if ( TRUE == requestAdultBPReading ) + { + requestAdultBPReading = FALSE; + startAdultBPMeasurement(); + nextState = BP_MODULE_MEASURE_STATE; + } + else if ( TRUE == requestPedsBPReading ) + { + requestPedsBPReading = FALSE; + startPedsBPMeasurement(); + nextState = BP_MODULE_MEASURE_STATE; + } + else if ( TRUE == requestAbortBPReading ) + { + requestAbortBPReading = FALSE; + abortBPMeasurement(); + } + + return nextState; } /*********************************************************************//** * @brief * The handleBPModuleMeasureState function executes the BP module * measurement state handling. - * @details \b Inputs: BP driver state/results + * @details \b Inputs: results * @details \b Outputs: bpModuleState - * @return none + * @return next BP module state ***************************************************************************/ -static void handleBPModuleMeasureState( void ) +static BP_MODULE_STATE_T handleBPModuleMeasureState( void ) { - execBPDriver(); + BP_MODULE_STATE_T nextState = BP_MODULE_MEASURE_STATE; if ( TRUE == isBPMeasurementReady() ) { - getBPResults( &bpModuleResults ); - bpModuleState = BP_MODULE_CHECK_STATE; + nextState = BP_MODULE_CHECK_STATE; } else if ( TRUE == hasBPDriverError() ) { - bpModuleErrorDetected = TRUE; - bpModuleState = BP_MODULE_IDLE_STATE; + nextState = BP_MODULE_IDLE_STATE; } + + return nextState; } /*********************************************************************//** - * @brief - * The handleBPModuleCheckState function executes the BP module - * validation state handling. - * @details \b Inputs: bpModuleResults - * @details \b Outputs: BP alarm detection flags - * @return none - ***************************************************************************/ -static void handleBPModuleCheckState( void ) +* @brief +* The handleBPModuleCheckState function executes the BP module +* validation state handling. +* @details \b Inputs: BP driver measurement results +* @details \b Outputs: BP alarms +* @return next BP module state. +***************************************************************************/ +static BP_MODULE_STATE_T handleBPModuleCheckState( void ) { - checkBloodPressureReading(); - bpModuleState = BP_MODULE_IDLE_STATE; -} + BP_MODULE_STATE_T nextState = BP_MODULE_IDLE_STATE; + BP_RESULTS_T bpResults; + if( TRUE == getBPResults( &bpResults ) ) + { + checkBloodPressureReading(); + } + return nextState; +} + /**@}*/