Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -rdb56d5a680ef1137cbeaad239e558f04e0be5b8d -r380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7 --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision db56d5a680ef1137cbeaad239e558f04e0be5b8d) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 380b0afc95467d0861ff3aa2cdcde5d5d7ac85e7) @@ -16,6 +16,7 @@ ***************************************************************************/ #include "FpgaTD.h" +#include "PersistentAlarm.h" #include "PressureCommon.h" #include "PressureSensor.h" @@ -26,11 +27,14 @@ // ********** private definitions ********** +#define PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Pressure sensors read and error count timeout in milliseconds. // ********** private data ********** static OVERRIDE_F32_T currentPressureReadings[ NUM_OF_PRESSURE_SENSORS ]; ///< Current pressure sensor pressure readings (overrideable). static OVERRIDE_F32_T currentPresTempReadings[ NUM_OF_PRESSURE_SENSORS ]; ///< Current pressure sensor temperature readings (overrideable). +static OVERRIDE_U32_T lastPressureReadCounter[ NUM_OF_PRESSURE_SENSORS ]; ///< Last pressure sensor read count (Overrideable). +static OVERRIDE_U32_T lastPressureErrorCounter[ NUM_OF_PRESSURE_SENSORS ]; ///< Last pressure sensor error count (Overrideable). // ********** private function prototypes ********** @@ -45,21 +49,45 @@ *************************************************************************/ void initPressureSensor( void ) { - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].data = 0; - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].ovData = 0; - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].ovInitData = 0; - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].override = OVERRIDE_RESET; + U32 i; - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].data = 0; - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].ovData = 0; - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].ovInitData = 0; - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].override = OVERRIDE_RESET; + // Initialize override structures for each pressure sensor + for ( i = 0; i < (U32)NUM_OF_PRESSURE_SENSORS; i++ ) + { + currentPressureReadings[ i ].data = 0.0F; + currentPressureReadings[ i ].ovData = 0.0F; + currentPressureReadings[ i ].ovInitData = 0.0F; + currentPressureReadings[ i ].override = OVERRIDE_RESET; + + currentPresTempReadings[ i ].data = 0.0F; + currentPresTempReadings[ i ].ovData = 0.0F; + currentPresTempReadings[ i ].ovInitData = 0.0F; + currentPresTempReadings[ i ].override = OVERRIDE_RESET; + + lastPressureReadCounter[ i ].data = 0; + lastPressureReadCounter[ i ].ovData = 0; + lastPressureReadCounter[ i ].ovInitData = 0; + lastPressureReadCounter[ i ].override = OVERRIDE_RESET; + + lastPressureErrorCounter[ i ].data = 0; + lastPressureErrorCounter[ i ].ovData = 0; + lastPressureErrorCounter[ i ].ovInitData = 0; + lastPressureErrorCounter[ i ].override = OVERRIDE_RESET; + } + + // Initialize the FPGA persistent alarms + initFPGAPersistentAlarm( FPGA_PERS_ERROR_ARTERIAL_PRESSURE_SENSOR, ALARM_ID_TD_ARTERIAL_SENSOR_TIMEOUT_FAULT, + PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS, PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ); + initFPGAPersistentAlarm( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, ALARM_ID_TD_VENOUS_SENSOR_TIMEOUT_FAULT, + PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS, PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ); } /*********************************************************************//** * @brief * The readPressureSensors function gets the current pressure reading - * for a all pressure sensors from the FPGA. + * for a all pressure sensors from the FPGA and also reads the freshness + * and error counters to verify that the pressure sensors are being read + * by the FPGA without issue. * @note This function should be called periodically to maintain fresh * sensor readings for all pressure sensors. * @details \b Inputs: FPGA @@ -68,23 +96,42 @@ *************************************************************************/ void readPressureSensors( void ) { - // Convert raw pressures to mmHg + // Update and convert raw pressures to mmHg currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureReading2mmHg( getPBAPressure() );; currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureReading2mmHg( getPBOPressure() ); - // Convert raw pressure sensor temperatures to deg C + // Update and convert raw pressure sensor temperatures to deg C currentPresTempReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureTempReading2DegC( getPBATemperature() ); currentPresTempReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureTempReading2DegC( getPBOTemperature() ); + // Update read and error counters for each pressure sensor + lastPressureReadCounter[ PRESSURE_SENSOR_ARTERIAL ].data = (U32)getPBAReadCounter(); + lastPressureReadCounter[ PRESSURE_SENSOR_VENOUS ].data = (U32)getPBOReadCounter(); + lastPressureErrorCounter[ PRESSURE_SENSOR_ARTERIAL ].data = (U32)getPBAErrorCounter(); + lastPressureErrorCounter[ PRESSURE_SENSOR_VENOUS ].data = (U32)getPBAErrorCounter(); + // Monitor pressure sensor health checkPressureSensors(); } -// TODO a function that gets and checks read and error counters for both pressure sensors +/*********************************************************************//** + * @brief + * The getPressure function gets the current pressure (in mmHg) for a given + * pressure sensor. + * @details \b Alarm: ALARM_ID_TD_ARTERIAL_SENSOR_TIMEOUT_FAULT if the + * arterial pressure sensor is not able to be read. + * @details \b Alarm: ALARM_ID_TD_VENOUS_SENSOR_TIMEOUT_FAULT if the + * venous pressure sensor is not able to be read. + * @details \b Inputs: lastPressureReadCounter, lastPressureErrorCounter + * @details \b Outputs: none + * @return none + *************************************************************************/ static void checkPressureSensors( void ) { - //U08 getPBAReadCounter( void ); - //U08 getPBAErrorCounter( void ); + checkFPGAPersistentAlarms( FPGA_PERS_ERROR_ARTERIAL_PRESSURE_SENSOR, getPressureSensorReadCount( PRESSURE_SENSOR_ARTERIAL ) ); + checkFPGAPersistentAlarms( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, getPressureSensorReadCount( PRESSURE_SENSOR_VENOUS ) ); + checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_ARTERIAL_PRESSURE_SENSOR, getPressureSensorErrorCount( PRESSURE_SENSOR_ARTERIAL ) ); + checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, getPressureSensorErrorCount( PRESSURE_SENSOR_VENOUS ) ); } /*********************************************************************//** @@ -145,6 +192,66 @@ } return result; -} +} + +/*********************************************************************//** + * @brief + * The getPressureSensorReadCount function gets the current pressure sensor + * read count for a given pressure sensor. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: lastPressureReadCounter + * @details \b Outputs: none + * @param sensor ID of pressure sensor to get read count for. + * @return The current pressure sensor read count of a given pressure sensor. + *************************************************************************/ +U32 getPressureSensorReadCount( PRESSURE_SENSORS_T sensor ) +{ + U08 result = 0; + + if ( sensor < NUM_OF_PRESSURE_SENSORS ) + { + result = lastPressureReadCounter[ sensor ].data; + if ( OVERRIDE_KEY == lastPressureReadCounter[ sensor ].override ) + { + result = lastPressureReadCounter[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_PRESSURE_SENSOR_INVALID_SENSOR3, sensor ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getPressureSensorErrorCount function gets the current pressure sensor + * error count for a given pressure sensor. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: lastPressureErrorCounter + * @details \b Outputs: none + * @param sensor ID of pressure sensor to get error count for. + * @return The current pressure sensor error count of a given pressure sensor. + *************************************************************************/ +U32 getPressureSensorErrorCount( PRESSURE_SENSORS_T sensor ) +{ + U08 result = 0; + + if ( sensor < NUM_OF_PRESSURE_SENSORS ) + { + result = lastPressureErrorCounter[ sensor ].data; + if ( OVERRIDE_KEY == lastPressureErrorCounter[ sensor ].override ) + { + result = lastPressureErrorCounter[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_PRESSURE_SENSOR_INVALID_SENSOR4, sensor ) + } + + return result; +} /**@}*/