Index: firmware/App/Controllers/Pressures.c =================================================================== diff -u -r44c977966ab7cfecbfbf5110e6abe4ec45ebab62 -rfeb93744f73bc0a3d58841bb02bd05c38357f35d --- firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 44c977966ab7cfecbfbf5110e6abe4ec45ebab62) +++ firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision feb93744f73bc0a3d58841bb02bd05c38357f35d) @@ -7,8 +7,8 @@ * * @file Pressures.c * -* @author (last) Sean Nash -* @date (last) 19-Aug-2020 +* @author (last) Quang Nguyen +* @date (last) 14-Sep-2020 * * @author (original) Sean * @date (original) 04-Apr-2020 @@ -18,7 +18,8 @@ #include "AlarmMgmt.h" #include "FPGA.h" #include "InternalADC.h" -#include "OperationModes.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" #include "Pressures.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -32,16 +33,16 @@ // ********** private definitions ********** -#define PUMP_PRESSURE_ZERO 777 ///< ADC counts equivalent to 0 PSI for pump in/out pressure sensors. -#define PUMP_PRESSURE_PSIA_PER_COUNT 0.06434 ///< PSIA per ADC count conversion factor for pump in/out pressure sensors. -#define PUMP_PRESSURE_PSIA_TO_PSI_OFFSET 14.7 ///< Subtract this offset to convert PSIA to PSI. +#define PUMP_PRESSURE_ZERO 777 ///< ADC counts equivalent to 0 PSI for pump in/out pressure sensors. +#define PUMP_PRESSURE_PSIA_PER_COUNT 0.06434 ///< PSIA per ADC count conversion factor for pump in/out pressure sensors. +#define PUMP_PRESSURE_PSIA_TO_PSI_OFFSET 14.7 ///< Subtract this offset to convert PSIA to PSI. -#define PRESSURE_SAMPLES_TO_AVERAGE (200 / TASK_PRIORITY_INTERVAL) ///< Averaging pressure data over the reporting interval. -#define PRESSURE_AVERAGE_MULTIPLIER (1.0 / (F32)PRESSURE_SAMPLES_TO_AVERAGE) ///< Optimization - multiplying is faster than dividing. +#define PRESSURE_SAMPLES_TO_AVERAGE ( 200 / TASK_PRIORITY_INTERVAL ) ///< Averaging pressure data over the reporting interval. +#define PRESSURE_AVERAGE_MULTIPLIER ( 1.0 / (F32)PRESSURE_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -#define MIN_INLET_WATER_PRESSURE 25 ///< Minimum water input pressure. -#define INLET_WATER_PRESSURE_PERSISTENCE_COUNT ( 5 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Persistence count for pressure out of range error. -#define PRESSURES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the pressures data is published on the CAN bus. +#define MIN_INLET_WATER_PRESSURE 25 ///< Minimum water input pressure. +#define INLET_WATER_PRESSURE_PERSISTENCE_PERIOD ( 5 * MS_PER_SECOND ) ///< Persistence period for pressure out of range error. +#define PRESSURES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the pressures data is published on the CAN bus. /// Defined states for the pressures monitor state machine. typedef enum PresOccl_States @@ -51,13 +52,13 @@ NUM_OF_PRESSURE_STATES ///< Number of pressure monitor states } PRESSURE_STATE_T; -/// Defined states for the pressures self test state machine. +/// Defined states for the pressures self-test state machine. typedef enum Pressures_Self_Test_States { - PRESSURE_SELF_TEST_STATE_START = 0, ///< Self test start state - PRESSURE_TEST_STATE_IN_PROGRESS, ///< Self test in progress state - PRESSURE_TEST_STATE_COMPLETE, ///< Self test completed state - NUM_OF_PRESSURE_SELF_TEST_STATES ///< Number of pressure self test states + PRESSURE_SELF_TEST_STATE_START = 0, ///< Self-test start state + PRESSURE_TEST_STATE_IN_PROGRESS, ///< Self-test in progress state + PRESSURE_TEST_STATE_COMPLETE, ///< Self-test completed state + NUM_OF_PRESSURE_SELF_TEST_STATES ///< Number of pressure self-test states } PRESSURE_SELF_TEST_STATE_T; // ********** private data ********** @@ -71,11 +72,9 @@ static S32 measuredPressureReadingsSum[ NUM_OF_PRESSURE_SENSORS ]; ///< Raw pressure sensor sums for averaging. static U32 pressureFilterCounter = 0; ///< Used to schedule pressure sensor filtering. -static U32 inletWaterLowPressureCounter = 0; ///< Persistence counter for inlet water low pressure. -static U32 inletWaterPressureInRangeCounter = 0; ///< Persistence counter for inlet water in range pressure. -static PRESSURE_SELF_TEST_STATE_T pressuresSelfTestState; ///< Current pressure self test state. -static SELF_TEST_STATUS_T pressuresSelfTestResult; ///< Self test result of the Pressures module. +static PRESSURE_SELF_TEST_STATE_T pressuresSelfTestState; ///< Current pressure self-test state. +static SELF_TEST_STATUS_T pressuresSelfTestResult; ///< Self-test result of the Pressures module. // ********** private function prototypes ********** @@ -89,9 +88,8 @@ /*********************************************************************//** * @brief * The initPressures function initializes the Pressures module. - * @details - * Inputs : none - * Outputs : Pressures module initialized. + * @details Inputs: none + * @details Outputs: Pressures module initialized. * @return none *************************************************************************/ void initPressures( void ) @@ -110,18 +108,20 @@ pressuresState = PRESSURE_INIT_STATE; pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; - inletWaterLowPressureCounter = 0; - inletWaterPressureInRangeCounter = 0; - pressuresDataPublicationTimerCounter = 0; + pressuresDataPublicationTimerCounter = 0; + + initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_LOW_PRESSURE, ALARM_ID_INLET_WATER_LOW_PRESSURE, + FALSE, INLET_WATER_PRESSURE_PERSISTENCE_PERIOD, INLET_WATER_PRESSURE_PERSISTENCE_PERIOD ); + initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_PRESSURE_FAULT, ALARM_ID_INLET_WATER_PRESSURE_FAULT, + FALSE, INLET_WATER_PRESSURE_PERSISTENCE_PERIOD, INLET_WATER_PRESSURE_PERSISTENCE_PERIOD ); } /*********************************************************************//** * @brief * The execPressures function executes the pressures' monitor state machine * and publish pressures' data. - * @details - * Inputs : pressuresState - * Outputs : pressuresState + * @details Inputs: pressuresState + * @details Outputs: pressuresState * @return none *************************************************************************/ void execPressures( void ) @@ -151,9 +151,8 @@ * @brief * The handlePressuresInitState function handles the pressures initialize state * of the pressures monitor state machine. - * @details - * Inputs : none - * Outputs : none + * @details Inputs: none + * @details Outputs: none * @return next state *************************************************************************/ static PRESSURE_STATE_T handlePressuresInitState( void ) @@ -167,9 +166,8 @@ * @brief * The handlePressuresContReadState function handles the continuous read state * of the pressures monitor state machine. - * @details - * Inputs : pressureFilterCounter - * Outputs : pressure sensor values updated + * @details Inputs: pressureFilterCounter + * @details Outputs: pressure sensor values updated * @return next state *************************************************************************/ static PRESSURE_STATE_T handlePressuresContReadState( void ) @@ -220,9 +218,8 @@ /*********************************************************************//** * @brief * The getPublishPressuresDataInterval function gets the pressure data publish internval. - * @details - * Inputs : pressuresDataPublishInterval - * Outputs : none + * @details Inputs: pressuresDataPublishInterval + * @details Outputs: none * @return the current pressures data publication interval (in task intervals). *************************************************************************/ static U32 getPublishPressuresDataInterval( void ) @@ -241,40 +238,41 @@ * @brief * The checkInletPressure function checks inlet water pressure value * and triggers an alarm when pressure value is out of allowed range. - * @details - * Inputs : RO pump inlet pressure sensor value - * Outputs : Triggers or clears pressure persistent alarm + * @details Inputs: RO pump inlet pressure sensor value + * @details Outputs: Triggers low pressure persistent alarm * @return none *************************************************************************/ void checkInletPressure( void ) { F32 const pressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ); - if ( pressure < MIN_INLET_WATER_PRESSURE ) - { - ++inletWaterLowPressureCounter; - inletWaterPressureInRangeCounter = 0; - if ( inletWaterLowPressureCounter > INLET_WATER_PRESSURE_PERSISTENCE_COUNT ) - { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_INLET_WATER_LOW_PRESSURE, pressure ); - } - } - else - { - ++inletWaterPressureInRangeCounter; - inletWaterLowPressureCounter = 0; - if ( inletWaterPressureInRangeCounter > INLET_WATER_PRESSURE_PERSISTENCE_COUNT ) - { - clearAlarm( ALARM_ID_INLET_WATER_LOW_PRESSURE ); - } - } + BOOL const isPressureTooLow = ( pressure < MIN_INLET_WATER_PRESSURE ); + + // TODO add the right limit values + checkPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_LOW_PRESSURE, isPressureTooLow, pressure, 0 ); } + +/*********************************************************************//** + * @brief + * The checkInletPressureFault function checks inlet water pressure value + * and triggers a machine fault when pressure value is out of allowed range. + * @details Inputs: RO pump inlet pressure sensor value + * @details Outputs: Triggers pressure fault persistent alarm + * @return none + *************************************************************************/ +void checkInletPressureFault( void ) +{ + F32 const pressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ); + BOOL const isPressureTooLow = ( pressure < MIN_INLET_WATER_PRESSURE ); + + // TODO add the right limit values + checkPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_PRESSURE_FAULT, isPressureTooLow, pressure, 0 ); +} /*********************************************************************//** * @brief * The getMeasuredArterialPressure function gets the current arterial pressure. - * @details - * Inputs : arterialPressure - * Outputs : none + * @details Inputs: arterialPressure + * @details Outputs: none * @param pressureID pressure sensor ID * @return the current arterial pressure (in mmHg). *************************************************************************/ @@ -304,9 +302,8 @@ /*********************************************************************//** * @brief * The publishPressuresData function publishes DG pressures data at a set interval. - * @details - * Inputs : pressuresDataPublicationTimerCounter - * Outputs : Pressures data are published to CAN bus + * @details Inputs: pressuresDataPublicationTimerCounter + * @details Outputs: Pressures data are published to CAN bus * @return none *************************************************************************/ static void publishPressuresData( void ) @@ -339,10 +336,9 @@ /*********************************************************************//** * @brief - * The execPressureSelfTest function executes the pressures self test's state machine. - * @details - * Inputs : pressuresSelfTestState - * Outputs : pressuresSelfTestState + * The execPressureSelfTest function executes the pressures self-test's state machine. + * @details Inputs: pressuresSelfTestState + * @details Outputs: pressuresSelfTestState * @return PressuresSelfTestResult (SELF_TEST_STATUS_T) *************************************************************************/ SELF_TEST_STATUS_T execPressureSelfTest( void ) @@ -360,7 +356,7 @@ break; case PRESSURE_TEST_STATE_COMPLETE: - // Done with self test + // Done with self-test break; default: @@ -376,9 +372,8 @@ * The handleSelfTestADCCheck function checks whether the ADC reads and * report status back. If the reads are above the maximum 12bit ADC count * or equals zero, it will throw an alarm. - * @details - * Inputs : ADC reading for RO pump inlet pressure sensor - * Outputs : Performed ADC check self test. + * @details Inputs: ADC reading for RO pump inlet pressure sensor + * @details Outputs: Performed ADC check self-test. * @return result (SELF_TEST_STATUS_T) *************************************************************************/ static SELF_TEST_STATUS_T handleSelfTestADCCheck( void ) @@ -405,9 +400,8 @@ * @brief * The testSetPressuresDataPublishIntervalOverride function overrides the * pressure data publish interval. - * @details - * Inputs : none - * Outputs : pressuresDataPublishInterval + * @details Inputs: none + * @details Outputs: pressuresDataPublishInterval * @param value value to override pressure data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -431,9 +425,8 @@ * @brief * The testResetPressuresDataPublishIntervalOverride function resets the override * of the pressure and occlusion data publish interval. - * @details - * Inputs : none - * Outputs : pressuresDataPublishInterval + * @details Inputs: none + * @details Outputs: pressuresDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetPressuresDataPublishIntervalOverride( void ) @@ -454,8 +447,8 @@ * @brief * The testSetDGPressureSensorOverride function overrides the value of the * specified pressure sensor with a given value. - * Inputs : none - * Outputs : pressures[] + * @details Inputs: none + * @details Outputs: pressures[] * @param sensor pressure sensor ID * @param value override value for pressure data * @return TRUE if override successful, FALSE if not @@ -481,9 +474,8 @@ * @brief * The testResetDGPressureSensorOverride function resets the override of the \n * specified DG pressure sensor. - * @details - * Inputs : none - * Outputs : pressures[] + * @details Inputs: none + * @details Outputs: pressures[] * @param sensor pressure sensor ID * @return TRUE if override successful, FALSE if not *************************************************************************/