📄 evm5509_flash_erase.c
字号:
/*
* Copyright 2002 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* ======== evm5509_flash_erase.c ========
* EVM5509_FLASH_erase() implementation
*/
#include <std.h>
#include <csl.h>
#include <evm5509.h>
#include <evm5509_flash.h>
#define EVM5509_FLASH_SECTORS 11
/* Constant table containing end address of each sector */
static Uint32 sector_end[EVM5509_FLASH_SECTORS] = {
EVM5509_FLASH_BASE + 0x007fff, /* Sector 0 */
EVM5509_FLASH_BASE + 0x00ffff, /* Sector 1 */
EVM5509_FLASH_BASE + 0x017fff, /* Sector 2 */
EVM5509_FLASH_BASE + 0x01ffff, /* Sector 3 */
EVM5509_FLASH_BASE + 0x027fff, /* Sector 4 */
EVM5509_FLASH_BASE + 0x02ffff, /* Sector 5 */
EVM5509_FLASH_BASE + 0x037fff, /* Sector 6 */
EVM5509_FLASH_BASE + 0x03bfff, /* Sector 7 */
EVM5509_FLASH_BASE + 0x03cfff, /* Sector 8 */
EVM5509_FLASH_BASE + 0x03dfff, /* Sector 9 */
EVM5509_FLASH_BASE + 0x03ffff /* Sector 10 */
};
/* Erase a segment of Flash memory */
void EVM5509_FLASH_erase(Uint32 start, Uint32 length)
{
Int16 i;
Uint32 sector_base, end;
/* Calculate extents of range to erase */
end = start + length - 1;
/* Walk through each sector, erase any sectors within range */
sector_base = EVM5509_FLASH_BASE;
for (i = 0; i < EVM5509_FLASH_SECTORS; i++)
{
if ((start <= sector_base) && (sector_end[i] <= end))
{
/* Start sector erase sequence */
EVM5509_mset(EVM5509_FLASH_CTL555, 0xaa);
EVM5509_mset(EVM5509_FLASH_CTL2AA, 0x55);
EVM5509_mset(EVM5509_FLASH_CTL555, 0x80);
EVM5509_mset(EVM5509_FLASH_CTL555, 0xaa);
EVM5509_mset(EVM5509_FLASH_CTL2AA, 0x55);
/* Start erase at sector address */
EVM5509_mset(sector_end[i], 0x30);
/* Wait for erase to complete */
while (1)
if (EVM5509_mget(sector_end[i]) & 0x80)
break;
/* Put back in read mode */
EVM5509_mset(EVM5509_FLASH_BASE, 0xf0);
}
/* Advance to next sector */
sector_base = sector_end[i] + 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -