Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r8c3db9c2d3957a1a9d53ad5d20d9594a09bc21be -rf308cc4c35eab630ebbbde405cfe47d049afeafb --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 8c3db9c2d3957a1a9d53ad5d20d9594a09bc21be) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision f308cc4c35eab630ebbbde405cfe47d049afeafb) @@ -14,8 +14,11 @@ * @date (original) 08-Apr-2020 * ***************************************************************************/ -#include // For temperature calculation +#ifndef _VECTORCAST_ + #include // For temperature calculation +#endif + #include "TemperatureSensors.h" #include "FPGA.h" #include "SystemCommMessages.h" @@ -306,9 +309,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, - SW_FAULT_ID_TEMPERATURE_SENSORS_EXEC_INVALID_STATE, - tempSensorsExecState ); + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_EXEC_INVALID_STATE, tempSensorsExecState ); tempSensorsExecState = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; break; } @@ -365,21 +366,24 @@ * @details * Inputs : none * Outputs : none - * @param sensor : Temperature sensor index + * @param sensor ID of sensor to get temperature for * @return temperature *************************************************************************/ F32 getTemperatureValue ( U32 sensorIndex ) { - F32 temperature; + F32 temperature = 0.0; - if ( tempSensors[ sensorIndex ].temperatureValues.override == OVERRIDE_KEY ) + if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; + if ( tempSensors[ sensorIndex ].temperatureValues.override == OVERRIDE_KEY ) + { + temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; + } + else + { + temperature = tempSensors[ sensorIndex ].temperatureValues.data; + } } - else - { - temperature = tempSensors[ sensorIndex ].temperatureValues.data; - } return temperature; } @@ -392,23 +396,22 @@ * ADC read from FPGA * @details * Inputs : none - * Outputs : none - * @param avgADC : Running average ADC - * @param gain : ADC gain - * @param refResistance : ADC reference resistance - * @param zeroDegResistance : ADC zero degree resistance - * @param adcConversionCoeff : ADC conversion coefficient - * @return temperature + * Outputs : temperatureValues + * @param avgADC average ADC value for given temperature sensor to convert + * @param gain gain value to apply + * @param refResistance resistance value to apply + * @param zeroDegResistance resistance value at zero degrees + * @return temperature (in degrees C) *************************************************************************/ static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ) { F32 temperature; - if ( adcConversionCoeff == 0.0 ) + if ( fabs( adcConversionCoeff ) < NEARLY_ZERO ) { - //R(RTD) = R(ref) * (adc – 2^N-1) / (G *2^N-1); + // R(RTD) = R(ref) * (adc – 2^N-1) / (G *2^N-1); F32 resistance = (refResistance * (avgADC - pow(2,(TEMP_SENSORS_ADC_BITS - 1)))) / (gain * pow(2,(TEMP_SENSORS_ADC_BITS - 1))); - //T=(-A+√(A^2-4B(1-R_T/R_0 )))/2B + // T=(-A+√(A^2-4B(1-R_T/R_0 )))/2B F32 secondSqrtPart = 4 * TEMP_EQUATION_COEFF_B * (1 - (resistance / zeroDegResistance)); temperature = (-TEMP_EQUATION_COEFF_A + sqrt(pow(TEMP_EQUATION_COEFF_A, 2) - secondSqrtPart)) / (2 * TEMP_EQUATION_COEFF_B); } @@ -427,8 +430,8 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param TCIndex : Heater thermo couple index - * @param CJIndex : Heater cold junction index + * @param TCIndex thermocouple index + * @param CJIndex cold junction index * @return none *************************************************************************/ static void getHeaterInternalTemp ( U32 TCIndex, U32 CJIndex ) @@ -462,7 +465,7 @@ } else { - //TODO Alarm + // TODO Alarm temperature = -1.0; } @@ -485,10 +488,10 @@ * @details * Inputs : none * Outputs : none - * @param sensorIndex : Temperature sensor index - * @param adc : ADC reading from FPGA - * @param fpgaError : FPGA error count - * @param fpgaCount : FPGA read count + * @param sensorIndex ID of temperature sensor to process + * @param adc ADC value for the temperature sensor + * @param fpgaError reported FPGA error status + * @param fpgaCount reported FPGA read count * @return none *************************************************************************/ static void processTempSnsrsADCRead ( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ) @@ -511,10 +514,10 @@ * @details * Inputs : none * Outputs : none - * @param sensorIndex : Temperature sensor index - * @param adc : ADC reading from FPGA - * @param fpgaError : FPGA error count - * @param fpgaCount : FPGA read count + * @param sensorIndex ID of temperature sensor to process + * @param adc reported ADC value for temperature sensor + * @param fpgaError reported error status by FPGA + * @param fpgaCount reported read count by FPGA * @return none *************************************************************************/ static void processHtrsTempSnsrsADCRead ( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ) @@ -554,11 +557,11 @@ * and the ADC value is not the same as the previous ADC read, it returns a * TRUE, signaling that the ADC is valid to be processed. * @details - * Inputs : readCount - * Outputs : readCount, internalErrorCount - * @param sensorIndex : Temperature sensor index - * @param fpgaError : FPGA error count - * @param fpgaCount : FPGA read count + * Inputs : readAndErrorCounts + * Outputs : readAndErrorCounts + * @param sensorIndex ID of temperature sensor to check + * @param fpgaError reported error status by FPGA + * @param fpgaCount reported read count by FPGA * @return isADCValid (BOOL) *************************************************************************/ static BOOL isADCReadValid ( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) @@ -601,10 +604,10 @@ * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated * @details - * Inputs : adcNextIndex, rawADCReads, adcRunningSum - * Outputs : adcNextIndex, rawADCReads, adcRunningSum, temperatureValues - * @param sensorIndex : Temperature sensor index - * @param adc : adc reading from fpga + * Inputs : runningSumAndIndex, rawADCReads, sampleCount, temperatureValues + * Outputs : runningSumAndIndex, rawADCReads, sampleCount, temperatureValues + * @param sensorIndex ID of temperature sensor to process + * @param adc reported ADC value for temperature sensor * @return none *************************************************************************/ static void processADCRead ( U32 sensorIndex, S32 adc ) @@ -635,7 +638,6 @@ * @details * Inputs : none * Outputs : none - * @param none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestStart ( void ) @@ -652,7 +654,6 @@ * @details * Inputs : none * Outputs : none - * @param none * @return TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestADCCheck ( void ) @@ -717,7 +718,6 @@ * @details * Inputs : none * Outputs : elapsedTime - * @param none * @return state (TEMPSENSORS_EXEC_STATES_T) *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecStart ( void ) @@ -745,7 +745,6 @@ * @details * Inputs : none * Outputs : internalHeatersConversionTimer, elapsedTime, temperatureValues - * @param none * @return state (TEMPSENSORS_EXEC_STATES_T) *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues ( void ) @@ -791,7 +790,6 @@ * @details * Inputs : tempSensorsPublishInterval * Outputs : none - * @param none * @return result *************************************************************************/ U32 getPublishTemperatureSensorsDataInterval ( void ) @@ -813,7 +811,6 @@ * @details * Inputs : dataPublicationTimerCounter, tempValuesForPublication * Outputs : dataPublicationTimerCounter, tempValuesForPublication - * @param none * @return none *************************************************************************/ static void publishTemperatureSensorsData ( void ) @@ -843,8 +840,8 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensorIndex : Temperature sensor index - * @param temperature : Temperature value to override if testing activated + * @param sensor ID of temperature sensor to override + * @param temperature override temperature value (in degrees C) * @return result *************************************************************************/ BOOL testSetMeasuredTemperatureOverride ( U32 sensorIndex, F32 temperature ) @@ -871,7 +868,7 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensorIndex : Temperature index + * @param sensor ID of temperature sensor to reset override * @return result *************************************************************************/ BOOL testResetMeasuredTemperatureOverride ( U32 sensorIndex ) @@ -898,7 +895,7 @@ * @details * Inputs : tempSensorsPublishInterval * Outputs : tempSensorsPublishInterval - * @param value : Publish interval in ms to override if testing activated + * @param value temperature sensor data broadcast interval (in ms) to override to * @return result *************************************************************************/ BOOL testSetTemperatureSensorsPublishIntervalOverride ( U32 value )