Index: firmware/App/Controllers/Temperatures.c =================================================================== diff -u -r19a8bf98a7154e24c35da25225d4b55bf70ddd09 -rfb1673d2282822995ed233f3e9ea5dfb0567780d --- firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 19a8bf98a7154e24c35da25225d4b55bf70ddd09) +++ firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision fb1673d2282822995ed233f3e9ea5dfb0567780d) @@ -51,7 +51,7 @@ /// Temperatures exec states typedef enum thermistors_Exec_States { - TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE = 0, ///< Temperatures exec state wait for POST state. + TEMPERATURES_EXEC_STATE_START_STATE = 0, ///< Temperatures exec state start 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; @@ -72,21 +72,17 @@ 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. -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. // ********** private function prototypes ********** -static TEMPERATURES_EXEC_STATES_T handleExecWaitForPOST( void ); +static TEMPERATURES_EXEC_STATES_T handleExecStart( void ); static TEMPERATURES_EXEC_STATES_T handleExecGetADCValues( void ); static void monitorTemperatures( void ); @@ -107,9 +103,8 @@ { U08 i; - temperaturesExecState = TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE; + temperaturesExecState = TEMPERATURES_EXEC_STATE_START_STATE; dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - isPOSTComplete = FALSE; for ( i = 0; i < NUM_OF_TEMPERATURES; i++ ) { @@ -125,17 +120,15 @@ * The execTemperaturesSelfTest function runs the temperatures POST during * the self-test. * @details Inputs: none - * @details Outputs: none - * @return execTemperaturesSelfTest which is the status of the self test + * @details Outputs: temperaturesCalRecord + * @return TRUE if the self test passed otherwise, FALSE *************************************************************************/ SELF_TEST_STATUS_T execTemperaturesSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + 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 ); - 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; - if ( TRUE == calStatus ) { result = SELF_TEST_STATUS_PASSED; @@ -167,8 +160,8 @@ // Read the sensors all the time switch ( temperaturesExecState ) { - case TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE: - temperaturesExecState = handleExecWaitForPOST(); + case TEMPERATURES_EXEC_STATE_START_STATE: + temperaturesExecState = handleExecStart(); break; case TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE: @@ -196,8 +189,8 @@ /*********************************************************************//** * @brief - * The getThermistorTemperatureValue function returns the temperature of - * a requested thermistor or temperature sensor. + * The getTemperatureValue function returns the temperature of a requested + * thermistor or a temperature sensor. * @details Inputs: thermistorsStatus * @details Outputs: none * @param sensorID index to get its temperature value @@ -210,14 +203,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 { @@ -229,21 +215,21 @@ /*********************************************************************//** * @brief - * The handleExecWaitForPOST function handles the wait for POST state of the + * The handleExecStart function handles the start 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 handleExecWaitForPOST( void ) +static TEMPERATURES_EXEC_STATES_T handleExecStart( void ) { - TEMPERATURES_EXEC_STATES_T state = TEMPERATURES_EXEC_STATE_WAIT_FOR_POST_STATE; + TEMPERATURES_EXEC_STATES_T state = TEMPERATURES_EXEC_STATE_START_STATE; // Give a short time for FPGA to boot up and start sending the ADC reads - if ( ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) && ( TRUE == isPOSTComplete ) ) + if ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) { - state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; adcReadCounter = 0; + state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; } return state; @@ -265,19 +251,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,35 +275,24 @@ 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++ ) + if ( getCurrentOperationMode() != MODE_INIT ) { - temperature = getTemperatureValue( sensor ); - - if ( ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ) ) + for ( sensor = THERMISTOR_ONBOARD_NTC; sensor < NUM_OF_TEMPERATURES; sensor++ ) { - isTempOutOfRange = TRUE; - lastFaultSensor = sensor; - faultSensorTemp = temperature; + temperature = getTemperatureValue( sensor ); -#ifndef _RELEASE_ - if ( ( TEMPSENSOR_ARTERIAL_PRESSURE_SENSOR == sensor ) && - ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) != SW_CONFIG_ENABLE_VALUE ) ) + if ( ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ) ) { - isTempOutOfRange = FALSE; + isTempOutOfRange |= TRUE; + lastFaultSensor = sensor; } -#endif } - } - 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 ); + checkPersistentAlarm( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange, lastFaultSensor, MAX_ALLOWED_TEMPERATURE ); } } @@ -361,43 +329,11 @@ 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: @@ -409,24 +345,15 @@ #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; + // 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; -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_DVT_ARTERIAL_PRESSURE_SENSOR ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - // 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; - } - } } @@ -497,13 +424,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