Index: NVDataMgmt.c =================================================================== diff -u -re1f9404958c9ddab9b004399fb0870e09e37512b -r8d336eee3efe362e9a690e40aadb16db2cf3d002 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision e1f9404958c9ddab9b004399fb0870e09e37512b) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 8d336eee3efe362e9a690e40aadb16db2cf3d002) @@ -29,8 +29,8 @@ #define QUEUE_MAX_SIZE 20U ///< Max queue size #define QUEUE_START_INDEX 0U ///< Queue start index -#define MIN_QUEUE_COUNT_FOR_DATA_LOG 3U ///< Min queue required for data log (3) -#define MIN_QUEUE_COUNT_FOR_SECTOR_0 4U ///< Min queue count needed to write all (4) records back in sector 0 +#define MIN_QUEUE_NEEDED_FOR_DATA_LOG 3U ///< Min queue required for data log (3) +#define MIN_QUEUE_NEEDED_FOR_SECTOR_0 4U ///< Min queue count needed to write all (4) records back in sector 0 // The clock frequency comes from HCLK_FREQ and it has to be rounded up to the // nearest number @@ -271,6 +271,7 @@ // Helper functions static BOOL didCommandTimeout ( ALARM_ID_T alarm, U08* state ); +static BOOL eraseDataLogSectors ( void ); // REMOVE THIS CODE //static U08 tempBufferForTest[5] = {'5', 'Y', 'I', 'D', 'P'}; @@ -296,6 +297,7 @@ NVDataMgmtSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; queueRearIndex = QUEUE_START_INDEX; queueFrontIndex = QUEUE_START_INDEX; + queueCount = 0; Fapi_initializeFlashBanks( ROUNDED_HCLK_FREQ ); Fapi_setActiveFlashBank( Fapi_FlashBank7 ); } @@ -453,7 +455,7 @@ BOOL status = FALSE; U32 availableQueue = getAvailableQueueCount(); - if ( availableQueue >= MIN_QUEUE_COUNT_FOR_DATA_LOG ) + if ( availableQueue >= MIN_QUEUE_NEEDED_FOR_DATA_LOG ) { enqueue( NVDATAMGMT_READ, NVDATAMGMT_EEPROM, 0, 0, buffer, length ); status = TRUE; @@ -489,6 +491,21 @@ } /************************************************************************* + * @brief getTreatmentTime + * The getTreatmentTime returns the total number treatment hours of the + * HD device + * @details + * Inputs : none + * Outputs : U32 + * @param none + * @return U32 + *************************************************************************/ +U32 getTreatmentTime ( void ) +{ + return treatmentTimeRecord.treatmentTime; +} + +/************************************************************************* * @brief setWaterConsumption * The setWaterConsumption sets a queue job to write the amount of water * that has been consumed in DG @@ -1101,10 +1118,10 @@ // The log header will be set to full by having the record count be at // maximum number of counts (1536 in this case) and the read index be a 0 // of the beginning of the log sectors - /*logRecord.logHeader.recordCount = MAX_NUM_OF_DATA_LOGS_IN_SECTOR3; + logRecord.logHeader.recordCount = MAX_NUM_OF_DATA_LOGS_IN_SECTOR3; logRecord.logHeader.nextReadIndex = 0; logRecord.logHeader.nextReadIndex = 0; - //logRecord.logHeader.isHdrCorrupted = TRUE; */ + logRecord.logHeader.isHdrCorrupted = TRUE; } // Check CRC for manufacturing record calcCRC = crc16 ( (U08*)&mfgRecord.mfgData, sizeof(MFG_DATA_T) ); @@ -1505,12 +1522,16 @@ // Check if the read index has been wrapped to 0 and the flag is for data corruption // is true, the record count will be 0 and the data corruption flag will be false for // normal operations - /*if ( logRecord.logHeader.nextReadIndex == 0 && - logRecord.logHeader.isHdrCorrupted == TRUE ) + if ( logRecord.logHeader.nextReadIndex == 0 && logRecord.logHeader.isHdrCorrupted == TRUE ) { logRecord.logHeader.recordCount = 0; - logRecord.logHeader.isHdrCorrupted = FALSE; - }*/ + // If there are enough queues to schedule 3 erases + // the flag will be turned off + if ( eraseDataLogSectors () ) + { + logRecord.logHeader.isHdrCorrupted = FALSE; + } + } logRecord.crc = crc16 ( (U08*)&logRecord.logHeader, sizeof(LOG_HEADER_T) ); // Update the log record @@ -1693,7 +1714,7 @@ BOOL status = FALSE; U32 currentQueueCount = getAvailableQueueCount(); - if ( currentQueueCount >= MIN_QUEUE_COUNT_FOR_SECTOR_0 ) + if ( currentQueueCount >= MIN_QUEUE_NEEDED_FOR_SECTOR_0 ) { // Sector 0 must be erased first enqueue ( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR0_START_ADDRESS, 0, 0, 0 ); @@ -1735,3 +1756,29 @@ return status; } + +/************************************************************************* + * @brief eraseDataLogSectors + * 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 + *************************************************************************/ +static BOOL eraseDataLogSectors ( void ) +{ + BOOL status = FALSE; + U32 availableQueue = getAvailableQueueCount(); + + if ( availableQueue >= MIN_QUEUE_NEEDED_FOR_DATA_LOG ) + { + enqueue( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR1_START_ADDRESS, 0, 0, 0 ); + enqueue( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR2_START_ADDRESS, 0, 0, 0 ); + enqueue( NVDATAMGMT_ERASE_SECTOR, NVDATAMGMT_EEPROM, BANK7_SECTOR3_START_ADDRESS, 0, 0, 0 ); + status = TRUE; + } + + return status; +}