Index: Accel.c =================================================================== diff -u -ra1447ce5c1e4e02edc3778114d69aa5c43fb9480 -ra9b547ec4b0122c3f405d25c372542267119b117 --- Accel.c (.../Accel.c) (revision a1447ce5c1e4e02edc3778114d69aa5c43fb9480) +++ Accel.c (.../Accel.c) (revision a9b547ec4b0122c3f405d25c372542267119b117) @@ -197,9 +197,14 @@ DG_ACCELEROMETER_SENSOR_CAL_RECORD_T cal = getDGAccelerometerSensorCalibrationRecord(); #endif - if ( cal.calibrationTime == 0 ) + if ( 0 == cal.calibrationTime ) { - // TODO - accel calibration invalid fault +#ifdef _HD_ + activateAlarmNoData( ALARM_ID_HD_ACCELEROMETERS_INVALID_CAL_RECORD ); +#endif +#ifdef _DG_ + activateAlarmNoData( ALARM_ID_DG_ACCELEROMETERS_INVALID_CAL_RECORD ); +#endif } // Update accelerometer calibration factors Index: NVDataMgmt.c =================================================================== diff -u -r9a022c4969d0e12d9c94d4d89232e1581584319e -ra9b547ec4b0122c3f405d25c372542267119b117 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 9a022c4969d0e12d9c94d4d89232e1581584319e) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision a9b547ec4b0122c3f405d25c372542267119b117) @@ -106,10 +106,20 @@ #define RECORD_DEFAULT_CONST 0.0 ///< Record default constant. #define RECORD_DEFAULT_RATIO 1.0 ///< Record default ratio. -/// Once a new calibration data is available the driver, sets a signal for the defined time. Once the time -/// is out, it turns the signal off. -#define NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS (1 * MS_PER_SECOND) +// Once a new calibration data is available the driver, sets a signal for the defined time. Once the time is out, it turns the signal off. +#define NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS (1 * MS_PER_SECOND) ///< New calibration available signal timeout in milliseconds. +// HD specific defines +#ifdef _HD_ +#endif + +// DG specific defines +#ifdef _DG_ +#define FLUSH_LINES_DEFAULT_VOLUME_L 0.01 ///< Water volume to flush when starting re-circulate mode in liters. +#define ACID_CONC_DEFAULT_MIXING_RATIO ( 2.35618 / FRACTION_TO_PERCENT_FACTOR ) ///< Ratio between RO water and acid concentrate mixing ratio. +#define BICARB_CONC_DEFAULT_MIXING_RATIO ( 4.06812 / FRACTION_TO_PERCENT_FACTOR ) ///< Ratio between RO water and bicarbonate concentrate mixing ratio. +#endif + /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States { @@ -489,6 +499,7 @@ // Record check helper functions static BOOL areRecordsValid( void ); static BOOL isPolynomialRecordValid( POLYNOMIAL_CAL_PAYLOAD_T* record ); +static void setRsrvdCalibrationRecordsToZero( void ); #ifdef _DG_ static BOOL isDGCalibrationRecordValid( void ); @@ -1937,10 +1948,8 @@ BOOL haveCalGroupsPassed = TRUE; BOOL haveRecordsPassed = TRUE; -#ifndef DISABLE_CAL_CHECK // Check the integrity of the records as a whole. Check the upper layer CRC haveRecordsPassed = areRecordsValid(); -#endif #ifdef _DG_ // Check all the calibration groups @@ -1959,7 +1968,7 @@ } // Check if the records' entire CRCs as well as the individual CRCs passed - if ( haveCalGroupsPassed && haveRecordsPassed ) + if ( ( TRUE == haveCalGroupsPassed ) && ( TRUE == haveRecordsPassed ) ) { nvDataMgmtSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -2954,8 +2963,8 @@ * @details Outputs: none * @param record: pointer to a polynomial payload. The actual calibration * data to be checked - * @param isRecordNeeded: TRUE is the calibration record is need in the firmware - * right now otherwise, FALSE + * @param isRecordNeeded: TRUE is the calibration record is need in the + * firmware right now otherwise, FALSE * @return TRUE if the records' data is valid otherwise FALSE *************************************************************************/ static BOOL isPolynomialRecordValid( POLYNOMIAL_CAL_PAYLOAD_T* record ) @@ -2972,7 +2981,11 @@ record->secondOrderCoeff = RECORD_SECOND_ORDER_COEFF; record->gain = RECORD_DEFAULT_GAIN; record->offset = RECORD_DEFAULT_OFFSET; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif // Recalculate the CRC with the default values record->crc = crc16 ( (U08*)record, sizeof(POLYNOMIAL_CAL_PAYLOAD_T) - sizeof(U16) ); @@ -2983,6 +2996,53 @@ return status; } +/*********************************************************************//** + * @brief + * The setRsrvdCalibrationRecordsToZero function sets the calibration + * records reserved spaces to 0. This is to make sure they are not set + * to NaN. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +static void setRsrvdCalibrationRecordsToZero( void ) +{ + U32 i; + POLYNOMIAL_CAL_PAYLOAD_T* record; + + // NOTE: the size of the reserved spaces in each calibration record do not have #define + // because they are based on assumptions and they may be reduced. + + // Get the calibration record of the hardware (i.e. pressure sensor) + DG_PRES_SENSORS_CAL_RECORD_T* pressure = &dgCalibrationRecord.dgCalibrationGroups.presSensorsCalRecord; + for ( i = 0; i < 6; i++ ) + { + record = (POLYNOMIAL_CAL_PAYLOAD_T*)&pressure->reservedSpace[ i ]; + memset( record, 0x0, sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + } + + DG_FLOW_SENSORS_CAL_RECORD_T* flow = &dgCalibrationRecord.dgCalibrationGroups.flowSensorsCalRecord; + for ( i = 0; i < 3; i++ ) + { + record = (POLYNOMIAL_CAL_PAYLOAD_T*)&flow->reservedSpace[ i ]; + memset( record, 0x0, sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + } + + DG_TEMP_SENSORS_CAL_RECORD_T* temperature = &dgCalibrationRecord.dgCalibrationGroups.tempSensorsCalRecord; + for ( i = 0; i < 5; i++ ) + { + record = (POLYNOMIAL_CAL_PAYLOAD_T*)&temperature->reservedSpace[ i ]; + memset( record, 0x0, sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + } + + DG_COND_SENSORS_CAL_RECORD_T* conductivity = &dgCalibrationRecord.dgCalibrationGroups.condSensorsCalRecord; + for ( i = 0; i < 2; i++ ) + { + record = (POLYNOMIAL_CAL_PAYLOAD_T*)&conductivity->reservedSpace[ i ]; + memset( record, 0x0, sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); + } +} + #ifdef _DG_ /*********************************************************************//** * @brief @@ -3122,6 +3182,9 @@ isHardwareRecordValid = isDGAccelerometerSensorRecordValid( accelerometer ); isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; + // Set all the reserved spaces to 0 + setRsrvdCalibrationRecordsToZero(); + return isCalRecordValid; } @@ -3144,7 +3207,11 @@ { // CRC did not pass so set all values to default record->stepSpeed2FlowRatio = RECORD_DEFAULT_RATIO; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_CONC_PUMPS_CAL_DATA_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3174,7 +3241,11 @@ // CRC did not pass so set all values to default record->stepSpeed2FlowRatio = RECORD_DEFAULT_RATIO; record->voltage2SpeedRatio = RECORD_DEFAULT_RATIO; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_DRAIN_PUMP_CAL_RECORD_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3205,7 +3276,11 @@ record->gain1Ratio = RECORD_DEFAULT_RATIO; record->gain2Ratio = RECORD_DEFAULT_RATIO; record->gain3Ratio = RECORD_DEFAULT_RATIO; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_RO_PUMP_CAL_RECORD_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3233,8 +3308,12 @@ if ( calcCRC != recordCRC ) { // CRC did not pass so set all values to default - record->volume = RECORD_DEFAULT_CONST; + record->volume = FLUSH_LINES_DEFAULT_VOLUME_L; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_DRAIN_LINE_VOLUME_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3266,7 +3345,11 @@ record->normalFillVolume = RECORD_DEFAULT_CONST; record->rsrvrUnfilledWeight = RECORD_DEFAULT_CONST; record->rsrvrVolume = RECORD_DEFAULT_CONST; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_RESERVOIR_VOLUME_DATA_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3295,7 +3378,11 @@ { // CRC did not pass so set all values to default record->volume = RECORD_DEFAULT_CONST; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_GENERIC_VOLUME_DATA_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3325,8 +3412,12 @@ // CRC did not pass so set all values to default record->startVolume = RECORD_DEFAULT_CONST; record->reserverdSpace = RECORD_DEFAULT_CONST; - record->acidConcMixRatio = RECORD_DEFAULT_RATIO; + record->acidConcMixRatio = ACID_CONC_DEFAULT_MIXING_RATIO; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_ACID_CONCENTRATE_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3356,8 +3447,12 @@ // CRC did not pass so set all values to default record->startVolume = RECORD_DEFAULT_CONST; record->reservedSpace = RECORD_DEFAULT_CONST; - record->bicarbConcMixRatio = RECORD_DEFAULT_RATIO; + record->bicarbConcMixRatio = BICARB_CONC_DEFAULT_MIXING_RATIO; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_BICARB_CONCENTRATE_T) - sizeof(U16) ); // Alarm if the CRC did not pass @@ -3391,7 +3486,11 @@ record->reservedSpace1 = RECORD_DEFAULT_CONST; record->reservedSpace2 = RECORD_DEFAULT_CONST; record->reservedSpace3 = RECORD_DEFAULT_CONST; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_FILTER_CAL_RECORD_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3421,7 +3520,11 @@ // CRC did not pass so set all values to default record->reservedSpace1 = RECORD_DEFAULT_CONST; record->reservedSpace2 = RECORD_DEFAULT_CONST; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_FAN_CAL_RECORD_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid @@ -3452,7 +3555,11 @@ record->accelXOffset = RECORD_DEFAULT_OFFSET; record->accelYOffset = RECORD_DEFAULT_OFFSET; record->accelZOffset = RECORD_DEFAULT_OFFSET; +#ifndef IGNORE_CAL_TIMESTAMP record->calibrationTime = RECORD_DEFAULT_TIME; +#else + record->calibrationTime = getRTCTimestamp(); +#endif record->crc = crc16 ( (U08*)record, sizeof(DG_ACCELEROMETER_SENSOR_CAL_RECORD_T) - sizeof(U16) ); // Set the to FALSE since the record is not valid Index: RTC.c =================================================================== diff -u -r88f02ec7299938cc99d60c357f663b88a82da91a -ra9b547ec4b0122c3f405d25c372542267119b117 --- RTC.c (.../RTC.c) (revision 88f02ec7299938cc99d60c357f663b88a82da91a) +++ RTC.c (.../RTC.c) (revision a9b547ec4b0122c3f405d25c372542267119b117) @@ -726,8 +726,8 @@ *************************************************************************/ static BOOL isRTCFunctional( void ) { -#ifndef DISABLE_RTC_CONFIG BOOL hasTestPassed = TRUE; +#ifndef DISABLE_RTC_CONFIG U16 controlReg1 = rxBuffer[ RTC_REG_1_INDEX ]; U16 controlReg2 = rxBuffer[ RTC_REG_2_INDEX ]; U16 controlReg3 = rxBuffer[ RTC_REG_3_INDEX ]; @@ -773,9 +773,8 @@ SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RTC_BATTERY_LOW, controlReg3, RTC_REG_3_BLF_MASK ); hasTestPassed = FALSE; } - - return hasTestPassed; #endif + return hasTestPassed; } /*********************************************************************//**