?? flashdev.c
字號:
/* This file contains all of the flash support code that does not need
to be relocated to RAM. Two separate files (flash.c and flashpic.c)
are maintained because under certain compilers, they may need to be
compiled with different options to be made position independent.
NOTE: THESE FUNCTIONS ARE NOT RE-ENTRANT!!! All of the FLASH routines
assume they can copy themselves into the array FlashFunc[]; hence, only
one operation can be active at any time.
*/
#include "cpu.h"
#include "flashdev.h"
#include "flash.h"
#include "config.h"
#include "genlib.h"
#if INCLUDE_FLASH
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
typedef volatile unsigned char vuchar;
typedef volatile unsigned short vushort;
typedef volatile unsigned long vulong;
typedef volatile unsigned int vuint;
typedef volatile int vint;
/*m
extern int FLASHERASE();
extern int ENDFLASHERASE();
extern int FLASHWRITE();
extern int ENDFLASHWRITE();
extern int FLASHEWRITE();
extern int ENDFLASHEWRITE();
extern int FLASHTYPE();
extern int ENDFLASHTYPE();
*/
#define printf mprintf
extern int FLASHERASE(struct flashinfo *,int);
extern int ENDFLASHERASE(void);
extern int FLASHWRITE(struct flashinfo *,unsigned char *,unsigned char *,long);
extern int ENDFLASHWRITE(void);
extern int FLASHEWRITE(struct flashinfo *,unsigned char *,unsigned char *,long);
extern int ENDFLASHEWRITE(void);
extern int FLASHTYPE(struct flashinfo *);
extern int ENDFLASHTYPE(void);
/* FlashXXXFbuf[]:
These arrays will contain the flash operation function that is executing.
Recall that to operate on the flash, you cannot be executing out of it.
The flash functions are copied here, then executed through the function
pointer flashfunc which is set to point to FlashFunc.
*/
ulong FlashTypeFbuf[FLASHFUNCSIZE];
ulong FlashEraseFbuf[FLASHFUNCSIZE];
ulong FlashWriteFbuf[FLASHFUNCSIZE];
ulong FlashEwriteFbuf[FLASHFUNCSIZE];
/*
extern int flashtype(struct flashinfo *);
extern int flasherase(struct flashinfo *,int);
extern int flashwrite(struct flashinfo *,unsigned char *,unsigned char *,long);
extern int flashewrite(struct flashinfo *,unsigned char *,unsigned char *,long);
*/
/* FlashBank[]:
This structure contains all of the information that must be made available
to the various flash operation commands. It is initialized by flashtype()
and used thereafter by the other operations.
*/
struct flashinfo FlashBank[FLASHBANKS];
/* FlashNamId[]:
Used to correlate between the ID and a string representing the name
of the flash device.
*/
struct flashdesc FlashNamId[] = {
{ SGS29F040, "SGS-29F040" },
{ SGS29LV040, "SGS-29LV040" },
{ AMD29F040, "AMD-29F040" },
{ AMD29F010, "AMD-29F010" },
{ AMD29LV040, "AMD-29LV040" }
};
struct sectorinfo sinfo040[8];
int FlashBankInit(struct flashinfo *,int);
extern int sectorProtect();
/* FlashInit():
Initialize data structures for each bank of flash...
*/
int
FlashInit(void)
{
int snum;
struct flashinfo *fbnk;
snum = 0;
FlashCurrentBank = 0;
/* Copy functions to ram space... */
/* Note that this MUST be done when cache is disabled to assure that */
/* the RAM is occupied by the designated block of code. */
if (flashopload((ulong *)FLASHTYPE,(ulong *)ENDFLASHTYPE,
FlashTypeFbuf,sizeof(FlashTypeFbuf)) < 0)
return(-1);
if (flashopload((ulong *)FLASHERASE,(ulong *)ENDFLASHERASE,
FlashEraseFbuf,sizeof(FlashEraseFbuf)) < 0)
return(-1);
if (flashopload((ulong *)FLASHEWRITE,(ulong *)ENDFLASHEWRITE,
FlashEwriteFbuf,sizeof(FlashEwriteFbuf)) < 0)
return(-1);
if (flashopload((ulong *)FLASHWRITE,(ulong *)ENDFLASHWRITE,
FlashWriteFbuf,sizeof(FlashWriteFbuf)) < 0)
return(-1);
fbnk = &FlashBank[0];
fbnk->base = (unsigned char *)FLASH_BANK0_BASE_ADDR;
fbnk->width = FLASH_BANK0_WIDTH;
//mfbnk->fltype = (int(*)())FlashTypeFbuf; /* flashtype(). */
//mfbnk->flerase = (int(*)())FlashEraseFbuf; /* flasherase(). */
//mfbnk->flwrite = (int(*)())FlashWriteFbuf; /* flashwrite(). */
//mfbnk->flewrite = (int(*)())FlashEwriteFbuf; /* flashewrite(). */
fbnk->fltype = (int(*)(struct flashinfo *))FlashTypeFbuf; /* flashtype(). */
fbnk->flerase = (int(*)(struct flashinfo *,int))FlashEraseFbuf; /* flasherase(). */
fbnk->flwrite = (int(*)(struct flashinfo *,unsigned char *,unsigned char *,long))FlashWriteFbuf; /* flashwrite(). */
fbnk->flewrite = (int(*)(struct flashinfo *,unsigned char *,unsigned char *,long))FlashEwriteFbuf; /* flashewrite(). */
fbnk->sectors = sinfo040;
snum += FlashBankInit(fbnk,snum);
sectorProtect(FLASH_PROTECT_RANGE,1);
return(0);
}
/* FlashBankInit():
Initialize flash structures and determine flash device type.
*/
int
FlashBankInit(struct flashinfo *fbnk, int snum)
{
int i, ssize;
flashtype(fbnk);
switch(fbnk->id) {
case AMD29LV040:
case SGS29LV040:
case SGS29F040:
case AMD29F040:
fbnk->sectorcnt = 8;
ssize = 0x10000 * fbnk->width;
fbnk->end = fbnk->base + (0x80000 * fbnk->width) - 1;
break;
case AMD29F010:
fbnk->sectorcnt = 8;
ssize = 0x4000 * fbnk->width;
fbnk->end = fbnk->base + (0x20000 * fbnk->width) - 1;
break;
default:
printf("Flash device id 0x%lx unknown\n", fbnk->id);
return(-1);
}
for(i=0;i<fbnk->sectorcnt;i++) {
fbnk->sectors[i].snum = snum+i;
fbnk->sectors[i].size = ssize;
fbnk->sectors[i].begin = fbnk->base + (i*ssize);
fbnk->sectors[i].end = fbnk->sectors[i].begin + ssize - 1;
fbnk->sectors[i].protected = 0;
}
return(8);
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -