Index: firmware/App/Controllers/Temperatures.c =================================================================== diff -u -rf5690caf1912afbf34596055bb8fd2a62e9a32f5 -re654b368ff8f4d194678db88f1cda57b04e7d947 --- firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision f5690caf1912afbf34596055bb8fd2a62e9a32f5) +++ firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision e654b368ff8f4d194678db88f1cda57b04e7d947) @@ -7,8 +7,8 @@ * * @file Temperatures.c * -* @author (last) Sean Nash -* @date (last) 12-Nov-2021 +* @author (last) Dara Navaei +* @date (last) 25-May-2022 * * @author (original) Dara Navaei * @date (original) 01-Aug-2021 @@ -34,17 +34,17 @@ #define TEMPERATURES_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Temperatures publish data time interval. #define TEMPERATURES_ADC_READ_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_GENERAL_INTERVAL ) ) ///< Temperatures ADC read time interval. -#define ADC_FPGA_READ_DELAY_COUNT 1.0 ///< FGPA read delay upon startup. +#define ADC_FPGA_READ_DELAY_COUNT 1.0F ///< FGPA read delay upon startup. #define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. -#define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. -#define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. -#define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. -#define THERMISTOR_BETA_VALUE 3380.0 ///< Thermistor beta value. -#define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. -#define ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1 272.5 ///< ADC board temperature sensor conversion constant 1. +#define THERMISTOR_REFERENCE_VOLTAGE 3.0F ///< Thermistors source voltage. +#define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0F ///< Thermistors reference resistor in ohms. +#define THERMISTOR_REFERENCE_TEMPERATURE 298.0F ///< Thermistors reference temperature in kelvin. +#define THERMISTOR_BETA_VALUE 3380.0F ///< Thermistor beta value. +#define CELSIUS_TO_KELVIN_CONVERSION 273.15F ///< Celsius to Kelvin temperature conversion. +#define ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_1 272.5F ///< ADC board temperature sensor conversion constant 1. #define ADC_BOARD_TEMP_SENSOR_CONVERSION_CONST_2 0x800000 ///< ADC board temperature sensor conversion constant 2. -#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 MIN_ALLOWED_TEMPERATURE 0.0F ///< Thermistors/sensors minimum allowed temperature reading. +#define MAX_ALLOWED_TEMPERATURE 80.0F ///< 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. @@ -74,15 +74,13 @@ 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. -static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1.0 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. -static const F32 FGPA_BOARD_TEMP_CONVERSION_COEFF = 503.975 / (F32)TWELVE_BIT_RESOLUTION; ///< FPGA board temperature conversion coefficient. -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. +static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / + (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. +static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1.0 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. +static const F32 FGPA_BOARD_TEMP_CONVERSION_COEFF = 503.975 / (F32)TWELVE_BIT_RESOLUTION; ///< FPGA board temperature conversion coefficient. +static const F32 VENOUS_ART_PRES_SENSOR_TEMP_CONV_COEFF = 200.0 / 2047.0; ///< Arterial and venous pressure sensor temperature conversion coefficient. +static const F32 VENOUS_ART_PRES_SENSOR_TEMP_CONV_CONSTANT = 50.0; ///< Arterial and 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. // ********** private function prototypes ********** @@ -210,14 +208,7 @@ // Check if the temperature sensor is in range if ( sensorID < NUM_OF_TEMPERATURES ) { - if ( OVERRIDE_KEY == temperaturesStatus[ sensorID ].temperatureValue.override ) - { - temperature = temperaturesStatus[ sensorID ].temperatureValue.ovData; - } - else - { - temperature = temperaturesStatus[ sensorID ].temperatureValue.data; - } + temperature = getF32OverrideValue( &temperaturesStatus[ sensorID ].temperatureValue ); } else { @@ -242,8 +233,8 @@ // Give a short time for FPGA to boot up and start sending the ADC reads if ( ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) && ( TRUE == isPOSTComplete ) ) { - state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; adcReadCounter = 0; + state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; } return state; @@ -265,19 +256,12 @@ if ( ++adcReadCounter >= TEMPERATURES_ADC_READ_INTERVAL ) { // Get all the raw readings in ADC - temperaturesStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); - temperaturesStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_PS_THERMISTOR ); - temperaturesStatus[ TEMPSENSOR_FPGA_BOARD_SENSOR ].rawADCRead = getFPGABoardTemperature(); - temperaturesStatus[ TEMPSENSOR_VENOUS_PRESSURE_SENSOR ].rawADCRead = getFPGAVenousPressureTemperature(); - temperaturesStatus[ TEMPSENSOR_PBA_ADC_SENSOR ].rawADCRead = getFPGAPBAADCTemperature(); + temperaturesStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); + temperaturesStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_PS_THERMISTOR ); + temperaturesStatus[ TEMPSENSOR_FPGA_BOARD_SENSOR ].rawADCRead = getFPGABoardTemperature(); + temperaturesStatus[ TEMPSENSOR_VENOUS_PRESSURE_SENSOR ].rawADCRead = getFPGAVenousPressureTemperature(); + temperaturesStatus[ TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR ].rawADCRead = getFPGADVTArterialTemperature(); -#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; } @@ -296,11 +280,9 @@ static void monitorTemperatures( void ) { TEMPERATURES_T sensor; - BOOL isTempOutOfRange = FALSE; F32 temperature = 0.0; U32 lastFaultSensor = 0; - F32 faultSensorTemp = 0.0; for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_TEMPERATURES; sensor++ ) { @@ -309,22 +291,13 @@ if ( ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ) ) { isTempOutOfRange = TRUE; - 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 + lastFaultSensor = sensor; } } if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange ) ) { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, lastFaultSensor, faultSensorTemp ); + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, lastFaultSensor ); } } @@ -361,65 +334,33 @@ break; case TEMPSENSOR_VENOUS_PRESSURE_SENSOR: + case TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR: // Temperature (C) = ((ADC / 2047) * 200) - 50 - temperature = ( rawADC * VENOUS_PRESS_SENSOR_TEMP_CONVERSION_COEFF ) - VENOUS_PRESS_SENSOR_TEMP_CONVERSION_CONSTANT; + temperature = ( rawADC * VENOUS_ART_PRES_SENSOR_TEMP_CONV_COEFF ) - VENOUS_ART_PRES_SENSOR_TEMP_CONV_CONSTANT; break; - case TEMPSENSOR_PBA_ADC_SENSOR: - -#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; - +#ifndef _VECTORCAST_ + // The default cannot be reached in VectorCAST since the cases are run in a for loop 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 ); // Wrong sensor, return temperature to be -1 temperature = -1.0; break; +#endif } // 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; - } + // 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, 2 ) * 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; } } @@ -453,7 +394,7 @@ ON_BOARD_THERMISTOR_REF_TEMP_INV; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius - F32 temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; + F32 temperature = ( 1.0F / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; return temperature; } @@ -491,13 +432,11 @@ if ( ++dataPublishCounter > getPublishTemperaturesDataInterval() ) { 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.arterialPressSensorTemp = getTemperatureValue( TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR ); // Broadcast the temperatures data