SPRADL4 January 2025 F29H850TU , F29H859TU-Q1
The Configure_Protection_Masks provides functionality to disable Write/Erase protection for any sector selected for EEPROM Emulation. This is done by calculating the appropriate Masks to pass to the Fapi_setupBankSectorEnable() function. It requires two parameters: a pointer to the selected Flash Sector numbers and the number of sectors used for emulation. For more information on the implementation of the Fapi_setupBankSectorEnable() function, see the F29H85x Flash API Reference Guide.
The return value of this function will be used to disable Write/Erase protection in Flash Sectors selected for EEPROM Emulation.
uint64_t Protection_Mask_Sectors = 0;
if (Num_EEPROM_Sectors > 1)
{
uint64_t Unshifted_Sectors;
uint8_t Shift_Amount;
if (Sector_Numbers[0] < 32 && Sector_Numbers[1] < 32)
{
Unshifted_Sectors = (uint64_t) 1 << Num_EEPROM_Sectors;
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= (Unshifted_Sectors << Sector_Numbers[0]);
}
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_t) 1 << Shift_Amount;
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= (Unshifted_Sectors << ((Sector_Numbers[0] - 32)/8));
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
}
else
{
Shift_Amount = ((Sector_Numbers[1] - 32)/8) + 1;
Unshifted_Sectors = (uint64_t) 1 << Shift_Amount;
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= Unshifted_Sectors;
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
Unshifted_Sectors = (uint64_t) 1 << ((32 - Sector_Numbers[0]) + 1);
Unshifted_Sectors -= 1;
Protection_Mask_Sectors |= (Unshifted_Sectors << Sector_Numbers[0]);
}
}
else {
if (Sector_Numbers[0] < 32)
{
Protection_Mask_Sectors |= ((uint64_t) 1 << Sector_Numbers[0]);
}
else
{
Protection_Mask_Sectors |= ((uint64_t) 1 << ((Sector_Numbers[0] - 32)/8));
Protection_Mask_Sectors = Protection_Mask_Sectors << 32;
}
}
return Protection_Mask_Sectors;