📄 flash.c
字号:
/****************************************************************************///// FLASH burnning functions used in burn.c// Created by Strong Embeded Studio// www.8800.org// If there are any concerns on the code// go to www.8800.org for discussion///****************************************************************************/typedef int uint; //// Change the type here////#define type F39SST160#define type F29LV160T#define F39SST160 100#define F29LV160T 101// // Define the FLASH sector structure//static uint SecData[] = {//// 29LV160T// F29LV160T, 0x000, 0x004000, 0x001, 0x002000, 0x002, 0x008000, 0x001, 0x010000, 0x01F,//// 39SST160// F39SST160, 0x000, 0x001000, 0x200,//// End// 0x000000, 0x000};//// Get the sector index from the offset//uint GetIndex(uint offset){ if (type == F39SST160) { return ((offset)/(0x1000)); } else { if (offset < 0x4000) return 0; else if (offset < 0x6000) return 1; else if (offset < 0x8000) return 2; else if (offset < 0x10000) return 3; else { return ((offset - 0x10000)/0x10000) + 4; } } return 0;}//////uint GetSecAddr(uint index){ uint i; uint sec; uint addr; addr = 0; i = 0; sec = 0; while (SecData[i]) { if (SecData[i]==type && SecData[i+1]==0) { i += 2; while (SecData[i+1]) { sec += SecData[i+1]; addr+= (SecData[i] * SecData[i+1]); if (sec > index) { addr -= (SecData[i] * (sec - index)); return addr; } i += 2; } return 0; } else { i += 2; continue; } } return 0;}#define FLASHBASEADDR 0uint WriteSector(int index,char *data_buffer){ volatile unsigned short *Dest; volatile unsigned short *Org; uint len=0,i; len = GetSecAddr(index+1)-GetSecAddr(index); Org = (volatile unsigned short *)data_buffer; Dest = (volatile unsigned short *)(FLASHBASEADDR+GetSecAddr(index)); *(volatile unsigned short *)(0x0000AAAA)=0xAAAA; *(volatile unsigned short *)(0x00005554)=0x5555; *(volatile unsigned short *)(0x0000AAAA)=0x8080; *(volatile unsigned short *)(0x0000AAAA)=0xAAAA; *(volatile unsigned short *)(0x00005554)=0x5555; *Dest =0x3030; while ((*Dest)!=0xFFFF); if (!data_buffer) return 0; for (i=0;i<len/2;i++) { *(volatile unsigned short *)(0x0000AAAA)=0xAAAA; *(volatile unsigned short *)(0x00005554)=0x5555; *(volatile unsigned short *)(0x0000AAAA)=0xA0A0; *(Dest+i)=*(Org+i); while ((*(Dest+i))!=(*(Org+i))); } for (i=0;i<len/2;i++) { if ((*(Dest+i))!=(*(Org+i))) { return 0; } } return len;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -