Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -ra91074d04b607deabe4fbf714d40e9d191590359 -reef41b7363d82763095a1317f1757f360f0d9ec1 --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision a91074d04b607deabe4fbf714d40e9d191590359) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision eef41b7363d82763095a1317f1757f360f0d9ec1) @@ -1,45 +1,109 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file PressureSensor.c * -* @author (last) Sean -* @date (last) 22-Aug-2024 +* @author (last) Varshini Nagabooshanam +* @date (last) 04-Feb-2026 * -* @author (original) Sean +* @author (original) Sean Nash * @date (original) 22-Aug-2024 * ***************************************************************************/ #include "FpgaTD.h" #include "Messaging.h" #include "PersistentAlarm.h" -#include "PressureCommon.h" -#include "PressureSensor.h" - +#include "PressureCommon.h" +#include "PressureSensor.h" +#include "Timers.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. +#if 0 +// This is for the 15psi pressure sensors in the future +#define PRESSURE_MIN_PSI ( -15.0F ) ///< Minimum of scale for pressure sensor reading (in PSI). +#define PRESSURE_MAX_PSI ( 15.0F ) ///< Maximum of scale for pressure sensor reading (in PSI). +#else +// Current pressure sensors are 30psi range +#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). +#endif +#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). + +#define PUMP_PRESSURE_PSIA_TO_PSI_OFFSET 14.7F ///< Subtract this offset to convert PSIA to PSI. +#define ONE_BAR_TO_PSI_CONVERSION 14.5F ///< 1 bar to PSI conversion. +#define ONE_BAR_TO_MILLI_BAR 1000 ///< 1 bar to milli-bar conversion. +#define COUNTS_TO_MILLI_BAR 100 ///< Counts to milli-bar conversion. +#define BARO_SENSOR_REFERENCE_TEMP_C 2000 ///< Barometric sensor reference temperature in C. +#define BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ( 20 * MS_PER_SECOND ) ///< Barometric sensor wait for coefficients timeout in milliseconds. +#define BARO_SENSOR_MAX_CRC_VALUE_TO_OVERRIDE 10000 ///< Barometric sensor maximum allowed CRC value to override to. + +static const U32 TWO_TO_POWER_OF_6 = ( 1 << 6 ); ///< 2^6. +static const U32 TWO_TO_POWER_OF_7 = ( 1 << 7 ); ///< 2^7. +static const U32 TWO_TO_POWER_OF_8 = ( 1 << 8 ); ///< 2^8. +static const U32 TWO_TO_POWER_OF_15 = ( 1 << 15 ); ///< 2^15. +static const U32 TWO_TO_POWER_OF_16 = ( 1 << 16 ); ///< 2^16. +static const U32 TWO_TO_POWER_OF_17 = ( 1 << 17 ); ///< 2^17. +static const U32 TWO_TO_POWER_OF_21 = ( 1 << 21 ); ///< 2^21. +static const U32 TWO_TO_POWER_OF_23 = ( 1 << 23 ); ///< 2^23. + +/// Barometric sensor conversion coefficients +typedef struct +{ + U16 pressureSensitivity; ///< Barometric sensor pressure sensitivity constant. + U16 pressureOffset; ///< Barometric sensor pressure offset constant. + U16 pressureSensitivityTempCoeff; ///< Barometric sensor pressure sensitivity temperature coefficient. + U16 pressureOffsetTempCoeff; ///< Barometric sensor pressure offset temperature coefficient. + U16 refTemperature; ///< Barometric sensor reference temperature. + U16 temperatureCoeff; ///< Barometric sensor temperature coefficient. + OVERRIDE_U32_T coeffsCRC; ///< Barometric sensor coefficients CRC. + BOOL hasCRCCheckBeenRequested; ///< Barometric sensor has CRC check been requested flag. +} BARO_SENSOR_CONSTS_T; + +// ********** 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. +static BARO_SENSOR_CONSTS_T baroConvConsts; ///< Barometric sensor conversion constants. +//static DG_PRES_SENSORS_CAL_RECORD_T pressuresCalRecord; ///< Pressures calibration record. // ********** private function prototypes ********** -static void checkPressureSensors( void ); +static void checkPressureSensors( void ); +static F32 convertPressureRdg2mmHg( U16 counts ); +static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); +static F32 calculateBaroPressurePSI( U32 baroPresCount ); +static S32 calculateBaroTemperatureDiff( U32 baroTempCount ); +static F32 calculateBaroTemperatureC( U32 baroTempCount ); +static void checkBaroSensorCoeffsCRC( void ); +static F32 getCalibrationAppliedPressure( U08 sensorId, F32 pressure ); /*********************************************************************//** * @brief @@ -55,27 +119,43 @@ // 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 ].data = 0.0F; + currentPressureReadings[ i ].ovData = 0.0F; currentPressureReadings[ i ].ovInitData = 0.0F; - currentPressureReadings[ i ].override = OVERRIDE_RESET; + currentPressureReadings[ i ].override = OVERRIDE_RESET; - currentPresTempReadings[ i ].data = 0.0F; - currentPresTempReadings[ i ].ovData = 0.0F; + currentPresTempReadings[ i ].data = 0.0F; + currentPresTempReadings[ i ].ovData = 0.0F; currentPresTempReadings[ i ].ovInitData = 0.0F; - currentPresTempReadings[ i ].override = OVERRIDE_RESET; + currentPresTempReadings[ i ].override = OVERRIDE_RESET; - lastPressureReadCounter[ i ].data = 0; - lastPressureReadCounter[ i ].ovData = 0; + lastPressureReadCounter[ i ].data = 0; + lastPressureReadCounter[ i ].ovData = 0; lastPressureReadCounter[ i ].ovInitData = 0; - lastPressureReadCounter[ i ].override = OVERRIDE_RESET; + lastPressureReadCounter[ i ].override = OVERRIDE_RESET; - lastPressureErrorCounter[ i ].data = 0; - lastPressureErrorCounter[ i ].ovData = 0; + lastPressureErrorCounter[ i ].data = 0; + lastPressureErrorCounter[ i ].ovData = 0; lastPressureErrorCounter[ i ].ovInitData = 0; - lastPressureErrorCounter[ i ].override = OVERRIDE_RESET; + lastPressureErrorCounter[ i ].override = OVERRIDE_RESET; + + currentPressureStatus[ i ] = PRESSURE_STALE_DATA; } + baroConvConsts.pressureSensitivity = 0; + baroConvConsts.pressureOffset = 0; + baroConvConsts.pressureSensitivityTempCoeff = 0; + baroConvConsts.pressureOffsetTempCoeff = 0; + baroConvConsts.refTemperature = 0; + baroConvConsts.temperatureCoeff = 0; + baroConvConsts.coeffsCRC.data = 0; + baroConvConsts.coeffsCRC.ovData = 0; + baroConvConsts.coeffsCRC.ovInitData = 0; + baroConvConsts.coeffsCRC.override = OVERRIDE_RESET; + baroConvConsts.hasCRCCheckBeenRequested = FALSE; + + initPersistentAlarm( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, 0, BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ); + // 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 ); @@ -97,26 +177,229 @@ *************************************************************************/ void readPressureSensors( void ) { + U16 h2 = getH2Pressure(); + U16 h14 = getH14Pressure(); + U16 h23 = getH23Pressure(); + + checkBaroSensorCoeffsCRC(); + + // Update status of pressure sensors + currentPressureStatus[ H2_PRES ] = getPressureStatusFromFPGARegReading( h2 ); + currentPressureStatus[ H14_PRES ] = getPressureStatusFromFPGARegReading( h14 ); + currentPressureStatus[ H23_PRES ] = 0; // TODO do have status from the baro pressure sensor? + // 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 baro pressure to psi + currentPressureReadings[ H23_PRES ].data = calculateBaroPressurePSI( h23 ); // 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() ); + currentPresTempReadings[ H23_PRES ].data = calculateBaroTemperatureC( getH23Temperature() ); // 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(); + lastPressureReadCounter[ H23_PRES ].data = (U32)getH23ReadCounter(); + lastPressureErrorCounter[ H2_PRES ].data = (U32)getH2ErrorCounter(); + lastPressureErrorCounter[ H14_PRES ].data = (U32)getH14ErrorCounter(); + lastPressureErrorCounter[ H23_PRES ].data = (U32)getH23ErrorCounter(); // Monitor pressure sensor health +#ifndef TEST_NO_PRESSURE_CHECKS checkPressureSensors(); +#endif } /*********************************************************************//** * @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 minPsi; + F32 maxPsi; + + if ( getTestConfigStatus( TEST_CONFIG_ENABLE_BETA_1_HW ) == TRUE ) + { + // Beta 1 Hardware: 30 PSI + minPsi = -30.0F; + maxPsi = 30.0F; + } + else + { + // Beta 1.9 Hardware: 15 PSI + minPsi = -15.0F; + maxPsi = 15.0F; + } + + presPSI = ( ( (F32)rdg - PRES_SENSORS_ZERO_OFFSET ) * ( maxPsi - minPsi ) / PRES_SENSORS_DIVISOR ) + minPsi; + + return ( presPSI * PSI_TO_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 calculateBaroPressurePSI function calculates the barometric pressure in psi. + * @details Inputs: measuredPressureReadingsSum + * @details Outputs: none + * @param baroPresCount barometric pressure sensor ADC count + * @return barometric pressure in psi + *************************************************************************/ +static F32 calculateBaroPressurePSI( U32 baroPresCount ) +{ + U32 h23Temperature = getH23Temperature(); + S32 tempDiff = calculateBaroTemperatureDiff( h23Temperature ); + S64 tempOffset = ( baroConvConsts.pressureOffsetTempCoeff * tempDiff ) / TWO_TO_POWER_OF_6; + S64 presOffset = baroConvConsts.pressureOffset * TWO_TO_POWER_OF_17; + S64 offset = presOffset + tempOffset; + S64 tempSensitivity = ( baroConvConsts.pressureSensitivityTempCoeff * tempDiff ) / TWO_TO_POWER_OF_7; + S64 presSensitivity = baroConvConsts.pressureSensitivity * TWO_TO_POWER_OF_16; + S64 sensitivity = tempSensitivity + presSensitivity; + S32 pres = (S32)( ( ( baroPresCount * sensitivity ) / TWO_TO_POWER_OF_21 ) - offset ) / TWO_TO_POWER_OF_15; + F32 presPSI = ( (F32)pres / (F32)( COUNTS_TO_MILLI_BAR * ONE_BAR_TO_MILLI_BAR ) ) * ONE_BAR_TO_PSI_CONVERSION; + F32 presPSIWithCal = getCalibrationAppliedPressure( H23_PRES, presPSI ); + + return presPSIWithCal; +} + +/*********************************************************************//** + * @brief + * The calculateBaroTemperatureDiff function calculates the barometric temperature + * difference that is used in calculating the baro pressure and the temperature. + * @details Inputs: baroConvConsts + * @details Outputs: none + * @param baroTempCount barometric temperature sensor ADC count + * @return barometric temperature sensor diff + *************************************************************************/ +static S32 calculateBaroTemperatureDiff( U32 baroTempCount ) +{ + S32 baroTempSensorsDiff = (S32)baroTempCount - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); + + return baroTempSensorsDiff; +} + +/*********************************************************************//** + * @brief + * The calculateBaroPressurePSI function calculates the barometric pressure in psi. + * @details Inputs: measuredPressureReadingsSum + * @details Outputs: none + * @param baroPresCount barometric pressure sensor ADC count + * @return barometric pressure in psi + *************************************************************************/ +static F32 calculateBaroTemperatureC( U32 baroTempCount ) +{ + S32 baroTempSensorsDiff = calculateBaroTemperatureDiff( baroTempCount ); //(S32)baroTempCount - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); + S64 differenceTimesCoefficient = (S64)baroTempSensorsDiff * (S64)baroConvConsts.temperatureCoeff; + S64 baroSnsrTemperature = BARO_SENSOR_REFERENCE_TEMP_C + ( differenceTimesCoefficient / TWO_TO_POWER_OF_23 ); + F32 temperatureC = (F32)( baroSnsrTemperature / 100.0F ); + + return temperatureC; +} + +/*********************************************************************//** + * @brief + * The checkBaroSensorCoeffsCRC function gets all the barometric sensor coefficients + * and calls crc4 function to calculate the CRC of the coefficients and compares + * them to the provided CRC by the manufacturer. + * @details Inputs: baroConvConsts + * @details Outputs: baroConvConsts + * @return none + *************************************************************************/ +static void checkBaroSensorCoeffsCRC( void ) +{ + BARO_PRES_SENSOR_MFG_T baroMfgCoeffs; + + getH23MfgCoeffs( &baroMfgCoeffs ); + + baroConvConsts.pressureSensitivity = baroMfgCoeffs.baroPresSensitivity; + baroConvConsts.pressureOffset = baroMfgCoeffs.baroPresOffset; + baroConvConsts.pressureSensitivityTempCoeff = baroMfgCoeffs.baroTempCoeffOfPresSense; + baroConvConsts.pressureOffsetTempCoeff = baroMfgCoeffs.baroTempCoeffPresOffset; + baroConvConsts.refTemperature = baroMfgCoeffs.baroRefTemp; + baroConvConsts.temperatureCoeff = baroMfgCoeffs.baroTempCoeffOfTemp; + + U32 baroCRC = (U32)baroMfgCoeffs.baroPromCRC; + BOOL hasCRCChanged = ( baroCRC != getU32OverrideValue( &baroConvConsts.coeffsCRC ) ? TRUE : FALSE ); + + // Clear the least significant byte prior to sending the data for CRC calculations + baroMfgCoeffs.baroPromCRC &= MASK_OFF_LSB; + + if ( ( TRUE == hasCRCChanged ) || ( TRUE == baroConvConsts.hasCRCCheckBeenRequested ) ) + { + U32 coeffsStoredCRC = getU32OverrideValue( &baroConvConsts.coeffsCRC ); + // CRC calculations based on: https://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=AN520_C-code_example_for_MS56xx&DocType=Specification+Or+Standard&DocLang=English&DocFormat=pdf&PartCntxt=CAT-BLPS0003 + U08 calculatedCRC = crc4( (U16*)&baroMfgCoeffs, sizeof( BARO_PRES_SENSOR_MFG_T ) ); + BOOL isBaroMFGCRCOut = FALSE; + + baroConvConsts.coeffsCRC.data = baroCRC; + // The CRC is only a nibble (4 bits) so clear the MSB and then the nibble MSB prior to comparing the calculated and the MFG CRCs. + baroCRC &= MASK_OFF_MSB; + baroCRC &= MASK_OFF_NIBBLE_MSB; + isBaroMFGCRCOut = ( calculatedCRC != baroCRC ? TRUE : FALSE ); + + checkPersistentAlarm( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, isBaroMFGCRCOut, (F32)calculatedCRC, (F32)coeffsStoredCRC ); + + if ( ( TRUE == baroConvConsts.hasCRCCheckBeenRequested ) && ( TRUE == isBaroMFGCRCOut ) ) + { + // If the CRC check is requested prior to starting a meeting and the CRC is out, do not wait for the persistent and alarm it directly + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, calculatedCRC, coeffsStoredCRC ); + } + + baroConvConsts.hasCRCCheckBeenRequested = FALSE; + } +} + +/*********************************************************************//** + * @brief + * The getCalibrationAppliedPressure function applies the calibration values + * to the provided pressure and returns the values. + * @details Inputs: pressuresCalRecord + * @details Outputs: none + * @param sensorId the ID of the pressure sensor + * @param pressure the pressure before applying calibration to it + * @return calibration applied pressure + *************************************************************************/ +static F32 getCalibrationAppliedPressure( U08 sensorId, F32 pressure ) +{ + // TODO placeholder for later + //F32 calPressure = pow( pressure, 4 ) * pressuresCalRecord.pressureSensors[ (PRESSURE_SENSORS_T)sensorId ].fourthOrderCoeff + + // pow( pressure, 3 ) * pressuresCalRecord.pressureSensors[ (PRESSURE_SENSORS_T)sensorId ].thirdOrderCoeff + + // pow( pressure, 2 ) * pressuresCalRecord.pressureSensors[ (PRESSURE_SENSORS_T)sensorId ].secondOrderCoeff + + // pressure * pressuresCalRecord.pressureSensors[ (PRESSURE_SENSORS_T)sensorId ].gain + + // pressuresCalRecord.pressureSensors[ (PRESSURE_SENSORS_T)sensorId ].offset; + //return calPressure; + return pressure; +} + +/*********************************************************************//** + * @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 +412,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? + } } /*********************************************************************//** @@ -151,11 +444,7 @@ if ( sensor < NUM_OF_PRESSURE_SENSORS ) { - result = currentPressureReadings[ sensor ].data; - if ( OVERRIDE_KEY == currentPressureReadings[ sensor ].override ) - { - result = currentPressureReadings[ sensor ].ovData; - } + result = getF32OverrideValue( ¤tPressureReadings[ sensor ] ); } else { @@ -181,11 +470,7 @@ if ( sensor < NUM_OF_PRESSURE_SENSORS ) { - result = currentPresTempReadings[ sensor ].data; - if ( OVERRIDE_KEY == currentPresTempReadings[ sensor ].override ) - { - result = currentPresTempReadings[ sensor ].ovData; - } + result = getF32OverrideValue( ¤tPresTempReadings[ sensor ] ); } else { @@ -211,11 +496,7 @@ if ( sensor < NUM_OF_PRESSURE_SENSORS ) { - result = lastPressureReadCounter[ sensor ].data; - if ( OVERRIDE_KEY == lastPressureReadCounter[ sensor ].override ) - { - result = lastPressureReadCounter[ sensor ].ovData; - } + result = getU32OverrideValue( &lastPressureReadCounter[ sensor ] ); } else { @@ -241,11 +522,7 @@ if ( sensor < NUM_OF_PRESSURE_SENSORS ) { - result = lastPressureErrorCounter[ sensor ].data; - if ( OVERRIDE_KEY == lastPressureErrorCounter[ sensor ].override ) - { - result = lastPressureErrorCounter[ sensor ].ovData; - } + result = getU32OverrideValue ( &lastPressureErrorCounter[ sensor ] ); } else { @@ -263,12 +540,29 @@ /*********************************************************************//** * @brief + * The testBaroPressureMFGCRCOverride function overrides the barometric pressure + * sensor's manufacturing CRC. + * @details \b \b Inputs: none + * @details \b \b Outputs: baroConvConsts.coeffsCRC + * @param message Override message from Dialin which includes the barometric + * pressure sensor manufacturing CRC override. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testBaroPressureMFGCRCOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &baroConvConsts.coeffsCRC, 0, BARO_SENSOR_MAX_CRC_VALUE_TO_OVERRIDE ); + + return result; +} + +/*********************************************************************//** + * @brief * The testPressureSensorOverride function overrides the pressure reading * for a given pressure sensor. * @details \b Inputs: none * @details \b Outputs: currentPressureReadings[] * @param message Override message from Dialin which includes an ID of - * the sensor to override and the state to override the sensor to. + * the sensor to override and the value to override the sensor to. * @return TRUE if override request is successful, FALSE if not *************************************************************************/ BOOL testPressureSensorOverride( MESSAGE_T *message ) @@ -277,5 +571,5 @@ return result; } - + /**@}*/