📄 flash.c
字号:
#include "flash_extr.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_idlejud
////////////////////////////////////////////////////////////////////////////////////////////////////////
STATUS NorFlash_idlejud(U32 address)
{
U16 temp = 0;
*(RP16)address = 0x70;
temp = *(RP16)address;
while( (temp & 0x80) != 0x80 )
{
temp = *(RP16)address ;
}
*(RP16)address = 0xff;
return E_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_read
////////////////////////////////////////////////////////////////////////////////////////////////////////
STATUS NorFlash_read(U32 noradd, U32 destadd)
{
*(RP16)noradd = 0xff;
*(RP16)destadd = *(RP16)noradd;
return NorFlash_idlejud(noradd);
}
STATUS NorFlash_Normal(U32 address)
{
*(RP16)address = 0xff;
return E_OK;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_write
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*STATUS NorFlash_write( U32 Pageadd, U32 Dataadd )
{
U32 k;
U32 temp,ads=0;
U16 a=0,b=0;
ads=*(RP)Dataadd;
a=ads;
ads=(ads>>16);
b=ads;
*(RP16)Pageadd = 0x40;
*(RP16)Pageadd = a;
temp = NorFlash_idlejud(Pageadd);
Pageadd=Pageadd+2;
//for(k=1;k<1000;k++); //两次写之间要延时1000
if (temp == E_OK)
{
*(RP16)Pageadd = 0x40;
*(RP16)Pageadd =b;
temp = NorFlash_idlejud(Pageadd);
return 1;
}
else return 0;
}*/
STATUS NorFlash_write( U32 Pageadd, U32 Dataadd )
{
U32 temp;
*(RP16)Pageadd = 0x40;
*(RP16)Pageadd = *(RP16)Dataadd;
temp = NorFlash_idlejud(Pageadd);
return temp;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_unlock
////////////////////////////////////////////////////////////////////////////////////////////////////////
STATUS NorFlash_unlock( U32 address)
{
*(RP16)address = 0x60;
*(RP16)address = 0xd0;
NorFlash_idlejud(address);
return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_bolckerase
////////////////////////////////////////////////////////////////////////////////////////////////////////
STATUS NorFlash_bolckerase(U32 blockadd)
{
U32 temp;
*(RP16)blockadd = 0x20;
*(RP16)blockadd = 0xd0;
temp = NorFlash_idlejud(blockadd);
temp = NorFlash_clearSR( ); //Clear SR
return 1;
}
void NorFlash_Write_EX(U32 flashadd, U32 dataadd, U32 length)
{
U32 i = 0;
U32 state;
/* begin write */
do
{
state = NorFlash_write(flashadd + i * WordLen, dataadd + i * WordLen);
i++;
}while(state && (i < (length >> 1) + 1));
NorFlash_Normal(flashadd);
}
void NorFlash_Erase_EX(U32 flashadd, U32 length)
{
U32 i;
U32 erase_block_count;
erase_block_count = length / ERASEBLOCKSIZE + 1;
/* erase first */
for (i = 0; i < erase_block_count; i++)
{
NorFlash_unlock(flashadd + i * ERASEBLOCKSIZE);
NorFlash_bolckerase(flashadd + i * ERASEBLOCKSIZE);
}
}
void NorFlash_Read_EX(U32 flashadd, U32 dataadd, U32 length)
{
U32 i = 0;
U32 state;
do
{
state = NorFlash_read(flashadd + i * WordLen, dataadd + i * WordLen);
i++;
}while(state && (i < (length >> 1) + 1));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NorFlash_clearSR
////////////////////////////////////////////////////////////////////////////////////////////////////////
STATUS NorFlash_clearSR(void)
{
*(RP16)0x0000000 = 0x50;
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -