Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -ra91074d04b607deabe4fbf714d40e9d191590359 -r961784c895cb8f551a2623cd02dcbfe42d04b7c2 --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision a91074d04b607deabe4fbf714d40e9d191590359) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 961784c895cb8f551a2623cd02dcbfe42d04b7c2) @@ -18,28 +18,47 @@ #include "FpgaTD.h" #include "Messaging.h" #include "PersistentAlarm.h" -#include "PressureCommon.h" -#include "PressureSensor.h" - +#include "PressureCommon.h" +#include "PressureSensor.h" +#include "Utilities.h" + /** * @addtogroup PressureSensor * @{ */ -// ********** private definitions ********** - +// ********** private definitions ********** + +#define PRES_SENSORS_ZERO_OFFSET ( 1638.0F ) ///< Zero offset for pressure sensor readings. +#define PRES_SENSORS_DIVISOR ( 14745.0F - PRES_SENSORS_ZERO_OFFSET ) ///< Divisor for pressure sensor conversion from counts to bars. +#define PRESSURE_MIN_PSI ( -30.0F ) ///< Minimum of scale for pressure sensor reading (in PSI). +#define PRESSURE_MAX_PSI ( 30.0F ) ///< Maximum of scale for pressure sensor reading (in PSI). +#define PSI_TO_MMHG ( 51.7149F ) ///< Conversion factor for converting PSI to mmHg. + #define PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Pressure sensors read and error count timeout in milliseconds. -// ********** private data ********** - +#define FPGA_PRESSURE_READING_BIT_COUNT 14 ///< Number of bits in a pressure reading from the FPGA. +#define FPGA_PRESSURE_STATUS_BITS_MASK 0xC000 ///< Bit mask for status bits of pressure reading register. +#define FPGA_PRESSURE_READING_BITS_MASK 0x3FFF ///< Bit mask for pressure bits of pressure reading register. + +#define PRESSURE_NORMAL_OP 0 ///< Pressure status bits indicate normal operation. +#define PRESSURE_CMD_MODE 1 ///< Pressure status bits indicate sensor in command mode. +#define PRESSURE_STALE_DATA 2 ///< Pressure status bits indicate data is stale (no new data since last fpga read). +#define PRESSURE_DIAG_CONDITION 3 ///< Pressure status bits diagnostic condition (alarm). + +// ********** 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). +static U32 currentPressureStatus[ NUM_OF_PRESSURE_SENSORS ]; ///< Current status of pressure sensors. // ********** private function prototypes ********** -static void checkPressureSensors( void ); +static void checkPressureSensors( void ); +static F32 convertPressureRdg2mmHg( U16 counts ); +static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); /*********************************************************************//** * @brief @@ -74,6 +93,8 @@ lastPressureErrorCounter[ i ].ovData = 0; lastPressureErrorCounter[ i ].ovInitData = 0; lastPressureErrorCounter[ i ].override = OVERRIDE_RESET; + + currentPressureStatus[ i ] = PRESSURE_STALE_DATA; } // Initialize the FPGA persistent alarms @@ -97,26 +118,72 @@ *************************************************************************/ void readPressureSensors( void ) { + U16 h2 = getH2Pressure(); + U16 h14 = getH14Pressure(); + + // Update status of pressure sensors + currentPressureStatus[ H2_PRES ] = getPressureStatusFromFPGARegReading( h2 ); + currentPressureStatus[ H14_PRES ] = getPressureStatusFromFPGARegReading( h14 ); + // Update and convert raw pressures to mmHg - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureReading2mmHg( getPBAPressure() ); - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureReading2mmHg( getPBOPressure() ); + currentPressureReadings[ H2_PRES ].data = convertPressureRdg2mmHg( h2 ); + currentPressureReadings[ H14_PRES ].data = convertPressureRdg2mmHg( h14 ); // Update and convert raw pressure sensor temperatures to deg C - currentPresTempReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureTempReading2DegC( getPBATemperature() ); - currentPresTempReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureTempReading2DegC( getPBOTemperature() ); + currentPresTempReadings[ H2_PRES ].data = convertPressureTempReading2DegC( getH2Temperature() ); + currentPresTempReadings[ H14_PRES ].data = convertPressureTempReading2DegC( getH14Temperature() ); // 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(); + lastPressureReadCounter[ H2_PRES ].data = (U32)getH2ReadCounter(); + lastPressureReadCounter[ H14_PRES ].data = (U32)getH14ReadCounter(); + lastPressureErrorCounter[ H2_PRES ].data = (U32)getH2ErrorCounter(); + lastPressureErrorCounter[ H14_PRES ].data = (U32)getH14ErrorCounter(); // Monitor pressure sensor health checkPressureSensors(); } /*********************************************************************//** * @brief + * The convertPressureRdg2mmHg function converts a raw pressure count from + * the FPGA and converts it to mmHg. + * @details \b Inputs: none + * @details \b Outputs: none + * @param counts the raw pressure reading in counts from the FPGA + * @return the pressure in mmHg + *************************************************************************/ +static F32 convertPressureRdg2mmHg( U16 counts ) +{ + S16 rdg = (S16)( counts & FPGA_PRESSURE_READING_BITS_MASK ); + F32 presPSI; + F32 mmHg; + + // If the arterial pressure status is normal, convert the counts to pressure in mmHg + presPSI = ( ( (F32)rdg - PRES_SENSORS_ZERO_OFFSET ) *( PRESSURE_MAX_PSI - PRESSURE_MIN_PSI ) / PRES_SENSORS_DIVISOR ) + PRESSURE_MIN_PSI; + mmHg = presPSI * PSI_TO_MMHG; + + return mmHg; +} + +/*********************************************************************//** + * @brief + * The getPressureStatusFromFPGARegReading function extracts the status + * from the FPGA register reading. + * @details \b Inputs: none + * @details \b Outputs: none + * @param fpgaReg the value read from the FPGA register + * @return the status portion of the FPGA register value + *************************************************************************/ +static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ) +{ + U16 rdg = fpgaReg & FPGA_PRESSURE_STATUS_BITS_MASK; // mask off reading bits + U32 result = rdg >> FPGA_PRESSURE_READING_BIT_COUNT; // shift status bits to lsb + + return result; +} + +/*********************************************************************//** + * @brief * The checkPressureSensors function checks the read and error counters for * each pressure sensor. * @details \b Alarm: ALARM_ID_TD_ARTERIAL_SENSOR_TIMEOUT_FAULT if the @@ -129,10 +196,20 @@ *************************************************************************/ static void checkPressureSensors( 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 ) ); + checkFPGAPersistentAlarms( FPGA_PERS_ERROR_ARTERIAL_PRESSURE_SENSOR, getPressureSensorReadCount( H2_PRES ) ); + checkFPGAPersistentAlarms( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, getPressureSensorReadCount( H14_PRES ) ); + checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_ARTERIAL_PRESSURE_SENSOR, getPressureSensorErrorCount( H2_PRES ) ); + checkFPGAPersistentErrorCountAlarm( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, getPressureSensorErrorCount( H14_PRES ) ); + + // verify status of pressure sensors + if ( currentPressureStatus[ H2_PRES ] != PRESSURE_NORMAL_OP ) + { + // TODO - alarm? + } + if ( currentPressureStatus[ H14_PRES ] != PRESSURE_NORMAL_OP ) + { + // TODO - alarm? + } } /*********************************************************************//** @@ -277,5 +354,5 @@ return result; } - + /**@}*/