?? te28f256.c
字號:
an extern routine.
On successful identification, the Flash structure is filled out and
the write and erase routines registered.
Parameters:
vol : Pointer identifying drive
Returns:
FLStatus : 0 on positive identificaion, failed otherwise
DEBUG : ok
********************************************************************/
FLStatus e28f256Identify(FLFlash vol)
{
FlashWPTR flashPtr;
#ifdef DEBUG_TFFS28F256
printf("into e28f256Identify function.\n");
#endif
flSetWindowBusWidth(vol.socket,16);/* use 16-bits */
flSetWindowSpeed(vol.socket,120); /* 120 nsec. */
flSetWindowSize(vol.socket,0x3f0000<<12); /* 8 KBytes */
vol.map = e28f256MTDMap;/*because can not use default,must map myself*/
flashPtr = (FlashWPTR)vol.map (&vol, (CardAddress)0, vol.interleaving);
vol.noOfChips = 0;/*clear the chips number,this is flash chip number define*/
flashPtr[0] = READ_ID;
if (flashPtr[0] == E28F256_MANU_ID && flashPtr[1] == E28F256_DEVICE_ID )
{
/* Word mode */
vol.type = E28F256_FLASH;
vol.interleaving = 1;/*hahaha*/
flashPtr[0] = READ_ARRAY;
}else
{
/* Use standard identification routine to detect byte-mode */
flIntelIdentify(&vol, NULL,0);
if (vol.interleaving == 1)
vol.type = NOT_FLASH; /* We cannot handle byte-mode interleaving-1 */
}
if (vol.type == E28F256_FLASH)
{
vol.chipSize = FLASH1_END -FLASH1_START +1-0x20000L;
vol.erasableBlockSize = 0x20000L * vol.interleaving; /*128K erase blocks*/
/* Register our flash handlers */
vol.noOfChips =0x1;/*one chip.*/
vol.flags |= SUSPEND_WRITE;
/* Register our flash handlers */
vol.write = e28f256Write;
vol.erase = e28f256Erase;
#ifdef DEBUG_TFFS28F256
printf("ok,the intel te28f256 is registered into system.\n");
printf("ok, successed exit e28f256Identify function.\n");
#endif
return flOK;
}else
{
#ifdef DEBUG_TFFS28F256
printf("error,the intel te28f256 register fail.\n");
printf("ya! error exit e28f256Identify function.\n");
#endif
return flUnknownMedia; /* not ours */
}
}
/********************************************************************
init the tffsfilesystem;
the fun will called at usrAppInit.c
如果調用失敗說明flash芯片還沒有初始化.
DEBUG: ok
********************************************************************/
/**/
int InitTffsFileSystem(void)
{
if (usrTffsConfig (0, 0, "/tffs0") == ERROR)
{
printf("error,the vxworks file system build failed.\n system must run tffsDevFormat() before.\n\n\n");
return ERROR;
}
else
return OK;
/*
else
printf("ok,the vxworks TureFFs file system build.\n");
*/
}
/*******************************************************************
****************** below private code test code no release*********
********************************************************************/
FLStatus flRegisterE28F256(void)
{
if (noOfMTDs >= MTDS)
return flTooManyComponents;
mtdTable[noOfMTDs++] = e28f256Identify;
return flOK;
}
int cmpWords(unsigned short* x,unsigned short* y, int n)
{
int i;
for(i=0;i<n;i++)
{
if(x[i]!=y[i])break;
}
if(i>=n)return 0;
else return -1;
}
static void * e28f256MTDMap_Write(unsigned long addr)
{
UINT32 ret;
ret = FLASH1_START + 0x20000+addr;
return (void *)ret;
}
static void * e28f256MTDMap_Erase(unsigned long addr)
{
UINT32 ret;
ret = FLASH1_START + 0x20000+ addr;
return (void *)ret;
}
STATUS e28f256_Write( unsigned long address,
const void *buffer,
int length)
{
int i,cLength;
STATUS status = OK;
volatile unsigned short int* flashPtr,*flashTmp;
volatile UINT16 *gBuffer;
flashTmp=flashPtr = (volatile unsigned short int*) e28f256MTDMap_Write(address);
#ifdef DEBUG_TFFS28F256
printf("e28f256_Write fun flashPtr= 0x%x address=0x%x length=%d\n",flashPtr,address,length);
#endif
cLength = length/2;
gBuffer = (UINT16 *)buffer;
for(i = 0; i < cLength; i++)
{
*flashPtr = SETUP_WRITE;
do{}while(!(flashPtr[0] & WSM_READY ));
*flashPtr = *gBuffer;
do{}while(!(flashPtr[0] & WSM_READY ));
if ( (flashPtr+1)>= (volatile unsigned short int*)(FLASH1_END+1) )
{
*flashPtr = READ_ARRAY;
break;
}
flashPtr++;
gBuffer++;
*flashPtr = READ_ARRAY;
}
/* verify the data */
if (status == OK && cmpWords((unsigned short *) flashTmp, (unsigned short *) buffer,length)) {
#ifdef DEBUG_TFFS28F256
printf("write failed .\n");
#endif
status = FALSE;
}
return status;
}
static STATUS e28f256_Erase( int firstErasableBlock,
int numOfErasableBlocks)
{
STATUS status = OK; /* unless proven otherwise */
unsigned short int* flashPtr;
unsigned short int* addr;
int i;
long int erasableBlockSize = 0x20000;
BOOL finished;
flashPtr = (unsigned short int*) e28f256MTDMap_Erase(firstErasableBlock*erasableBlockSize);
for(i=0;i<numOfErasableBlocks;i++)
{
addr = flashPtr + (i*erasableBlockSize/2);
/*unlock*/
addr[0] = CLEAR_LOCK_BIT;
do{}while(!(addr[0] & WSM_READY ));
addr[0] = CONFIRM_CLEAR_LOCK_BIT ;
do{}while(!(addr[0] & WSM_READY ));
/*start erase*/
addr[0] = SETUP_ERASE;
do{}while(!(addr[0] &WSM_READY ));
/*confirm erase*/
addr[0] = CONFIRM_ERASE;
do{}while(!(addr[0] &WSM_READY ));
do
{
finished = TRUE;
if (!(addr[0] & WSM_READY ))
finished = FALSE;
else
{
if ( addr[0] & WSM_ERROR )
{
#ifdef DEBUG_TFFS28F256
printf(" erase error .\n");
#endif
status = (addr[0] & WSM_VPP_ERROR ) ? 50 : 29;
addr[0] = CLEAR_STATUS;
}
/*set device read mode*/
addr[0] = READ_ARRAY;
}
} while (!finished);
#ifdef DEBUG_TFFS28F256
printf("e28f256_Erase fun flashPtr= 0x%x addr=0x%x num=%d\n",flashPtr,addr,i);
#endif
}
return status;
}
STATUS e28f256_Write_( unsigned long address,
const void *buffer,
int length)
{
e28f256_Erase(31,1);
e28f256_Write(address,buffer, length);
}
void Flash28f256Test()
{
short abc[3]={0x88,0x77,0x66};
e28f256_Write_(FLASH1_START,abc,2);
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -