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