Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rcd3f58205f4dab89291b29ee73b7fa9c31773abc -r33d262afee2fd0dd9d714ed86a21b8907ed84e25 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision cd3f58205f4dab89291b29ee73b7fa9c31773abc) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 33d262afee2fd0dd9d714ed86a21b8907ed84e25) @@ -180,6 +180,7 @@ static U32 temporaryTODORemove[2][ 300 ]; static U32 temporaryIdx = 0; +static U32 tempTest = 0; // ********** private function prototypes ********** @@ -190,7 +191,6 @@ static void getHeaterInternalTemp( U32 TCIndex, U32 CJIndex ); static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount, BOOL fpgaCheck ); static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ); -static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); static void monitorTemperatureSenors( void ); @@ -328,11 +328,6 @@ // Persistent alarm for the temperature sensors error bit fault check initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); - // 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 - // driver. This is internal because FPGA does not error out if the FPGA read count does not increment. - initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ); - initFPGAPersistentAlarm( TWO_WIRE_ADC_TEMP_SENSORS, ALARM_ID_DG_TEMPERATURE_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); } @@ -613,21 +608,8 @@ *************************************************************************/ static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount, BOOL fpgaCheck ) { - BOOL isADCValid = TRUE; S32 convertedADC = (S32)( adc & MASK_OFF_U32_MSB ); - if ( TRUE == fpgaCheck ) - { - // All the sensors have ADC read and count values that have to be checked - // but the FPGA read and error counts are shared among some of the sensors so if that counts has been checked - // once, do not check it again - isADCValid = isADCReadValid( sensorIndex, fpgaError, fpgaCount ); - } - - // Some of the temperature sensors have an MSB bit that is used as an - // error flag. This flag will be a TRUE by default. - BOOL isTemperatureNotValid = FALSE; - switch( sensorIndex ) { case TEMPSENSORS_LOAD_CELL_A1_B1: @@ -645,30 +627,29 @@ case TEMPSENSORS_INTERNAL_THD_RTD: { U08 i; + // Some of the temperature sensors have an MSB bit that is used as an + // error flag. This flag will be a TRUE by default. + BOOL isErrorBitNotValid = FALSE; + U32 faultySensorIndex = 0; // Shift bits by 31 to right to check the error bit status tempSensors[ sensorIndex ].sensorErrorBitStatus = adc >> SHIFT_BITS_BY_31; - /*for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) + for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { // If that bit is a 1, there is either CRC error or Status error that are ored on top of each other // NOTE: only a few sensors have the error bit available but for simplicity, all the sensors are looped. - // This variable is zeroed in the init function and the sensors that do not use this bit are never checked ( and set) to + // This variable is zeroed in the init function and the sensors that do not use this bit are never checked (and set) to // any other values so those sensors will never trigger this fault. // If any of the sensors have this bit to be 1, set the error occurred be 1 - isTemperatureNotValid |= ( tempSensors[ i ].sensorErrorBitStatus > 0 ? TRUE : FALSE ); - }*/ - -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT - // TODO for debugging only remove - if ( TRUE == isTemperatureNotValid ) - { - BOOL test = FALSE; + if ( tempSensors[ i ].sensorErrorBitStatus > 0 ) + { + isErrorBitNotValid = TRUE; + faultySensorIndex = i; + } } - // TODO remove for debugging only - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, isTemperatureNotValid, sensorIndex, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); -#endif + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, isErrorBitNotValid, faultySensorIndex, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); } break; @@ -679,12 +660,7 @@ break; } - // To update the moving average of a temperature sensor, both ADC and internal - // error flags must be valid - //if ( ( TRUE == isADCValid ) && ( FALSE == isTemperatureNotValid ) ) - { - processADCRead( sensorIndex, convertedADC ); - } + processADCRead( sensorIndex, convertedADC ); } /*********************************************************************//** @@ -704,60 +680,12 @@ *************************************************************************/ static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ) { - if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) - { - S16 convert = (S16)adc; - processADCRead( sensorIndex, (S32)convert ); - } + S16 convert = (S16)adc; + processADCRead( sensorIndex, (S32)convert ); } /*********************************************************************//** * @brief - * The isADCReadValid function checks if there is an FPGA error and FPGA - * count. If there is any FPGA, it raises an alarm. If the count has changed - * 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: tempSensors - * @details Outputs: tempSensors - * @param sensorIndex Temperature sensor index - * @param fpgaError FPGA error count - * @param fpgaCount FPGA read count - * @return returns TRUE if ADC was valid otherwise FALSE - *************************************************************************/ -static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) -{ - U08 i; - BOOL isADCValid = FALSE; - BOOL isTemperatureNotValid = FALSE; - // Check the status of FPGA error and FPGA count - BOOL isFPGAErrorZero = ( 0 == fpgaError ? TRUE : FALSE ); - BOOL isFPGACountChanging = ( tempSensors[ sensorIndex ].readCount != fpgaCount ? TRUE : FALSE ); - - if ( ( TRUE == isFPGAErrorZero ) && ( TRUE == isFPGACountChanging ) ) - { - tempSensors[ sensorIndex ].readCount = fpgaCount; - isADCValid = TRUE; - } - - tempSensors[ sensorIndex ].fpgaErrorStatus = ( ( FALSE == isFPGACountChanging ) || ( FALSE == isFPGAErrorZero ) ? TRUE : FALSE ); - - for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) - { - // Loop through all the sensors and read their FPGA error status - isTemperatureNotValid |= tempSensors[ sensorIndex ].fpgaErrorStatus; - } - -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_FPGA_FAULT, isTemperatureNotValid, sensorIndex, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ); - - return isADCValid; -#else - return TRUE; -#endif -} - -/*********************************************************************//** - * @brief * The processADCRead function receives the ADC value and the sensor * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated. @@ -902,7 +830,7 @@ errorCount = (U32)getFPGARTDErrorCount(); readCount = (U32)getFPGARTDReadCount(); - //checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount ); + checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp(), errorCount, readCount, TRUE ); processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp(), errorCount, readCount, FALSE ); processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp(), errorCount, readCount, FALSE ); @@ -933,24 +861,24 @@ errorCount = (U32)getFPGATRoErrorCount(); readCount = (U32)getFPGATRoReadCount(); - checkFPGAPersistentAlarms( TRO_ADC_TEMP_SENSORS, errorCount, readCount ); + //checkFPGAPersistentAlarms( TRO_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); errorCount = (U32)getFPGATDiErrorCount(); readCount = (U32)getFPGATDiReadCount(); - checkFPGAPersistentAlarms( TDI_ADC_TEMP_SENSORS, errorCount, readCount ); + //checkFPGAPersistentAlarms( TDI_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); errorCount = (U32)getFPGAPrimaryHeaterFlags(); // TODO remove these and do not check in the new persistent alarm readCount = (U32)getFPGAPrimaryHeaterReadCount(); // TODO remove these and do not check in the new persistent alarm - //processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); - //processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), errorCount, readCount ); errorCount = (U32)getFPGATrimmerHeaterFlags(); readCount = (U32)getFPGATrimmerHeaterReadCount(); - //processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), errorCount, readCount ); - //processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), errorCount, readCount ); // NOTE: FPGA board temperature sensor is different from the rest of the sensors. This sensor does not have FPGA count and error // coming from FPGA. It is kept here to do moving average on the values. The supporting functions need to see the FPGA read count @@ -962,7 +890,6 @@ processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TRO_RTD, getFPGATRoInternalTemp(), getFPGATRoErrorCount(), getFPGATRoReadCount(), TRUE ); processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount(), TRUE ); processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), getFPGABaroErrorCount(), getFPGABaroReadCount(), TRUE ); // Check if time has elapsed to calculate the internal temperature of the heaters if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL )