IAR EWARM下44b0x的FlashLoader Flash Loader 是用IAR Embedded Workbench 开发的本地应用程序。其任务是通过文件I/O 从主机读取应用程序的二进制映象,将映象拆包,并写进Flash 存储器。Flash Loader 可以分成两个部分。一是所有Flash Loader 所共用的框架部分,其源代码由IAR Systems提供并包含在IAR Embedded Workbench 中;二是驱动部份,它是一小段用于实际烧写Flash 存储器的小程序。在IAR Embedded Workbench 中已经包含了一组用于各种内含FLASH的芯片的Flash Loader 驱动程序。而对于S3C44B0X,就得自己写Flash Loader 驱动程序了。本文主要针对44b0x + SST39VF160 (1M*16Bit FLASH) 目标板,在IAR-EWARM下的FLASHLOADER程序提供实例。 /* ;bank0 FLASH: SST39VF160 (1Mb*16) ;bank1 ;bank2 16bit IDE ;bank3 rtl8019 ;bank4 ;bank5 ext ;bank6 16bit SDRAM ;bank7 16bit SDRAM */ #include <stdio.h> #include <stdlib.h> #include <ios3c44b0x.h> #include "FlashS3C44B0x.h" //#include "Interface.h" // The flash loader framework API declarations. //#include "C:Program FilesIAR SystemsEmbedded Workbench 4.0 EvaluationARMsrcflashloaderframeworkInterface.c" #define int8 signed char #define int16 signed short #define int32 signed long #define int64 signed double #define uint8 unsigned char #define uint16 unsigned short #define uint32 unsigned long #define uint64 unsigned double #define EmiWrite(addr, dat) *((uint16 *)(addr))=(uint16)dat #define EmiRead(addr) *((uint32 *)(addr)) void cmd_toggle_bit() { uint8 dat1, dat2; dat1 = EmiRead(0x1000<<1); dat2 = EmiRead(0x1000<<1); while((dat1^dat2) & 0x40) { dat1 = dat2; dat2 = EmiRead(0x1000<<1); } } void cmd_exit() { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0xF0); } uint32 cmd_getid() { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0x90); return EmiRead(0x0000<<1); }; //--- 2K WORD,4K BYTE, per sector. //-- sst39VF160 has 512 sectors void cmd_sector_erase(uint32 sector) { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0x80); EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(sector<<12, 0x30); }; //--- 32K WORD,64K BYTE, per block. //-- sst39VF160 has 32 blocks void cmd_block_erase(uint32 block) { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0x80); EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(block<<16, 0x50); }; void cmd_chip_erase() { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0x80); EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0x10); }; void cmd_word_program(uint32 ads, uint16 dat) { EmiWrite(0x5555<<1, 0xAA); EmiWrite(0x2AAA<<1, 0x55); EmiWrite(0x5555<<1, 0xA0); EmiWrite(ads, dat); }; // 512 个扇区状态,标识是否已经擦除过,默认没有 uint16 secBitMap[512] = {0}; __root void FlashWriteByte(uint32 addr, int byte) { static uint16 cnt = 0; uint16 dat = byte; uint16 sector; cnt++; if(addr > 0xfffff) { // 超过FLASH的1MB范围 *((char *)addr) = byte; }else { if(byte == -1) return; sector = addr>>12; // 所在扇区 if(secBitMap[sector]==0) { cmd_sector_erase(sector); cmd_toggle_bit(); secBitMap[sector]=0xffff; } if(addr & 01) { dat <<=8; dat |= 0x00ff; }else { dat |= 0xff00; } addr>>=1; cmd_word_program(addr<<1, dat); cmd_toggle_bit(); } return; char msg[80]; sprintf(msg, "第 %d 次:FlashWriteByte(0x%X, 0x%X)
", cnt, addr, byte); FlMessageLog (msg); }
void FlashDriverInitialize(int argc, char const* argv[]) { const char* str; // Register the flash write function. FlRegisterWriteFunction(FlashWriteByte); /* // See if user has passed a clock speed option. // If not, the default CCLK value is used. str = FlFindOption("--clock", 1, argc, argv); if (str){ clock = strtoul(str, 0, 0); } */ } |