Index: NVDataMgmt.c =================================================================== diff -u -rcd1dbf44ebce97f61ad4a757d47449562ec366f0 -r547c33d5e13614b5e8de4739a45db7c3475721d1 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision cd1dbf44ebce97f61ad4a757d47449562ec366f0) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 547c33d5e13614b5e8de4739a45db7c3475721d1) @@ -20,6 +20,8 @@ #include // For memcpy #include "F021.h" + +#include "MsgQueues.h" #include "NVDataMgmt.h" #include "RTC.h" #include "system.h" @@ -81,6 +83,8 @@ #define COMMAND_TIME_OUT 500U // time in ms ///< Timeout for an EEPROM or RTC command in ms +#define ERASE_CALIBRATION_KEY 0xD2C3B4A5 ///< 32-bit key required for clearing calibration data. + /// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States { @@ -226,6 +230,9 @@ static BOOL calRecordIsValid = FALSE; ///< Flag indicates whether stored calibration record was found to be valid static volatile BOOL powerOffIsImminent = FALSE; ///< Power off warning has been signaled. Non-volatile memory operations should be completed ASAP and then ceased +// *** This declaration will cause a compiler error if CALIBRATION_DATA_T record size exceeds max message payload size. +U08 calRecordSizeAssertion[ ( sizeof( CALIBRATION_DATA_T ) <= MAX_MSG_PAYLOAD_SIZE ? 1 : -1 ) ]; + // Private functions static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestStart ( void ); @@ -367,7 +374,7 @@ /*********************************************************************//** * @brief - * The getCalibrationData returns the data in the structure that hold + * The getCalibrationData function returns the data in the structure that hold * calibration record to buffer that the caller has provided. * @details Inputs: calibrationRecord * @details Outputs: none @@ -389,6 +396,37 @@ /*********************************************************************//** * @brief + * The testResetCalibrationData function erases the calibration data. + * @details + * Inputs: calibrationRecord + * Outputs: none + * @param key a key is required to erase calibration data + * @return TRUE if calibration record valid + *************************************************************************/ +BOOL testResetCalibrationData( U32 key ) +{ + BOOL status = FALSE; + + // tester must be logged in + if ( TRUE == isTestingActivated() ) + { + // verify key + if ( ERASE_CALIBRATION_KEY == key ) + { + // erase calibration record + memset( (U08*)&calibrationRecord.calData, 0, sizeof(CALIBRATION_DATA_T) ); + // zero CRC so integrity check will fail unless calibration data set again + calibrationRecord.crc = 0; + // save erased calibration record + status = enqueueBank7Sector0Records(); + } + } + + return status; +} + +/*********************************************************************//** + * @brief * The setServiceDate updates the structure that holds the calibration data, * calls another function to calculate the CRC for the provided data if * there is enough queues available, it schedules a write to RTC RAM.