Index: NVDataMgmt.c =================================================================== diff -u -r2f7355279ef1d1330623472538a4ff2150a929ad -r6c744022aca4f4ec8c3bcf581da066487db3aa82 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 2f7355279ef1d1330623472538a4ff2150a929ad) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 6c744022aca4f4ec8c3bcf581da066487db3aa82) @@ -77,7 +77,7 @@ typedef enum NVDataMgmt_Self_Test_States { NVDATAMGMT_SELF_TEST_STATE_START = 0, - NVDATAMGMT_SELF_TEST_STATE_ENABLE_EEPROM, // TODO ADD TO AE + NVDATAMGMT_SELF_TEST_STATE_ENABLE_EEPROM, NVDATAMGMT_SELF_TEST_STATE_READ_BOOTLOADER_FLAG, NVDATAMGMT_SELF_TEST_STATE_READ_LOG_RECORD, NVDATAMGMT_SELF_TEST_STATE_READ_TREATMENT_TIME, @@ -204,7 +204,6 @@ static NVDATAMGMT_SELF_TEST_STATE_T NVDataMgmtSelfTestState = NVDATAMGMT_SELF_TEST_STATE_START; static NVDATAMGMT_EXEC_STATE_T NVDataMgmtExecState = NVDATAMGMT_EXEC_STATE_WAIT_FOR_POST; static SELF_TEST_STATUS_T NVDataMgmtSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; -static BOOL isServiceOnEntry = TRUE; static U32 bootloaderFlag = 0; static BOOL hasLogRecordCRCFailed = FALSE; static BOOL hasCommandFailed = FALSE; @@ -326,11 +325,69 @@ calibrationRecord.calData = data; calibrationRecord.crc = crc16 ( (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); + // The entire sector 0 must be erased and re-written again BOOL 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 : U08* (buffer) + * Outputs : none + * @param none + * @return none + *************************************************************************/ +void getCalibrationData ( U08* buffer ) +{ + memcpy ( buffer, (U08*)&calibrationRecord.calData, sizeof(CALIBRATION_DATA_T) ); +} + +/************************************************************************* + * @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 + * @details + * Inputs : SERVICE_DATA_T (data) + * Outputs : BOOL + * @param none + * @return BOOL + *************************************************************************/ +BOOL setServiceDate ( SERVICE_DATA_T data ) +{ + BOOL status = FALSE; + serviceRecord.serviceData = data; + serviceRecord.crc = crc16 ( (U08*)&serviceRecord.serviceData, sizeof(SERVICE_DATA_T) ); + + if ( !isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, SERVICE_DATE_START_ADDRESS, + (U08*)&serviceRecord, 0, sizeof(SERVICE_RECORD_T) ); + status = TRUE; + } + + 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 : U08* (buffer) + * Outputs : none + * @param none + * @return none + *************************************************************************/ +void getServiceDate ( U08* buffer ) +{ + memcpy ( buffer, (U08*)&serviceRecord.serviceData, sizeof(SERVICE_DATA_T) ); +} + +/************************************************************************* * @brief writeLogData * 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 @@ -656,9 +713,11 @@ if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { + // Enable was successful, Request a read for bootloader if ( getRTCRAMState() == RTC_RAM_STATE_READY ) { readFromRAM( BOOTLOADER_FLAG_ADDRESS, BOOTLOADER_FLAG_LENGTH_BYTES ); + // Get the time to check for timeout currentTime = getMSTimerCount(); } state = NVDATAMGMT_SELF_TEST_STATE_READ_BOOTLOADER_FLAG; @@ -681,15 +740,12 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_BOOTLOADER_FLAG; - /* if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM( BOOTLOADER_FLAG_ADDRESS, BOOTLOADER_FLAG_LENGTH_BYTES ); - //currentTime = getMSTimerCount(); - isServiceOnEntry= FALSE; - }*/ + // If the read for bootloader is done, read it if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM( (U08*)&bootloaderFlag, BOOTLOADER_FLAG_LENGTH_BYTES ); +// If the device is HD, read treatment time, +// If the device is DG, read water consumption #ifdef _HD_ if ( getRTCRAMState() == RTC_RAM_STATE_READY ) { @@ -735,22 +791,18 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_TREATMENT_TIME; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM ( HD_TREATMENT_TIME_ADDRESS, sizeof(TREATMENT_TIME_RECORD_T) ); - isServiceOnEntry= FALSE; - }*/ + // If the RTC RAM is ready, read the results if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM ( (U08*)&treatmentTimeRecord, sizeof(TREATMENT_TIME_RECORD_T) ); + // If the RAM is ready, request a read for the log records (RAM) if ( getRTCRAMState() == RTC_RAM_STATE_READY ) { readFromRAM ( LOG_RECORD_START_ADDRESS, sizeof(LOG_RECORD_T) ); state = NVDATAMGMT_SELF_TEST_STATE_READ_LOG_RECORD; } } - /*else if ( didTimeout( currentTime, COMMAND_TIME_OUT ) ) { Fapi_StatusType status; @@ -777,11 +829,7 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_WATER_CONSUMPTION; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM ( DG_CONSUMED_WATER_ADDRESS, sizeof(WATER_CONSUMPTION_RECORD_T) ); - isServiceOnEntry= FALSE; - }*/ + // If the RAM is ready, request a read for water consumption if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM ( (U08*)&waterConsumptionRecord, sizeof(WATER_CONSUMPTION_RECORD_T) ); @@ -808,15 +856,12 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_LOG_RECORD; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM ( LOG_RECORD_START_ADDRESS, sizeof(LOG_RECORD_T) ); - isServiceOnEntry= FALSE; - }*/ + // If the RAM is in Idle, read the log records if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM ( (U08*)&logRecord, sizeof(LOG_RECORD_T) ); + // Get ready for reading the manufacturing record Fapi_doMarginRead ( (U32*)BANK7_SECTOR0_START_ADDRESS, (U32*)&mfgRecord, sizeof(MFG_RECORD_T), Fapi_NormalRead ); state = NVDATAMGMT_SELF_TEST_STATE_READ_MFG_RECORD; @@ -838,14 +883,11 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadMfgRecord ( void ) { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_MFG_RECORD; - /*if ( isServiceOnEntry ) - { - Fapi_doMarginRead ( (U32*)BANK7_SECTOR0_START_ADDRESS, (U32*)&mfgRecord, - sizeof(MFG_RECORD_T), Fapi_NormalRead ); - isServiceOnEntry = FALSE; - }*/ + + // Wait for the read from EEPROM to be successful if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { + // Send the read command for calibration record Fapi_doMarginRead ( (U32*)CALIBRATION_RECORD_START_ADDRESS, (U32*)&calibrationRecord, sizeof(CALIBRATION_RECORD_T), Fapi_NormalRead ); state = NVDATAMGMT_SELF_TEST_STATE_READ_CAL_RECORD; @@ -868,12 +910,8 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_CAL_RECORD; - /*if ( isServiceOnEntry ) - { - Fapi_doMarginRead ( (U32*)CALIBRATION_RECORD_START_ADDRESS, (U32*)&calibrationRecord, - sizeof(CALIBRATION_RECORD_T), Fapi_NormalRead ); - isServiceOnEntry = FALSE; - }*/ + // If the EEPROM read was successful, request a read from RAM to + // read the service record if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { if ( getRTCRAMState() == RTC_RAM_STATE_READY ) @@ -900,11 +938,6 @@ { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_READ_SERVICE_RECORD; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM( SERVICE_DATE_START_ADDRESS, sizeof(SERVICE_RECORD_T) ); - isServiceOnEntry= FALSE; - }*/ if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM ( (U08*)&serviceRecord, sizeof(SERVICE_RECORD_T) ); @@ -1020,14 +1053,15 @@ mytest.externalBuffer = readBufferForTest; //writeLogData ( (U08*)&logData, 32 ); - readLogData ( &mytest, sizeof(readBufferForTest) ); + //readLogData ( &mytest, sizeof(readBufferForTest) ); //calTest.occSensorOffset = 3.4; //calTest.tempSensorOffset = 13.2; //setCalibrationData(calTest); char a[10] = {'0','3','-', '0','3','-','2','0','2','0'};; memcpy(service.currentServiceDate, a, 10); memcpy(service.nextServiceDate, a, 10); + //setServiceDate(service); //setTreatmentTime(750); /*MFG_DATA_T test; @@ -1123,16 +1157,9 @@ { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_WRITE_TO_EEPROM; - /*if ( isServiceOnEntry ) - { - Fapi_issueProgrammingCommand ( currentJob.startAddress, currentJob.buffer, - currentJob.length, 0x00, 0, Fapi_DataOnly ); - isServiceOnEntry = FALSE; - }*/ if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - //isServiceOnEntry = TRUE; } return state; @@ -1152,20 +1179,10 @@ { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_READ_FROM_EEPROM; - /*if ( isServiceOnEntry ) - { - Fapi_doMarginRead ( currentJob.startAddress, - (U32*)currentJob.externalAddress->externalBuffer, - currentJob.length, Fapi_NormalRead ); - // Change the status to in progress until the read operation is done - currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; - isServiceOnEntry = FALSE; - }*/ if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { currentJob.externalAddress->status = NVDATAMGMT_READ_COMPLETE; state = NVDATAMGMT_EXEC_STATE_IDLE; - //isServiceOnEntry = TRUE; } return state; @@ -1185,15 +1202,9 @@ { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_ERASE_EEPROM; - /*if ( isServiceOnEntry ) - { - Fapi_issueAsyncCommandWithAddress ( Fapi_EraseSector, currentJob.startAddress ); - isServiceOnEntry = FALSE; - }*/ if ( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - //isServiceOnEntry = TRUE; } return state; @@ -1214,16 +1225,9 @@ { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_WRITE_TO_RTC; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - writeToRAM ( (U32)( currentJob.startAddress ), currentJob.buffer, - currentJob.length ); - isServiceOnEntry= FALSE; - }*/ if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { state = NVDATAMGMT_EXEC_STATE_IDLE; - //isServiceOnEntry = TRUE; } return state; @@ -1244,18 +1248,14 @@ static NVDATAMGMT_EXEC_STATE_T handleExecReadFromRAMState ( void ) { NVDATAMGMT_EXEC_STATE_T state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; - /*if ( isServiceOnEntry && getRTCRAMState() == RTC_RAM_STATE_READY ) - { - readFromRAM( (U32)( currentJob.startAddress ), currentJob.length ); - isServiceOnEntry= FALSE; - }*/ + if ( getRTCRAMStatus() == RTC_RAM_STATUS_IDLE ) { getDataFromRAM( currentJob.externalAddress->externalBuffer, currentJob.length ); currentJob.externalAddress->status = NVDATAMGMT_READ_COMPLETE; state = NVDATAMGMT_EXEC_STATE_IDLE; - //isServiceOnEntry = TRUE; } + return state; } @@ -1323,7 +1323,7 @@ // Modulus is 0 so it is at any of the edges if ( modulus == 0 ) { - // If full + // If full (1536) // 1. set readIndexChange = +512 // 2. set recordCountchange = -512 if ( logRecord.logHeader.recordCount >= MAX_NUM_OF_DATA_LOGS_IN_SECTOR3 - 1 ) Index: NVDataMgmt.h =================================================================== diff -u -r2f7355279ef1d1330623472538a4ff2150a929ad -r6c744022aca4f4ec8c3bcf581da066487db3aa82 --- NVDataMgmt.h (.../NVDataMgmt.h) (revision 2f7355279ef1d1330623472538a4ff2150a929ad) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 6c744022aca4f4ec8c3bcf581da066487db3aa82) @@ -83,9 +83,9 @@ void getCalibrationData ( U08* buffer ); -BOOL setServiceDate ( SERVICE_DATA_T data ); // TODO ADD TO AE +BOOL setServiceDate ( SERVICE_DATA_T data ); -void getServiceDate ( U08* buffer ); // TODO ADD TO AE +void getServiceDate ( U08* buffer ); BOOL setTreatmentTime ( U32 mins );