/*************************************************************************************************** ** Function name : NVMHand_Init ** ** Description : To initialize the FEE module and read the data into memory ** ** Parameter index : None ** ** Return value : None ** ** Remarks : None ** ***************************************************************************************************/ uint32_t NVMHand_Init(void) { Std_ReturnType Uc_Result = (Std_ReturnType)E_OK; /* Variable to hold the return value of read function */ TI_FeeJobResultType Enm_JobResult; /* Variable to hold the last FEE operation result */ TI_FeeModuleStatusType Enm_Status; /* Variable to hold the status of FEE */ uint16_t Us_CurrBlkIdx; /* Variable to hold the block number */ /* Initialize the TI FEE. This will create Virtual sectors, initialize global variables etc.*/ TI_Fee_Init(); /* Wait till the FEE is in IDLE State */ do { TI_Fee_MainFunction(); Delay_Us(100U); /* 100 micro sec*/ Enm_Status = TI_Fee_GetStatus(NVMHAND_0U); } while (Enm_Status != IDLE); /* Check and fix possible FEE initialization errors */ Uc_Result = (uint8_t)NVMHand_ManageError(0); if (Uc_Result == (Std_ReturnType)E_OK) { for (Us_CurrBlkIdx = NVMHAND_0U; Us_CurrBlkIdx < TI_FEE_NUMBER_OF_BLOCKS; Us_CurrBlkIdx++) { /* Read block data into the respective buffer */ Uc_Result = TI_Fee_ReadSync((Us_CurrBlkIdx + NVMHAND_1U), NVMHAND_0U, St_ArrBlkInfo[Us_CurrBlkIdx].Ptr_BlkBuf, St_ArrBlkInfo[Us_CurrBlkIdx].Us_BlkSz); do { TI_Fee_MainFunction(); Delay_Us(10U); /* 10 micro sec*/ Enm_Status = TI_Fee_GetStatus(NVMHAND_0U); }while(Enm_Status != IDLE); if (Uc_Result == (Std_ReturnType)E_OK) { Enm_JobResult = TI_Fee_GetJobResult(NVMHAND_0U); if (Enm_JobResult == JOB_OK) { /* Copy NVM data into the respective data fields */ St_ArrBlkInfo[Us_CurrBlkIdx].Ptr_FnUpdtNVMReadBuf(); } else { if (Enm_JobResult != BLOCK_INVALID) { /* Operation failed */ Uc_Result = (Std_ReturnType)E_NOT_OK; } else { St_ArrBlkInfo[Us_CurrBlkIdx].Ptr_FnSetdefaultvalue(); } } } if (Uc_Result == (Std_ReturnType)E_NOT_OK) { break; } } } /* If all the blocks were successfully read, set the flag to commence write operation */ if (Us_CurrBlkIdx >= TI_FEE_NUMBER_OF_BLOCKS) { Ucs_WriteReq = NVMHAND_1U; NvmRd_Complete = TRUE; } return (uint32_t)Uc_Result; } /*************************************************************************************************** ** Function name : NVMHand_Write ** ** Description : write the data into memory ** ** Parameter index : None ** ** Return value : None ** ** Remarks : None ** ***************************************************************************************************/ uint32_t NVMHand_Write(uint32 NVM_WRITE) { Std_ReturnType Uc_Result = (Std_ReturnType)E_OK; /* Variable to hold the return value of the write function */ TI_FeeJobResultType Enm_JobResult; /* Variable to hold the last job result */ static uint16 Us_CurrBlkIdx = NVMHAND_0U; /* Variable to hold the current block index */ TI_FeeModuleStatusType Enm_Status; /* Variable to hold the status of FEE */ static Uc_BlkWrFailCnt = NVMHAND_0U; if (Ucs_WriteReq == NVMHAND_1U) { /* Update the RAM Buffer with the latest data */ St_ArrBlkInfo[Us_CurrBlkIdx].Ptr_FnUpdtNVMWriteBuf(); Ucs_WriteReq = NVMHAND_0U; } /* Set the FEE Bank (Bank 7) as the active bank */ (void)Fapi_setActiveFlashBank(Fapi_FlashBank7); /* Write the block into the EEP Synchronously */ Uc_Result = TI_Fee_WriteSync((Us_CurrBlkIdx + NVMHAND_1U), St_ArrBlkInfo[Us_CurrBlkIdx].Ptr_BlkBuf); do { TI_Fee_MainFunction(); Delay_Us(10U); /* 100 micro sec*/ Enm_Status = TI_Fee_GetStatus(NVMHAND_0U); }while(Enm_Status != IDLE); if (Uc_Result == (Std_ReturnType)E_OK) { Enm_JobResult = TI_Fee_GetJobResult(NVMHAND_0U); if(Enm_JobResult != JOB_OK) { /* Operation failed */ Uc_Result = (Std_ReturnType)E_NOT_OK; } } if(Uc_Result == (Std_ReturnType)E_NOT_OK) { Uc_BlkWrFailCnt++; if(Uc_BlkWrFailCnt >= 10u) { } } /* If the operation is successful, proceed to write the next block */ if (Uc_Result == (Std_ReturnType)E_OK) { if((Us_CurrBlkIdx == (TI_FEE_NUMBER_OF_BLOCKS - NVMHAND_1U))&&(TRUE == SleepModeTriggered)) { NVM_FCMAgingCntWrSucessful = TRUE; // NVMHAND_WrBlkAvailable = 0; } Us_CurrBlkIdx = ((Us_CurrBlkIdx + NVMHAND_1U) % TI_FEE_NUMBER_OF_BLOCKS); Ucs_WriteReq = NVMHAND_1U; } return (uint32_t)Uc_Result; }