ZHCADD5A November 2023 – April 2024 TMS320F28P650DH , TMS320F28P650DK , TMS320F28P650SH , TMS320F28P650SK , TMS320F28P659DH-Q1 , TMS320F28P659DK-Q1 , TMS320F28P659SH-Q1
EEPROM_UpdatePageData() 函数的功能是更新 EEPROM 页数据。此函数由 EEPROM_Write() 函数调用。
为了实现这一目标,需要采取以下步骤:
// Clears status of previous Flash operation
ClearFSMStatus();
Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTA, WE_Protection_A_Mask);
Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTB, WE_Protection_B_Mask);
// Variable for page offset
// (first write position has offset of 2 (64 bits),
// second has offset of 4 (128 bits), etc.)
uint32 Page_Offset = 4 + (2 * i);
// Program data located in Write_Buffer to current page
oReturnCheck = Fapi_issueProgrammingCommand((uint32*) Page_Pointer + Page_Offset, Write_Buffer + (i*4), 4, 0, 0, Fapi_AutoEccGeneration);
// Wait for completion and check for any programming errors
EEPROM_CheckStatus(&oReturnCheck);
以下参数被传递至闪存 API 以进行编程。
使用 Fapi_AutoEccGeneration 模式时,第四个和第五个参数为零。有关更多详细信息,请参阅 TMS320F28P65x 闪存 API 版本 3.02.00.00 参考指南。
如果编程成功,则会更新当前页面的页面状态并清除 Empty_EEPROM 标志。代码如下所示:
if(oReturnCheck == Fapi_Status_Success) { // Set Page Status to Current Page Page_Status[0] = CURRENT_PAGE; Page_Status[1] = CURRENT_PAGE; Page_Status[2] = CURRENT_PAGE; Page_Status[3] = CURRENT_PAGE; Fapi_setupBankSectorEnable( FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTA, WE_Protection_A_Mask); Fapi_setupBankSectorEnable( FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTB, WE_Protection_B_Mask); oReturnCheck = Fapi_issueProgrammingCommand((uint32*)Page_Pointer, Page_Status, 4, 0, 0, Fapi_AutoEccGeneration); // Wait for completion and check for any programming errors EEPROM_CheckStatus(&oReturnCheck); Empty_EEPROM = 0; }
成功写入后,该函数会检查是否需要擦除非活动 EEPROM 单元。如果需要,则该函数调用 EEPROM_Erase,清除标志并重新配置 W/E 保护掩码。在调用擦除之前发出用于设置空白检查的标志。擦除非活动单元的标志在 EEPROM_GetValid_Bank 中设置。
if (Erase_Inactive_Unit)
{
// Erase the inactive (full) EEPROM Bank
Erase_Blank_Check = 1;
EEPROM_Erase();
Erase_Inactive_Unit = 0;
// Re-configure Write/Erase Protection Masks for active EEPROM Bank
uint64 WE_Protection_AB_Mask = Configure_Protection_Masks(
FIRST_AND_LAST_SECTOR[EEPROM_ACTIVE_UNIT], NUM_EEPROM_SECTORS);
WE_Protection_A_Mask = 0xFFFFFFFF ^ (uint32)WE_Protection_AB_Mask;
WE_Protection_B_Mask = 0x00000FFF ^ WE_Protection_AB_Mask >> 32;
}