Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rdc0d9b087c609e71cacdb7f0395cccf29d749c00 -r660a97b10ac500184b1c9554cf770e2f5df7f615 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision dc0d9b087c609e71cacdb7f0395cccf29d749c00) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 660a97b10ac500184b1c9554cf770e2f5df7f615) @@ -14,14 +14,12 @@ * @date (original) 08-Apr-2020 * ***************************************************************************/ +#include // For temperature calculation -#ifndef _VECTORCAST_ - #include // For temperature calculation -#endif - -#include "TemperatureSensors.h" #include "FPGA.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" +#include "TemperatureSensors.h" #include "Timers.h" #include "TaskPriority.h" #include "TaskGeneral.h" @@ -123,10 +121,6 @@ static U32 elapsedTime; ///< Elapsed time variable static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature -static U32 inletWaterHighTempCounter; ///< Temperature too high persistence counter -static U32 inletWaterLowTempCounter; ///< Temperature too low persistence counter -static U32 inletWaterTempInRangeCounter; ///< Temperature in range persistence counter - static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, @@ -187,9 +181,6 @@ tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; elapsedTime = 0; internalHeatersConversionTimer = 0; - inletWaterLowTempCounter = 0; - inletWaterHighTempCounter = 0; - inletWaterTempInRangeCounter = 0; dataPublicationTimerCounter = 0; /* NOTE: The temperature sensors do not have conversion coefficient. @@ -243,8 +234,11 @@ // Initialize the heaters calculated internal temperature sensors. The constants are zero since they will not be used for conversion // Windowed time count for FPGA temperature sensor error - initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, - MAX_TEMPERATURE_SENSOR_FAILURES, MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, MAX_TEMPERATURE_SENSOR_FAILURES, MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ); + + initPersistentAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, ALARM_DATA_TYPE_F32, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); + + initPersistentAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, ALARM_DATA_TYPE_F32, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); } /************************************************************************* @@ -322,41 +316,16 @@ * @details * Inputs : Inlet water temperature value * Outputs : Trigger alarms when temperature is out of allowed range - * @param none * @return none *************************************************************************/ void checkInletWaterTemperature( void ) { F32 const temperature = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); - if ( temperature < MIN_WATER_INPUT_TEMPERATURE ) - { - ++inletWaterLowTempCounter; - inletWaterTempInRangeCounter = 0; - if ( inletWaterLowTempCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) - { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, temperature ); - } - } - else if ( temperature > MAX_WATER_INPUT_TEMPERATURE ) - { - ++inletWaterHighTempCounter; - inletWaterTempInRangeCounter = 0; - if ( inletWaterHighTempCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) - { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, temperature ); - } - } - else - { - ++inletWaterTempInRangeCounter; - inletWaterLowTempCounter = 0; - inletWaterHighTempCounter = 0; - if ( inletWaterTempInRangeCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) - { - clearAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE ); - clearAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE ); - } - } + BOOL const isWaterTempTooHigh = temperature > MAX_WATER_INPUT_TEMPERATURE; + BOOL const isWaterTempTooLow = temperature < MIN_WATER_INPUT_TEMPERATURE; + + checkPersistentAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, isWaterTempTooHigh, temperature ); + checkPersistentAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, isWaterTempTooLow, temperature ); } /************************************************************************* @@ -366,7 +335,7 @@ * @details * Inputs : none * Outputs : none - * @param sensor ID of sensor to get temperature for + * @param sensor Temperature sensor index * @return temperature *************************************************************************/ F32 getTemperatureValue ( U32 sensorIndex ) @@ -396,12 +365,13 @@ * ADC read from FPGA * @details * Inputs : none - * 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) + * 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 *************************************************************************/ static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ) { @@ -487,7 +457,7 @@ * function to process the ADC value and covert it to temperature * @details * Inputs : none - * Outputs : none + * Outputs : Processed valid ADC reading * @param sensorIndex ID of temperature sensor to process * @param adc ADC value for the temperature sensor * @param fpgaError reported FPGA error status @@ -513,7 +483,7 @@ * process the ADC and convert it to temperature * @details * Inputs : none - * Outputs : none + * Outputs : Processed heater ADC reading * @param sensorIndex ID of temperature sensor to process * @param adc reported ADC value for temperature sensor * @param fpgaError reported error status by FPGA @@ -557,11 +527,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 : 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 + * Inputs : readCount + * Outputs : readCount, internalErrorCount + * @param sensorIndex Temperature sensor index + * @param fpgaError FPGA error count + * @param fpgaCount FPGA read count * @return isADCValid (BOOL) *************************************************************************/ static BOOL isADCReadValid ( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) @@ -604,10 +574,10 @@ * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated * @details - * 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 + * Inputs : adcNextIndex, rawADCReads, adcRunningSum + * Outputs : adcNextIndex, rawADCReads, adcRunningSum, temperatureValues + * @param sensorIndex Temperature sensor index + * @param adc adc reading from fpga * @return none *************************************************************************/ static void processADCRead ( U32 sensorIndex, S32 adc ) @@ -636,7 +606,7 @@ * The handleSelfTestStart function transitions the self test state to * check ADC * @details - * Inputs : none + * Inputs : tempSensorsSelfTestResult * Outputs : none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ @@ -652,7 +622,7 @@ * reads are above the maximum 24bit ADC count, it will throw an alarm and * switches to the next state * @details - * Inputs : none + * Inputs : TPi ADC reading from FPGA * Outputs : none * @return TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ @@ -676,9 +646,8 @@ * The handleSelfTestConsistencyCheck function checks the values of the * sensors to make sure they are within the allowed range from each other * @details - * Inputs : none + * Inputs : TPi and TPo ADC reading from FPGA * Outputs : none - * @param none * @return TEMPSENSORS_SELF_TEST_COMPLETE (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestConsistencyCheck ( void ) @@ -840,8 +809,8 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensor ID of temperature sensor to override - * @param temperature override temperature value (in degrees C) + * @param sensorIndex Temperature sensor index + * @param temperature Temperature value to override if testing activated * @return result *************************************************************************/ BOOL testSetMeasuredTemperatureOverride ( U32 sensorIndex, F32 temperature ) @@ -868,7 +837,7 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensor ID of temperature sensor to reset override + * @param sensorIndex Temperature sensor index * @return result *************************************************************************/ BOOL testResetMeasuredTemperatureOverride ( U32 sensorIndex )