Index: Accel.c =================================================================== diff -u -ra9b547ec4b0122c3f405d25c372542267119b117 -rd7aa99f9c6ad48eaff310ad489786733d87600cf --- Accel.c (.../Accel.c) (revision a9b547ec4b0122c3f405d25c372542267119b117) +++ Accel.c (.../Accel.c) (revision d7aa99f9c6ad48eaff310ad489786733d87600cf) @@ -30,23 +30,23 @@ // ********** private definitions ********** -/// Interval (ms/task time) at which the accelerometer data is published on the CAN bus +/// Interval (ms/task time) at which the accelerometer data is published on the CAN bus. #define ACCEL_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) -/// Vector for tilt is filtered w/ moving average +/// Vector for tilt is filtered w/ moving average. #define SIZE_OF_ROLLING_AVG ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) -#define G_PER_LSB ( 0.00390625 ) ///< Conversion from counts (LSB) to gravities -/// Maximum time w/o new accelerometer sample from FPGA +#define G_PER_LSB ( 0.00390625 ) ///< Conversion from counts (LSB) to gravities. +/// Maximum time w/o new accelerometer sample from FPGA. static const U32 NO_NEW_ACCEL_SAMPLES_TIMEOUT = ( 100 / TASK_PRIORITY_INTERVAL ); -#define NOMINAL_ACCEL_VECTOR_LENGTH ( 1.0 ) ///< Expect unit vector length when system is stable -#define MAX_ACCEL_VECTOR_LENGTH_ERROR ( 0.1 ) ///< POST test looks at vector length at presumably stable moment - should be 1 +/- 0.1 -#define MAX_TILT_ANGLE ( 7.0 ) ///< Maximum tilt of system before alarm -#define MAX_TILT_ANGLE_TO_CLEAR_ALARM ( 5.0 ) ///< Maximum tilt of system before alarm is cleared -/// Maximum time (in task intervals) that a tilt in excess of limit can persist before alarm +#define NOMINAL_ACCEL_VECTOR_LENGTH ( 1.0 ) ///< Expect unit vector length when system is stable. +#define MAX_ACCEL_VECTOR_LENGTH_ERROR ( 0.1 ) ///< POST test looks at vector length at presumably stable moment - should be 1 +/- 0.1. +#define MAX_TILT_ANGLE ( 7.0 ) ///< Maximum tilt of system before alarm. +#define MAX_TILT_ANGLE_TO_CLEAR_ALARM ( 5.0 ) ///< Maximum tilt of system before alarm is cleared. +/// Maximum time (in task intervals) that a tilt in excess of limit can persist before alarm. static const U32 MAX_TILT_PERSISTENCE = ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ); -#define MAX_SHOCK_ACCELERATION ( 2.5 ) ///< Maximum shock (acceleration) measured on any axis before alarm -#define MAX_SHOCK_TO_CLEAR_ALARM ( 1.0 ) ///< Maximum shock (acceleration) measured on any axis in order to clear alarm -#define MAX_TILT_G ( 1.0 ) ///< Maximum tilt (in g) -#define MAX_TILT_ANGLE_DEG ( 90.0 ) ///< Maximum tilt angle (in degrees) +#define MAX_SHOCK_ACCELERATION ( 2.5 ) ///< Maximum shock (acceleration) measured on any axis before alarm. +#define MAX_SHOCK_TO_CLEAR_ALARM ( 1.0 ) ///< Maximum shock (acceleration) measured on any axis in order to clear alarm. +#define MAX_TILT_G ( 1.0 ) ///< Maximum tilt (in g). +#define MAX_TILT_ANGLE_DEG ( 90.0 ) ///< Maximum tilt angle (in degrees). /// Enumeration of accelerometer monitor states. typedef enum Accelerometer_States @@ -56,50 +56,45 @@ NUM_OF_ACCELEROMETER_STATES ///< Number of accelerometer states } ACCEL_STATE_T; -/// Enumeration of accelerometer self-test states. -typedef enum Accelerometer_Self_Test_States -{ - ACCELEROMETER_SELF_TEST_STATE_START = 0, ///< Accelerometer self-test start state - ACCELEROMETER_SELF_TEST_STATE_IN_PROGRESS, ///< Accelerometer self-test in progress state - ACCELEROMETER_SELF_TEST_STATE_COMPLETE, ///< Accelerometer self-test completed state - NUM_OF_ACCELEROMETER_SELF_TEST_STATES ///< Number of accelerometer self-test states -} ACCELEROMETER_SELF_TEST_STATE_T; - // ********** private data ********** + +static ACCEL_STATE_T accelState = ACCELEROMETER_START_STATE; ///< current state of accelerometer monitor state machine. +static U32 accelDataPublicationTimerCounter = 0; ///< used to schedule accelerometer data publication to CAN bus. -static ACCEL_STATE_T accelState = ACCELEROMETER_START_STATE; ///< current state of accelerometer monitor state machine -static U32 accelDataPublicationTimerCounter = 0; ///< used to schedule accelerometer data publication to CAN bus -static F32 accelCalOffsets[ NUM_OF_ACCEL_AXES ] = { 0, 0, 0 }; ///< accelerometer calibration offsets +static OVERRIDE_U32_T accelDataPublishInterval = { ACCEL_DATA_PUB_INTERVAL, + ACCEL_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms/task interval) at which to publish accelerometer data to CAN bus. +static OVERRIDE_F32_T accelAxes[ NUM_OF_ACCEL_AXES ]; ///< Measured accelerometer axis readings (calibrated, converted to gravities). +static OVERRIDE_F32_T accelMaxs[ NUM_OF_ACCEL_AXES ]; ///< Maximum axis readings since last sample (calibrated, converted to gravities). +static U16 accelFPGAFaultReg = 0; ///< FPGA accelerometer fault register value indicates whether issues with reading accelerometer. +static U16 accelFPGASampleCtr = 0; ///< Sample counter from FPGA indicates when new sample(s) are available. +static U32 accelNoNewSampleTimerCounter = 0; ///< used to enforce timeout on no new samples. -static OVERRIDE_U32_T accelDataPublishInterval = { ACCEL_DATA_PUB_INTERVAL, ACCEL_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms/task interval) at which to publish accelerometer data to CAN bus -static OVERRIDE_F32_T accelAxes[ NUM_OF_ACCEL_AXES ]; ///< Measured accelerometer axis readings (calibrated, converted to gravities) -static OVERRIDE_F32_T accelMaxs[ NUM_OF_ACCEL_AXES ]; ///< Maximum axis readings since last sample (calibrated, converted to gravities) -static U16 accelFPGAFaultReg = 0; ///< FPGA accelerometer fault register value indicates whether issues with reading accelerometer -static U16 accelFPGASampleCtr = 0; ///< Sample counter from FPGA indicates when new sample(s) are available -static U32 accelNoNewSampleTimerCounter = 0; ///< used to enforce timeout on no new samples - -static F32 accelReadings[ NUM_OF_ACCEL_AXES ][ SIZE_OF_ROLLING_AVG ]; ///< holds flow samples for a rolling average -static F32 accelReadingsTotal[ NUM_OF_ACCEL_AXES ]; ///< rolling total - used to calc average -static U32 accelReadingsIdx = 0; ///< index for next sample in rolling average array -static U32 accelReadingsCount = 0; ///< number of samples in flow rolling average buffer -static F32 accelAvgVector[ NUM_OF_ACCEL_AXES ]; ///< Filtered accelerometer vector for tilt -static F32 accelTilt[ NUM_OF_ACCEL_AXES ]; ///< Axis angles for tilt determination (filtered and converted to degrees) -static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error +static F32 accelReadings[ NUM_OF_ACCEL_AXES ][ SIZE_OF_ROLLING_AVG ]; ///< holds flow samples for a rolling average. +static F32 accelReadingsTotal[ NUM_OF_ACCEL_AXES ]; ///< rolling total - used to calc average. +static U32 accelReadingsIdx = 0; ///< index for next sample in rolling average array. +static U32 accelReadingsCount = 0; ///< number of samples in flow rolling average buffer. +static F32 accelAvgVector[ NUM_OF_ACCEL_AXES ]; ///< Filtered accelerometer vector for tilt. +static F32 accelTilt[ NUM_OF_ACCEL_AXES ]; ///< Axis angles for tilt determination (filtered and converted to degrees). +static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error. -static BOOL tiltErrorDetected; ///< Flag indicates a tilt error has been detected and tilt must now come below alarm clear threshold to clear alarm. -static BOOL shockErrorDetected; ///< Flag indicates a shock error has been detected and g-force must now come below alarm clear threshold to clear alarm. - -static ACCELEROMETER_SELF_TEST_STATE_T accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_START; ///< current accelerometer self-test state +static BOOL tiltErrorDetected; ///< Flag indicates a tilt error has been detected and tilt must now come below alarm clear threshold to clear alarm. +static BOOL shockErrorDetected; ///< Flag indicates a shock error has been detected and g-force must now come below alarm clear threshold to clear alarm. +#ifdef _HD_ +static HD_ACCELEROMETER_SENSOR_CAL_RECORD_T accelSensorCalRecord ///< HD accelerometer calibration record. +#endif +#ifdef _DG_ +static DG_ACCELEROMETER_SENSOR_CAL_RECORD_T accelSensorCalRecord; ///< DG accelerometer calibration record. +#endif // ********** private function prototypes ********** static ACCEL_STATE_T handleAccelMonitorState( void ); static void publishAccelData( void ); static void resetAccelMovingAverage( void ); static void filterAccelReadings( void ); -static F32 calcVectorLength( F32 x, F32 y, F32 z ); static void checkForTiltError( void ); -static void checkForShockError( void ); +static void checkForShockError( void ); +static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -140,7 +135,13 @@ * @return none *************************************************************************/ void execAccel( void ) -{ +{ + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + processCalibrationData(); + } + switch ( accelState ) { case ACCELEROMETER_START_STATE: @@ -168,9 +169,10 @@ * @brief * The handleAccelMonitorState function handles the accelerometer monitor * state of the accelerometer monitor state machine. - * @details Inputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes, - * accelFPGAFaultReg, accelCalOffsets - * @details Outputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes + * @details Inputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, + * accelAxes, accelFPGAFaultReg, accelSensorCalRecord + * @details Outputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, + * accelAxes * alarm if accelerometer failed * @return next state *************************************************************************/ @@ -186,33 +188,7 @@ getFPGAAccelAxes( &x, &y, &z ); getFPGAAccelMaxes( &xm, &ym, &zm ); getFPGAAccelStatus( &cnt, &accelFPGAFaultReg ); - - // Check if a new calibration is available - if ( TRUE == isNewCalibrationRecordAvailable() ) - { -#ifdef _HD_ - HD_ACCELEROMETER_SENSOR_CAL_RECORD_T cal = getHDAccelerometerSensorCalibrationRecord(); -#endif -#ifdef _DG_ - DG_ACCELEROMETER_SENSOR_CAL_RECORD_T cal = getDGAccelerometerSensorCalibrationRecord(); -#endif - if ( 0 == cal.calibrationTime ) - { -#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 - accelCalOffsets[ ACCEL_AXIS_X ] = cal.accelXOffset; - accelCalOffsets[ ACCEL_AXIS_X ] = cal.accelYOffset; - accelCalOffsets[ ACCEL_AXIS_X ] = cal.accelZOffset; - } - // check fresh sample if ( cnt != accelFPGASampleCtr ) { @@ -242,9 +218,9 @@ } // convert to gravities and apply calibration (axis offsets) - accelAxes[ ACCEL_AXIS_X ].data = (F32)x * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_X ]; - accelAxes[ ACCEL_AXIS_Y ].data = (F32)y * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Y ]; - accelAxes[ ACCEL_AXIS_Z ].data = (F32)z * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Z ]; + accelAxes[ ACCEL_AXIS_X ].data = (F32)x * G_PER_LSB + accelSensorCalRecord.accelXOffset; + accelAxes[ ACCEL_AXIS_Y ].data = (F32)y * G_PER_LSB + accelSensorCalRecord.accelYOffset; + accelAxes[ ACCEL_AXIS_Z ].data = (F32)z * G_PER_LSB + accelSensorCalRecord.accelZOffset; xMax = fabs( (F32)xm * G_PER_LSB ); yMax = fabs( (F32)ym * G_PER_LSB ); zMax = fabs( (F32)zm * G_PER_LSB ); @@ -475,24 +451,6 @@ /*********************************************************************//** * @brief - * The calcVectorLength function calculates the length of a vector with - * given vector axis magnitudes. - * @details Inputs: none - * @details Outputs: none - * @param x X axis magnitude of vector - * @param y Y axis magnitude of vector - * @param z Z axis magnitude of vector - * @return the length of the given vector. - *************************************************************************/ -static F32 calcVectorLength( F32 x, F32 y, F32 z ) -{ - F32 result = sqrt( x * x + y * y + z * z ); - - return result; -} - -/*********************************************************************//** - * @brief * The checkForTiltError function checks for a tilt error. * @details Inputs: accelTilt, accelTiltErrorTimerCounter * @details Outputs: accelTiltErrorTimerCounter, alarm if persistent excessive @@ -607,6 +565,49 @@ clearAlarmCondition( ALARM_ID_HD_SHOCK ); #endif } +} + +/*********************************************************************//** + * @brief + * The processCalibrationData function gets the calibration data and makes + * sure it is valid by checking the calibration date. The calibration date + * should not be 0. + * @details Inputs: none + * @details Outputs: accelSensorCalRecord + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + +#ifdef _HD_ + DG_ACCELEROMETER_SENSOR_CAL_RECORD_T calData = getHDAccelerometerSensorCalibrationRecord(); +#endif + +#ifdef _DG_ + DG_ACCELEROMETER_SENSOR_CAL_RECORD_T calData = getDGAccelerometerSensorCalibrationRecord(); +#endif + + // Check if the calibration data that was received from NVDataMgmt is legitimate + // The calibration date item should not be zero. If the calibration date is 0, + // then the accelerometer data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.calibrationTime ) + { +#ifdef _HD_ + activateAlarmNoData( ALARM_ID_HD_ACCELEROMETERS_INVALID_CAL_RECORD ); +#endif +#ifdef _DG_ + activateAlarmNoData( ALARM_ID_DG_ACCELEROMETERS_INVALID_CAL_RECORD ); +#endif + status = FALSE; + } + + // The calibration data was valid, update the local copy + accelSensorCalRecord.accelXOffset = calData.accelXOffset; + accelSensorCalRecord.accelYOffset = calData.accelYOffset; + accelSensorCalRecord.accelZOffset = calData.accelZOffset; + + return status; } /*********************************************************************//** @@ -621,77 +622,15 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - switch ( accelSelfTestState ) - { - case ACCELEROMETER_SELF_TEST_STATE_START: - { -#ifdef _HD_ - HD_ACCELEROMETER_SENSOR_CAL_RECORD_T cal = getHDAccelerometerSensorCalibrationRecord(); -#endif -#ifdef _DG_ - DG_ACCELEROMETER_SENSOR_CAL_RECORD_T cal = getDGAccelerometerSensorCalibrationRecord(); -#endif + BOOL calStatus = processCalibrationData(); - accelCalOffsets[ ACCEL_AXIS_X ] = cal.accelXOffset; - accelCalOffsets[ ACCEL_AXIS_Y ] = cal.accelYOffset; - accelCalOffsets[ ACCEL_AXIS_Z ] = cal.accelZOffset; - - // Ensure calibration has been done for accelerometer -#ifndef DISABLE_CAL_CHECK - if ( cal.calibrationTime == 0 ) -#else - if ( FALSE ) -#endif - { - result = SELF_TEST_STATUS_FAILED; - accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_COMPLETE; -#ifdef _DG_ - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_ACCELEROMETER_SELF_TEST_FAILURE, 0 ) // TODO - use invalid cal fault instead. -#else - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_ACCELEROMETER_SELF_TEST_FAILURE, 0 ) -#endif - } - else - { - accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_IN_PROGRESS; - } - } - break; - - case ACCELEROMETER_SELF_TEST_STATE_IN_PROGRESS: - { - F32 vectorLen = calcVectorLength( accelAxes[ ACCEL_AXIS_X ].data, accelAxes[ ACCEL_AXIS_Y ].data, accelAxes[ ACCEL_AXIS_Z ].data ); - -#ifndef SKIP_POST - if ( fabs(NOMINAL_ACCEL_VECTOR_LENGTH - vectorLen) < MAX_ACCEL_VECTOR_LENGTH_ERROR ) - { - result = SELF_TEST_STATUS_PASSED; - } - else - { - result = SELF_TEST_STATUS_FAILED; -#ifdef _DG_ - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_ACCELEROMETER_SELF_TEST_FAILURE, vectorLen ) -#else - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_HD_ACCELEROMETER_SELF_TEST_FAILURE, vectorLen ) -#endif - } -#else - result = SELF_TEST_STATUS_PASSED; -#endif - accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_COMPLETE; - } - break; - - case ACCELEROMETER_SELF_TEST_STATE_COMPLETE: - default: - result = SELF_TEST_STATUS_FAILED; -#ifdef _DG_ - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_ACCEL_INVALID_SELF_TEST_STATE, accelSelfTestState ) -#else - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_ACCEL_INVALID_SELF_TEST_STATE, accelSelfTestState ) -#endif - break; + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; } return result; Index: NVDataMgmt.c =================================================================== diff -u -ra9b547ec4b0122c3f405d25c372542267119b117 -rd7aa99f9c6ad48eaff310ad489786733d87600cf --- NVDataMgmt.c (.../NVDataMgmt.c) (revision a9b547ec4b0122c3f405d25c372542267119b117) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision d7aa99f9c6ad48eaff310ad489786733d87600cf) @@ -80,7 +80,7 @@ #define DG_SCHEDULED_RUNS_START_ADDRESS (SERVICE_RECORD_START_ADDRESS + sizeof(DG_SERVICE_GROUP_T)) ///< DG scheduled runs start address in RTC RAM. #define COMMAND_TIME_OUT 500U ///< Timeout for an EEPROM or RTC command in ms. -/// EEPROM functions use the buffer length as the size of U32. So before send the length to any of FAPI functions, it should be divide by 4. +/// EEPROM functions use the buffer length as the size of U32. So before send the length to any of FAPI functions, it should be divided by 4. #define EEPROM_OPS_SIZE_OF_CONVERTER 4 // ********** Calibration data defines ********** @@ -506,6 +506,7 @@ static BOOL isDGConcPumpRecordValid( DG_CONC_PUMPS_CAL_DATA_T* record ); static BOOL isDGDrainPumpRecordValid( DG_DRAIN_PUMP_CAL_RECORD_T* record ); static BOOL isDGROPumpRecordValid( DG_RO_PUMP_CAL_RECORD_T* record ); +static BOOL isDGPreROPurgeVolumeRecordValid( DG_PRE_RO_PURGE_VOLUME_T* record ); static BOOL isDGDrainLineVolRecordValid( DG_DRAIN_LINE_VOLUME_T* record ); static BOOL isDGReservoirVolRecordValid( DG_RESERVOIR_VOLUME_DATA_T* record ); static BOOL isDGGenericVolRecordValid( DG_GENERIC_VOLUME_DATA_T* record ); @@ -1709,7 +1710,7 @@ PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS [ NVDATAMGMT_CALIBRATION_RECORD ]; U32 startAddress = specs.startAddress; U08* bufferAddress = specs.structAddressPtr; - U32 maxBufferLength = ( specs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER ); + U32 maxBufferLength = specs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; Fapi_doMarginRead ( (U32*)startAddress, (U32*)bufferAddress, maxBufferLength, Fapi_NormalRead ); currentTime = getMSTimerCount(); @@ -1737,7 +1738,7 @@ PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS [ NVDATAMGMT_SYSTEM_RECORD ]; U32 startAddress = specs.startAddress; U08* bufferAddress = specs.structAddressPtr; - U32 maxBufferLength = ( specs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER ); + U32 maxBufferLength = specs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; Fapi_doMarginRead ( (U32*)startAddress, (U32*)bufferAddress, maxBufferLength, Fapi_NormalRead ); currentTime = getMSTimerCount(); @@ -1927,6 +1928,7 @@ currentTime = getMSTimerCount(); // Get ready for reading the manufacturing record + // TODO uncomment. currently not working //Fapi_doMarginRead( (U32*)BANK7_SECTOR0_START_ADDRESS, addr, len, Fapi_NormalRead ); state = NVDATAMGMT_SELF_TEST_STATE_READ_SYS_RECORD; } @@ -2022,7 +2024,7 @@ if ( powerOffIsImminent != TRUE ) { // If the record processing queue is not empty, process the queues - if ( !isRecordQueueEmpty() ) + if ( FALSE == isRecordQueueEmpty() ) { dequeueRecordJob(); @@ -2045,14 +2047,14 @@ } else if ( ops == NVDATAMGMT_READ ) { - maxBufferLength = jobSpecs.maxReadBufferSize; + maxBufferLength = jobSpecs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; } } // TODO add the log queue later in the future phases. } // Check if a queue job is available - if ( areQueuesNotEmpty ) + if ( TRUE == areQueuesNotEmpty ) { if ( ops == NVDATAMGMT_ERASE_SECTOR ) { @@ -2122,8 +2124,11 @@ // Clear the buffer from the previous content memset( writtenRecordCheckBuffer, 0, sizeof(writtenRecordCheckBuffer)); + // The length should be divided by 4 + U32 maxBufferLength = jobSpecs.maxWriteBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; + // Issue a FAPI read command but only the bytes that were written, so use maxWriteBufferSize - Fapi_doMarginRead ( (U32*)startAddress, (U32*)writtenRecordCheckBuffer, jobSpecs.maxWriteBufferSize, Fapi_NormalRead ); + Fapi_doMarginRead ( (U32*)startAddress, (U32*)writtenRecordCheckBuffer, maxBufferLength, Fapi_NormalRead ); state = NVDATAMGMT_EXEC_STATE_VERIFY_EEPROM_WRITE; } @@ -2144,8 +2149,11 @@ writtenRecordStatus = NVDATAMGMT_RECORD_NOT_CHECKED; + // The length should be divided by 4 + U32 maxBufferLength = jobSpecs.maxWriteBufferSize; + // Issue the write command - Fapi_issueProgrammingCommand ( (U32*)memoryPtr, structPtr, jobSpecs.maxWriteBufferSize, 0x00, 0, Fapi_DataOnly ); + Fapi_issueProgrammingCommand ( (U32*)memoryPtr, structPtr, maxBufferLength, 0x00, 0, Fapi_DataOnly ); } } } @@ -2443,7 +2451,7 @@ { PROCESS_RECORD_STATE_T state = NVDATAMGMT_PROCESS_RECORD_STATE_IDLE; - if ( hasPublishRecordBeenRequested ) + if ( TRUE == hasPublishRecordBeenRequested ) { // Set the publish flag to FALSE hasPublishRecordBeenRequested = FALSE; @@ -3041,6 +3049,9 @@ record = (POLYNOMIAL_CAL_PAYLOAD_T*)&conductivity->reservedSpace[ i ]; memset( record, 0x0, sizeof( POLYNOMIAL_CAL_PAYLOAD_T ) ); } + + DG_PRE_RO_PURGE_VOLUME_T* preROPurge = &dgCalibrationRecord.dgCalibrationGroups.preROPurgeVolumeRecord; + memset( preROPurge, 0x0, sizeof( DG_PRE_RO_PURGE_VOLUME_T ) ); } #ifdef _DG_ @@ -3119,6 +3130,10 @@ isHardwareRecordValid = isDGROPumpRecordValid( roPump ); isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; + DG_PRE_RO_PURGE_VOLUME_T* preROPurgeVolume = &dgCalibrationRecord.dgCalibrationGroups.preROPurgeVolumeRecord; + isHardwareRecordValid = isDGPreROPurgeVolumeRecordValid( preROPurgeVolume ); + isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; + DG_DRAIN_LINE_VOLUME_T* drainLineVol = &dgCalibrationRecord.dgCalibrationGroups.drainLineVolumeRecord; isHardwareRecordValid = isDGDrainLineVolRecordValid( drainLineVol ); isCalRecordValid = isCalRecordValid == FALSE ? FALSE : isHardwareRecordValid; @@ -3292,6 +3307,40 @@ /*********************************************************************//** * @brief + * The isDGPreROPurgeVolumeRecordValid function checks whether the + * calibration record of pre RO purge is valid or not. + * @details Inputs: none + * @details Outputs: none + * @param record: DG_PRE_RO_PURGE_VOLUME_T pointer + * @return TRUE if the record is valid otherwise FALSE + *************************************************************************/ +static BOOL isDGPreROPurgeVolumeRecordValid( DG_PRE_RO_PURGE_VOLUME_T* record ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16 ( (U08*)record, sizeof(DG_PRE_RO_PURGE_VOLUME_T) - sizeof(U16) ); + U16 recordCRC = record->crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + record->pressure2FlowRatio = RECORD_DEFAULT_RATIO; + 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_PRE_RO_PURGE_VOLUME_T) - sizeof(U16) ); + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The isDGDrainLineVolRecordValid function checks whether the calibration * record of drain line volume is valid or not. * @details Inputs: none