www.pudn.com > mp3decoder.rar > FLASH.C
#include "..\inc\board.h"
#include "..\inc\bios.h"
#include "..\inc\flash.h"
unsigned long flash_base;
unsigned short mfr_id;
unsigned short dev_id;
void send_cmd(unsigned long addr,unsigned char cmd)
{
*(unsigned short *)(addr*2)=cmd;
}
void send_unlock()
{
*(unsigned short *)((ROM_BASE+0x5555)*2) =0xAA;
*(unsigned short *)((ROM_BASE+0x2AAA)*2) =0x55;
}
int probe_chip()
{
int i;
/* Enter autoselect mode. */
send_unlock();
send_cmd(ROM_BASE+0x5555, 0x90);
mfr_id =*(unsigned short *)(ROM_BASE+0x0*2);
dev_id =*(unsigned short *)(ROM_BASE+0x1*2);
send_cmd(ROM_BASE, 0xf0);
return 0;
}
int flash_is_busy(unsigned long addr1)
{
unsigned short d1,d2;
d1=*(unsigned short*)(addr1*2) & D6_MASK;
d2=*(unsigned short*)(addr1*2) & D6_MASK;
return(d1!=d2);
// return((*(unsigned short*)addr1 & D7_MASK)==0);
}
int flash_erase()
{
int times_left,ret;
send_unlock();
send_cmd(ROM_BASE+0x5555, 0x80);
send_unlock();
send_cmd(ROM_BASE+0x5555, 0x10);
delay(20);
times_left = 0x500000;
while (times_left-- && flash_is_busy(0));
if (!times_left)
{
ret = -1;
}
send_cmd(ROM_BASE, 0xf0);
return ret;
}
int flash_read(unsigned long from,unsigned long len,unsigned short *buf)
{
int i;
unsigned short buff[100];
for(i=0;i<100;i++)
buff[i]=*(unsigned short *)i*2;
return 0;
}
int write_one_word(unsigned long addr, unsigned short dat)
{
int times_left;
int ret = 0;
send_unlock();
send_cmd(ROM_BASE+0x5555, 0xA0);
*(unsigned short *)(ROM_BASE+addr)= dat;
delay(20);
times_left = 200000;
while (times_left-- && flash_is_busy(ROM_BASE+addr));
if (!times_left)
{
ret = -1;
}
return ret;
}
int flash_write(unsigned long to,unsigned long len,unsigned short *buf)
{
int n;
unsigned short dat,*buff;
to=0;
len=0x2000;
buff=(unsigned short *)0x0c000000;
for (n =0; n