Index: firmware/App/Controllers/Temperatures.c =================================================================== diff -u -r07cdd44ffd0905cb115405e22cc7586585034e7f -r0a4dcd288d4347b85baaa0b07da568b6add5eac7 --- firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 07cdd44ffd0905cb115405e22cc7586585034e7f) +++ firmware/App/Controllers/Temperatures.c (.../Temperatures.c) (revision 0a4dcd288d4347b85baaa0b07da568b6add5eac7) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2021-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2023 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) 25-May-2022 +* @date (last) 01-Nov-2022 * * @author (original) Dara Navaei * @date (original) 01-Aug-2021 @@ -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,7 +72,6 @@ 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. @@ -83,7 +82,7 @@ // ********** 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 ); @@ -104,12 +103,12 @@ { 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++ ) { + benignPolynomialCalRecord( &temperaturesCalRecord.hdTemperatureSensors[ i ] ); memset( &temperaturesStatus[ i ], 0x0, sizeof( TEMPERATURE_SENSORS_T ) ); } @@ -122,17 +121,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; @@ -164,8 +161,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: @@ -193,16 +190,16 @@ /*********************************************************************//** * @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 * @return temperature of a thermistor or temperature sensor *************************************************************************/ F32 getTemperatureValue( TEMPERATURES_T sensorID ) { - F32 temperature = 0.0; + F32 temperature = 0.0F; // Check if the temperature sensor is in range if ( sensorID < NUM_OF_TEMPERATURES ) @@ -219,18 +216,18 @@ /*********************************************************************//** * @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 ) && ( MODE_INIT == getCurrentOperationMode() ) ) + if ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) { adcReadCounter = 0; state = TEMPERATURES_EXEC_STATE_GET_ADC_VALUES_STATE; @@ -280,21 +277,24 @@ { TEMPERATURES_T sensor; BOOL isTempOutOfRange = FALSE; - F32 temperature = 0.0; + F32 temperature = 0.0F; U32 lastFaultSensor = 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; + temperature = getTemperatureValue( sensor ); + + if ( ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ) ) + { + isTempOutOfRange |= TRUE; + lastFaultSensor = sensor; + } } - } - checkPersistentAlarm( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange, lastFaultSensor, MAX_ALLOWED_TEMPERATURE ); + checkPersistentAlarm( ALARM_ID_HD_TEMPERATURES_OUT_OF_RANGE, isTempOutOfRange, lastFaultSensor, MAX_ALLOWED_TEMPERATURE ); + } } /*********************************************************************//** @@ -341,7 +341,7 @@ // 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; + temperature = -1.0F; break; #endif }