Index: firmware/App/Controllers/Pressures.c =================================================================== diff -u -rbeb6f17e872c1f31df1095e693b28c2661628cbe -r54085945764c46cdeea975ace15ba0f2612bd5e9 --- firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision beb6f17e872c1f31df1095e693b28c2661628cbe) +++ firmware/App/Controllers/Pressures.c (.../Pressures.c) (revision 54085945764c46cdeea975ace15ba0f2612bd5e9) @@ -21,7 +21,8 @@ #include "FPGA.h" #include "InternalADC.h" #include "OperationModes.h" -#include "SystemCommMessages.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" @@ -32,18 +33,19 @@ // ********** private definitions ********** -#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 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 PRESSURE_SENSORS_ADC_BITS 12U ///< Pressure sensors ADC bits +#define PRESSURE_SENSORS_ADC_MAX_COUNT ( pow(2, PRESSURE_SENSORS_ADC_BITS) ) ///< Pressure sensors max ADC count -#define PRESSURE_SENSORS_ADC_BITS 12U ///< Pressure sensors ADC bits -#define PRESSURE_SENSORS_ADC_MAX_COUNT ( pow(2, PRESSURE_SENSORS_ADC_BITS) ) ///< Pressure sensors max ADC count - +#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. /// Defined states for the pressures monitor state machine. typedef enum PresOccl_States @@ -72,21 +74,23 @@ static OVERRIDE_F32_T pressures[ NUM_OF_PRESSURE_SENSORS ]; ///< Measured pressure from sensors. 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 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 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 ********** static PRESSURE_STATE_T handlePressuresInitState( void ); static PRESSURE_STATE_T handlePressuresContReadState( void ); -static void checkPressures( void ); static void publishPressuresData( void ); static DATA_GET_PROTOTYPE( U32, getPublishPressuresDataInterval ); static SELF_TEST_STATUS_T handleSelfTestADCCheck( void ); -/*********************************************************************//** +/************************************************************************* * @brief * The initPressures function initializes the Pressures module. * @details @@ -109,11 +113,13 @@ } pressuresState = PRESSURE_INIT_STATE; - pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; + pressuresSelfTestState = PRESSURE_SELF_TEST_STATE_START; + inletWaterLowPressureCounter = 0; + inletWaterPressureInRangeCounter = 0; pressuresDataPublicationTimerCounter = 0; } -/*********************************************************************//** +/************************************************************************* * @brief * The execPressures function executes the pressure monitor. * @details @@ -144,7 +150,7 @@ publishPressuresData(); } -/*********************************************************************//** +/************************************************************************* * @brief * The handlePressuresInitState function handles the pressures initialize state \n * of the pressures monitor state machine. @@ -160,7 +166,7 @@ return result; } -/*********************************************************************//** +/************************************************************************* * @brief * The handlePressuresContReadState function handles the continuous read state \n * of the pressures monitor state machine. @@ -209,37 +215,21 @@ measuredPressureReadingsSum[ PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = 0; } - // check for pressure ranges - checkPressures(); - // TODO - any other checks return result; } -/*********************************************************************//** +/************************************************************************* * @brief - * The checkPressures function checks the pressure sensors are in range. - * @details - * Inputs : pressures[] - * Outputs : none - * @return none - *************************************************************************/ -static void checkPressures( void ) -{ - // TODO - RO inlet s/b 30..90 PSI when inlet valve is open (w/ persistence) -} - -/*********************************************************************//** - * @brief * The getPublishPresOcclDataInterval function gets the pressure/occlusion data \n * publication interval. * @details * Inputs : pressuresDataPublishInterval * Outputs : none * @return the current pressures data publication interval (in task intervals). *************************************************************************/ -U32 getPublishPressuresDataInterval( void ) +static U32 getPublishPressuresDataInterval( void ) { U32 result = pressuresDataPublishInterval.data; @@ -250,8 +240,40 @@ return result; } + +/************************************************************************* + * @brief + * The checkInletPressures function checks inlet water pressure value + * and triggers an alarm when pressure value is out of allowed range. + * @details + * Inputs : pressures[] + * Outputs : none + * @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 ); + } + } +} -/*********************************************************************//** +/************************************************************************* * @brief * The getMeasuredArterialPressure function gets the current arterial pressure. * @details @@ -282,7 +304,7 @@ return result; } -/*********************************************************************//** +/************************************************************************* * @brief * The publishPressuresData function publishes DG pressures data at the \n * set interval. @@ -319,7 +341,7 @@ } } -/*********************************************************************//** +/************************************************************************* * @brief * The execPressureSelfTest function executes the state machine for the \n * Pressures self test. @@ -382,13 +404,11 @@ /**@}*/ - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ - -/*********************************************************************//** +/************************************************************************* * @brief * The testSetPressuresDataPublishIntervalOverride function overrides the \n * pressure and occlusion data publish interval. @@ -414,7 +434,7 @@ return result; } -/*********************************************************************//** +/************************************************************************* * @brief * The testResetPressuresDataPublishIntervalOverride function resets the override \n * of the pressure and occlusion data publish interval. @@ -437,7 +457,7 @@ return result; } -/*********************************************************************//** +/************************************************************************* * @brief * The testSetDGPressureSensorOverride function overrides the value of the \n * specified pressure sensor with a given value. @@ -464,7 +484,7 @@ return result; } -/*********************************************************************//** +/************************************************************************* * @brief * The testResetDGPressureSensorOverride function resets the override of the \n * specified DG pressure sensor. @@ -492,4 +512,3 @@ } /**@}*/ -