Index: firmware/App/Controllers/Temperatures.c =================================================================== diff -u -r8bd1ae47aa13a843aa8abd6321ddc050deacb4a6 -r37a9fd8f15e413db5337371a7d1a1cb65567af7c --- firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 8bd1ae47aa13a843aa8abd6321ddc050deacb4a6) +++ firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2022 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 Temperatures.c * -* @author (last) Dara Navaei -* @date (last) 14-Oct-2021 +* @author (last) Darren Cox +* @date (last) 10-Mar-2022 * * @author (original) Dara Navaei * @date (original) 01-Aug-2021 @@ -19,6 +19,7 @@ #include "FPGA.h" #include "InternalADC.h" +#include "NVDataMgmt.h" #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "Temperatures.h" @@ -45,11 +46,12 @@ #define MIN_ALLOWED_TEMPERATURE 0.0 ///< Thermistors/sensors minimum allowed temperature reading. #define MAX_ALLOWED_TEMPERATURE 80.0 ///< Thermistors/sensors maximum allowed temperature reading. #define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( 5 * MS_PER_SECOND ) ///< Thermistors/sensors maximum allowed temperature out of range period. +#define DATA_PUBLISH_COUNTER_START_COUNT 6 ///< Data publish counter start count. /// Temperatures exec states typedef enum thermistors_Exec_States { - TEMPERATURES_EXEC_STATE_START_STATE = 0, ///< Temperatures exec state start state. + TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE = 0, ///< Temperatures exec state wait for POST state. TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Temperatures exec state get ADC values state. NUM_OF_TEMPERATURES_EXEC_STATES, ///< Number of temperatures exec state. } TEMPERATURES_EXEC_STATES_T; @@ -69,6 +71,8 @@ TEMPERATURES_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperatures publish time interval override. static U32 dataPublishCounter; ///< Temperatures data publish timer counter. static U32 adcReadCounter; ///< Temperatures ADC read counter. +static HD_TEMP_SENSORS_CAL_RECORD_T temperaturesCalRecord; ///< Temperatures calibration record. +static BOOL isPOSTComplete; ///< Temperatures POST complete flag. static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. @@ -77,31 +81,35 @@ static const F32 VENOUS_PRESS_SENSOR_TEMP_CONVERSION_COEFF = 200.0 / 2047.0; ///< Venous pressure sensor temperature conversion coefficient. static const F32 VENOUS_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT = 50.0; ///< Venous pressure sensor temperature conversion constant. static const F32 ADC_BOARD_TEMP_SENSOR_CONVERSION_COEFF = 1.0 / 13584.0; ///< ADC board temperatures sensor conversion coefficient. +static const F32 ART_PRESS_SENSOR_TEMP_CONVERSION_COEFF = 200.0 / 2047.0; ///< Arterial pressure sensor temperature conversion coefficient. +static const F32 ART_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT = 50.0; ///< Arterial pressure sensor temperature conversion constant. // ********** private function prototypes ********** -static TEMPERATURES_EXEC_STATES_T handleExecStart( void ); +static TEMPERATURES_EXEC_STATES_T handleExecWaitForPOST( void ); static TEMPERATURES_EXEC_STATES_T handleExecGetADCValues( void ); static void monitorTemperatures( void ); static void convertADC2Temperature( void ); -static F32 calculateThemristorTemperature( S32 adcValue ); +static F32 calculateThemristorTemperature( S32 adcValue ); static void publishTemperaturesData( void ); -static U32 getPublishTemperaturesDataInterval( void ); +static U32 getPublishTemperaturesDataInterval( void ); /*********************************************************************//** * @brief * The initTemperatures function initializes the temperatures module. * @details Inputs: none - * @details Outputs: temperaturesExecState, dataPublishCounter, temperaturesStatus + * @details Outputs: temperaturesExecState, dataPublishCounter, temperaturesStatus, + * isPOSTComplete * @return none *************************************************************************/ void initTemperatures( void ) { U08 i; - temperaturesExecState = TEMPERATURES_EXEC_STATE_START_STATE; - dataPublishCounter = 0; + temperaturesExecState = TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE; + dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; + isPOSTComplete = FALSE; for ( i = 0; i < NUM_OF_TEMPERATURES; i++ ) { @@ -122,13 +130,22 @@ *************************************************************************/ SELF_TEST_STATUS_T execTemperaturesSelfTest( void ) { - SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - // TODO implement the calibration processing function. - // It returns a pass for now - status = SELF_TEST_STATUS_PASSED; + BOOL calStatus = getNVRecord2Driver( GET_CAL_TEMPERATURE_SESNORS, (U08*)&temperaturesCalRecord, sizeof( HD_TEMP_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_HD_TEMP_SENSORS, ALARM_ID_NO_ALARM ); + isPOSTComplete = TRUE; - return status; + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; } /*********************************************************************//** @@ -140,11 +157,18 @@ *************************************************************************/ void execTemperatures( void ) { + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + getNVRecord2Driver( GET_CAL_TEMPERATURE_SESNORS, (U08*)&temperaturesCalRecord, sizeof( HD_TEMP_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_HD_TEMP_SENSORS, ALARM_ID_NO_ALARM ); + } + // Read the sensors all the time switch ( temperaturesExecState ) { - case TEMPERATURES_EXEC_STATE_START_STATE: - temperaturesExecState = handleExecStart(); + case TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE: + temperaturesExecState = handleExecWaitForPOST(); break; case TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE: @@ -205,18 +229,18 @@ /*********************************************************************//** * @brief - * The handleExecStart function handles the start state of the exec state - * machine. + * The handleExecWaitForPOST function handles the wait for POST state of the + * exec state machine. * @details Inputs: adcReadCounter * @details Outputs: adcReadCounter * @return next state of the exec state machine *************************************************************************/ -static TEMPERATURES_EXEC_STATES_T handleExecStart( void ) +static TEMPERATURES_EXEC_STATES_T handleExecWaitForPOST( void ) { - TEMPERATURES_EXEC_STATES_T state = TEMPERATURES_EXEC_STATE_START_STATE; + TEMPERATURES_EXEC_STATES_T state = TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE; // Give a short time for FPGA to boot up and start sending the ADC reads - if ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) + if ( ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) && ( TRUE == isPOSTComplete ) ) { state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; adcReadCounter = 0; @@ -247,6 +271,13 @@ temperaturesStatus[ TEMPSENSOR_VENOUS_PRESSURE_SENSOR ].rawADCRead = getFPGAVenousPressureTemperature(); temperaturesStatus[ TEMPSENSOR_PBA_ADC_SENSOR ].rawADCRead = getFPGAPBAADCTemperature(); +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) ) +#endif + { + temperaturesStatus[ TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR ].rawADCRead = getFPGADVTArterialTemperature(); + } + // Zero the counter for the next round of reading adcReadCounter = 0; } @@ -265,19 +296,29 @@ static void monitorTemperatures( void ) { TEMPERATURES_T sensor; + BOOL isTempOutOfRange = FALSE; - F32 temperature = 0.0; - U32 lastFaultSensor = 0; - F32 faultSensorTemp = 0.0; + F32 temperature = 0.0; + U32 lastFaultSensor = 0; + F32 faultSensorTemp = 0.0; for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_TEMPERATURES; sensor++ ) { temperature = getTemperatureValue( sensor ); + if ( ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ) ) { isTempOutOfRange = TRUE; - lastFaultSensor = sensor; - faultSensorTemp = temperature; + lastFaultSensor = sensor; + faultSensorTemp = temperature; + +#ifndef _RELEASE_ + if ( ( TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR == sensor ) && + ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) != SW_CONFIG_ENABLE_VALUE ) ) + { + isTempOutOfRange = FALSE; + } +#endif } } @@ -325,11 +366,38 @@ break; case TEMPSENSOR_PBA_ADC_SENSOR: - // Temperature (C) = ((ADC - 0x800000) / 13584) - 272.5 - temperature = ( ( rawADC - ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_2 ) * ADC_BOARD_TEMP_SENSOR_CONVERSION_COEFF ) - - ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1; + +#ifndef _RELEASE_ + // If the software configuration is not enabled to read the DVT arterial pressure, set the temperature to 30 to make sure + // there is no temperature error because the sensor is not available. The old arterial sensor did not have a temperature sensor + // inside it. NOTE: this line of code should be remove later. + if ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + // Temperature (C) = ((ADC - 0x800000) / 13584) - 272.5 + temperature = ( ( rawADC - ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_2 ) * ADC_BOARD_TEMP_SENSOR_CONVERSION_COEFF ) - + ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1; + } + temperature = 30.0; // TODO PBA_ADC temperature sensor has been remove from all of the devices. Remove the feature in DEN-12224. break; + case TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR: + +#ifndef _RELEASE_ + // TODO + // If the software configuration is not enable to read the DVT arterial pressure, set the temperature to 30 to make sure + // there is no temperature error because the sensor is not available. The old arterial sensor did not have a temperature sensor + // inside it. NOTE: this line of code should be remove later. + temperature = 30.0; + + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) ) +#endif + { + // Temperature (C) = ((ADC / 2047) * 200) - 50 + temperature = ( rawADC * ART_PRESS_SENSOR_TEMP_CONVERSION_COEFF ) - ART_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT; + } + break; + default: // Wrong sensor was called, raise an alarm SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_TEMPERATURE_SENSOR_SELECTED, sensor ); @@ -338,7 +406,21 @@ break; } + // TODO remove this code and the if statement. This configuration is until the new arterial sensor is implemented everywhere so the temperature calibration + // structure can be updated permanently. This way the PBA sensor will be replaced with the new arterial sensor. This is to make sure the + // calibration structure does not fail in different devices with different sensors temperaturesStatus[ sensor ].temperatureValue.data = temperature; + if ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) != SW_CONFIG_ENABLE_VALUE ) + { + // Apply the calibration record the temperature values prior to updating the structures + temperaturesStatus[ sensor ].temperatureValue.data = + pow(temperature, 4) * temperaturesCalRecord.hdTemperatureSensors[ (CAL_DATA_HD_TEMEPERATURE_SENSORS_T)sensor ].fourthOrderCoeff + + pow(temperature, 3) * temperaturesCalRecord.hdTemperatureSensors[ (CAL_DATA_HD_TEMEPERATURE_SENSORS_T)sensor ].thirdOrderCoeff + + pow(temperature, 3) * temperaturesCalRecord.hdTemperatureSensors[ (CAL_DATA_HD_TEMEPERATURE_SENSORS_T)sensor ].secondOrderCoeff + + temperature * temperaturesCalRecord.hdTemperatureSensors[ (CAL_DATA_HD_TEMEPERATURE_SENSORS_T)sensor ].gain + + temperaturesCalRecord.hdTemperatureSensors[ (CAL_DATA_HD_TEMEPERATURE_SENSORS_T)sensor ].offset; + } + } } @@ -411,11 +493,12 @@ TEMPERATURES_DATA_T sensorsData; // Get all the sensors/thermistors temperature values for publication - sensorsData.onboardThermistor = getTemperatureValue( THERMISTOR_ONBOARD_NTC ); - sensorsData.powerSupply1Thermistor = getTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); - sensorsData.venousPressSensorTemp = getTemperatureValue( TEMPSENSOR_VENOUS_PRESSURE_SENSOR ); - sensorsData.fpgaBoardTempSensor = getTemperatureValue( TEMPSENSOR_FPGA_BOARD_SENSOR ); - sensorsData.pbaADCTempSensor = getTemperatureValue( TEMPSENSOR_PBA_ADC_SENSOR ); + sensorsData.onboardThermistor = getTemperatureValue( THERMISTOR_ONBOARD_NTC ); + sensorsData.powerSupply1Thermistor = getTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); + sensorsData.venousPressSensorTemp = getTemperatureValue( TEMPSENSOR_VENOUS_PRESSURE_SENSOR ); + sensorsData.fpgaBoardTempSensor = getTemperatureValue( TEMPSENSOR_FPGA_BOARD_SENSOR ); + sensorsData.pbaADCTempSensor = getTemperatureValue( TEMPSENSOR_PBA_ADC_SENSOR ); + sensorsData.arterialPressSensorTemp = getTemperatureValue( TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR ); // Broadcast the temperatures data broadcastData( MSG_ID_HD_TEMPERATURES_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&sensorsData, sizeof( TEMPERATURES_DATA_T ) );