Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r0f4fbb2a56cdbe35dcedd9cad23867fd7248f86e -r45a5b4b93d1793860d5a000406591ee5cf6935d6 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 0f4fbb2a56cdbe35dcedd9cad23867fd7248f86e) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 45a5b4b93d1793860d5a000406591ee5cf6935d6) @@ -8,7 +8,7 @@ * @file TemperatureSensors.c * * @author (last) Dara Navaei -* @date (last) 25-May-2022 +* @date (last) 21-Sep-2022 * * @author (original) Dara Navaei * @date (original) 08-Apr-2020 @@ -76,15 +76,13 @@ #define CELSIUS_TO_KELVIN_CONVERSION 273.15F ///< Celsius to Kelvin temperature conversion. #define ADC_BOARD_TEMP_SENSORS_CONVERSION_CONST 272.5F ///< ADC board temperature sensors conversion constant. -#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. #define ADC_BOARD_TEMP_SENSORS_CONST 0x800000 ///< ADC board temperature sensors constant. #define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 ///< External temperature sensors error value. #define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 ///< Heaters internal temperature sensor fault. #define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. #define TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors FPGA error timeout in milliseconds. -#define FPGA_RAW_ADC_READ_INTERVAL_COUNT 8 ///< Time interval in counts to read the raw ADC reads from FPGA. #define TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors error bit timeout in milliseconds. #define TEMP_SENSORS_MIN_ALLOWED_DEGREE_C 0.0F ///< Temperature sensors minimum allowed temperature in C. @@ -94,16 +92,8 @@ #define TEMP_SENSORS_OUT_OF_RANGE_TIME_OUT_MS ( 5 * MS_PER_SECOND ) ///< Temperature sensor out of range persistent period in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. #define BARO_SENSOR_REFERENCE_TEMP_C 2000 ///< Barometric sensor reference temperature in C. +#define BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ( 20 * MS_PER_SECOND ) ///< Barometric sensor wait for coefficients timeout in milliseconds. -// The count cannot be within 0.1V of the rail on both sides therefore: -// ADC count = ((2^12) - 1 / ref voltage) * voltage -// Max allowed voltage = 3.0 - 0.1 = 2.0V -// Min allowed voltage = 0.1 - 0.0 = 0.1V -// Max count = ((2^12) - 1 / ref voltage) * voltage -> ((4096 - 1)/3.0) * (3.0 - 0.1) -// Min count = ((2^12) - 1 / ref voltage) * voltage -> ((4096 - 1)/3.0) * (0.1 - 0.0) -#define TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT 3959U ///< Temperature sensors max allowed ADC count. -#define TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT 137U ///< Temperature sensors min allowed ADC count. - /// Temperature sensor exec states. typedef enum tempSensors_Exec_States { @@ -122,7 +112,6 @@ S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Raw ADC reads array S32 adcNextIndex; ///< Next ADC read index S32 adcRunningSum; ///< ADC running sum - U32 readCount; ///< Read counts from FPGA OVERRIDE_F32_T temperatureValues; ///< Temperature values with override F32 maxAllowedTemp; ///< Maximum allowed temperature of the sensor U32 alarmStartTime; ///< Alarm start time @@ -137,13 +126,28 @@ { U16 refTemperature; ///< Barometric sensor reference temperature. U16 temperatureCoeff; ///< Barometric sensor temperature coefficient. + OVERRIDE_U32_T coeffsCRC; ///< Barometric sensor coefficients CRC. + U32 waitForCoeffStartTimeMS; ///< Barometric sensor wait for coefficients start time in milliseconds. + BOOL hasCRCBeenChecked; ///< Barometric sensor has CRC been checked flag. } BARO_SENSOR_CONSTS_T; +/// Barometric sensor coefficients +typedef struct +{ + U16 mfgInfo; ///< Barometric sensor manufacturing info. + U16 pressSensitivity; ///< Barometric sensor pressure sensitivity. + U16 pressOffset; ///< Barometric sensor pressure offset. + U16 tempCoeffOfPressSens; ///< Barometric sensor temperature coefficient of pressure sensor. + U16 tempCoeffPressOffset; ///< Barometric sensor temperature coefficient of pressure offset. + U16 referenceTemp; ///< Barometric sensor reference temperature. + U16 tempCoeffOfTemp; ///< Barometric sensor temperature coefficient of Temperature sensor. + U16 crc; ///< Barometric sensor CRC of the coefficients. +} BARO_SENSORS_COEFFS_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; ///< 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 BARO_SENSOR_CONSTS_T baroConvConsts; ///< Barometric sensor conversion constants. @@ -176,8 +180,11 @@ static const U32 TWO_TO_POWER_OF_8 = ( 1 << 8 ); ///< 2^8. static const U32 TWO_TO_POWER_OF_23 = ( 1 << 23 ); ///< 2^23. -static U32 temporaryTODORemove[2][ 300 ]; -static U32 temporaryIdx = 0; +// The count cannot be within 0.1V of the rail on both sides therefore: +// Maximum ADC count -> (2^24) * ( 3.0V - 0.1V ) / 3V +// Minimum ADC count -> (2^24) * ( 0.1V - 0.0V ) / 3V +static const U32 TEMP_SENSORS_MAX_ADC_COUNT = ( BITS_24_FULL_SCALE * ( 3.0F - 0.1F ) ) / 3.0F; ///< Temperature sensors max allowed ADC count. +static const U32 TEMP_SESNORS_MIN_ADC_COUNT = ( BITS_24_FULL_SCALE * ( 0.1F - 0.0F ) ) / 3.0F; ///< Temperature sensors min allowed ADC count. // ********** private function prototypes ********** @@ -186,33 +193,35 @@ static F32 getADC2TempConversion( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ); 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 processTempSnsrsADCRead( U32 sensorIndex, U32 adc ); +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); static void monitorTemperatureSenors( void ); -static void adjustTemperatureSensorsV3DVTRefResistance( void ); +static void checkBaroSensorCRC( void ); +static void adjustTemperatureSensorsRefResistance( void ); /*********************************************************************//** * @brief * The initTemperatureSensors function initializes the module. * @details Inputs: none * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors, fpgaRawADCReadInterval, baroConvConsts + * tempSensors, baroConvConsts * @return none *************************************************************************/ void initTemperatureSensors( void ) { U08 i; - // Initialize the variables - tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; - elapsedTime = 0; - internalHeatersConversionTimer = 0; - dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - fpgaRawADCReadInterval = 0; + tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; + elapsedTime = 0; + internalHeatersConversionTimer = 0; + dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + baroConvConsts.coeffsCRC.data = 0; + baroConvConsts.hasCRCBeenChecked = FALSE; + baroConvConsts.waitForCoeffStartTimeMS = 0; + /* NOTE: The temperature sensors do not have conversion coefficient. * The conversion coefficients are used for the heaters internal temperature sensors and * the temperature will be calculated using a quadratic equation @@ -285,7 +294,7 @@ tempSensors[ TEMPSENSORS_TRIMMER_HEATER_INTERNAL ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; // FPGA board temperature conversion coefficient - tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoeff = 503.975 / (F32)TWELVE_BIT_RESOLUTION; + tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoeff = 503.975 / (F32)BITS_12_FULL_SCALE; tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].maxAllowedTemp = NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; F32 conversionCoeff = 1.0 / 13584.0; @@ -324,12 +333,12 @@ // 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); + // Initialize the FPGA persistent alarms + initFPGAPersistentAlarm( TWO_WIRE_ADC_TEMP_SENSORS, ALARM_ID_DG_TWO_WIRE_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( THD_ADC_TEMP_SENSORS, ALARM_ID_DG_THD_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( TDI_ADC_TEMP_SENSORS, ALARM_ID_DG_TDI_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( TRO_ADC_TEMP_SENSORS, ALARM_ID_DG_TRO_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( BARO_SENSOR, ALARM_ID_DG_BARO_SENSOR_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); } /*********************************************************************//** @@ -370,7 +379,7 @@ void execTemperatureSensors( void ) { // Check the status of the software configuration - adjustTemperatureSensorsV3DVTRefResistance(); + adjustTemperatureSensorsRefResistance(); // Read the sensors all the time switch ( tempSensorsExecState ) @@ -455,6 +464,8 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { temperature = getF32OverrideValue( &tempSensors[ sensorIndex ].temperatureValues ); + +#ifndef _RELEASE_ // If the system is V3 and THd or its ADC internal temperature is requested, return TRo instead. V3 does not have // the electrical connection of THd sensor. if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) @@ -463,7 +474,13 @@ { temperature = getF32OverrideValue( &tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].temperatureValues ); } + + if ( TEMPSENSORS_OUTLET_REDUNDANT == sensorIndex ) + { + temperature = getF32OverrideValue( &tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].temperatureValues ); + } } +#endif } else { @@ -593,69 +610,52 @@ * @details Outputs: none * @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 - * @param fpgaCheck whether to check the FPGA error and count prior to converting - * the ADC to temperature * @return none *************************************************************************/ -static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount, BOOL fpgaCheck ) +static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc ) { - 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: // 267 - case TEMPSENSORS_LOAD_CELL_A2_B2: // 279 - case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: // 283 - case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: // 287 - case TEMPSENSORS_OUTLET_PRIMARY_HEATER: // 291 - case TEMPSENSORS_INLET_PRIMARY_HEATER: // 295 - case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: // 299 - case TEMPSENSORS_OUTLET_REDUNDANT: // 303 - case TEMPSENSORS_INTERNAL_TRO_RTD: // 307 - case TEMPSENSORS_INLET_DIALYSATE: // 311 - case TEMPSENSORS_INTERNAL_TDI_RTD: // 315 + case TEMPSENSORS_LOAD_CELL_A1_B1: + case TEMPSENSORS_LOAD_CELL_A2_B2: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: + case TEMPSENSORS_INLET_PRIMARY_HEATER: + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: + case TEMPSENSORS_OUTLET_REDUNDANT: + case TEMPSENSORS_INTERNAL_TRO_RTD: + case TEMPSENSORS_INLET_DIALYSATE: + case TEMPSENSORS_INTERNAL_TDI_RTD: case TEMPSENSORS_HEAT_DISINFECT: 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; @@ -666,12 +666,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 ); } /*********************************************************************//** @@ -685,62 +680,13 @@ * @details Outputs: none * @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, U16 adc, U32 fpgaError, U32 fpgaCount ) +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc ) { - if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) - { - S16 convert = (S16)adc; - processADCRead( sensorIndex, (S32)convert ); - } -} + S16 convert = (S16)adc; -/*********************************************************************//** - * @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 + processADCRead( sensorIndex, (S32)convert ); } /*********************************************************************//** @@ -762,24 +708,24 @@ BOOL isADCNotValid = FALSE; U32 index = tempSensors[ sensorIndex ].adcNextIndex; S32 indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; + // Update the temperature sensors' structure 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; avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; // Calculate the average // Check if the average ADC is within the accepted range - tempSensors[ sensorIndex ].adcErrorStatus = ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT ) || - ( (U32)avgADCReads > TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT ) ? TRUE : FALSE ); + tempSensors[ sensorIndex ].adcErrorStatus = ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ADC_COUNT ) || + ( (U32)avgADCReads > TEMP_SENSORS_MAX_ADC_COUNT ) ? TRUE : FALSE ); for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { // Loop through the ADC errors isADCNotValid |= tempSensors[ sensorIndex ].adcErrorStatus; } -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isADCNotValid, sensorIndex, avgADCReads ); -#endif // Different sensors have different ADC to temperature conversion methods switch( sensorIndex ) @@ -820,7 +766,7 @@ case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: { tempSensors[ sensorIndex ].baroTempSnsrDiff = (S32)avgADCReads - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); - U64 baroSnsrTemperature = BARO_SENSOR_REFERENCE_TEMP_C + ( ( tempSensors[ sensorIndex ].baroTempSnsrDiff * + S64 baroSnsrTemperature = BARO_SENSOR_REFERENCE_TEMP_C + ( ( tempSensors[ sensorIndex ].baroTempSnsrDiff * baroConvConsts.temperatureCoeff ) / TWO_TO_POWER_OF_23 ); temperature = (F32)( (U32)( baroSnsrTemperature ) / 100 ); } @@ -843,7 +789,7 @@ * The handleExecStart function waits for a period of time and switches to * the state that reads the ADC values from FPGA. * @details Inputs: elapsedTime - * @details Outputs: elapsedTime + * @details Outputs: elapsedTime, baroCoeffsWaitToRcvStartTime * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecStart( void ) @@ -857,8 +803,9 @@ // A delay to let FPGA to boot up else if ( TRUE == didTimeout( elapsedTime, ADC_FPGA_READ_DELAY ) ) { - elapsedTime = 0; - state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; + elapsedTime = 0; + baroConvConsts.waitForCoeffStartTimeMS = getMSTimerCount(); + state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; } return state; @@ -878,80 +825,72 @@ U32 errorCount = 0; U32 readCount = 0; - // TODO remove - //temporaryTODORemove[0][temporaryIdx] = (U32)getFPGARTDErrorCount(); - //temporaryTODORemove[1][temporaryIdx] = (U32)getFPGARTDReadCount(); - //temporaryIdx = INC_WRAP(temporaryIdx, 0, 300); - // TODO remove + errorCount = (U32)getFPGARTDErrorCount(); + readCount = (U32)getFPGARTDReadCount(); - // 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 - //if ( ++fpgaRawADCReadInterval >= FPGA_RAW_ADC_READ_INTERVAL_COUNT ) - { - errorCount = (U32)getFPGARTDErrorCount(); - readCount = (U32)getFPGARTDReadCount(); - //checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount, TEMPSENSORS_INLET_PRIMARY_HEATER ); - 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 ); - processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, getFPGACD2Temp(), errorCount, readCount, FALSE ); + checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, getFPGACD2Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp() ); #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif - { - errorCount = (U32)getFPGATHdErrorCount(); - readCount = (U32)getFPGATHdReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp(), errorCount, readCount, TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp(), errorCount, readCount, FALSE ); + { + errorCount = (U32)getFPGATHdErrorCount(); + readCount = (U32)getFPGATHdReadCount(); - // Once FPGA is ready get the barometric sensor's temperature conversion constants - baroConvConsts.refTemperature = getFPGABaroReferenceTemperature(); - baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); - errorCount = getFPGABaroErrorCount(); - readCount = getFPGABaroReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), errorCount, readCount, TRUE ); - } + checkFPGAPersistentAlarms( THD_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp() ); - errorCount = (U32)getFPGATRoErrorCount(); - readCount = (U32)getFPGATRoReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); + // Make sure the baro sensor coefficients are not corrupted + checkBaroSensorCRC(); - errorCount = (U32)getFPGATDiErrorCount(); - readCount = (U32)getFPGATDiReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); + baroConvConsts.refTemperature = getFPGABaroReferenceTemperature(); + baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); + errorCount = getFPGABaroErrorCount(); + readCount = getFPGABaroReadCount(); - errorCount = (U32)getFPGAPrimaryHeaterFlags(); - readCount = (U32)getFPGAPrimaryHeaterReadCount(); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), errorCount, readCount ); + checkFPGAPersistentAlarms( BARO_SENSOR, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature() ); + } - errorCount = (U32)getFPGATrimmerHeaterFlags(); - readCount = (U32)getFPGATrimmerHeaterReadCount(); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), errorCount, readCount ); + errorCount = (U32)getFPGATRoErrorCount(); + readCount = (U32)getFPGATRoReadCount(); - // 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 - // incrementing internally so there will not be any errors. - U32 simulatedCounter = tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].readCount; - processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, ++simulatedCounter, TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), getFPGAADC1ErrorCount(), getFPGAADC1ReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), getFPGAADC2ErrorCount(), getFPGAADC2ReadCount(), TRUE ); - 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 ); + checkFPGAPersistentAlarms( TRO_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TRO_RTD, getFPGATRoInternalTemp() ); - // Check if time has elapsed to calculate the internal temperature of the heaters - if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) - { - getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); - getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); - internalHeatersConversionTimer = 0; - } + errorCount = (U32)getFPGATDiErrorCount(); + readCount = (U32)getFPGATDiReadCount(); - fpgaRawADCReadInterval = 0; + checkFPGAPersistentAlarms( TDI_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp() ); + + // The heaters' temperature sensors have read and error counts but the heaters' internal sensors are only updated for information + // and no alarm shall be raised on them including the read and error counts + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp() ); + + // The FPGA board sensor does not have read and error count. + // The load cells' temperature sensors are not read and a constant value is reported to firmware by FPGA + processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp() ); + + // Check if time has elapsed to calculate the internal temperature of the heaters + if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) + { + getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); + getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); + internalHeatersConversionTimer = 0; } return TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; @@ -970,6 +909,7 @@ if ( ++dataPublicationTimerCounter >= getU32OverrideValue( &tempSensorsPublishInterval ) ) { TEMPERATURE_SENSORS_DATA_T data; + data.inletPrimaryHeater = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); data.heatDisinfect = getTemperatureValue( TEMPSENSORS_HEAT_DISINFECT ); data.outletPrimaryHeater = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); @@ -988,14 +928,8 @@ data.loadCellA2B2 = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A2_B2 ); data.internalTHDORTD = getTemperatureValue( TEMPSENSORS_INTERNAL_TRO_RTD ); data.internalTDIRTD = getTemperatureValue( TEMPSENSORS_INTERNAL_TDI_RTD ); + data.interalTHDRTD = getTemperatureValue( TEMPSENSORS_INTERNAL_THD_RTD ); data.internalCondSnsrTemp = getTemperatureValue( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR ); - data.primaryThermoCoupleRaw = getFPGAPrimaryHeaterTemp(); - data.primaryColdjuncRaw = getFPGAPrimaryColdJunctionTemp(); - data.trimmerThermoCoupleRaw = getFPGATrimmerHeaterTemp(); - data.trimmerColdjuncRaw = getFPGATrimmerColdJunctionTemp(); - data.cond1Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; - data.cond2Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; - broadcastData( MSG_ID_DG_TEMPERATURE_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( TEMPERATURE_SENSORS_DATA_T ) ); dataPublicationTimerCounter = 0; } @@ -1017,43 +951,78 @@ #endif { U08 i; - F32 temperature = 0.0; + F32 temperature = 0.0F; BOOL isTemperatureOutOfRange = FALSE; + F32 alarmTemperature = 0.0F; + U08 alarmIndex = 0; for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { - temperature = getTemperatureValue( i ); - - // Check both temperature and to be in range - if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ i ].maxAllowedTemp ) ) && - ( getCurrentOperationMode() != DG_MODE_INIT ) ) + switch ( i ) { - isTemperatureOutOfRange |= TRUE; + case TEMPSENSORS_INLET_PRIMARY_HEATER: + case TEMPSENSORS_HEAT_DISINFECT: + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: + case TEMPSENSORS_OUTLET_REDUNDANT: + case TEMPSENSORS_INLET_DIALYSATE: + case TEMPSENSORS_FPGA_BOARD_SENSOR: + case TEMPSENSORS_LOAD_CELL_A1_B1: + case TEMPSENSORS_LOAD_CELL_A2_B2: + case TEMPSENSORS_INTERNAL_TRO_RTD: + case TEMPSENSORS_INTERNAL_TDI_RTD: + case TEMPSENSORS_INTERNAL_THD_RTD: + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: + case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: + // All the temperature sensors are monitored except the heaters' temperature sensors. + // The heaters' temperature sensors are only broadcast for information + temperature = getTemperatureValue( i ); + + // Check both temperature and to be in range + if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ i ].maxAllowedTemp ) ) && + ( getCurrentOperationMode() != DG_MODE_INIT ) ) + { + isTemperatureOutOfRange |= TRUE; + alarmIndex = i; + alarmTemperature = temperature; + } + break; + + default: + // Ignore the rest of the sensors + break; } + } - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, alarmIndex, alarmTemperature ); } } /*********************************************************************//** * @brief - * The adjustTemperatureSensorsV3DVTRefResistance function adjusts the temperature + * The adjustTemperatureSensorsRefResistance function adjusts the temperature * sensors V3 or DVT reference resistance values. * @details Inputs: tempSensors * @details Outputs: tempSensors * @return none *************************************************************************/ -static void adjustTemperatureSensorsV3DVTRefResistance( void ) +static void adjustTemperatureSensorsRefResistance( void ) { // The defaults are DVT values U32 primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; U32 externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; - if ( ( getCurrentOperationMode() != DG_MODE_INIT ) && ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) ) +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) +#endif { - primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; - externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; + if ( getCurrentOperationMode() != DG_MODE_INIT ) + { + primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; + externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; + } } tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = primaryAndCondSensorsRefResistance; @@ -1065,7 +1034,52 @@ tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].refResistance = externalTempSesnorsRefResitance; } +/*********************************************************************//** + * @brief + * The checkBaroSensorCRC function gets all the barometric sensor coefficients + * and calls crc4 function to calculate the CRC of the coefficients and compares + * them to the provided CRC by the manufacturer. + * @details Inputs: hasBaroCoeffsBeenChecked + * @details Outputs: hasBaroCoeffsBeenChecked + * @return none + *************************************************************************/ +static void checkBaroSensorCRC( void ) +{ + U32 baroCRC = (U32)getFPGABaroCoeffsCRC(); + BOOL hasCRCChanged = ( baroCRC != getU32OverrideValue( &baroConvConsts.coeffsCRC ) ? TRUE : FALSE ); + // Once FPGA is ready get the barometric sensor's temperature conversion constants + if ( TRUE == hasCRCChanged ) + { + U08 calculatedCRC; + BARO_SENSORS_COEFFS_T baroCoeffs; + + baroCoeffs.mfgInfo = getFPGABaroMfgInfo(); + baroCoeffs.pressSensitivity = getFPGABaroPressureSensitivity(); + baroCoeffs.pressOffset = getFPGABaroPressureOffset(); + baroCoeffs.tempCoeffOfPressSens = getFPGABaroTempCoeffOfPressSensitvity(); + baroCoeffs.tempCoeffPressOffset = getFPGABaroTempCoeffOfPressOffset(); + baroCoeffs.referenceTemp = getFPGABaroReferenceTemperature(); + baroCoeffs.tempCoeffOfTemp = getFPGABaroTempCoeffOfTemperature(); + baroCoeffs.crc = MASK_OFF_LSB & getFPGABaroCoeffsCRC(); + calculatedCRC = crc4( (U16*)&baroCoeffs, sizeof( baroCoeffs ) ); + baroConvConsts.coeffsCRC.data = baroCRC; + baroCRC = (U16)( baroCRC & MASK_OFF_MSB ) & MASK_OFF_NIBBLE_MSB; + baroConvConsts.hasCRCBeenChecked = TRUE; + + if ( calculatedCRC != baroCRC ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, calculatedCRC, baroCoeffs.crc ); + } + } + else if ( ( TRUE == didTimeout( baroConvConsts.waitForCoeffStartTimeMS, BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ) ) && + ( FALSE == baroConvConsts.hasCRCBeenChecked ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, 0, baroCRC ); + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/