?? flash.c
字號:
typedef unsigned short U16; /* unsigned 16-bit integer */
typedef unsigned char U8; /* unsigned 8-bit integer */
typedef unsigned long U32; /* unsigned 32-bit integer */
typedef volatile U16 * RP16;
typedef int ER;
typedef volatile unsigned short * POINTER;
typedef volatile U8 * RP8;
#define YES 1
#define NO 0 /* 3?′í·μ???μ */
#define E_OK 1
#define WordLen 2 //32??Norflash?á?3?è
#define ERASEBLOCKSIZE 0x2000 /* 8Kbye:?????2¨¢3y|ì???¨?D??ê??¨′?Yflash?á¨o¨¢?|ì?|ì??ê?2??¨|??¨°a?à???¥ */
/***************************************************************************************************************************
*filename: HA_EMI.C
*author: wuer
*create date: 2005-5-10 12:45
*description: The file consists of some functions of Nor Flash
*modify history:
*misc: òò?aD????a16??£?1ê?ùóD??D???μ?£??üá?2ù×÷??ê?16??2ù×÷?£
****************************************************************************************************************************/
#include <stdio.h>
ER NorFlash_clearSR(void)
{
*(RP16)0x20000000 = 0x50;
return YES;
}
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_Normal(U32 address)
{
*(RP16)address = 0xff;
return YES;
}
ER NorFlash_bolckerase(U32 blockadd)
{
U16 temp;
*(RP16)blockadd = 0x20;
*(RP16)blockadd = 0xd0;
temp = NorFlash_idlejud(blockadd);
temp = NorFlash_clearSR( );
return YES;
}
ER NorFlash_Chiperase(void)
{
U32 anyaddress = 0x20000000;
*(RP16)anyaddress = 0x30;
*(RP16)anyaddress = 0xd0;
NorFlash_idlejud(anyaddress);
NorFlash_clearSR();
return YES;
}
ER NorFlash_read( U32 address)
{
U16 i;
*(RP16)address = 0xff;
i = *(RP16)address;
NorFlash_idlejud(address);
return i;
}
ER NorFlash_unlock( U32 address)
{
*(RP16)address = 0x60;
*(RP16)address = 0xd0;
NorFlash_idlejud(address);
return YES;
}
ER NorFlash_lock( U32 address)
{
*(RP16)address = 0x60;
*(RP16)address = 0x01;
NorFlash_idlejud(address);
return YES;
}
ER NorFlash_write( U32 address, U16 data )
{
U16 temp;
*(RP16)address = 0x40;
*(RP16)address = data;
NorFlash_idlejud(address);
temp = NorFlash_read(address);
if(temp != data)
printf("write error!original data is 0x%x and data read out is 0x%x!!\n",(U16)temp,(U16)data);
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++))
{
printf("the copyed data is not the orignal one!!\n");
return NO;
}
}
return YES;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -