📄 norflash.h
字号:
/***************************************************************************************************************************
*filename: NorFlash.h
*author: wuer
*create date: 2005-5-10 12:45
*description: The file consists of some functions of Nor Flash
*modify history:
*misc: 因为芯片分为16位和32位,故所有对芯片的命令操作也分16位和32位操作。
****************************************************************************************************************************/
#include "HA_TypeDef.h"
#include <stdio.h>
#include "config.h"
#ifndef GE01
/*宏NorFlash_32Bit,若定义了为32位NorFlash,否则为16位NorFlash*/
#define NorFlash_32Bit
#endif
#ifdef NorFlash_32Bit
//////////////////////////////////
// 32位NorFlash操作 //
//////////////////////////////////
extern void InitEMI(void);
extern ER NorFlash_write( U32 address, U32 data );
extern ER NorFlash_read( U32 address);
extern ER NorFlash_idlejud(U32 address);
extern ER NorFlash_clearSR(U32 address);
extern ER NorFlash_bolckerase(U32 blockadd);
extern ER NorFlash_Normal(U32 address);
extern ER NorFlash_unlock( U32 address);
extern ER check(U32 head1, U32 head2, U32 num);
void InitEMI(void)
{
*(RP)EMIADDR_CSGBAB = 0x24002000;
*(RP)EMIADDR_CSGBCD = 0x2c002800;
*(RP)EMIADDR_CSGBEF = 0x34003000;
*(RP)EMIADDR_SMCONF |= 0x00000200;
*(RP)EMIADDR_SDCONF1= 0x0110a077;
*(RP)EMIADDR_SDCONF2= 0x80000500;
*(RP)EMIADDR_REMAP = 0x0000000b;
}
ER NorFlash_idlejud(U32 address)
{
U32 temp;
U16 i = 0;
U16 j = 0;
*(RP)address = 0x700070;
temp = *(RP)address;
while( (temp & 0x800080) != 0x800080 )
{
for(i=0; i<0x1000; i++);
temp = *(RP)address ;
if(j++ >= 0x1000)
{
#ifdef USB_ICE
print("It takes too many time! I can not put up with it!\n");
#else
printf("It takes too many time! I can not put up with it!\n");
#endif
return NO;
}
}
*(RP)address = 0xff00ff;
return YES;
}
ER NorFlash_clearSR(U32 blockadd)
{
*(RP)0x20000000 = 0x500050;
if( NorFlash_idlejud(blockadd) != YES)
{
#ifdef USB_ICE
print("clear SR FAIL!!\n");
#else
printf("clear SR FAIL!!\n");
#endif
return NO;
}
return YES;
}
ER NorFlash_Normal(U32 address)
{
*(RP)address = 0xff00ff;
return YES;
}
ER NorFlash_unlock( U32 address)
{
int i;
char *PrintTemp;
*(RP)address = 0x600060;
*(RP)address = 0xd000d0;
for(i=0; i<0x1000; i++);
if(NorFlash_idlejud(address) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "unlock at 0x%x failed!!\n", (U16)address);
print(PrintTemp);
#else
printf("unlock at 0x%x failed!!\n", (U16)address);
#endif
return NO;
}
return YES;
}
ER NorFlash_lock( U32 address)
{
*(RP)address = 0x600060;
*(RP)address = 0x010001;
NorFlash_idlejud(address);
return YES;
}
ER NorFlash_bolckerase(U32 blockadd)
{
U32 i;
char *PrintTemp;
*(RP)blockadd = 0x200020;
*(RP)blockadd = 0xd000d0;
for(i=0; i<0x80000; i++);
if(NorFlash_idlejud(blockadd) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "blcokerase at 0x%x time out!\n", (U16)blockadd);
print(PrintTemp);
#else
printf("blcokerase at 0x%x time out!\n", (U16)blockadd);
#endif
return NO;
}
NorFlash_clearSR(blockadd);
return YES;
}
ER NorFlash_read( U32 address)
{
U32 i;
*(RP)address = 0xff00ff;
i = *(RP)address;
return i;
}
ER NorFlash_write( U32 address, U32 data )
{
int i;
U32 temp;
char *PrintTemp;
*(RP)address = 0x400040;
*(RP)address = data;
for(i=0; i<0x800; i++);
if(NorFlash_idlejud(address) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "write at 0x%x failed!! \n", (U16)address);
print(PrintTemp);
#else
printf("write at 0x%x failed!! \n", (U16)address);
#endif
return NO;
}
temp = *(RP)address;
if(temp != data)
{
#ifdef USB_ICE
sprintf(PrintTemp, "____write at 0x%x error!! 0x%x VS 0x%x!!\n",address, temp,data);
print(PrintTemp);
#else
printf("____write at 0x%x error!! 0x%x VS 0x%x!!\n",address, temp,data);
#endif
return NO;
}
else
return YES;
}
ER check(U32 head1, U32 head2, U32 num)
{
RP8 p1, p2;
char data;
p1 = (RP8)head1;
p2 = (RP8)head2;
while(num-->0)
{
data = *((RP8)p1++);
if(data!= *((RP8)p2++))
{
#ifdef USB_ICE
print("the copyed data is not the orignal one!!\n");
#else
printf("the copyed data is not the orignal one!!\n");
#endif
return NO;
}
}
return YES;
}
#else
//////////////////////////////////
// 16位NorFlash操作 //
//////////////////////////////////
extern void InitEMI(void);
extern ER NorFlash_write( U32 address, U16 data );
extern ER NorFlash_read( U32 address);
extern ER NorFlash_idlejud(U32 address);
extern ER NorFlash_clearSR(U32 address);
extern ER NorFlash_bolckerase(U32 blockadd);
extern ER NorFlash_Normal(U32 address);
extern ER NorFlash_unlock( U32 address);
extern ER check(U32 head1, U32 head2, U32 num);
void InitEMI(void)
{
*(RP)EMIADDR_CSGBAB = 0x24002000;
*(RP)EMIADDR_CSGBCD = 0x2c002800;
*(RP)EMIADDR_CSGBEF = 0x34003000;
*(RP)EMIADDR_SMCONF &= ~0x00000200;
*(RP)EMIADDR_SDCONF1= 0x0110a077;
*(RP)EMIADDR_SDCONF2= 0x80000500;
*(RP)EMIADDR_REMAP = 0x0000000b;
}
ER NorFlash_idlejud(U32 address)
{
U16 temp = 0;
*(RP16)address = 0x70;
temp = *(RP16)address;
while( (temp & 0x80) != 0x80 )
{
temp = *(RP16)address ;
}
*(RP16)address = 0xff;
return YES;
}
ER NorFlash_clearSR(U32 blockadd)
{
*(RP16)0x20000000 = 0x50;
if( NorFlash_idlejud(blockadd) != YES)
{
#ifdef USB_ICE
print("clear SR FAIL!!\n");
#else
printf("clear SR FAIL!!\n");
#endif
return NO;
}
return YES;
}
ER NorFlash_Normal(U32 address)
{
*(RP16)address = 0xff;
return YES;
}
ER NorFlash_unlock( U32 address)
{
int i;
char *PrintTemp;
*(RP16)address = 0x60;
*(RP16)address = 0xd0;
for(i=0; i<0x1000; i++);
if(NorFlash_idlejud(address) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "unlock at 0x%x failed!!\n", (U16)address);
print(PrintTemp);
#else
printf("unlock at 0x%x failed!!\n", (U16)address);
#endif
return NO;
}
return YES;
}
ER NorFlash_lock( U32 address)
{
*(RP16)address = 0x60;
*(RP16)address = 0x01;
NorFlash_idlejud(address);
return YES;
}
ER NorFlash_bolckerase(U32 blockadd)
{
int i;
U16 temp;
char *PrintTemp;
*(RP16)blockadd = 0x20;
*(RP16)blockadd = 0xd0;
for(i=0; i<0x80000; i++);
if(NorFlash_idlejud(blockadd) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "blcokerase at 0x%x time out!\n", (U16)blockadd);
print(PrintTemp);
#else
printf("blcokerase at 0x%x time out!\n", (U16)blockadd);
#endif
return NO;
}
temp = NorFlash_clearSR(blockadd );
return YES;
}
ER NorFlash_read( U32 address)
{
U16 i;
*(RP16)address = 0xff;
i = *(RP16)address;
NorFlash_idlejud(address);
return i;
}
ER NorFlash_write( U32 address, U16 data )
{
int i;
U16 temp;
char *PrintTemp;
*(RP16)address = 0x40;
*(RP16)address = data;
for(i=0; i<0x800; i++);
if(NorFlash_idlejud(address) != YES)
{
#ifdef USB_ICE
sprintf(PrintTemp, "write at 0x%x failed!! \n", (U16)address);
print(PrintTemp);
#else
printf("write at 0x%x failed!! \n", (U16)address);
#endif
return NO;
}
temp = *(RP)address;
if(temp != data)
{
#ifdef USB_ICE
sprintf(PrintTemp, "____write at 0x%x error!! 0x%x VS 0x%x!!\n",address, temp,data);
print(PrintTemp);
#else
printf("____write at 0x%x error!! 0x%x VS 0x%x!!\n",address, temp, data);
#endif
return NO;
}
return YES;
}
ER check(U32 head1, U32 head2, U32 num)
{
RP8 p1, p2;
char data;
p1 = (RP8)head1;
p2 = (RP8)head2;
while(num-->0)
{
data = *((RP8)p1++);
if(data!= *((RP8)p2++))
{
#ifdef USB_ICE
print("the copyed data is not the orignal one!!\n");
#else
printf("the copyed data is not the orignal one!!\n");
#endif
return NO;
}
}
return YES;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -