Index: firmware/App/Controllers/BPModule.c =================================================================== diff -u -r2e3f8b77a9ffcf6e19152c0475d33def40d93fb1 -r5a601a06c2423c4379a618608974159366b10553 --- firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 2e3f8b77a9ffcf6e19152c0475d33def40d93fb1) +++ firmware/App/Controllers/BPModule.c (.../BPModule.c) (revision 5a601a06c2423c4379a618608974159366b10553) @@ -16,6 +16,7 @@ ***************************************************************************/ #include "AlarmDefs.h" +#include "AlarmMgmtTD.h" #include "BPDriver.h" #include "BPModule.h" #include "FpgaTD.h" @@ -39,18 +40,28 @@ BP_MODULE_IDLE_STATE = 0, ///< Blood Pressure idle state. BP_MODULE_MEASURE_STATE, ///< Blood pressure measurement state BP_MODULE_CHECK_STATE, ///< Blood pressure validation state - NUM_OF_BP_MODULE_STATES ///< Number of blood pressure states. + NUM_OF_BP_MODULE_STATES ///< Number of blood pressure module states. } BP_MODULE_STATE_T; // ********** 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 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. // ********** private function prototypes ********** +static void clearBPAlarmFlags( void ); static void checkBloodPressureReading( void ); +static void handleBPModuleIdleState( void ); +static void handleBPModuleMeasureState( void ); +static void handleBPModuleCheckState( void ); /*********************************************************************//** * @brief @@ -62,52 +73,61 @@ void initBPModule( void ) { initBPDriver(); - bpModuleState = BP_MODULE_IDLE_STATE; + bpModuleState = BP_MODULE_IDLE_STATE; + clearBPAlarmFlags(); } /*********************************************************************//** -* @brief -* The execBPModule function executes the blood pressure module state -* machine. -* @details \b Inputs: bpModuleState -* @details \b Outputs: bpModuleState, bpModuleResults -* @return none -***************************************************************************/ + * @brief + * The clearBPAlarmFlags function clears all blood pressure alarm + * detection flags. + * @details \b Inputs: none + * @details \b Outputs: BP alarm detection flags + * @return none + ***************************************************************************/ +static void clearBPAlarmFlags( 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 + * @return none + ***************************************************************************/ void execBPModule( void ) { switch ( bpModuleState ) { case BP_MODULE_IDLE_STATE: { + handleBPModuleIdleState(); break; } case BP_MODULE_MEASURE_STATE: { - execBPDriver(); - - if ( TRUE == isBPMeasurementReady() ) - { - getBPResults( &bpModuleResults ); - bpModuleState = BP_MODULE_CHECK_STATE; - } - else if ( TRUE == hasBPDriverError() ) - { - activateAlarm( ALARM_ID_TD_BP_MODULE_ERROR ); - bpModuleState = BP_MODULE_IDLE_STATE; - } + handleBPModuleMeasureState(); break; } case BP_MODULE_CHECK_STATE: { - checkBloodPressureReading(); - bpModuleState = BP_MODULE_IDLE_STATE; + handleBPModuleCheckState(); break; } default: { + activateAlarm( ALARM_ID_TD_SOFTWARE_FAULT ); bpModuleState = BP_MODULE_IDLE_STATE; break; } @@ -157,44 +177,185 @@ } /*********************************************************************//** -* @brief -* The checkBloodPressureReading function validates blood pressure measurement -* results against configured limits. -* @details \b Inputs: bpModuleResults -* @details \b Outputs: BP alarm -* @return none -***************************************************************************/ + * @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 + * @return none + ***************************************************************************/ static void checkBloodPressureReading( void ) { + clearBPAlarmFlags(); + if ( bpModuleResults.systolic <= BP_SYSTOLIC_LOW_LIMIT ) { - activateAlarm( ALARM_ID_TD_BP_SYSTOLIC_LOW ); + 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 { 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 ) { + bpHeartRateLowDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_HEART_RATE_LOW ); } if ( bpModuleResults.heartRate >= BP_HEART_RATE_HIGH_LIMIT ) { + bpHeartRateHighDetected = TRUE; activateAlarm( ALARM_ID_TD_BP_HEART_RATE_HIGH ); } } +/*********************************************************************//** + * @brief + * The handleBPModuleIdleState function executes the BP module idle + * state handling. + * @details \b Inputs: none + * @details \b Outputs: none + * @return none + ***************************************************************************/ +static void handleBPModuleIdleState( void ) +{ + // TODO +} + +/*********************************************************************//** + * @brief + * The handleBPModuleMeasureState function executes the BP module + * measurement state handling. + * @details \b Inputs: BP driver state/results + * @details \b Outputs: bpModuleState + * @return none + ***************************************************************************/ +static void handleBPModuleMeasureState( void ) +{ + execBPDriver(); + + if ( TRUE == isBPMeasurementReady() ) + { + getBPResults( &bpModuleResults ); + bpModuleState = BP_MODULE_CHECK_STATE; + } + else if ( TRUE == hasBPDriverError() ) + { + bpModuleErrorDetected = TRUE; + bpModuleState = BP_MODULE_IDLE_STATE; + } +} + +/*********************************************************************//** + * @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 ) +{ + checkBloodPressureReading(); + bpModuleState = BP_MODULE_IDLE_STATE; +} + + /**@}*/ Index: firmware/App/Controllers/BPModule.h =================================================================== diff -u -r2e3f8b77a9ffcf6e19152c0475d33def40d93fb1 -r5a601a06c2423c4379a618608974159366b10553 --- firmware/App/Controllers/BPModule.h (.../BPModule.h) (revision 2e3f8b77a9ffcf6e19152c0475d33def40d93fb1) +++ firmware/App/Controllers/BPModule.h (.../BPModule.h) (revision 5a601a06c2423c4379a618608974159366b10553) @@ -38,6 +38,12 @@ void initiatePedsBPReading( void ); void abortBPReading( void ); +BOOL isBPSystolicLowDetected( void ); +BOOL isBPSystolicLowTooManyDetected( void ); +BOOL isBPSystolicHighDetected( void ); +BOOL isBPHeartRateLowDetected( void ); +BOOL isBPHeartRateHighDetected( void ); +BOOL hasBPModuleError( void ); /**@}*/ Index: firmware/App/Drivers/BPDriver.c =================================================================== diff -u -r74dd4df044948a45ba71b71269ff5b703072d310 -r5a601a06c2423c4379a618608974159366b10553 --- firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision 74dd4df044948a45ba71b71269ff5b703072d310) +++ firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision 5a601a06c2423c4379a618608974159366b10553) @@ -15,6 +15,7 @@ * ***************************************************************************/ +#include "AlarmMgmtTD.h" #include "BPDriver.h" #include "FpgaTD.h" @@ -28,6 +29,7 @@ #define BP_RESP_CODE_MASK 0x3C ///< Blood pressure response code mask. #define BP_RESP_CODE_SHIFT 2 ///< Blood pressure response code bit shift. #define BP_MODULE_ERROR_MASK 0x40 ///< Blood pressure module error mask. +#define BP_MODULE_BUSY_MASK 0x80 ///< Blood Pressure module busy mask #define BP_RESP_CODE_BPDATA 0x07 ///< Blood pressure response code indicating BP data is available. /// Blood pressure driver states. @@ -37,7 +39,7 @@ BP_DRIVER_MEASURE_STATE, ///< Measurement state. BP_DRIVER_GET_DATA_STATE, ///< Get data state. BP_DRIVER_ERROR_STATE, ///< Error state. - NUM_OF_BP_DRIVER_STATES ///< Number of driver states. + NUM_OF_BP_DRIVER_STATES ///< Number of BP driver states. } BP_DRIVER_STATE_T; // ********** private data ********** @@ -46,15 +48,22 @@ static BP_RESULTS_T bpResults; ///< Latest blood pressure measurement results. static BOOL bpMeasurementReady; ///< Blood pressure measurement ready static BOOL bpDriverError; ///< Blood pressure driver error flag. +static BOOL bpMeasurementReady; ///< Blood pressure measurement ready flag. +static BOOL requestAdultBPMeasurement; ///< Request adult BP measurement flag. +static BOOL requestPedsBPMeasurement; ///< Request pediatric BP measurement flag. +static BOOL requestAbortBPMeasurement; ///< Request abort BP measurement flag. // ********** private function prototypes ********** static U08 getBPResponseCode( void ); +static void handleBPDriverIdleState( void ); +static void handleBPDriverMeasureState( void ); +static void handleBPDriverGetDataState( void ); /*********************************************************************//** * @brief * The getBPResponseCode function returns the FPGA NIBP response code. - * @details \b Inputs: FPGA NIBP response register + * @details \b Inputs: getNIBPStatusResponse * @details \b Outputs: none * @return FPGA NIBP response code. ***************************************************************************/ @@ -72,13 +81,16 @@ ***************************************************************************/ void initBPDriver( void ) { - bpDriverState = BP_DRIVER_IDLE_STATE; + bpDriverState = BP_DRIVER_IDLE_STATE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; } /*********************************************************************//** * @brief * The execBPDriver function executes the blood pressure driver state * machine. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT * @details \b Inputs: FPGA NIBP registers * @details \b Outputs: bpDriverState, bpResults * @return none @@ -89,92 +101,146 @@ { case BP_DRIVER_IDLE_STATE: { - // TODO + handleBPDriverIdleState(); break; } case BP_DRIVER_MEASURE_STATE: { - if ( BP_RESP_CODE_BPDATA == getBPResponseCode() ) - { - bpDriverState = BP_DRIVER_GET_DATA_STATE; - } - else if ( ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) != 0 ) - { - bpDriverError = TRUE; - bpDriverState = BP_DRIVER_ERROR_STATE; - } + handleBPDriverMeasureState(); break; } case BP_DRIVER_GET_DATA_STATE: { - bpResults.systolic = getNIBPSystolicPressure(); - bpResults.diastolic = getNIBPDiastolicPressure(); - bpResults.heartRate = getNIBPHeartRate(); - bpMeasurementReady = TRUE; - bpDriverState = BP_DRIVER_IDLE_STATE; + handleBPDriverGetDataState(); break; } - case BP_DRIVER_ERROR_STATE: - { - bpDriverState = BP_DRIVER_IDLE_STATE; - break; - } - default: { + activateAlarm( ALARM_ID_TD_SOFTWARE_FAULT ); bpDriverState = BP_DRIVER_IDLE_STATE; break; } } } /*********************************************************************//** +* @brief +* The handleBPDriverIdleState function executes the BP driver idle +* state handling. +* @details \b Inputs: requestAdultBPMeasurement, requestPedsBPMeasurement, +* requestAbortBPMeasurement +* @details \b Outputs: bpDriverState +* @return none +***************************************************************************/ +static void handleBPDriverIdleState( void ) +{ + if ( TRUE == requestAdultBPMeasurement ) + { + requestAdultBPMeasurement = FALSE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; + setNIBPCommand( FPGA_NIBP_CMD_START_BP ); + bpDriverState = BP_DRIVER_MEASURE_STATE; + } + else if ( TRUE == requestPedsBPMeasurement ) + { + requestPedsBPMeasurement = FALSE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; + setNIBPCommand( FPGA_NIBP_CMD_START_PEDS_BP ); + bpDriverState = BP_DRIVER_MEASURE_STATE; + } + else if ( TRUE == requestAbortBPMeasurement ) + { + requestAbortBPMeasurement = FALSE; + setNIBPCommand( FPGA_NIBP_CMD_ABORT_BP ); + bpDriverState = BP_DRIVER_IDLE_STATE; + } +} + +/*********************************************************************//** +* @brief +* The handleBPDriverMeasureState function executes the BP driver +* measurement state handling. +* @details \b Inputs: setNIBPCommand +* @details \b Outputs: bpDriverState +* @return none +***************************************************************************/ +static void handleBPDriverMeasureState( void ) +{ + if ( BP_RESP_CODE_BPDATA == getBPResponseCode() ) + { + setNIBPCommand( FPGA_NIBP_CMD_GET_BP_DATA ); + bpDriverState = BP_DRIVER_GET_DATA_STATE; + } + + else if ( ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) != 0 ) + { + bpDriverError = TRUE; + bpDriverState = BP_DRIVER_IDLE_STATE; + } +} + +/*********************************************************************//** +* @brief +* The handleBPDriverGetDataState function executes the BP driver +* get data state handling. +* @details \b Inputs: getNIBPStatusResponse +* @details \b Outputs: bpResults +* @return none +***************************************************************************/ +static void handleBPDriverGetDataState( void ) +{ + if ( ( getNIBPStatusResponse() & BP_MODULE_BUSY_MASK ) == 0 ) + { + bpResults.systolic = getNIBPSystolicPressure(); + bpResults.diastolic = getNIBPDiastolicPressure(); + bpResults.heartRate = getNIBPHeartRate(); + bpMeasurementReady = TRUE; + bpDriverState = BP_DRIVER_IDLE_STATE; + } +} + +/*********************************************************************//** * @brief - * The startAdultBPMeasurement function initiates an adult blood pressure + * The startAdultBPMeasurement function requests an adult blood pressure * measurement. * @details \b Inputs: none - * @details \b Outputs: bpDriverState + * @details \b Outputs: requestAdultBPMeasurement * @return none ***************************************************************************/ void startAdultBPMeasurement( void ) { - setNIBPCommand( FPGA_NIBP_CMD_START_BP ); - bpMeasurementReady = FALSE; - bpDriverError = FALSE; - bpDriverState = BP_DRIVER_MEASURE_STATE; + requestAdultBPMeasurement = TRUE; } /*********************************************************************//** * @brief - * The startPedsBPMeasurement function initiates a pediatric blood pressure + * The startPedsBPMeasurement function requests a pediatric blood pressure * measurement. * @details \b Inputs: none - * @details \b Outputs: bpDriverState + * @details \b Outputs: requestPedsBPMeasurement * @return none ***************************************************************************/ void startPedsBPMeasurement( void ) { - setNIBPCommand( FPGA_NIBP_CMD_START_PEDS_BP ); - bpMeasurementReady = FALSE; - bpDriverError = FALSE; - bpDriverState = BP_DRIVER_MEASURE_STATE; + requestPedsBPMeasurement = TRUE; } /*********************************************************************//** * @brief * The abortBPMeasurement function aborts the active blood pressure * measurement. * @details \b Inputs: none - * @details \b Outputs: bpDriverState + * @details \b Outputs: requestAbortBPMeasurement * @return none ***************************************************************************/ void abortBPMeasurement( void ) { - setNIBPCommand( FPGA_NIBP_CMD_ABORT_BP ); - bpDriverState = BP_DRIVER_IDLE_STATE; + requestAbortBPMeasurement = TRUE; } /*********************************************************************//** @@ -214,7 +280,7 @@ { BOOL result = FALSE; - if ( NULL != results ) + if ( ( NULL != results ) && ( TRUE == bpMeasurementReady ) ) { *results = bpResults; result = TRUE;