Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -ra91074d04b607deabe4fbf714d40e9d191590359 -rd9b5f588d81e15ed3849222bed3362e15dbf4b0a --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision a91074d04b607deabe4fbf714d40e9d191590359) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision d9b5f588d81e15ed3849222bed3362e15dbf4b0a) @@ -19,7 +19,8 @@ #include "Messaging.h" #include "PersistentAlarm.h" #include "PressureCommon.h" -#include "PressureSensor.h" +#include "PressureSensor.h" +#include "Utilities.h" /** * @addtogroup PressureSensor @@ -28,18 +29,37 @@ // ********** private definitions ********** +#define BAR_TO_MMHG ( 750.062F ) ///< Conversion factor for converting bar to mmHg. + +#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 PRES_SENSORS_RANGE_IN_BARS ( 1.6F - 0.0F ) ///< Range (in bars) of the pressure sensors (0..1.6). + #define PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Pressure sensors read and error count timeout in milliseconds. +#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 F32 convertPressureRdg2mmHg( S16 counts ); +static F32 getPresureReadingFromFPGARegReading( U16 fpgaReg ); +static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); /*********************************************************************//** * @brief @@ -74,6 +94,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,9 +119,16 @@ *************************************************************************/ void readPressureSensors( void ) { + U16 PBA = getPBAPressure(); + U16 PBO = getPBOPressure(); + + // Update status of pressure sensors + currentPressureStatus[ PRESSURE_SENSOR_ARTERIAL ] = getPressureStatusFromFPGARegReading( PBA ); + currentPressureStatus[ PRESSURE_SENSOR_VENOUS ] = getPressureStatusFromFPGARegReading( PBO ); + // Update and convert raw pressures to mmHg - currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureReading2mmHg( getPBAPressure() ); - currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureReading2mmHg( getPBOPressure() ); + currentPressureReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureRdg2mmHg( PBA ); + currentPressureReadings[ PRESSURE_SENSOR_VENOUS ].data = convertPressureRdg2mmHg( PBO ); // Update and convert raw pressure sensor temperatures to deg C currentPresTempReadings[ PRESSURE_SENSOR_ARTERIAL ].data = convertPressureTempReading2DegC( getPBATemperature() ); @@ -117,6 +146,58 @@ /*********************************************************************//** * @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( S16 counts ) +{ + F32 rdg = getPresureReadingFromFPGARegReading( counts ); + F32 bar = ( ( rdg - PRES_SENSORS_ZERO_OFFSET ) * ( PRES_SENSORS_RANGE_IN_BARS ) / ( PRES_SENSORS_DIVISOR ) ); + F32 mmHg = bar * BAR_TO_MMHG; + + return mmHg; +} + +/*********************************************************************//** + * @brief + * The getPresureReadingFromFPGARegReading function extracts the signed + * pressure reading (in counts) from the FPGA register reading. + * @details \b Inputs: none + * @details \b Outputs: none + * @param fpgaReg the value read from the FPGA register + * @return the pressure portion of the FPGA register value, sign extended + *************************************************************************/ +static F32 getPresureReadingFromFPGARegReading( U16 fpgaReg ) +{ + U16 rdg = fpgaReg & FPGA_PRESSURE_READING_BITS_MASK; // mask off status bits + S16 ext = signExtend16( rdg, FPGA_PRESSURE_READING_BIT_COUNT - 1 ); // sign extend reading in case it's negative + + return (F32)ext; +} + +/*********************************************************************//** + * @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 @@ -133,6 +214,16 @@ 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 ) ); + + // verify status of pressure sensors + if ( currentPressureStatus[ PRESSURE_SENSOR_ARTERIAL ] != PRESSURE_NORMAL_OP ) + { + // TODO - alarm? + } + if ( currentPressureStatus[ PRESSURE_SENSOR_ARTERIAL ] != PRESSURE_NORMAL_OP ) + { + // TODO - alarm? + } } /*********************************************************************//**