Description
Source
Call Graph
Start Line: 319
unsigned char AMD_EraseChip(struct NorFlashInfo *pNorFlashInfo)
{
unsigned int pollingData;
unsigned char busWidth;
unsigned int address;
unsigned char done = 0;
busWidth = NorFlash_GetDataBusWidth(pNorFlashInfo);
//Programming is a six-bus-cycle operation.
// The erase command sequence is initiated by writing two unlock write cycles.
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_1),
AMD_CMD_UNLOCK_1);
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_2),
AMD_CMD_UNLOCK_2);
// Followed by the program set-up command.
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_1),
AMD_CMD_ERASE_SETUP);
// Two additional unlock cycles are written.
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_1),
AMD_CMD_UNLOCK_1);
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_2),
AMD_CMD_UNLOCK_2);
// Then followed by the chip erase command.
WriteCommand(busWidth ,
NorFlash_GetByteAddressInChip(pNorFlashInfo, AMD_OFFSET_UNLOCK_1),
AMD_CMD_ERASE_CHIP);
address = NorFlash_GetByteAddressInChip(pNorFlashInfo, 0);
// Data polling
do {
ReadRawData(busWidth , address, (unsigned char*)&pollingData);
// Check if the chip erase algorithm is completed.
if ((pollingData & AMD_POLLING_DQ7) == AMD_POLLING_DQ7 ) {
// Erase operation successful. Device in read mode.
done = 1;
}
else {
// When the time-out period is complete, DQ3 switches from a ¡°0¡± to a ¡°1.¡±
if (pollingData & AMD_POLLING_DQ3 ) {
return NorCommon_ERROR_CANNOTERASE;
}
// check if chip earse algrithm exceeded timing limits
if (pollingData & AMD_POLLING_DQ5 ) {
// I/O should be rechecked.
ReadRawData(busWidth , address, (unsigned char*)&pollingData);
if ((pollingData & AMD_POLLING_DQ7) == AMD_POLLING_DQ7 ){
// Erase operation successful. Device in read mode.
done = 1;
}
else {
// Erase operation not successful, write reset command.
amd_Reset(pNorFlashInfo, 0);
return NorCommon_ERROR_CANNOTERASE;
}
}
}
} while (!done);
return 0;
}