Index: firmware/App/Drivers/BPDriver.c =================================================================== diff -u -r3e6b89e98c3725c7afd94a3c37fe3efce3fde65f -ra8396c9e402372dd7c6ad9df69d5b5fb500a66bf --- firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision 3e6b89e98c3725c7afd94a3c37fe3efce3fde65f) +++ firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision a8396c9e402372dd7c6ad9df69d5b5fb500a66bf) @@ -31,7 +31,9 @@ #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. +#define BP_MODULE_BUSY_CLEAR 0 + /// Blood pressure driver states. typedef enum { @@ -104,29 +106,21 @@ switch ( bpDriverState ) { case BP_DRIVER_IDLE_STATE: - { bpDriverState = handleBPDriverIdleState(); break; - } case BP_DRIVER_MEASURE_STATE: - { bpDriverState = handleBPDriverMeasureState(); break; - } case BP_DRIVER_GET_DATA_STATE: - { bpDriverState = handleBPDriverGetDataState(); break; - } default: - { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_BP_DRIVER_STATE, bpDriverState ); bpDriverState = BP_DRIVER_IDLE_STATE; break; - } } } @@ -173,23 +167,26 @@ * The handleBPDriverMeasureState function executes the BP driver * measurement state handling. * @details \b Inputs: getNIBPStatusResponse -* @details \b Outputs: nextState +* @details \b Outputs: setNIBPCommand, bpDriverState, bpDriverError * @return next BP driver state ***************************************************************************/ static BP_DRIVER_STATE_T handleBPDriverMeasureState( void ) { BP_DRIVER_STATE_T nextState = BP_DRIVER_MEASURE_STATE; - if ( ( getNIBPStatusResponse() & BP_MODULE_BUSY_MASK ) == 0 ) + if ( BP_MODULE_BUSY_CLEAR == ( getNIBPStatusResponse() & BP_MODULE_BUSY_MASK ) ) { + // Verify BP measurement data is available if ( BP_RESP_CODE_BPDATA == getBPResponseCode() ) { setNIBPCommand( FPGA_NIBP_CMD_GET_BP_DATA ); nextState = BP_DRIVER_GET_DATA_STATE; } - else if ( ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) != 0 ) + // Check whether BP module error occurred + else if ( BP_MODULE_BUSY_CLEAR != ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) ) { bpDriverError = TRUE; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, getNIBPStatusResponse(), bpDriverState ); nextState = BP_DRIVER_IDLE_STATE; } } @@ -289,8 +286,11 @@ /*********************************************************************//** * @brief * The getBPResults function returns the latest BP measurement results. + * @note + * This function shall only be called from the GeneralTask context to + * avoid concurrent access while bpResults is being updated. * @details \b Inputs: bpResults - * @details\b Outputs: results + * @details \b Outputs: results * @return TRUE if results copied, FALSE otherwise. ***************************************************************************/ BOOL getBPResults( BP_RESULTS_T *results )