//***************************************************************************** // //! Save sector protection to make it permanent // //***************************************************************************** uint32_t FlashProtectionSave(uint32_t ui32SectorAddress) { uint32_t ui32ErrorReturn; uint32_t ui32SectorNumber; uint32_t ui32CcfgSectorAddr; uint32_t ui32ProgBuf; ui32ErrorReturn = FAPI_STATUS_SUCCESS; // // Check the arguments. // ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet())); ASSERT((ui32SectorAddress & (FlashSectorSizeGet() - 1)) == 00); if(FlashProtectionGet(ui32SectorAddress) == FLASH_WRITE_PROTECT) { // // Find sector number for specified sector. // ui32SectorNumber = (ui32SectorAddress - FLASHMEM_BASE) / FlashSectorSizeGet(); ui32CcfgSectorAddr = FLASHMEM_BASE + FlashSizeGet() - FlashSectorSizeGet(); // // Adjust CCFG address to the 32-bit CCFG word holding the // protect-bit for the specified sector. // ui32CcfgSectorAddr += (((ui32SectorNumber >> 5) * 4) + CCFG_OFFSET_SECT_PROT); // // Find value to program by setting the protect-bit which // corresponds to specified sector number, to 0. // Leave other protect-bits unchanged. // ui32ProgBuf = (~(1 << (ui32SectorNumber & 0x1F))) & *(uint32_t *)ui32CcfgSectorAddr; ui32ErrorReturn = FlashProgram((uint8_t*)&ui32ProgBuf, ui32CcfgSectorAddr, CCFG_SIZE_SECT_PROT); }
//***************************************************************************** // //! Get sector protection // //***************************************************************************** uint32_t FlashsafeProtectionGet(uint32_t ui32SectorAddress) { uint32_t ui32SectorProtect; // // Check the arguments. // ASSERT(ui32SectorAddress <= (FLASHMEM_BASE + FlashsafeSizeGet() - FlashsafeSectorSizeGet())); ASSERT((ui32SectorAddress & (FlashsafeSectorSizeGet() - 1)) == 00); if(FlashsafeSMPHTryAcquire()) { ui32SectorProtect = FlashProtectionGet(ui32SectorAddress); FlashsafeSMPHRelease(); return(ui32SectorProtect); } return(FLASHSAFE_ACCESS_DENIED); }