📄 main.c
字号:
/********************************************************************************************
*filename: main.c
*author: WUER xiao
*create date: 2005-5-10 16:25
*description: This file is used for 16 bit NOR FLASH burner and test
*modify history:
*misc:
********************************************************************************************/
#include "HA_typedef.h"
#include "NorFlash.h"
#include <stdio.h>
#include <string.h>
#include "config.h"
/* 宏NOR_TEST如果定义,表示仅仅为test Nor Flash,未定义则表示需要烧录bootloader和OS kernel等内容 */
//#define NOR_TEST
/************************************************/
#ifdef GE00
#ifndef NOR_TEST
#define ERASENUM 0x1 /* 擦除大小,需要根据具体烧录内容大小计算得到 */
#define SIZE1 0x5000 /* 第一次烧录的文件大小,单位为所使用的Flash字长 */
#else
#define ERASENUM 0x01 /* 测试擦除大小,根据需要自行选择 */
#define SIZE1 0x10000 /* 测试数据的大小,单位为所使用的Flash字长 */
#endif
#define ERASESIZE 0x40000 /* 每次擦除的大小,根据flash资料得到,不可随意变动 */
#define SIZE2 0x50000 /* 第二次烧录的文件(kernel code)大小,单位为所使用的Flash字长 */
#define NorFlash_32Bit
U32 temp;
#endif
#ifdef GE01
#ifndef NOR_TEST
#define ERASENUM 39 /* 擦除大小,需要根据具体烧录内容大小计算得到 */
#define SIZE1 0x100 /* 第一次烧录的文件大小,单位为所使用的Flash字长 */
#else
#define ERASENUM 0x39 /* 测试擦除大小,根据需要自行选择 */
#define SIZE1 0x100000 /* 测试数据的大小,单位为所使用的Flash字长 */
#endif
#define ERASESIZE 0x2000 /* 每次擦除的大小,根据flash资料得到,不可随意变动 */
#define SIZE2 0x98000 /* 第二次烧录的文件(kernel code)大小,单位为所使用的Flash字长 */
U16 temp;
#endif
#ifdef GE02
#ifndef NOR_TEST
#define ERASENUM 0x39 /* 擦除块数量,需要根据具体烧录内容大小计算得到 */
#define SIZE1 0x100 /* 第一次烧录的文件大小,单位为所使用的Flash字长 */
#else
#define ERASENUM 0x01 /* 测试擦除块数量,根据需要自行选择 */
#define SIZE1 0x1000 /* 测试数据的大小,单位为所使用的Flash字长 */
#endif
#define ERASESIZE 0x4000 /* 擦除块的大小,根据flash资料得到,不可随意变动 */
#define SIZE2 0xffc00 /* 第二次烧录的文件(kernel code)大小,单位为所使用的Flash字长 */
#define NorFlash_32Bit
U32 temp;
#endif
#define DataHead 0x30001000 /* 存放烧录内容的内存地址,用户可改变 */
#define NorHead 0x20000000 /* 需要烧录的Nor Flash中的目标地址,取决于用户需要和bootloader的内容 */
#define kernelHead 0x20001000 /* 需要烧录kernel的Nor Flash中的目标地址,取决于用户需要和bootloader的内容 */
/************************************************/
int main(void)
{
U32 i;
#ifdef NOR_TEST
memset((RP*)DataHead,0xaa,SIZE1); /* 初始化一块数据块,用于测试用途 */
#endif
/***** EMI Confige *******/
InitEMI();
/***** erase operation first ******/
for(i = 0; i<ERASENUM; i++)
{
if (i < 8) {
NorFlash_unlock(NorHead + i*ERASESIZE ); /* 擦除前需要解锁需要擦除的块,以防止芯片被锁无法擦除 */
NorFlash_bolckerase(NorHead + i*ERASESIZE ); /* 擦除操作 */
}
else {
NorFlash_unlock(NorHead + (i-7)*ERASESIZE*8 ); /* 擦除前需要解锁需要擦除的块,以防止芯片被锁无法擦除 */
NorFlash_bolckerase(NorHead + (i-7)*ERASESIZE*8 ); /* 擦除操作 */
}
}
#ifdef USB_ICE
print("Erase operation OK!!\n");
#else
printf("Erase operation OK!!\n");
#endif
/***** test or burn bootleader ****/ /* 如果是烧录bootloader。需要设置断点load二进制文件*/
for(i=0;i<SIZE1;i++)
{
temp = *(RP)(DataHead + i*sizeof(temp));
NorFlash_write( (NorHead + i*sizeof(temp)), temp );
}
#ifdef USB_ICE
print("write finished!!\n\n");
#else
printf("write finished!!\n");
#endif
if( (check(DataHead, NorHead, SIZE1*sizeof(temp))) != YES) /* 比较写入前后的数据,如果一致说明读写都正确 */
{
#ifdef USB_ICE
print("____Something wrong! PLZ check now!!\n");
#else
printf("____Something wrong! PLZ check now!!\n");
#endif
}
else
{
#ifdef USB_ICE
print("Everything is OK now!!\n");
#else
printf("Everything is OK now!!\n");
#endif
}
/***** burn kernel only ***********/ /* 需要再次设置断点,load OS kernel代码,然后继续执行*/
#ifndef NOR_TEST
for(i=0;i<SIZE2;i++){ /* kernel 烧录 */
temp = *(RP)(DataHead + i*sizeof(temp));
NorFlash_write( (kernelHead + i*sizeof(temp)), temp ); /* 0x20001000地址需要和采用的bootloader相对应 */
}
if( (check(DataHead, kernelHead, SIZE2*sizeof(temp))) != YES)
{
#ifdef USB_ICE
print("____Something wrong in second burning! PLZ check now!!\n");
#else
printf("____Something wrong in second burning! PLZ check now!!\n");
#endif
}
else
{
#ifdef USB_ICE
print("Everything is OK during second burning.\nFinished now!!\n");
#else
printf("Everything is OK during second burning.\nFinished now!!\n");
#endif
}
#endif
/****** set to normal back ******/
NorFlash_Normal(NorHead );
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -