?? intelflash.c
字號:
/*
* Copyright (C) 2001, Spectrum Digital, Inc. All Rights Reserved.
*/
#include "5509.h"
#include "util.h"
#include "data.h"
#define FLASH_NORMALBLOCKS 31
#define FLASH_NORMALBLOCKSIZE 0x8000
#define FLASH_PARAMBLOCKS 8
#define FLASH_PARAMBLOCKSIZE 0x1000
#define FLASH_MFGID 0x0089
#define FLASH_DEVID 0x8890
#define TIMEOUT_PROGRAM 200
#define TIMEOUT_ERASE 5000000
#define CMD_READ_ARRAY 0x00ff // Intel commands
#define CMD_READ_ID 0x0090
#define CMD_READ_STATUS 0x0070
#define CMD_CLEAR_STATUS 0x0050
#define CMD_WRITE_ARRAY 0x0040
#define CMD_ALTWRITE_ARRAY 0x0010
#define CMD_ERASE_ARRAY 0x0020
#define CMD_CONFIRM_ERASE 0x00d0
#define CMD_ERASE_SUSPEND 0x00b0
#define BIT_R 0x0001 // Intel status
#define BIT_BLS 0x0002
#define BIT_PSS 0x0004
#define BIT_VPPS 0x0008
#define BIT_PS 0x0010
#define BIT_ES 0x0020
#define BIT_ESS 0x0040
#define BIT_WSMS 0x0080
int Flash_Poll(unsigned long addr, unsigned short mask, unsigned short maskval, unsigned long usectimeout)
{
unsigned short i, status;
for (i = 0; i < usectimeout; i++)
{
// Read location
status = Logic_ReadFlash(addr);
// Check for bit
if ((status & mask) == maskval)
return 1;
// Wait 1 usec before trying again
SWDelayUsec(1);
}
// Return 0 if timeout
return 0;
}
unsigned short Flash_CheckMfgId()
{
unsigned short mfgid, devid;
// Issue Read ID command
Logic_WriteFlash((unsigned long)0, CMD_READ_ID);
// Read IDs
mfgid = Logic_ReadFlash((unsigned long)0);
devid = Logic_ReadFlash((unsigned long)1);
// Check IDs
if ((mfgid != FLASH_MFGID) || (devid != FLASH_DEVID))
return ERR_FLASH_MFGID;
return 0;
}
unsigned short Flash_EraseBlocks()
{
Logic_WriteFlash(0x00020000, CMD_CLEAR_STATUS);
Logic_WriteFlash(0x00020000, CMD_ERASE_ARRAY);
Logic_WriteFlash(0x00020000, CMD_CONFIRM_ERASE);
if (!Flash_Poll(0x00020000, BIT_WSMS, BIT_WSMS, TIMEOUT_ERASE))
return ERR_FLASH_ERASE;
Logic_WriteFlash(0x00028000, CMD_CLEAR_STATUS);
Logic_WriteFlash(0x00028000, CMD_ERASE_ARRAY);
Logic_WriteFlash(0x00028000, CMD_CONFIRM_ERASE);
if (!Flash_Poll(0x00028000, BIT_WSMS, BIT_WSMS, TIMEOUT_ERASE))
return ERR_FLASH_ERASE;
return 0;
}
unsigned short Flash_TestBlock1(unsigned long addr, unsigned long size)
{
unsigned short pattern;
unsigned long i;
for(i = 0; i < size; i++)
{
pattern = (*((unsigned short *)(0x8003+i)))& 0xffff;
Logic_WriteFlash(addr, CMD_CLEAR_STATUS);
Logic_WriteFlash(addr, CMD_WRITE_ARRAY);
Logic_WriteFlash(addr, pattern);
if (!Flash_Poll(addr, BIT_WSMS, BIT_WSMS, TIMEOUT_PROGRAM))
return ERR_FLASH_PROGRAM;
Logic_WriteFlash(addr, CMD_READ_ARRAY);
if (pattern != Logic_ReadFlash(addr))
{
return ERR_FLASH_VERIFY;
}
addr++;
}
return 0;
}
unsigned short Flash_TestBlock2(unsigned long addr, unsigned long size)
{
unsigned short pattern;
unsigned long i;
for(i = 0; i < 32767; i++)
{
pattern = (*((unsigned short *)(0x010003+i)))& 0xffff;
Logic_WriteFlash(addr, CMD_CLEAR_STATUS);
Logic_WriteFlash(addr, CMD_WRITE_ARRAY);
Logic_WriteFlash(addr, pattern);
if (!Flash_Poll(addr, BIT_WSMS, BIT_WSMS, TIMEOUT_PROGRAM))
return ERR_FLASH_PROGRAM;
Logic_WriteFlash(addr, CMD_READ_ARRAY);
if (pattern != Logic_ReadFlash(addr))
{
return ERR_FLASH_VERIFY;
}
addr++;
}
pattern = 0x0002;
Logic_WriteFlash(addr, CMD_CLEAR_STATUS);
Logic_WriteFlash(addr, CMD_WRITE_ARRAY);
Logic_WriteFlash(addr, pattern);
if (!Flash_Poll(addr, BIT_WSMS, BIT_WSMS, TIMEOUT_PROGRAM))
return ERR_FLASH_PROGRAM;
Logic_WriteFlash(addr, CMD_READ_ARRAY);
if (pattern != Logic_ReadFlash(addr))
{
return ERR_FLASH_VERIFY;
}
return 0;
}
unsigned short Flash_write_div()
{
unsigned long addr, size;
unsigned short status;
#if(0)
while(1)
{
*((unsigned short *)0x401000) = 0x0000;
SWDelayMsec(1);
*((unsigned short *)0x401000) = 0xffff;
SWDelayMsec(1);
}
#endif
if ((status = Flash_CheckMfgId()) > 0)
return status;
if ((status = Flash_EraseBlocks()) > 0)
return status;
addr = 0x00020000;
size = 0x8000;
if ((status = Flash_TestBlock1(addr, size)) > 0)
return status;
addr = 0x00028000;
if ((status = Flash_TestBlock2(addr, size)) > 0)
return status;
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -