ZHCAEX4 January 2025 F29H850TU , F29H859TU-Q1
Configure_Protection_Masks 提供了为选择用于 EEPROM 仿真的任何扇区禁用写入/擦除保护的功能。这是通过计算要传递到 Fapi_setupBankSectorEnable 函数的适当掩码来完成的。该函数需要两个参数,即指向所选闪存扇区编号的指针和要仿真的闪存扇区的数量。有关 Fapi_setupBankSectorEnable 函数实现的更多信息,请参阅 F29H85x 闪存 API 参考指南。
该函数的返回值用于禁用为 EEPROM 仿真选择的闪存扇区中的写入/擦除保护。
uint64 Protection_Mask_Sectors = 0;
if (Num_EEPROM_Sectors > 1)
{
uint64_t Unshifted_Sectors;
uint8_t Shift_Amount;
// All sectors use Mask A
if (Sector_Numbers[0] < 32 && Sector_Numbers[1] < 32)
{
// Push 1 out to 1 past the number of sectors
Unshifted_Sectors = (uint64_t) 1 << Num_EEPROM_Sectors;
// Subtract 1 --> now we have all 1s for the sectors we want
Unshifted_Sectors -= 1;
// Shift over by start location and OR with master
Protection_Mask_Sectors |= (Unshifted_Sectors << Sector_Numbers[0]);
}
// All sectors use Mask B
else if (Sector_Numbers[0] > 31 && Sector_Numbers[1] > 31)
{
Shift_Amount = ((Sector_Numbers[1] - 32) / 8) - ((Sector_Numbers[0] - 32) / 8) + 1;
Unshifted_Sectors = (uint64) 1 << Shift_Amount;
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= (Unshifted_Sectors << ((Sector_Numbers[0] - 32)/8));
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
}
// Mix of Masks A and B
else
{
// Configure Mask B
Shift_Amount = ((Sector_Numbers[1] - 32)/8) + 1;
Unshifted_Sectors = (uint64) 1 << Shift_Amount;
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= Unshifted_Sectors;
// Zero out the bottom half so we can configure Mask A
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
// Configure Mask A
Unshifted_Sectors = (uint64) 1 << ((32 - Sector_Numbers[0]) + 1);
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= (Unshifted_Sectors << Sector_Numbers[0]);
}
}
// Only using 1 sector
else
{
// Mask A
if(Sector_Numbers[0] < 32)
{
Protection_Mask_Sectors |= ((uint64) 1 << Sector_Numbers[0]);
}
// Mask B
else
{
Protection_Mask_Sectors |= ((uint64) 1 << ((Sector_Numbers[0] - 32)/8));
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
}
}
return Protection_Mask_Sectors;