Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r0f4fbb2a56cdbe35dcedd9cad23867fd7248f86e -rae823785919192402707da5083e9b0ad40bd4938 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 0f4fbb2a56cdbe35dcedd9cad23867fd7248f86e) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ae823785919192402707da5083e9b0ad40bd4938) @@ -84,7 +84,6 @@ #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,6 +93,7 @@ #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 @@ -137,13 +137,15 @@ { 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; // ********** 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. @@ -193,25 +195,27 @@ static void publishTemperatureSensorsData( void ); static void monitorTemperatureSenors( void ); static void adjustTemperatureSensorsV3DVTRefResistance( void ); +static void checkBaroSensorCRC( 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 @@ -843,7 +847,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 +861,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; @@ -884,74 +889,68 @@ //temporaryIdx = INC_WRAP(temporaryIdx, 0, 300); // TODO remove - // 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 ); + 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 ); #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(); + processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp(), errorCount, readCount, TRUE ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp(), errorCount, readCount, FALSE ); - // 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 ); - } + checkBaroSensorCRC(); - errorCount = (U32)getFPGATRoErrorCount(); - readCount = (U32)getFPGATRoReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); + baroConvConsts.refTemperature = getFPGABaroReferenceTemperature(); + baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); + errorCount = getFPGABaroErrorCount(); + readCount = getFPGABaroReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), errorCount, readCount, TRUE ); + } - errorCount = (U32)getFPGATDiErrorCount(); - readCount = (U32)getFPGATDiReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); + errorCount = (U32)getFPGATRoErrorCount(); + readCount = (U32)getFPGATRoReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); - errorCount = (U32)getFPGAPrimaryHeaterFlags(); - readCount = (U32)getFPGAPrimaryHeaterReadCount(); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), errorCount, readCount ); + errorCount = (U32)getFPGATDiErrorCount(); + readCount = (U32)getFPGATDiReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); - 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)getFPGAPrimaryHeaterFlags(); + readCount = (U32)getFPGAPrimaryHeaterReadCount(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), 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 - // 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 ); + errorCount = (U32)getFPGATrimmerHeaterFlags(); + readCount = (U32)getFPGATrimmerHeaterReadCount(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), errorCount, readCount ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), errorCount, readCount ); - // 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; - } + // 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 ); - fpgaRawADCReadInterval = 0; + // 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; @@ -1065,7 +1064,61 @@ 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; + struct + { + U16 mfgInfo; + U16 pressSensitivity; + U16 pressOffset; + U16 tempCoeffOfPressSens; + U16 tempCoeffPressOffset; + U16 referenceTemp; + U16 tempCoeffOfTemp; + U16 crc; + } 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 *************************************************************************/