Description
Source
Call Graph
Start Line: 294
unsigned char INTEL_EraseSector(struct NorFlashInfo *NorFlashInfo, unsigned int sectorAddr)
{
unsigned int status;
unsigned int busAddress;
unsigned char busWidth;
unsigned char done = 0;
busWidth = NorFlash_GetDataBusWidth(pNorFlashInfo);
// Check the lock status is locked.
status = intel_GetBlockLockStatus(pNorFlashInfo, address);
if(( status & INTEL_LOCKSTATUS_LOCKED ) == INTEL_LOCKSTATUS_LOCKED){
intel_UnlockSector(pNorFlashInfo, address);
}
// Clear the status register first.
intel_ClearStatus(pNorFlashInfo);
busAddress = NorFlash_GetAddressInChip(pNorFlashInfo,address);
// Block erase operations are initiated by writing the Block Erase Setup command to the address of the block to be erased.
WriteCommand(busWidth, busAddress, INTEL_CMD_BLOCK_ERASE_1);
// Next, the Block Erase Confirm command is written to the address of the block to be erased.
WriteCommand(busWidth, busAddress, INTEL_CMD_BLOCK_ERASE_2);
// Status register polling
do {
status = intel_ReadStatus(pNorFlashInfo,address);
// Check if the device is ready.
if ((status & INTEL_STATUS_DWS) == INTEL_STATUS_DWS ) {
// Check if the erase block operation is completed.
if ((status & INTEL_STATUS_ES) == 0 ) {
done = 1;
}
else {
// check if VPP within acceptable limits during program or erase operation.
if ((status & INTEL_STATUS_VPPS) == INTEL_STATUS_VPPS ) {
return NorCommon_ERROR_CANNOTERASE;
}
// check if Block locked during program or erase, operation aborted.
else if ((status & INTEL_STATUS_BLS) == INTEL_STATUS_BLS ) {
return NorCommon_ERROR_CANNOTERASE;
}
}
}
} while (!done);
intel_Reset(pNorFlashInfo, 0);
return 0;
}