Index: NVDataMgmt.c =================================================================== diff -u -r51178541e201275f227c8b3e8084a455bb78cf39 -r0f1d0c443daee3e30ae823711e85f3410bbf49fe --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 51178541e201275f227c8b3e8084a455bb78cf39) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 0f1d0c443daee3e30ae823711e85f3410bbf49fe) @@ -1,30 +1,39 @@ /************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file NVDataMgmt.c - * - * @date 11-FEB-2020 - * @author D. Navaei - * - * @brief NVDataMgmt source file - * - **************************************************************************/ +* +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file NVDataMgmt.c +* +* @author (last) Sean Nash +* @date (last) 01-Dec-2020 +* +* @author (original) Dara Navaei +* @date (original) 12-Feb-2020 +* +***************************************************************************/ // Includes #include // For memcpy +#include "system.h" #include "F021.h" + +#include "MsgQueues.h" #include "NVDataMgmt.h" #include "RTC.h" -#include "system.h" +#include "SystemCommMessages.h" #include "Timers.h" #include "Utilities.h" +/** + * @addtogroup NVDataMgmt + * @{ + */ + // Private defines #define QUEUE_MAX_SIZE 20U ///< Max queue size @@ -71,11 +80,13 @@ #define LAST_DISINFECTION_DATE_ADDRESS 0x00000060 // 96 ///< Last disinfection date start address in RTC RAM (96) // Data addresses in EEPROM -#define CALIBRATION_RECORD_START_ADDRESS (BANK7_SECTOR0_START_ADDRESS + 0x100) ///< Calibration record start address in EEPROM +#define CALIBRATION_RECORD_START_ADDRESS ( BANK7_SECTOR0_START_ADDRESS + sizeof(MFG_RECORD_T) ) ///< Calibration record start address in EEPROM #define COMMAND_TIME_OUT 500U // time in ms ///< Timeout for an EEPROM or RTC command in ms -/// NVDataMgmt self test states +#define ERASE_CALIBRATION_KEY 0xD2C3B4A5 ///< 32-bit key required for clearing calibration data. + +/// NVDataMgmt self-test states enumeration. typedef enum NVDataMgmt_Self_Test_States { NVDATAMGMT_SELF_TEST_STATE_START = 0, ///< Self test start @@ -90,10 +101,10 @@ NVDATAMGMT_SELF_TEST_STATE_READ_LAST_DISINFECTION_DATE, ///< Self test read last disinfection date NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC, ///< Self test check CRC NVDATAMGMT_SELF_TEST_STATE_COMPLETE, ///< Self test complete - NUM_OF_NVDATAMGMT_SELF_TEST_STATES ///< Total number of self test states + NUM_OF_NVDATAMGMT_SELF_TEST_STATES ///< Total number of self-test states } NVDATAMGMT_SELF_TEST_STATE_T; -/// NVDataMgmt Exec states +/// NVDataMgmt Exec states enumeration. typedef enum NVDataMgmt_Exec_State { NVDATAMGMT_EXEC_STATE_WAIT_FOR_POST = 0, ///< Exec state wait for POST @@ -106,7 +117,7 @@ NUM_OF_NVDATAMGMT_EXEC_STATES ///< Total number of exec states } NVDATAMGMT_EXEC_STATE_T; -/// NVDataMgmt memory operation modes +/// NVDataMgmt memory operation modes enumeration. typedef enum NVDataMgmt_Operation { NVDATAMGMT_NONE = 0, ///< Default mode to prevent any accidental ops @@ -116,7 +127,7 @@ NUM_OF_NVDATAMGMT_OPS_STATES ///< Total number of operation states } NVDATAMGMT_OPERATION_STATE_T; -/// NVDataMgmt memory locations +/// NVDataMgmt memory locations enumeration. typedef enum NVDataMgmt_Location { NVDATAMGMT_EEPROM = 0, ///< Location EEPROM @@ -125,18 +136,18 @@ } NVDATAMGMT_LOCATION_STATE_T; #pragma pack(push, 1) -/// Memory operations struct +/// Memory operations structure. typedef struct { NVDATAMGMT_OPERATION_STATE_T memoryOperation; ///< Memory operation NVDATAMGMT_LOCATION_STATE_T memoryLocation; ///< Memory location - U32* startAddress; ///< Operation start address + U32 startAddress; ///< Operation start address U08 buffer [ MAX_JOB_DATA_SIZE_BYTES ]; ///< Buffer READ_DATA_T* externalAddress; ///< External address of a buffer U32 length; ///< Length of a buffer } MEMORY_OPS_T; -/// Log header struct +/// Log header structure. typedef struct { U16 recordCount; ///< Record count @@ -145,49 +156,51 @@ BOOL isHdrCorrupted; ///< Log header corruption flag } LOG_HEADER_T; -/// Log record struct +/// Log record structure. typedef struct { LOG_HEADER_T logHeader; ///< Log header struct U16 crc; ///< Log header CRC } LOG_RECORD_T; -/// Treatment time struct +/// Treatment time structure. typedef struct { U32 treatmentTime; ///< Treatment time U16 crc; ///< Treatment time CRC } TREATMENT_TIME_RECORD_T; -/// Water consumption struct +/// Water consumption structure. typedef struct { U32 waterConsumption; ///< Water consumption U16 crc; ///< Water consumption CRC } WATER_CONSUMPTION_RECORD_T; -/// Manufacturing data struct +/// Manufacturing data structure. typedef struct { MFG_DATA_T mfgData; ///< Manufacturing data struct U16 crc; ///< Manufacturing data CRC + U08 Padding[ 0x30 - sizeof(MFG_DATA_T) - sizeof(U16) ]; ///< Padding for reserved mfg data space } MFG_RECORD_T; -/// Service record struct +/// Service record structure. typedef struct { SERVICE_DATA_T serviceData; ///< Service date struct U16 crc; ///< Service data CRC } SERVICE_RECORD_T; -/// Calibration record struct +/// Calibration record structure. typedef struct { CALIBRATION_DATA_T calData; ///< Calibration data struct U16 crc; ///< Calibration data CRC + U08 Padding[ 0x50 - sizeof(CALIBRATION_DATA_T) - sizeof(U16) ]; ///< Padding for reserved cal data space } CALIBRATION_RECORD_T; -/// Last disinfection record struct +/// Last disinfection record structure. typedef struct { DISINFECTION_DATE_T date; ///< Disinfection date (char array) @@ -209,13 +222,18 @@ static U08 queueRearIndex = QUEUE_START_INDEX; ///< Queue rear index static U08 queueFrontIndex = QUEUE_START_INDEX; ///< Queue front index static U08 queueCount = 0; ///< Queue count -static NVDATAMGMT_SELF_TEST_STATE_T NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_START; ///< NVDataMgmt self test state variable +static NVDATAMGMT_SELF_TEST_STATE_T NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_START; ///< NVDataMgmt self-test state variable static NVDATAMGMT_EXEC_STATE_T NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_WAIT_FOR_POST; ///< NVDataMgmt exec state variable -static SELF_TEST_STATUS_T NVDataMgmtSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< NVDataMgmt self test result +static SELF_TEST_STATUS_T NVDataMgmtSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< NVDataMgmt self-test result static U32 bootloaderFlag = 0; ///< Bootloader flag static BOOL hasCommandTimedout = FALSE; ///< Boolean flag for timeout of the commands static U32 currentTime = 0; ///< Current time +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 ); @@ -257,13 +275,13 @@ static BOOL didCommandTimeout ( ALARM_ID_T alarm, U08* state ); static BOOL eraseDataLogSectors ( void ); -/************************************************************************* - * @brief initNVDataMgmt - * The initNVDataMgmt initializes EEPROM - * @details - * Inputs : none - * Outputs : none - * @param none +/*********************************************************************//** + * @brief + * The initNVDataMgmt function initializes the module. + * @details Inputs: NVDataMgmtSelfTestState, NVDataMgmtExecState, NVDataMgmtSelfTestResult, + * queueRearIndex, queueFrontIndex, queueCount + * @details Outputs: NVDataMgmtSelfTestState, NVDataMgmtExecState, NVDataMgmtSelfTestResult, + * queueRearIndex, queueFrontIndex, queueCount * @return none *************************************************************************/ void initNVDataMgmt ( void ) @@ -278,17 +296,29 @@ Fapi_setActiveFlashBank( Fapi_FlashBank7 ); } -/************************************************************************* - * @brief setMfgData - * The setMfgData updates the struct that holds the manufacturing data, +/*********************************************************************//** + * @brief + * The signalPowerOffWarning signals this module that system power off is + * imminent and any non-volatile data writes in progress should be wrapped up + * quickly and any pending non-volatile data writes should not be started. + * @details Inputs: none + * @details Outputs: powerOffIsImminent + * @return none + *************************************************************************/ +void signalPowerOffWarning( void ) +{ + powerOffIsImminent = TRUE; +} + +/*********************************************************************//** + * @brief + * The setMfgData updates the structure that holds the manufacturing data, * calls another function to calculate the CRC for the provided data and * calls another function to erase sector 0 and write the new manufacturing * data. - * @details - * Inputs : MFG_DATA_T (data) - * Outputs : BOOL - * @param none - * @return BOOL + * @details Inputs: mfgRecord + * @details Outputs: mfgRecord + * @return TRUE is the enqueue was successfully scheduled *************************************************************************/ BOOL setMfgData ( MFG_DATA_T data ) { @@ -298,15 +328,14 @@ return status; } -/************************************************************************* - * @brief getMfgData - * The getMfgData returns the data in the struct that holds manufacturing - * record to buffer that the caller has provided - * @details - * Inputs : MFG_DATA_T* (buffer) - * Outputs : BOOL (status) - * @param none - * @return BOOL (status) +/*********************************************************************//** + * @brief + * The getMfgData returns the data in the structure that holds manufacturing + * record to buffer that the caller has provided. + * @details Inputs: mfgRecord + * @details Outputs: none + * @param buffer address of manufacturing data buffer + * @return TRUE if the buffer pointer was not null and the copy was successful *************************************************************************/ BOOL getMfgData ( MFG_DATA_T* buffer ) { @@ -321,37 +350,37 @@ return status; } -/************************************************************************* - * @brief setCalibrationData - * The setCalibrationData updates the struct that holds the calibration data, +/*********************************************************************//** + * @brief + * The setCalibrationData updates the structure that holds the calibration data, * calls another function to calculate the CRC for the provided data and * calls another function to erase sector 0 and write the new manufacturing * data. - * @details - * Inputs : MFG_DATA_T (data) - * Outputs : BOOL - * @param none - * @return BOOL + * @details Inputs: calibrationRecord + * @details Outputs: calibrationRecord + * @param data calibration data structure + * @return TRUE if updating was successfully scheduled *************************************************************************/ BOOL setCalibrationData ( CALIBRATION_DATA_T data ) { + BOOL status; + calibrationRecord.calData = data; - calibrationRecord.crc = crc16 ( (U08*)&calibrationRecord.calData, - sizeof(CALIBRATION_DATA_T) ); + calibrationRecord.crc = crc16( (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); // The entire sector 0 must be erased and re-written again - BOOL status = enqueueBank7Sector0Records(); + status = enqueueBank7Sector0Records(); + return status; } -/************************************************************************* - * @brief getCalibrationData - * The getCalibrationData returns the data in the struct that hold calibration - * record to buffer that the caller has provided - * @details - * Inputs : CALIBRATION_DATA_T* (buffer) - * Outputs : BOOL (status) - * @param none - * @return BOOL (status) +/*********************************************************************//** + * @brief + * 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 + * @param buffer address of calibration data buffer + * @return TRUE if calibration record valid *************************************************************************/ BOOL getCalibrationData ( CALIBRATION_DATA_T* buffer ) { @@ -360,22 +389,54 @@ if ( buffer != NULL ) { memcpy ( buffer, (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); - status = TRUE; + status = calRecordIsValid; } return status; - } -/************************************************************************* - * @brief setServiceDate - * The setServiceDate updates the struct 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 +} + +/*********************************************************************//** + * @brief + * The testResetCalibrationData function erases the calibration data. * @details - * Inputs : SERVICE_DATA_T (data) - * Outputs : BOOL - * @param none - * @return BOOL + * 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 + // queue job to re-store all non-volatile data records to memory bank 7, sector 0 (sector allocated for these records) from RAM + 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. + * @details Inputs: serviceRecord + * @details Outputs: serviceRecord + * @param data service data buffer + * @return TRUE if the queue had enough space to schedule the job + *************************************************************************/ BOOL setServiceDate ( SERVICE_DATA_T data ) { BOOL status = FALSE; @@ -392,15 +453,14 @@ return status; } -/************************************************************************* - * @brief getServiceDate - * The getServiceDate returns the data in the struct that holds service - * date to buffer that the caller has provided - * @details - * Inputs : SERVICE_DATA_T* (buffer) - * Outputs : BOOL (status) - * @param none - * @return BOOL (status) +/*********************************************************************//** + * @brief + * The getServiceDate returns the data in the structure that holds service + * date to buffer that the caller has provided. + * @details Inputs: serviceRecord + * @details Outputs: none + * @param buffer address of service data buffer + * @return TRUE if the buffer address was not null *************************************************************************/ BOOL getServiceDate ( SERVICE_DATA_T* buffer ) { @@ -415,15 +475,14 @@ return status; } -/************************************************************************* - * @brief writeLogData +/*********************************************************************//** + * @brief * The writeLogData checks if the queue is not full and if it is not, it calls - * enqueue to schedule a job for writing the log data - * @details - * Inputs : LOG_DATA_T* (data) - * Outputs : BOOL - * @param none - * @return BOOL + * enqueue to schedule a job for writing the log data. + * @details Inputs: logRecord + * @details Outputs: none + * @param data address of log data buffer + * @return TRUE if the queue is not full and if the log header is not corrupted *************************************************************************/ BOOL writeLogData ( LOG_DATA_T* data ) { @@ -439,15 +498,15 @@ return status; } -/************************************************************************* - * @brief readLogData +/*********************************************************************//** + * @brief * The readLogData checks if the queue is not full and if it is not, it calls - * enqueue to schedule a job for writing the log data - * @details - * Inputs : READ_DATA_T* (buffer), U32 (length) - * Outputs : BOOL - * @param none - * @return BOOL + * enqueue to schedule a job for writing the log data. + * @details Inputs: none + * @details Outputs: none + * @param buffer address of read data buffer + * @param length length of the data log + * @return TRUE if there are enough queues available for the job *************************************************************************/ BOOL readLogData ( READ_DATA_T* buffer, U32 length ) { @@ -463,15 +522,14 @@ return status; } -/************************************************************************* - * @brief setTreatmentTime +/*********************************************************************//** + * @brief * The setTreatmentTime sets a queue job to write the treatment time in - * the specified RAM address - * @details - * Inputs : U32 (mins) - * Outputs : BOOL - * @param none - * @return BOOL + * the specified RAM address. + * @details Inputs: treatmentTimeRecord + * @details Outputs: treatmentTimeRecord + * @param hours treatmet time in hours + * @return TRUE if the queue was not full so the job was scheduled successfully *************************************************************************/ BOOL setTreatmentTime ( U32 hours ) { @@ -489,30 +547,27 @@ return status; } -/************************************************************************* - * @brief getTreatmentTime +/*********************************************************************//** + * @brief * The getTreatmentTime returns the total number treatment hours of the - * HD device - * @details - * Inputs : none - * Outputs : U32 - * @param none - * @return U32 + * HD device. + * @details Inputs: none + * Output: none + * @return treatment time as U32 *************************************************************************/ U32 getTreatmentTime ( void ) { return treatmentTimeRecord.treatmentTime; } -/************************************************************************* - * @brief setWaterConsumption +/*********************************************************************//** + * @brief * The setWaterConsumption sets a queue job to write the amount of water - * that has been consumed in DG - * @details - * Inputs : U32 (liters) - * Outputs : BOOL - * @param none - * @return BOOL + * that has been consumed in DG. + * @details Inputs: waterConsumptionRecord + * @details Outputs: waterConsumptionRecord + * @param liters consumed water is liters + * @return TRUE if queue is not full *************************************************************************/ BOOL setWaterConsumption ( U32 liters ) { @@ -530,30 +585,27 @@ return status; } -/************************************************************************* - * @brief getWaterConsumption - * The getWaterConsumption returns the amount of consumed water - * @details - * Inputs : none - * Outputs : U32 - * @param none - * @return U32 +/*********************************************************************//** + * @brief + * The getWaterConsumption returns the amount of consumed water. + * @details Inputs: none + * @details Outputs: none + * @return water consumption as a U32 *************************************************************************/ U32 getWaterConsumption ( void ) { return waterConsumptionRecord.waterConsumption; } -/************************************************************************* - * @brief setDisinfectionDate +/*********************************************************************//** + * @brief * The setDisinfectionDate gets the last disinfection date, calculates the * CRC for it and if the queue is not full, it schedules a write to RTC RAM - * to store the last date - * @details - * Inputs : DISINFECTION_DATE_T (date) - * Outputs : BOOL (status) - * @param none - * @return BOOL (status) + * to store the last date. + * @details Inputs: lastDisinfectionRecord + * @details Outputs: lastDisinfectionRecord + * @param date disinfection date buffer + * @return TRUE if the queue was not full *************************************************************************/ BOOL setDisinfectionDate ( DISINFECTION_DATE_T date ) { @@ -571,15 +623,14 @@ return status; } -/************************************************************************* - * @brief getDisinfectionDate +/*********************************************************************//** + * @brief * The getDisinfectionDate populates the provided buffer with the last - * disinfection date - * @details - * Inputs : DISINFECTION_DATE_T* (buffer) - * Outputs : BOOL (status) - * @param none - * @return BOOL (status) + * disinfection date. + * @details Inputs: lastDisinfectionRecord + * @details Outputs: none + * @param buffer address of disinfection date buffer + * @return TRUE if the buffer address was not null *************************************************************************/ BOOL getDisinfectionDate ( DISINFECTION_DATE_T* buffer ) { @@ -594,14 +645,12 @@ return status; } -/************************************************************************* - * @brief execNVDataMgmtSelfTest - * The execNVDataMgmtSelfTest runs the NVDataMgmt POST during the self test - * @details - * Inputs : none - * Outputs : SELF_TEST_STATUS_T - * @param none - * @return SELF_TEST_STATUS_T +/*********************************************************************//** + * @brief + * The execNVDataMgmtSelfTest runs the NVDataMgmt POST during the self-test. + * @details Inputs: NVDataMgmtSelfTestState + * @details Outputs: NVDataMgmtSelfTestState, alarm if there was a software fault + * @return NVDataMgmtSelfTestResult the result of self-test *************************************************************************/ SELF_TEST_STATUS_T execNVDataMgmtSelfTest ( void ) { @@ -668,9 +717,13 @@ break; default: - - SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, NVDataMgmtSelfTestState ); +#else + SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_INVALID_SELF_TEST_STATE, + NVDataMgmtSelfTestState ); +#endif NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; NVDataMgmtSelfTestResult = SELF_TEST_STATUS_FAILED; break; @@ -679,14 +732,13 @@ return NVDataMgmtSelfTestResult; } -/************************************************************************* - * @brief setBootloaderFlag - * The setBootloaderFlag sets the bootloader flag to RTC RAM - * @details - * Inputs : U32 (flag) - * Outputs : BOOL - * @param none - * @return BOOL +/*********************************************************************//** + * @brief + * The setBootloaderFlag sets the bootloader flag to RTC RAM. + * @details Inputs: none + * @details Outputs: none + * @param flag the bootloader flag + * @return TRUE if the queue was not full *************************************************************************/ BOOL setBootloaderFlag ( U32 flag ) { @@ -702,31 +754,28 @@ return status; } -/************************************************************************* - * @brief getBootloaderFlag - * The getBootloaderFlag gets the bootloader flag from RTC RAM - * @details - * Inputs : none - * Outputs : U32 (flag value) - * @param none - * @return U32 (flag value) +/*********************************************************************//** + * @brief + * The getBootloaderFlag gets the bootloader flag from RTC RAM. + * @details Inputs: none + * @details Outputs: none + * @return bootloader flag as a U32 *************************************************************************/ U32 getBootloaderFlag( void ) { return bootloaderFlag; } -/************************************************************************* - * @brief execNVDataMgmt - * The execNVDataMgmt runs the NVDataMgmt main tasks - * @details - * Inputs : none - * Outputs : none - * @param none +/*********************************************************************//** + * @brief + * The execNVDataMgmt runs the NVDataMgmt main tasks. + * @details Inputs: NVDataMgmtExecState + * @details Outputs: NVDataMgmtExecState, alarm if exec state was invalid * @return none *************************************************************************/ -void execNVDataMgmt ( void ) -{ +void execNVDataMgmt( void ) +{ // TODO - not sure where it should go Dara, but need to look at powerOffIsImminent flag and block + // queuing of any new jobs, maybe even block starting of any new jobs if flag is set switch ( NVDataMgmtExecState ) { case NVDATAMGMT_EXEC_STATE_WAIT_FOR_POST: @@ -766,23 +815,24 @@ default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, +#ifdef _DG_ + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, NVDataMgmtExecState ); +#else + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_NVDATAMGMT_EXEC_INVALID_STATE, + NVDataMgmtExecState ); +#endif NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_IDLE; break; } } -// Private functions - -/************************************************************************* - * @brief handleSelfTestStart - * The handleSelfTestStart enables the EEPROM bank sectors - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T +/*********************************************************************//** + * @brief + * The handleSelfTestStart enables the EEPROM bank sectors. + * @details Inputs: currentTime + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestStart ( void ) { @@ -796,15 +846,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestEnableEEPROM +/*********************************************************************//** + * @brief * The handleSelfTestEnableEEPROM waits for EEPROM to return with ready from - * enabling the EEPROM command - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * enabling the EEPROM command. + * @details Inputs: currentTime + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestEnableEEPROM ( void ) { @@ -826,15 +874,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadBootloaderFlag +/*********************************************************************//** + * @brief * The handleSelfTestReadBootloaderFlag reads the bootloader flag - * from RTC RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * from RTC RAM. + * @details Inputs: currentTime, bootloaderFlag + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadBootloaderFlag ( void ) { @@ -867,15 +913,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadHDTreatmentTime +/*********************************************************************//** + * @brief * The handleSelfTestReadHDTreatmentTime reads the HD treatment time - * from RTC RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * from RTC RAM. + * @details Inputs: currentTime, treatmentTimeRecord + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadHDTreatmentTime ( void ) { @@ -898,15 +942,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadDGWaterConsumption +/*********************************************************************//** + * @brief * The handleSelfTestReadDGWaterConsumption reads the DG water consumption - * from RTC RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * from RTC RAM. + * @details Inputs: currentTime, waterConsumptionRecord + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadDGWaterConsumption ( void ) { @@ -928,14 +970,12 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadLogRecord - * The handleSelfTestReadLogRecord reads the log record from RTC RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T +/*********************************************************************//** + * @brief + * The handleSelfTestReadLogRecord reads the log record from RTC RAM. + * @details Inputs: currentTime, logRecord, mfgRecord + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadLogRecord ( void ) { @@ -945,27 +985,27 @@ // If the RAM is in Idle, read the log records if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE || timeoutStatus == TRUE ) { + U32 len = sizeof(MFG_RECORD_T) / sizeof(U32); + U32 *addr = (U32*)&mfgRecord; + getDataFromRAM ( (U08*)&logRecord, sizeof(LOG_RECORD_T) ); currentTime = getMSTimerCount(); // Get ready for reading the manufacturing record - Fapi_doMarginRead ( (U32*)BANK7_SECTOR0_START_ADDRESS, (U32*)&mfgRecord, - sizeof(MFG_RECORD_T), Fapi_NormalRead ); + Fapi_doMarginRead( (U32*)BANK7_SECTOR0_START_ADDRESS, addr, len, Fapi_NormalRead ); state = NVDATAMGMT_SELF_TEST_STATE_READ_MFG_RECORD; } return state; } -/************************************************************************* - * @brief handleSelfTestReadMfgRecords +/*********************************************************************//** + * @brief * The handleSelfTestReadMfgRecords reads the manufacturing record from - * EEPROM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * EEPROM. + * @details Inputs: currentTime, calibrationRecord + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadMfgRecord ( void ) { @@ -978,22 +1018,20 @@ currentTime = getMSTimerCount(); // Send the read command for calibration record Fapi_doMarginRead ( (U32*)CALIBRATION_RECORD_START_ADDRESS, (U32*)&calibrationRecord, - sizeof(CALIBRATION_RECORD_T), Fapi_NormalRead ); + sizeof(CALIBRATION_RECORD_T) / sizeof(U32), Fapi_NormalRead ); state = NVDATAMGMT_SELF_TEST_STATE_READ_CAL_RECORD; } return state; } -/************************************************************************* - * @brief handleSelfTestReadCalibrationRecord +/*********************************************************************//** + * @brief * The handleSelfTestReadCalibrationRecord reads the calibration record - * from EEPROM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * from EEPROM. + * @details Inputs: currentTime + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadCalibrationRecord ( void ) { @@ -1015,15 +1053,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadServiceRecord +/*********************************************************************//** + * @brief * The handleSelfTestReadServiceRecord reads the service dates from RTC - * RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * RAM. + * @details Inputs: currentTime, serviceRecord + * @details Outputs: currentTime + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadServiceRecord ( void ) { @@ -1044,15 +1080,13 @@ return state; } -/************************************************************************* - * @brief handleSelfTestReadLastDisinfectionDate +/*********************************************************************//** + * @brief * The handleSelfTestReadLastDisinfectionDate reads the last disinfection date - * from RTC RAM - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * from RTC RAM. + * @details Inputs: lastDisinfectionRecord + * @details Outputs: none + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadLastDisinfectionDate ( void ) { @@ -1069,15 +1103,15 @@ } -/************************************************************************* - * @brief handleSelfTestCheckCRC +/*********************************************************************//** + * @brief * The handleSelfTestCheckCRC calculates the CRC of the records and compares - * them to the CRC that was read. If they don't match, it will fail POST - * @details - * Inputs : none - * Outputs : NVDATAMGMT_SELF_TEST_STATE_T - * @param none - * @return NVDATAMGMT_SELF_TEST_STATE_T + * them to the CRC that was read. If they don't match, it will fail POST. + * @details Inputs: treatmentTimeRecord, waterConsumptionRecord, lastDisinfectionRecord, + * logRecord, mfgRecord, calibrationRecord, calibrationRecord, serviceRecord, + * NVDataMgmtSelfTestResult + * @details Outputs: NVDataMgmtSelfTestResult, alarm if any of the CRC checks failed + * @return next state *************************************************************************/ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestCheckCRC ( void ) { @@ -1088,11 +1122,13 @@ #ifdef _HD_ calcCRC = crc16 ( (U08*)&treatmentTimeRecord.treatmentTime, sizeof(U32) ); recordCRC = treatmentTimeRecord.crc; +#ifndef LIMITED_NVDATA_CRC_CHECKS if ( calcCRC != recordCRC ) { hasCRCPassed = FALSE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_NVDATA_HW_USAGE_DATA_CRC_ERROR, recordCRC, calcCRC ); } +#endif #else calcCRC = crc16 ( (U08*)&waterConsumptionRecord.waterConsumption, sizeof(U32) ); recordCRC = waterConsumptionRecord.crc; @@ -1110,6 +1146,7 @@ SET_ALARM_WITH_2_U32_DATA( AlARM_ID_NVDATA_DISINFECTION_DATE_CRC_ERROR, recordCRC, calcCRC ); } #endif +#ifndef LIMITED_NVDATA_CRC_CHECKS // Check log header record calcCRC = crc16 ( (U08*)&logRecord.logHeader, sizeof(LOG_HEADER_T) ); recordCRC = logRecord.crc; @@ -1133,14 +1170,20 @@ hasCRCPassed = FALSE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_NVDATA_MFG_RECORD_CRC_ERROR, recordCRC, calcCRC ); } +#endif // Check CRC for calibration record - calcCRC = crc16 ( (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); + calcCRC = crc16( (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); recordCRC = calibrationRecord.crc; if ( calcCRC != recordCRC ) { hasCRCPassed = FALSE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_NVDATA_CAL_RECORD_CRC_ERROR, recordCRC, calcCRC ); } + else + { + calRecordIsValid = TRUE; + } +#ifndef LIMITED_NVDATA_CRC_CHECKS // Check CRC for service record calcCRC = crc16 ( (U08*)&serviceRecord.serviceData, sizeof(SERVICE_DATA_T) ); recordCRC = serviceRecord.crc; @@ -1149,8 +1192,8 @@ hasCRCPassed = FALSE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_NVDATA_SRVC_RECORD_CRC_ERROR, recordCRC, calcCRC ); } - // There should be no failed CRCs or no command should - // timeout for the self test to pass +#endif + // There should be no failed CRCs and no command should timeout for the self-test to pass if ( hasCRCPassed && !hasCommandTimedout ) { NVDataMgmtSelfTestResult = SELF_TEST_STATUS_PASSED; @@ -1163,14 +1206,12 @@ return state; } -/************************************************************************* - * @brief handleExecWaitForPostState - * The handleExecWaitForPostState waits for POST to be completed - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T +/*********************************************************************//** + * @brief + * The handleExecWaitForPostState waits for POST to be completed. + * @details Inputs: NVDataMgmtSelfTestState + * @details Outputs: none + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecWaitForPostState ( void ) { @@ -1184,15 +1225,13 @@ return state; } -/************************************************************************* - * @brief handleExecIdleState +/*********************************************************************//** + * @brief * The handleExecIdleState checks if the queue is empty and if it is not - * empty, it sets the state of the job - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * empty, it sets the state of the job. + * @details Inputs: currentJob, currentTime + * @details Outputs: currentJob + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecIdleState ( void ) { @@ -1203,20 +1242,20 @@ dequeue(); NVDATAMGMT_OPERATION_STATE_T ops = currentJob.memoryOperation; NVDATAMGMT_LOCATION_STATE_T location = currentJob.memoryLocation; - U32* startAddress = currentJob.startAddress; + U32 startAddress = currentJob.startAddress; U32 length = currentJob.length; if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM ) { currentTime = getMSTimerCount(); - Fapi_issueProgrammingCommand ( startAddress, currentJob.buffer, length, + Fapi_issueProgrammingCommand ( (U32*)startAddress, currentJob.buffer, length, 0x00, 0, Fapi_DataOnly ); state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; } else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_EEPROM ) { currentTime = getMSTimerCount(); - Fapi_doMarginRead ( startAddress, (U32*)( currentJob.externalAddress->externalBuffer ), + Fapi_doMarginRead ( (U32*)startAddress, (U32*)( currentJob.externalAddress->externalBuffer ), length, Fapi_NormalRead ); // Change the status to in progress until the read operation is done currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; @@ -1225,15 +1264,15 @@ else if ( ops == NVDATAMGMT_ERASE_SECTOR ) { currentTime = getMSTimerCount(); - Fapi_issueAsyncCommandWithAddress ( Fapi_EraseSector, startAddress ); + Fapi_issueAsyncCommandWithAddress ( Fapi_EraseSector, (U32*)startAddress ); state = NVDATAMGMT_EXEC_STATE_ERASE_EEPROM; } else if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_RTC ) { if ( getRTCRAMState() == RTC_RAM_STATE_READY ) { currentTime = getMSTimerCount(); - writeToRAM ( (U32)startAddress, currentJob.buffer, length ); + writeToRAM ( startAddress, currentJob.buffer, length ); state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; } @@ -1243,7 +1282,7 @@ if ( getRTCRAMState() == RTC_RAM_STATE_READY ) { currentTime = getMSTimerCount(); - readFromRAM( (U32)startAddress, length ); + readFromRAM( startAddress, length ); currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; } @@ -1253,15 +1292,13 @@ return state; } -/************************************************************************* - * @brief handleExecWriteToEEPROMState +/*********************************************************************//** + * @brief * The handleExecWriteToEEPROMState issues a write command to EEPROM on entry - * and if the write was successful, it sets the state to Idle - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * and if the write was successful, it sets the state to Idle. + * @details Inputs: none + * @details Outputs: none + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecWriteToEEPROMState ( void ) { @@ -1276,15 +1313,13 @@ return state; } -/************************************************************************* +/*********************************************************************//** * @brief handleExecReadFromEEPROMState * The handleExecReadFromEEPROMState issues a read command to EEPROM on entry - * and if the read was successful, it sets the state to Idle - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * and if the read was successful, it sets the state to Idle. + * @details Inputs: currentJob + * @details Outputs: currentJob + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecReadFromEEPROMState ( void ) { @@ -1300,15 +1335,13 @@ return state; } -/************************************************************************* - * @brief handleExecEraseState +/*********************************************************************//** + * @brief * The handleExecEraseState issues an erase command to EEPROM on entry - * and if the erase was successful, it sets the state to Idle - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * and if the erase was successful, it sets the state to Idle. + * @details Inputs: none + * @details Outputs: none + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecEraseState ( void ) { @@ -1323,16 +1356,14 @@ return state; } -/************************************************************************* - * @brief handleExecWriteToRAMState +/*********************************************************************//** + * @brief * The handleExecWriteToRAMState issues a write command to RTC RAM if the * RAM was ready, and if the RAM got back to Idle after the write command, - * it sets the state to Idle - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * it sets the state to Idle. + * @details Inputs: none + * @details Outputs: none + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecWriteToRAMState ( void ) { @@ -1347,17 +1378,15 @@ return state; } -/************************************************************************* - * @brief handleExecReadFromRAMState +/*********************************************************************//** + * @brief * The handleExecReadFromRAMState issues a read command to RTC RAM if the * RAM was ready, and if the RAM got back to Idle after the read command, * it calls another function to read the data back from RTC RAM and - * it sets the state to Idle - * @details - * Inputs : none - * Outputs : NVDATAMGMT_EXEC_STATE_T - * @param none - * @return NVDATAMGMT_EXEC_STATE_T + * it sets the state to Idle. + * @details Inputs: currentJob + * @details Outputs: currentJob + * @return next state *************************************************************************/ static NVDATAMGMT_EXEC_STATE_T handleExecReadFromRAMState ( void ) { @@ -1374,15 +1403,23 @@ return state; } -/************************************************************************* - * @brief setMemoryOpsStruct - * The setMemoryOpsStruct fills up the job struct - * @details - * Inputs : NVDATAMGMT_OPERATION_STATE_T (ops), NVDATAMGMT_LOCATION_STATE_T - * (location), U32 (startAddress), U08* (data), READ_DATA_T* (extAddress) - * U32 (length) - * Outputs : none - * @param none +/*********************************************************************//** + * @brief + * The setMemoryOpsStruct function checks whether it is an EEPROM write, + * EEPROM read, or RTC RAM operation. For read or write data logs into EEPROM, + * it calls other functions to check for wraps and to find the next address for + * read or write. The function then checks for the length of the buffer and if + * it is greater than the specified max buffer, it breaks the operation into + * multiple jobs. + * @details Inputs: jobQueue, queueCount, queueRearIndex + * @details Outputs: jobQueue, queueCount, queueRearIndex + * @param ops type of operation (i.e. write to EEPROM) + * @param location location of operation (i.e. RTC RAM) + * @param startAddress start address of operation + * @param data address to the data buffer + * @param extAddress address of the external buffer. Used for reading the log + * data by a client + * @param length length of data for operation * @return none *************************************************************************/ static void setMemoryOpsStruct ( NVDATAMGMT_OPERATION_STATE_T ops, NVDATAMGMT_LOCATION_STATE_T location, @@ -1399,7 +1436,7 @@ jobQueue [ myAddIndex ].memoryOperation = ops; jobQueue [ myAddIndex ].memoryLocation = location; - jobQueue [ myAddIndex ].startAddress = (U32*)startAddress; + jobQueue [ myAddIndex ].startAddress = startAddress; jobQueue [ myAddIndex ].length = length; jobQueue [ myAddIndex ].externalAddress = extAddress; @@ -1411,17 +1448,16 @@ _enable_IRQ(); } -/************************************************************************* - * @brief prepareWriteLogJobAndGetStartAddress +/*********************************************************************//** + * @brief * The prepareWriteLogJobAndGetStartAddress checks whether the next write * is at edge of the any of the sectors and if yes, it will update the log * header accordingly. If the write is not at the edge, it will prepare a * normal write to EEPROM job. - * @details - * Inputs : U08* (data) - * Outputs : U32 (opsStartAddress) - * @param none - * @return U32 (opsStartAddress) + * @details Inputs: logRecord + * @details Outputs: logRecord + * @param data address of data buffer + * @return address of the next write as a U32 *************************************************************************/ static U32 prepareWriteLogJobAndGetStartAddress ( U08* data ) { @@ -1466,15 +1502,13 @@ return opsStartAddress; } -/************************************************************************* - * @brief prepareReadLogJobAndGetStartAddress +/*********************************************************************//** + * @brief * The prepareReadLogJobAndGetStartAddress prepares a read from the specified * address of the EEPROM. - * @details - * Inputs : none - * Outputs : U32 (opsStartAddress) - * @param none - * @return U32 (opsStartAddress) + * @details Inputs: logRecord + * @details Outputs: logRecord + * @return address of the next read as a U32 *************************************************************************/ static U32 prepareReadLogJobAndGetStartAddress ( void ) { @@ -1507,20 +1541,23 @@ return opsStartAddress; } -/************************************************************************* - * @brief enqueue +/*********************************************************************//** + * @brief * The enqueue prepares the jobs to be processed. It checks if the requested * job is read or write, or if it is RTC or EEPROM and sets the job struct. * It checks for the corner cases, for instance, if the next write log to EEPROM * is at the beginning of the next sector, it schedules and erase first and then * it schedules the write jobs. The function breaks the write to EEPROM jobs to - * 16 bytes at the time - * @details - * Inputs : NVDATAMGMT_OPERATION_STATE_T (ops), NVDATAMGMT_LOCATION_STATE_T - * (location), U32 (startAddress), U08* (data), READ_DATA_T* (extAddress) - * U32 (length) - * Outputs : none - * @param none + * 16 bytes at the time. + * @details Inputs: none + * @details Outputs: none + * @param ops type of operation (i.e. write to EEPROM) + * @param location location of operation (i.e. RTC RAM) + * @param startAddress start address of operation + * @param data address to the data buffer + * @param extAddress address of the external buffer. Used for reading the log + * data by a client + * @param length length of data for operation * @return none *************************************************************************/ static void enqueue ( NVDATAMGMT_OPERATION_STATE_T ops, NVDATAMGMT_LOCATION_STATE_T location, @@ -1536,6 +1573,9 @@ if ( ops == NVDATAMGMT_WRITE && location == NVDATAMGMT_EEPROM ) { maxBufferLength = MAX_EEPROM_WRITE_BUFFER_BYTES; + + // If the start address is 0, it means it is a data log and the start + // address must be found by referring to the log record header if ( startAddress == 0 ) { opsStartAddress = prepareWriteLogJobAndGetStartAddress ( data ); @@ -1544,6 +1584,8 @@ // Setup EEPROM read log event else if ( ops == NVDATAMGMT_READ && location == NVDATAMGMT_EEPROM ) { + // If the start address is 0, it means it is a data log and the start + // address must be found by referring to the log record header if ( startAddress == 0 ) { opsStartAddress = prepareReadLogJobAndGetStartAddress(); @@ -1575,14 +1617,12 @@ } } -/************************************************************************* - * @brief dequeue +/*********************************************************************//** + * @brief * The dequeue increments the front index counter and if it is equal to - * rear index, it sets it to -1, meaning that the queue is empty - * @details - * Inputs : none - * Outputs : none - * @param none + * rear index, it sets it to -1, meaning that the queue is empty. + * @details Inputs: queueFrontIndex, queueCount + * @details Outputs: queueFrontIndex, queueCount * @return none *************************************************************************/ static void dequeue ( void ) @@ -1603,15 +1643,13 @@ _enable_IRQ(); } -/************************************************************************* - * @brief isQueueEmpty +/*********************************************************************//** + * @brief * The isQueueEmpty checks whether the queue is empty and if it is empty, - * it will return a false - * @details - * Inputs : none - * Outputs : isEmpty (BOOL) - * @param none - * @return isEmpty (BOOL) + * it will return a false. + * @details Inputs: queueCount + * @details Outputs: none + * @return TRUE if queue is not empty *************************************************************************/ static BOOL isQueueEmpty ( void ) { @@ -1625,15 +1663,13 @@ return isEmpty; } -/************************************************************************* - * @brief isQueueFull +/*********************************************************************//** + * @brief * The isQueueFull checks whether the queue is full and if it is full, - * it will return a true - * @details - * Inputs : none - * Outputs : isFull (BOOL) - * @param none - * @return isFull (BOOL) + * it will return a true. + * @details Inputs: queueCount + * @details Outputs: none + * @return TRUE is queue is full *************************************************************************/ static BOOL isQueueFull ( void ) { @@ -1647,31 +1683,27 @@ return isFull; } -/************************************************************************* - * @brief getAvailableQueueCount - * The getAvailableQueueCount returns the number of available queues left - * @details - * Inputs : none - * Outputs : U32 - * @param none - * @return U32 +/*********************************************************************//** + * @brief + * The getAvailableQueueCount returns the number of available queues left. + * @details Inputs: queueCount + * @details Outputs: none + * @return available queue counts as a U32 *************************************************************************/ static U32 getAvailableQueueCount ( void ) { return QUEUE_MAX_SIZE - queueCount; } -/************************************************************************* - * @brief enqueueBank7Sector0Records +/*********************************************************************//** + * @brief * The enqueueBank7Sector0Records checks whether there are enough number of * queues for erasing and setting the records. If there are enough queues, * it schedules an erase job and then schdules jobs to write all the records - * back to Bank 7 Sector 0 - * @details - * Inputs : none - * Outputs : BOOL - * @param none - * @return BOOL + * back to Bank 7 Sector 0. + * @details Inputs: mfgRecord, calibrationRecord + * @details Outputs: none + * @return TRUE if there are enough queue jobs available *************************************************************************/ static BOOL enqueueBank7Sector0Records( void ) { @@ -1682,31 +1714,29 @@ { // Sector 0 must be erased first enqueue ( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, 0, 0, 0 ); - enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, - (U08*)&mfgRecord, 0, sizeof(MFG_RECORD_T) ); - enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, CALIBRATION_RECORD_START_ADDRESS, - (U08*)&calibrationRecord, 0, sizeof(CALIBRATION_RECORD_T) ); + enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, (U08*)&mfgRecord, 0, sizeof(MFG_RECORD_T) ); + enqueue ( NVDATAMGMT_WRITE, NVDATAMGMT_EEPROM, CALIBRATION_RECORD_START_ADDRESS, (U08*)&calibrationRecord, 0, sizeof(CALIBRATION_RECORD_T) ); status = TRUE; } return status; } -/************************************************************************* - * @brief didCommandTimedout +/*********************************************************************//** + * @brief * The didCommandTimedout checks whether the a command whether RTC RAM or * EEPROM has timedout. If it has timedout, it sets the alarm and turns - * flag to TRUE - * @details - * Inputs : ALARM_ID_T (alarm), U08* state (pointer to the state) - * Outputs : BOOL - * @param none - * @return BOOL + * flag to TRUE. + * @details Inputs: none + * @details Outputs: alarm if command timed out + * @param alarm alarm ID + * @param state the state that the command timed out + * @return TRUE if a command timed out *************************************************************************/ static BOOL didCommandTimeout ( ALARM_ID_T alarm, U08* state ) { /* - * NOTE: The state is a pointer so it can cover both the self test + * NOTE: The state is a pointer so it can cover both the self-test * states and exec states */ BOOL status = FALSE; @@ -1721,15 +1751,13 @@ return status; } -/************************************************************************* - * @brief eraseDataLogSectors +/*********************************************************************//** + * @brief * The eraseDataLogSectors checks whether there are enough queues available - * and if there are, it schedules 3 erases to erase sectors 1,2, and 3 - * @details - * Inputs : none - * Outputs : BOOL - * @param none - * @return BOOL + * and if there are, it schedules 3 erases to erase sectors 1,2, and 3. + * @details Inputs: none + * @details Outputs: non + * @return TRUE if there are enough queues available *************************************************************************/ static BOOL eraseDataLogSectors ( void ) { @@ -1746,3 +1774,5 @@ return status; } + +/**@}*/