Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -rf979c391268b595e44fb6747d43487e4d2294e68 -r0eb4b76d5209ff2adf583a9ab6ec8f87a5aa011b --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision f979c391268b595e44fb6747d43487e4d2294e68) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 0eb4b76d5209ff2adf583a9ab6ec8f87a5aa011b) @@ -73,8 +73,6 @@ U16 refTemperature; ///< Barometric sensor reference temperature. U16 temperatureCoeff; ///< Barometric sensor temperature coefficient. OVERRIDE_U32_T coeffsCRC; ///< Barometric sensor coefficients CRC. - U32 waitForCoeffStartTimeMS; ///< Barometric sensor wait for coefficients start time in milliseconds. - BOOL hasCRCBeenChecked; ///< Barometric sensor has CRC been checked flag. BOOL hasCRCCheckBeenRequested; ///< Barometric sensor has CRC check been requested flag. } BARO_SENSOR_CONSTS_T; @@ -94,6 +92,7 @@ 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 ); @@ -145,10 +144,10 @@ baroConvConsts.coeffsCRC.ovData = 0; baroConvConsts.coeffsCRC.ovInitData = 0; baroConvConsts.coeffsCRC.override = OVERRIDE_RESET; - baroConvConsts.waitForCoeffStartTimeMS = getMSTimerCount(); - baroConvConsts.hasCRCBeenChecked = FALSE; 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 ); @@ -255,7 +254,8 @@ *************************************************************************/ static F32 calculateBaroPressurePSI( U32 baroPresCount ) { - S32 tempDiff = calculateBaroTemperatureC( getH23Temperature() ); + 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; @@ -271,6 +271,22 @@ /*********************************************************************//** * @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 @@ -279,7 +295,7 @@ *************************************************************************/ static F32 calculateBaroTemperatureC( U32 baroTempCount ) { - S32 baroTempSensorsDiff = (S32)baroTempCount - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); + 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 ); @@ -302,31 +318,42 @@ 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 ); - // Once FPGA is ready get the barometric sensor's temperature conversion constants + // Clear the least significant byte prior to sending the data for CRC calculations + baroMfgCoeffs.baroPromCRC &= MASK_OFF_LSB; + if ( ( TRUE == hasCRCChanged ) || ( TRUE == baroConvConsts.hasCRCCheckBeenRequested ) ) { - U08 calculatedCRC = crc4( (U16*)&baroMfgCoeffs, sizeof( BARO_PRES_SENSOR_MFG_T ) ); + 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; - baroCRC = (U16)( baroCRC & MASK_OFF_MSB ) & MASK_OFF_NIBBLE_MSB; - baroConvConsts.hasCRCBeenChecked = TRUE; - baroConvConsts.hasCRCCheckBeenRequested = 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 ); - if ( calculatedCRC != baroCRC ) - { - U32 coeffsCRC = getU32OverrideValue( &baroConvConsts.coeffsCRC ); + checkPersistentAlarm( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, isBaroMFGCRCOut, (F32)calculatedCRC, (F32)coeffsStoredCRC ); - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, calculatedCRC, coeffsCRC ); + 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; } - else if ( ( TRUE == didTimeout( baroConvConsts.waitForCoeffStartTimeMS, BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ) ) && - ( FALSE == baroConvConsts.hasCRCBeenChecked ) ) - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, 0, baroCRC ); - } } /*********************************************************************//**