Index: NVDataMgmt.c =================================================================== diff -u -r0132727168202dc86bc18561eef868ef40476270 -rc215373479cb13791bd7fa53ab12f9dae3a054f5 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 0132727168202dc86bc18561eef868ef40476270) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision c215373479cb13791bd7fa53ab12f9dae3a054f5) @@ -500,6 +500,7 @@ static volatile BOOL powerOffIsImminent = FALSE; ///< Power off warning has been signaled. Non-volatile memory operations should be completed ASAP and then ceased. static BOOL isNewCalAvailable = FALSE; ///< Signal to indicate whether a new calibration data is available. static U32 newCalStartTimer = 0; ///< New calibration availability start timer. +static BOOL hasServiceRecordBeenUpdated; ///< Flag that indicates the service record has been updated once the calibration record has been updated. // Private functions static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestStart( void ); @@ -549,6 +550,7 @@ static BOOL didCommandTimeout( ALARM_ID_T alarm, U08* state ); static BOOL eraseDataLogSectors( void ); static void monitorNewCalSignal( void ); +static void updateServiceRecord( void ); // Record operations queue functions static void enqueueRecordJob( NVDATAMGMT_OPERATION_STATE_T ops, NVDATAMGMT_LOCATION_STATE_T location, RECORD_JOBS_STATE_T job ); @@ -604,7 +606,7 @@ * queueFrontIndex, queueCount, recordUpdateAddress, recordQueueRearIndex, * recordQueueFrontIndex, recordQueueCount, recordAddressOffset, * writtenRecordStatus, hasPublishRecordBeenRequested, isNewCalAvailable, - * newCalStartTimer + * newCalStartTimer, hasServiceRecordBeenUpdated * @return none *************************************************************************/ void initNVDataMgmt( void ) @@ -627,6 +629,7 @@ hasPublishRecordBeenRequested = FALSE; isNewCalAvailable = FALSE; newCalStartTimer = 0; + hasServiceRecordBeenUpdated = FALSE; // Initialize and activate flash bank 7 Fapi_initializeFlashBanks( ROUNDED_HCLK_FREQ ); @@ -1988,6 +1991,9 @@ // If power off command has been issued, do not process any new jobs if ( powerOffIsImminent != TRUE ) { + // Check if the service record has to be updated + updateServiceRecord(); + // If the record processing queue is not empty, process the queues if ( FALSE == isRecordQueueEmpty() ) { @@ -2015,7 +2021,7 @@ maxBufferLength = jobSpecs.maxReadBufferSize / EEPROM_OPS_SIZE_OF_CONVERTER; } } - // TODO add the log queue later in the future phases. + // TODO add the log queue later in Phase 1B. } // Check if a queue job is available @@ -2905,6 +2911,35 @@ /*********************************************************************//** * @brief + * The updateServiceRecord function updates the service record once there is + * a new calibration record received. + * @details Inputs: isNewCalAvailable + * @details Outputs: isNewCalAvailable, hasServiceRecordBeenUpdated + * @return none + *************************************************************************/ +static void updateServiceRecord( void ) +{ + // If a new calibration is available and the service record has not been updated, updated the service record + // Right now, the last service date is updated once a new calibration record is received by the service personnel + if ( ( TRUE == isNewCalAvailable ) && ( FALSE == hasServiceRecordBeenUpdated ) ) + { +#ifdef _HD_ + hdServiceGroup.hdServiceRecord.lastServiceEpochDate = getRTCTimestamp(); + hdServiceGroup.hdServiceRecord.serviceLoc = 0; + hdServiceGroup.hdServiceRecord.crc = crc16( (U08*)&hdServiceGroup.hdServiceRecord, sizeof( HD_SERVICE_RECORD_T ) - sizeof( U16 ) ); + hdServiceGroup.crc = crc16( (U08*)&hdServiceGroup, sizeof( HD_SERVICE_GROUP_T ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, SERVICE_RECORD_START_ADDRESS, (U08*)&hdServiceGroup, 0, sizeof( HD_SERVICE_RECORD_T ) ); + hasServiceRecordBeenUpdated = TRUE; + } +#endif + } +} + +/*********************************************************************//** + * @brief * The areRecordsValid function checks whether the records are still valid * by calculating the CRCs and comparing it to the strucutre's CRC. * @details Inputs: none