Index: firmware/App/Drivers/BPDriver.c =================================================================== diff -u -r5a601a06c2423c4379a618608974159366b10553 -r3e6b89e98c3725c7afd94a3c37fe3efce3fde65f --- firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision 5a601a06c2423c4379a618608974159366b10553) +++ firmware/App/Drivers/BPDriver.c (.../BPDriver.c) (revision 3e6b89e98c3725c7afd94a3c37fe3efce3fde65f) @@ -38,7 +38,6 @@ BP_DRIVER_IDLE_STATE = 0, ///< Idle state. 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 BP driver states. } BP_DRIVER_STATE_T; @@ -47,21 +46,40 @@ static BP_DRIVER_STATE_T bpDriverState = BP_DRIVER_IDLE_STATE; ///< Current blood pressure driver state. 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. +static BOOL bpDriverError; ///< Blood pressure driver error +static BOOL requestAdultBPMeasurement; ///< Request adult BP measurement +static BOOL requestPedsBPMeasurement; ///< Request pediatric BP measurement +static BOOL requestAbortBPMeasurement; ///< Request abort BP measurement // ********** private function prototypes ********** static U08 getBPResponseCode( void ); -static void handleBPDriverIdleState( void ); -static void handleBPDriverMeasureState( void ); -static void handleBPDriverGetDataState( void ); +static BP_DRIVER_STATE_T handleBPDriverIdleState( void ); +static BP_DRIVER_STATE_T handleBPDriverMeasureState( void ); +static BP_DRIVER_STATE_T handleBPDriverGetDataState( void ); /*********************************************************************//** * @brief + * The initBPDriver function initializes the blood pressure driver. + * @details \b Inputs: none + * @details \b Outputs: BPDriver variables initialized + * @return none + ***************************************************************************/ +void initBPDriver( void ) +{ + bpDriverState = BP_DRIVER_IDLE_STATE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; + requestAdultBPMeasurement = FALSE; + requestPedsBPMeasurement = FALSE; + requestAbortBPMeasurement = FALSE; + bpResults.systolic = 0; + bpResults.diastolic = 0; + bpResults.heartRate = 0; +} + +/*********************************************************************//** + * @brief * The getBPResponseCode function returns the FPGA NIBP response code. * @details \b Inputs: getNIBPStatusResponse * @details \b Outputs: none @@ -74,24 +92,10 @@ /*********************************************************************//** * @brief - * The initBPDriver function initializes the blood pressure driver. - * @details \b Inputs: none - * @details \b Outputs: bpDriverState, bpResults, bpErrorCode - * @return none - ***************************************************************************/ -void initBPDriver( void ) -{ - 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 Inputs: bpDriverState * @details \b Outputs: bpDriverState, bpResults * @return none ***************************************************************************/ @@ -101,25 +105,25 @@ { case BP_DRIVER_IDLE_STATE: { - handleBPDriverIdleState(); + bpDriverState = handleBPDriverIdleState(); break; } case BP_DRIVER_MEASURE_STATE: { - handleBPDriverMeasureState(); + bpDriverState = handleBPDriverMeasureState(); break; } case BP_DRIVER_GET_DATA_STATE: { - handleBPDriverGetDataState(); + bpDriverState = handleBPDriverGetDataState(); break; } default: { - activateAlarm( ALARM_ID_TD_SOFTWARE_FAULT ); + 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; } @@ -132,76 +136,89 @@ * state handling. * @details \b Inputs: requestAdultBPMeasurement, requestPedsBPMeasurement, * requestAbortBPMeasurement -* @details \b Outputs: bpDriverState -* @return none +* @details \b Outputs: nextState +* @return next BP module state ***************************************************************************/ -static void handleBPDriverIdleState( void ) +static BP_DRIVER_STATE_T handleBPDriverIdleState( void ) { + BP_DRIVER_STATE_T nextState = BP_DRIVER_IDLE_STATE; + if ( TRUE == requestAdultBPMeasurement ) { requestAdultBPMeasurement = FALSE; - bpMeasurementReady = FALSE; - bpDriverError = FALSE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; setNIBPCommand( FPGA_NIBP_CMD_START_BP ); - bpDriverState = BP_DRIVER_MEASURE_STATE; + nextState = BP_DRIVER_MEASURE_STATE; } else if ( TRUE == requestPedsBPMeasurement ) { requestPedsBPMeasurement = FALSE; - bpMeasurementReady = FALSE; - bpDriverError = FALSE; + bpMeasurementReady = FALSE; + bpDriverError = FALSE; setNIBPCommand( FPGA_NIBP_CMD_START_PEDS_BP ); - bpDriverState = BP_DRIVER_MEASURE_STATE; + nextState = BP_DRIVER_MEASURE_STATE; } else if ( TRUE == requestAbortBPMeasurement ) { requestAbortBPMeasurement = FALSE; setNIBPCommand( FPGA_NIBP_CMD_ABORT_BP ); - bpDriverState = BP_DRIVER_IDLE_STATE; } + + return nextState; } /*********************************************************************//** * @brief * The handleBPDriverMeasureState function executes the BP driver * measurement state handling. -* @details \b Inputs: setNIBPCommand -* @details \b Outputs: bpDriverState -* @return none +* @details \b Inputs: getNIBPStatusResponse +* @details \b Outputs: nextState +* @return next BP driver state ***************************************************************************/ -static void handleBPDriverMeasureState( void ) +static BP_DRIVER_STATE_T handleBPDriverMeasureState( void ) { - if ( BP_RESP_CODE_BPDATA == getBPResponseCode() ) - { - setNIBPCommand( FPGA_NIBP_CMD_GET_BP_DATA ); - bpDriverState = BP_DRIVER_GET_DATA_STATE; - } + BP_DRIVER_STATE_T nextState = BP_DRIVER_MEASURE_STATE; - else if ( ( getNIBPStatusResponse() & BP_MODULE_ERROR_MASK ) != 0 ) + if ( ( getNIBPStatusResponse() & BP_MODULE_BUSY_MASK ) == 0 ) { - bpDriverError = TRUE; - bpDriverState = BP_DRIVER_IDLE_STATE; + 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 ) + { + bpDriverError = TRUE; + nextState = BP_DRIVER_IDLE_STATE; + } } + + return nextState; } /*********************************************************************//** * @brief -* The handleBPDriverGetDataState function executes the BP driver -* get data state handling. +* The handleBPDriverGetDataState function retrieves blood pressure +* measurement results. * @details \b Inputs: getNIBPStatusResponse * @details \b Outputs: bpResults -* @return none +* @return next BP driver state ***************************************************************************/ -static void handleBPDriverGetDataState( void ) +static BP_DRIVER_STATE_T 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; - } + BP_DRIVER_STATE_T nextState = BP_DRIVER_GET_DATA_STATE; + + if ( ( getNIBPStatusResponse() & BP_MODULE_BUSY_MASK ) == 0 ) + { + bpResults.systolic = getNIBPSystolicPressure(); + bpResults.diastolic = getNIBPDiastolicPressure(); + bpResults.heartRate = getNIBPHeartRate(); + bpMeasurementReady = TRUE; + nextState = BP_DRIVER_IDLE_STATE; + } + + return nextState; } /*********************************************************************//** @@ -246,7 +263,7 @@ /*********************************************************************//** * @brief * The isBPMeasurementReady function returns the blood pressure - * measurement ready state + * measurement ready status * @details \b Inputs: bpMeasurementReady * @details \b Outputs: none * @return TRUE if measurement ready, FALSE otherwise. @@ -259,7 +276,7 @@ /*********************************************************************//** * @brief * The hasBPDriverError function returns the blood pressure driver - * error state. + * error status. * @details \b Inputs: bpDriverError * @details \b Outputs: none * @return TRUE if module error exists, FALSE otherwise.