Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -rb88a8fd2c5fca8f055d6df1437635692388fcb0d -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision b88a8fd2c5fca8f055d6df1437635692388fcb0d) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -20,6 +20,7 @@ #include "PersistentAlarm.h" #include "PressureCommon.h" #include "PressureSensor.h" +#include "Timers.h" #include "Utilities.h" /** @@ -46,19 +47,56 @@ #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. + +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. + 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; + // ********** 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 F32 convertPressureRdg2mmHg( U16 counts ); -static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); +static F32 convertPressureRdg2mmHg( U16 counts ); +static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); +static F32 calculateBaroPressurePSI( U32 baroPresCount ); +static F32 calculateBaroTemperatureC( U32 baroTempCount ); +static void checkBaroSensorCoeffsCRC( void ); +static F32 getCalibrationAppliedPressure( U08 sensorId, F32 pressure ); /*********************************************************************//** * @brief @@ -74,29 +112,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.waitForCoeffStartTimeMS = getMSTimerCount(); + baroConvConsts.hasCRCBeenChecked = FALSE; + baroConvConsts.hasCRCCheckBeenRequested = FALSE; + // 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 ); @@ -118,26 +170,35 @@ *************************************************************************/ void readPressureSensors( void ) { - U16 h2 = getH2Pressure(); + U16 h2 = getH2Pressure(); U16 h14 = getH14Pressure(); + U16 h23 = getH23Pressure(); + checkBaroSensorCoeffsCRC(); + // Update status of pressure sensors - currentPressureStatus[ H2_PRES ] = getPressureStatusFromFPGARegReading( h2 ); + 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[ H2_PRES ].data = convertPressureRdg2mmHg( h2 ); - currentPressureReadings[ H14_PRES ].data = convertPressureRdg2mmHg( h14 ); + 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[ H2_PRES ].data = convertPressureTempReading2DegC( getH2Temperature() ); + 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[ H2_PRES ].data = (U32)getH2ReadCounter(); - lastPressureReadCounter[ H14_PRES ].data = (U32)getH14ReadCounter(); - lastPressureErrorCounter[ H2_PRES ].data = (U32)getH2ErrorCounter(); + 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 @@ -186,6 +247,111 @@ /*********************************************************************//** * @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 ) +{ + S32 tempDiff = calculateBaroTemperatureC( getH23Temperature() ); + 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 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 = (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 ); + + 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 + if ( ( TRUE == hasCRCChanged ) || ( TRUE == baroConvConsts.hasCRCCheckBeenRequested ) ) + { + U08 calculatedCRC = crc4( (U16*)&baroMfgCoeffs, sizeof( BARO_PRES_SENSOR_MFG_T ) ); + + baroConvConsts.coeffsCRC.data = baroCRC; + baroCRC = (U16)( baroCRC & MASK_OFF_MSB ) & MASK_OFF_NIBBLE_MSB; + baroConvConsts.hasCRCBeenChecked = TRUE; + baroConvConsts.hasCRCCheckBeenRequested = FALSE; + + if ( calculatedCRC != baroCRC ) + { + // TODO enable the alarm + //SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, calculatedCRC, baroCoeffs.crc ); + } + } + 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_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, 0, baroCRC ); + } +} + +/*********************************************************************//** + * @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 Index: firmware/App/Drivers/PressureSensor.h =================================================================== diff -u -r961784c895cb8f551a2623cd02dcbfe42d04b7c2 -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Drivers/PressureSensor.h (.../PressureSensor.h) (revision 961784c895cb8f551a2623cd02dcbfe42d04b7c2) +++ firmware/App/Drivers/PressureSensor.h (.../PressureSensor.h) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -24,6 +24,7 @@ * @defgroup PressureSensor PressureSensor * @brief The Pressure Sensor unit provides low-level functions for interfacing * with a MicroSensor (MPM258) pressure sensor. + * TODO add the baro sensor part number * * @addtogroup PressureSensor * @{ @@ -35,7 +36,8 @@ typedef enum PressureSensors { H2_PRES = 0, ///< Arterial blood line pressure sensor - H14_PRES, ///< Vensous blood line pressure sensor + H14_PRES, ///< Venous blood line pressure sensor + H23_PRES, ///< Barometric pressure sensor NUM_OF_PRESSURE_SENSORS ///< Number of pressure sensors } PRESSURE_SENSORS_T; Index: firmware/App/Monitors/Pressures.c =================================================================== diff -u -rfe9b77e60850fe37da225d4348f0a6a8defc28db -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision fe9b77e60850fe37da225d4348f0a6a8defc28db) +++ firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -101,6 +101,8 @@ #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. +#define BARO_MOVING_AVG_NUM_OF_SAMPLES 10 ///< Barometric pressure sensor moving average number of samples. + /// Defined states for the pressure monitor state machine. typedef enum Pressure_States { @@ -118,6 +120,15 @@ NUM_OF_PRESSURE_SELF_TEST_STATES ///< Number of pressure/occlusion self-test states. } PRESSURE_SELF_TEST_STATE_T; +/// Barometric pressure sensor moving average structure +typedef struct +{ + F32 baroRunningSumPSI; ///< Baro pressure sensor running sum in psi. + OVERRIDE_F32_T baroAvgPSI; ///< Baro pressure sensor average in psi. + F32 baroSamplesPSI[ BARO_MOVING_AVG_NUM_OF_SAMPLES ]; ///< Baro pressure sensor samples array in psi. + U32 baroSamplesNextIndex; ///< Baro pressure sensor sample next index number. +} BARO_MOVING_AVG_DATA_T; + // ********** private data ********** static PRESSURE_STATE_T pressureState; ///< Current state of pressure monitor state machine. @@ -168,6 +179,7 @@ static U32 venPressureReadingsShortIdx; ///< Index for next sample in rolling average array. static F32 venPressureReadingsShortTotal; ///< Rolling total - used to calc average. static U32 venPressureReadingsShortCount; ///< Number of samples in flow rolling average buffer. +static BARO_MOVING_AVG_DATA_T baroMovingAvg; ///< Barometric sensor moving average. static PRESSURE_SELF_TEST_STATE_T pressurePostState; ///< Pressure self test post state. //static HD_PRESSURE_SENSORS_CAL_RECORD_T pressureSensorsCalRecord; ///< Pressure sensors calibration record. @@ -182,6 +194,7 @@ static void publishPressureData( void ); static void determineArtVenPressureLimits( void ); static void filterInlinePressureReadings( F32 artPres, F32 venPres ); +static void filterBaroPressureReadings( F32 baroPresPSI ); /*********************************************************************//** * @brief @@ -258,6 +271,14 @@ venPressureReadingsShortIdx = 0; venPressureReadingsShortTotal = 0.0F; venPressureReadingsShortCount = 0; + + baroMovingAvg.baroAvgPSI.data = 0.0F; + baroMovingAvg.baroAvgPSI.ovData = 0.0F; + baroMovingAvg.baroAvgPSI.ovInitData = 0.0F; + baroMovingAvg.baroAvgPSI.override = OVERRIDE_RESET; + baroMovingAvg.baroRunningSumPSI = 0.0F; + baroMovingAvg.baroSamplesNextIndex = 0; + memset( baroMovingAvg.baroSamplesPSI, 0.0F, BARO_MOVING_AVG_NUM_OF_SAMPLES ); } /*********************************************************************//** @@ -526,11 +547,14 @@ static PRESSURE_STATE_T handlePressureContReadState( void ) { PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; - F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; - F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; + F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 fpgaBaroPresPSI = getPressure( H23_PRES ); // Filter inline pressure readings filterInlinePressureReadings( fpgaArtPres, fpgaVenPres ); + // Filter the baro pressure + filterBaroPressureReadings( fpgaBaroPresPSI ); // Get latest dialysate pressure so we can calculate TMP tmpPressure.data = getLongFilteredVenousPressure() - getDialysatePressure(); @@ -914,6 +938,18 @@ /*********************************************************************//** * @brief + * The getBaroPressurePSI function gets the averaged barometric pressure in psi. + * @details \b Inputs: baroMovingAvg.baroAvgPS + * @details \b Outputs: none + * @return the current average barometric pressure in psi. + *************************************************************************/ +F32 getBaroPressurePSI( void ) +{ + return getF32OverrideValue( &baroMovingAvg.baroAvgPSI ); +} + +/*********************************************************************//** + * @brief * The filterInlinePressureReadings function adds a new arterial and venous * pressure sample to the filters. * @details \b Inputs: none @@ -974,6 +1010,26 @@ /*********************************************************************//** * @brief + * The filterBaroPressureReadings function calculates the barometric pressure + * in psi. + * @details \b Inputs: none + * @details \b Outputs: baroMovingAvg + * @param baroPresPSI newest barometric pressure from FPGA + * @return none + *************************************************************************/ +static void filterBaroPressureReadings( F32 baroPresPSI ) +{ + F32 prevSampleToRemovePSI = baroMovingAvg.baroSamplesPSI[ baroMovingAvg.baroSamplesNextIndex ]; + U32 currentIndex = baroMovingAvg.baroSamplesNextIndex; + + baroMovingAvg.baroSamplesPSI[ currentIndex ] = baroPresPSI; + baroMovingAvg.baroRunningSumPSI = baroMovingAvg.baroRunningSumPSI + baroPresPSI - prevSampleToRemovePSI; + baroMovingAvg.baroSamplesNextIndex = INC_WRAP( currentIndex, 0, BARO_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + baroMovingAvg.baroAvgPSI.data = baroMovingAvg.baroRunningSumPSI / (F32)BARO_MOVING_AVG_NUM_OF_SAMPLES; +} + +/*********************************************************************//** + * @brief * The publishPressureData function publishes pressure data at the set * interval. * @details \b Message \b Sent: MSG_ID_TD_PRESSURE_DATA @@ -1003,6 +1059,7 @@ data.tmpPressure = getTMPPressure(); data.tmpMinLimit = -400.0F; // TODO - use windowed min/max values based on user set params when implemented data.tmpMaxLimit = 100.0F; + data.h23Pressure = getBaroPressurePSI(); broadcastData( MSG_ID_TD_PRESSURE_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( PRESSURE_DATA_T ) ); pressureDataPublicationTimerCounter = 0; Index: firmware/App/Monitors/Pressures.h =================================================================== diff -u -rf6aa1ffddb85a233371e3e7e4d7c0c0eb3e61493 -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Monitors/Pressures.h (.../Pressures.h) (revision f6aa1ffddb85a233371e3e7e4d7c0c0eb3e61493) +++ firmware/App/Monitors/Pressures.h (.../Pressures.h) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -68,6 +68,7 @@ F32 tmpPressure; ///< Latest trans-membrane pressure (mmHg) F32 tmpMinLimit; ///< Current TMP minimum pressure limit (mmHg) F32 tmpMaxLimit; ///< Current TMP maximum pressure limit (mmHg) + F32 h23Pressure; ///< Current barometric pressure (psi) } PRESSURE_DATA_T; // ********** public function prototypes ********** @@ -91,6 +92,7 @@ F32 getFilteredVenousPressure( void ); F32 getLongFilteredVenousPressure( void ); F32 getTMPPressure( void ); +F32 getBaroPressurePSI( void ); BOOL testPressuresDataPublishIntervalOverride( MESSAGE_T *message ); BOOL testTMPOverride( MESSAGE_T *message ); Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r22a8500467c47070dff55824e2ec567c007434ce -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 22a8500467c47070dff55824e2ec567c007434ce) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -150,7 +150,20 @@ S16 h4RotorHallCount; ///< Reg 344. H4 rotor count from hall sensor. U08 h6RotorStatus; ///< Reg 346. H6 rotor status. U08 reserved5; ///< - U16 h12Speed; ///< Reg 348. H12 speed (in RPM). + U16 h12Speed; ///< Reg 348. H12 speed (air pump in RPM). + U16 rotorRevsCounter; ///< Reg 350. Rotor revs counter + U16 baroManufactInfo; ///< Reg 352. Baro sensor manufacturing information. + U16 baroPresSensitivity; ///< Reg 354. Baro sensor prom coefficient 1. + U16 baroPresOffset; ///< Reg 356. Baro sensor prom coefficient 2. + U16 baroTempCoeffOfPresSense; ///< Reg 358. Baro sensor prom coefficient 3. + U16 baroTempCoeffPresOffset; ///< Reg 360. Baro sensor prom coefficient 4. + U16 baroRefTemp; ///< Reg 362. Baro sensor prom coefficient 5. + U16 baroTempCoeffOfTemp; ///< Reg 364. Baro sensor prom coefficient 6. + U16 baroPromCRC; ///< Reg 366. Baro prom CRC. + U32 baroPressure; ///< Reg 368. Baro pressure value in counts. + U32 baroTemperature; ///< Reg 372. Baro temperature value in counts. + U08 baroReadCount; ///< Reg 376. Baro read count. + U08 baroErrorCount; ///< Reg 377. Baro error count. } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -746,6 +759,81 @@ /*********************************************************************//** * @brief + * The getH23MfgCoeffs function updates the baro sensor's manufacturing + * information into the provided buffer. + * @details \b Inputs: fpgaSensorReadings.baroManufactInfo, + * fpgaSensorReadings.baroPromCoeff1, fpgaSensorReadings.baroPromCoeff2, + * fpgaSensorReadings.baroPromCoeff3, fpgaSensorReadings.baroPromCoeff4, + * fpgaSensorReadings.baroPromCoeff5, fpgaSensorReadings.baroPromCoeff6, + * fpgaSensorReadings.baroPromCRC + * @details \b Outputs: none + * @param baroMfgCoeffs The baro sensor mfg info buffer. + * @return none + *************************************************************************/ +void getH23MfgCoeffs( BARO_PRES_SENSOR_MFG_T* baroMfgCoeffs ) +{ + baroMfgCoeffs->baroManufactInfo = fpgaSensorReadings.baroManufactInfo; + baroMfgCoeffs->baroPresSensitivity = fpgaSensorReadings.baroPresSensitivity; + baroMfgCoeffs->baroPresOffset = fpgaSensorReadings.baroPresOffset; + baroMfgCoeffs->baroTempCoeffOfPresSense = fpgaSensorReadings.baroTempCoeffOfPresSense; + baroMfgCoeffs->baroTempCoeffPresOffset = fpgaSensorReadings.baroTempCoeffPresOffset; + baroMfgCoeffs->baroRefTemp = fpgaSensorReadings.baroRefTemp; + baroMfgCoeffs->baroTempCoeffOfTemp = fpgaSensorReadings.baroTempCoeffOfTemp; + baroMfgCoeffs->baroPromCRC = fpgaSensorReadings.baroPromCRC; +} + +/*********************************************************************//** + * @brief + * The getH23Pressure function reads the baro sensor pressure. + * @details \b Inputs: fpgaSensorReadings.baroPressure + * @details \b Outputs: none + * @return Latest baro sensor pressure. + *************************************************************************/ +U32 getH23Pressure( void ) +{ + return fpgaSensorReadings.baroPressure; +} + +/*********************************************************************//** + * @brief + * The getH23Temperature function reads the baro sensor temperature. + * @details \b Inputs: fpgaSensorReadings.baroTemperature + * @details \b Outputs: none + * @return Latest baro sensor temperature. + *************************************************************************/ +U32 getH23Temperature( void ) +{ + return fpgaSensorReadings.baroTemperature; +} + +/*********************************************************************//** + * @brief + * The getH23ReadCounter function gets the latest baro pressure + * sensor read counter. + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return latest baro pressure sensor read counter + *************************************************************************/ +U08 getH23ReadCounter( void ) +{ + return fpgaSensorReadings.baroReadCount; +} + +/*********************************************************************//** + * @brief + * The getH23ErrorCounter function gets the latest baro pressure + * sensor error counter. + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return latest baro pressure sensor error counter + *************************************************************************/ +U08 getH23ErrorCounter( void ) +{ + return fpgaSensorReadings.baroErrorCount; +} + +/*********************************************************************//** + * @brief * The getFPGABackupAlarmAudioCurrent function gets the latest piezo alarm * audio current reading. * @details \b Inputs: fpgaSensorReadings Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -r22a8500467c47070dff55824e2ec567c007434ce -r87d45fcfcfdfa6d7638834181fd07bed56a3af67 --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 22a8500467c47070dff55824e2ec567c007434ce) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 87d45fcfcfdfa6d7638834181fd07bed56a3af67) @@ -51,6 +51,19 @@ #define SYRINGE_PUMP_CONTROL_FORWARD_DIR 0x00 ///< Syringe pump control register bit mask for forward direction. #define SYRINGE_PUMP_CONTROL_32TH_STEP 0x03 ///< Syringe pump control register bits for 1/32 micro-stepping mode. +/// Baro sensor manufacturing coefficients +typedef struct +{ + U16 baroManufactInfo; ///< Reg 352. Baro sensor manufacturing information. + U16 baroPresSensitivity; ///< Reg 354. Baro sensor prom coefficient 1. + U16 baroPresOffset; ///< Reg 356. Baro sensor prom coefficient 2. + U16 baroTempCoeffOfPresSense; ///< Reg 358. Baro sensor prom coefficient 3. + U16 baroTempCoeffPresOffset; ///< Reg 360. Baro sensor prom coefficient 4. + U16 baroRefTemp; ///< Reg 362. Baro sensor prom coefficient 5. + U16 baroTempCoeffOfTemp; ///< Reg 364. Baro sensor prom coefficient 6. + U16 baroPromCRC; ///< Reg 366. Baro prom CRC. +} BARO_PRES_SENSOR_MFG_T; + // ********** public function prototypes ********** void initFpgaTD( void ); @@ -94,6 +107,12 @@ U08 getH14ReadCounter( void ); U08 getH14ErrorCounter( void ); +void getH23MfgCoeffs( BARO_PRES_SENSOR_MFG_T* baroMfgCoeffs ); +U32 getH23Pressure( void ); +U32 getH23Temperature( void ); +U08 getH23ReadCounter( void ); +U08 getH23ErrorCounter( void ); + F32 getFPGABackupAlarmAudioCurrent( void ); void getFPGAAirTrapLevels( BOOL *airAtLower, BOOL *airAtUpper );