Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rab14e70c7bac24b0c3ebd02c6763285cdd3951ce -r4853f9f01e6a406783201902937d9ace760b0b38 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ab14e70c7bac24b0c3ebd02c6763285cdd3951ce) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 4853f9f01e6a406783201902937d9ace760b0b38) @@ -120,15 +120,16 @@ U32 readCount; ///< Read counts from FPGA OVERRIDE_F32_T temperatureValues; ///< Temperature values with override F32 maxAllowedTemperature; ///< Maximum allowed temperature of the sensor + U32 alarmStartTime; ///< Alarm start time } TEMP_SENSOR_T; // ********** private data ********** static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. -static U32 fpgaRawADCReadInterval = 0; ///< FPGA raw ADC read interval count. -static U32 elapsedTime = 0; ///< Elapsed time variable. -static U32 internalHeatersConversionTimer = 0; ///< Conversion timer variable to calculate the heaters internal temperature. +static U32 fpgaRawADCReadInterval; ///< FPGA raw ADC read interval count. +static U32 elapsedTime; ///< Elapsed time variable. +static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, @@ -172,6 +173,7 @@ static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); static void monitorTemperatureSnsrs( U32 sensorIndex ); +static void checkAlarmStatus( U32 sensorIndex, ALARM_ID_T alarm, BOOL alarmOccurred, U32 alarmTimeout ); /*********************************************************************//** * @brief @@ -294,7 +296,7 @@ // Persistent alarm for the temperature sensors error bit fault check initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS, - TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS ); + TEMP_SENSORS_OUT_OF_RANGE_PERSISTENT_PEROID_MS ); // TODO remove? // Persistent alarm for temperature sensors ADC error // When the FPGA read count does not increment for a period of time, it is considered as an internal error of the temperature sensors @@ -596,10 +598,23 @@ // is shifted 31 bits to the first bit of the U32 variable. // If that bit is a 1, there is either CRC error or Status error // that are ored on top of each other - U32 errorBit = adc >> 31; - isTemperatureNotValid = errorBit > 0; - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, sensorIndex, - TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); + U32 errorBit = adc >> 31; + isTemperatureNotValid = ( errorBit > 0 ? TRUE : FALSE ); + + // TODO for debugging only remove + if ( TRUE == isTemperatureNotValid ) + { + BOOL test = FALSE; + } + // TODO remove + + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, sensorIndex ); + + //checkAlarmStatus( sensorIndex, ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); + + // TODO remove this + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, sensorIndex, + // TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); } break; @@ -658,28 +673,27 @@ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) { BOOL isADCValid = FALSE; -#ifndef _VECTORCAST_ - isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed - //THIS ISSUE HAS BEEN FIXED. TRY IT. -#endif // Check the status of FPGA error and FPGA count - BOOL isFPGAErrorZero = ( fpgaError == 0 ? TRUE : FALSE ); + BOOL isFPGAErrorZero = ( fpgaError == 0 ? TRUE : FALSE ); BOOL isFPGACountChanging = ( tempSensors[ sensorIndex ].readCount != fpgaCount ? TRUE : FALSE ); if ( TRUE == isFPGAErrorZero ) { if ( TRUE == isFPGACountChanging ) { tempSensors[ sensorIndex ].readCount = fpgaCount; - isADCValid = TRUE; + isADCValid = TRUE; } } BOOL isThereAnError = ( ( FALSE == isFPGACountChanging ) || ( FALSE == isFPGAErrorZero ) ? TRUE : FALSE ); - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + //checkAlarmStatus( sensorIndex, ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + // TODO remove + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + return isADCValid; } @@ -698,15 +712,15 @@ { F32 temperature; - U32 const index = tempSensors[ sensorIndex ].adcNextIndex; - S32 const indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; + U32 index = tempSensors[ sensorIndex ].adcNextIndex; + S32 indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; tempSensors[ sensorIndex ].rawADCReads[ index ] = adc; tempSensors[ sensorIndex ].adcNextIndex = INC_WRAP( index, 0, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); tempSensors[ sensorIndex ].adcRunningSum = tempSensors[ sensorIndex ].adcRunningSum - indexValue + adc; // Calculate the average - F32 const avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; + F32 avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; // Check if the ADC value of the sensor is not out of range if ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT ) || ( (U32)avgADCReads > TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT ) ) @@ -805,9 +819,9 @@ *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues( void ) { - U32 rawADC = 0; + U32 rawADC = 0; U32 errorCount = 0; - U32 readCount = 0; + U32 readCount = 0; // Look at the error counter and the specific error flag to make sure the error is a temperature sensor // Add a byte array to have bits for each sensor to find out exactly what sensor failed @@ -950,7 +964,41 @@ } } +/*********************************************************************//** + * @brief + * The checkAlarmStatus function checks the status of an alarm and check whether + * it has timed out. + * @details Inputs: tempSensors + * @details Outputs: tempSensors + * @param sensorIndex the index of the temperature sensor + * @param alarm the alarm ID + * @param alarmOccures the boolean signal that indicates whether the error has + * occurred. + * @param alarmTimeout the timeout of the provided timeout + * @return none + *************************************************************************/ +static void checkAlarmStatus( U32 sensorIndex, ALARM_ID_T alarm, BOOL alarmOccurred, U32 alarmTimeout ) +{ + U32 startTime = tempSensors[ sensorIndex ].alarmStartTime; + if ( TRUE == alarmOccurred ) + { + if ( 0 == startTime ) + { + tempSensors[ sensorIndex ].alarmStartTime = getMSTimerCount(); + } + else if ( TRUE == didTimeout( startTime, alarmTimeout ) ) + { + SET_ALARM_WITH_2_U32_DATA( alarm, sensorIndex, alarmTimeout ); + } + } + else if ( ( FALSE == alarmOccurred ) && ( startTime != 0 ) ) + { + tempSensors[ sensorIndex ].alarmStartTime = 0; + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/