📄 flash.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "includes.h"
#include "Flash.h"
WORD bFlashOperationEnabled = FALSE;
SectorInfo sinfo320[67];
int FLASHTYPE(FlashInfo *fdev)
{
int i;
ftype val;
WORD wManufactureID, wDeviceID;
val = Read_0000();
/* Issue the autoselect command sequence: */
Write_aa_to_5555();
Write_55_to_2aaa();
Write_90_to_5555();
wManufactureID = (WORD)Read_0000(); /* manufacturer ID */
wDeviceID = (WORD)Read_0001(); /* device ID */
wManufactureID &= 0xff;
wDeviceID &= 0xff;
wManufactureID <<= 8;
wDeviceID |= wManufactureID;
fdev->id = (WORD)wDeviceID;
/* Issue the read/reset command sequence: */
Write_aa_to_5555();
Write_55_to_2aaa();
Write_f0_to_5555();
/* The SGS29040 seems to need this, and it doesn't hurt anything */
/* when using the AMD parts... */
for(i=0;i<FLASH_TIMEOUT;i++)
{
if (val == Read_0000())
break;
}
return((int)(fdev->id));
}
int FLASHWRITE(ftype *dest,ftype *src,unsigned long bytecnt)
{
unsigned long i, ret,temp;
ftype val;
int times_left,saveSyscfg;
/* Each pass through this loop writes 'fdev->width' bytes... */
ret = 0;
OS_ENTER_CRITICAL();
saveSyscfg=rSYSCFG;
rSYSCFG=SYSCFG_0KB;
for (i=0;i<bytecnt;i=i+2)
{
/* Flash write command */
Write_aa_to_5555();
Write_55_to_2aaa();
Write_a0_to_5555();
/* Write the value */
Fwrite(dest,src);
times_left = 50;
while(1) {
temp = *(ftype *)dest;
if (Is_Equal(dest,src))
{
if (Is_Equal(dest,src))
break;
}
times_left--;
if (!times_left)
{
ret = -1;
break;
}
}
dest++; src++;
}
rSYSCFG=saveSyscfg;
OS_EXIT_CRITICAL();
return(ret);
}
///////////////////////////////////////////////////////////////////////////
int ReadFlash(long dest,unsigned char *buf,unsigned long bytecnt)
{
unsigned long i;
for (i=0;i<bytecnt;i+=2)
{
buf[i] = *(ftype *)dest;
buf[i+1] = (*(ftype *)dest)>>8;
dest+=2;
}
}
int EraseFlash(int snum)
{
ftype val;
DWORD add,temp,temp1;
int ret, sector,times_left,saveSyscfg;
ret = 0;
add = (DWORD)(unsigned char *)FLASH_BANK0_BASE_ADDR;
OS_ENTER_CRITICAL();
saveSyscfg=rSYSCFG;
rSYSCFG=SYSCFG_0KB;
/* Erase the request sector(s): */
for (sector=0;sector<64;sector++)
{
if (snum == sector)
{
/* Issue the sector erase command sequence: */
temp=add<<1;
Write_aa_to_5555();
Write_55_to_2aaa();
Write_80_to_5555();
Write_aa_to_5555();
Write_55_to_2aaa();
Write_30_to_(temp);
/* Wait for sector erase to complete or timeout.. */
/* DQ7 polling: wait for D7 to be 1. */
/* DQ6 toggling: wait for D6 to not toggle. */
/* DQ5 timeout: if DQ7 is 0, and DQ5 = 1, timeout. */
times_left = 500000;
while(1)
{
temp1 = *(ftype *)temp;
if (Is_ff(temp))
{
if (Is_ff(temp))
break;
}
times_left--;
if (!times_left)
{
ret = -1;
break;
}
}
}
add += 0x8000;
}
rSYSCFG=saveSyscfg;
OS_EXIT_CRITICAL();
return(ret);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -