?? 39vf6401.c
字號:
#include "tffs/flflash.h"
#include "tffs/backgrnd.h"
#include "stdio.h"
#include "config.h"
#include "intLib.h"
/*需與sysTffs.c中相同定義一致*/
#define TFLASH_BASE_ADRS (0x00200000)
#define TFLASH_SIZE (0x00600000)
typedef struct
{
FlashWPTR unlockAddr1;
FlashWPTR unlockAddr2;
} Vars;
static Vars mtdVars[DRIVES];
#define thisVars ((Vars *) vol.mtdVars)
#define SETUP_ERASE 0x80
#define SETUP_WRITE 0xa0
#define READ_ID 0x90
#define SECTOR_ERASE 0x30
#define BLOCK_ERASE 0x50 /*塊擦除*/
#define READ_ARRAY 0xf0 /*軟件ID讀模式退出*/
#define UNLOCK_1 0xaa /*解鎖寫入值*/
#define UNLOCK_2 0x55
#define UNLOCK_ADDR1 0x5555 /*解鎖偏移地址[字]*/
#define UNLOCK_ADDR2 0x2aaa
/* JEDEC ids for this MTD */
#define LV6401B_DEID 0x236d /*設備ID*/
#define DEBUG_PRINT printErr
static STATUS lv6401OpOverDetect(void * ptr, int timeCounter);
/*------------------------------------------------------------------------
Procedure: lv6401MTDMap ID:1
Purpose: 映射Flash片內地址為CPU全局地址
Input: addr-相對地址
Output:
Errors:
------------------------------------------------------------------------*/
static void FAR0 *lv6401MTDMap(FLFlash *vol, CardAddress addr, int length)
{
UINT32 ret;
ret = TFLASH_BASE_ADRS + addr;
return (void FAR0 *)ret;
}
/*------------------------------------------------------------------------
Procedure: lv6401OpOverDetect ID:1
Purpose: 探測write,erase操作是否結束,超時錯誤
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static STATUS lv6401OpOverDetect(void * ptr, int timeCounter)
{
FlashWPTR pFlash = ptr;
INT16 buf1,buf2;
buf1 = *pFlash & 0x40;
while(1)
{
buf2 = *pFlash & 0x40;
if(buf1 == buf2)
break;
else
buf1 = buf2;
if(timeCounter-- <= 0)
{
return ERROR;
}
}
return OK;
}
/*------------------------------------------------------------------------
Procedure: lv6401MTDWrite ID:1
Purpose: MTD寫Flash函數
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static FLStatus lv6401MTDWrite(FLFlash vol, CardAddress address, const void FAR1 *buffer, int length, FLBoolean overwrite)
{
int cLength;
FlashWPTR flashPtr, flashTmp;
volatile UINT16 *gBuffer;
int i=intLock();
flashTmp = flashPtr = (FlashWPTR) vol.map(&vol, address, length);
if(length&1)
{
/* printf("warning! the data length can not divided by 2.");*/
}
cLength = length/2;
gBuffer = (UINT16 *)buffer;
while (cLength >= 1)
{
*thisVars->unlockAddr1 = UNLOCK_1;
*thisVars->unlockAddr2 = UNLOCK_2;
*thisVars->unlockAddr1 = SETUP_WRITE;
*flashPtr = *gBuffer;
if(lv6401OpOverDetect((void *)flashPtr, 0x1000000));
if(*flashPtr != *gBuffer)
{
*flashPtr = READ_ARRAY;
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: lv6401MTDWrite timeout.\n");
#endif
return flWriteFault;
}
cLength--;
flashPtr++;
gBuffer++;
}
if (tffscmp((void FAR0 *) flashTmp, buffer,length))
{
/* verify the data */
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: lv6401MTDWrite fail.\n");
#endif
return flWriteFault;
}
intUnlock(i);
return flOK;
}
/*------------------------------------------------------------------------
Procedure: lv6401MTDWrite ID:1
Purpose: MTD擦除Flash函數
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static FLStatus lv6401MTDErase(FLFlash vol, int firstErasableBlock, int numOfErasableBlocks)
{
int iBlock;
FlashWPTR flashPtr;
unsigned int offset;
int i=intLock();
if(numOfErasableBlocks <= 0) return ERROR;
for (iBlock = 0; iBlock < numOfErasableBlocks; iBlock++)
{
int i;
offset = (firstErasableBlock + iBlock) * vol.erasableBlockSize;
flashPtr = (FlashWPTR) vol.map(&vol, offset, vol.interleaving);
*thisVars->unlockAddr1 = UNLOCK_1;
*thisVars->unlockAddr2 = UNLOCK_2;
*thisVars->unlockAddr1 = SETUP_ERASE;
*thisVars->unlockAddr1 = UNLOCK_1;
*thisVars->unlockAddr2 = UNLOCK_2;
*flashPtr = SECTOR_ERASE;
lv6401OpOverDetect((void *)flashPtr, 0x2000000);
for(i=0; i<vol.erasableBlockSize/2; i++,flashPtr++)
{
if(*flashPtr != 0xffff) break;
}
*flashPtr = READ_ARRAY;
if(i < vol.erasableBlockSize/2)
{
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: lv6401MTDErase fail.\n");
#endif
return flWriteFault;
}
}
intUnlock(i);
/*printf("\Erase ok\n");*/
return flOK;
}
/*------------------------------------------------------------------------
Procedure: fllv6401Identify ID:1
Purpose: MTD讀Flash標識
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static FLStatus fllv6401Identify(FLFlash vol, UINT32 offset)
{
FlashWPTR flashPtr;
flashPtr = (FlashWPTR) vol.map(&vol, 0, vol.interleaving);
/*printf("\nenter the fllv160Identify\n");*/
*thisVars->unlockAddr1 = UNLOCK_1;
*thisVars->unlockAddr2 = UNLOCK_2;
*thisVars->unlockAddr1 = READ_ID;
/* printf("\nthisVars->unlockAddr1 %x,*thisVars->unlockAddr2 %x\n", thisVars->unlockAddr1, thisVars->unlockAddr2);*/
/* 0X01 read device Id, 0X00 manufacture Id.*/
flashPtr = (FlashWPTR) vol.map(&vol, offset, vol.interleaving);
/* printf("\nthe flashPtr is %x\n",flashPtr);*/
vol.type = *flashPtr;
flashPtr = (FlashWPTR)vol.map(&vol, 0, vol.interleaving) ;
*flashPtr = READ_ARRAY; /*回到讀狀態*/
return flOK;
}
/*------------------------------------------------------------------------
Procedure: lv6401MTDIdentify ID:1
Purpose: MTD讀Flash標識[extern]
Input:
Output:
Errors:
------------------------------------------------------------------------*/
FLStatus lv6401MTDIdentify(FLFlash vol)
{
FlashWPTR baseFlashPtr;
int i;
vol.interleaving = 1;
flSetWindowBusWidth(vol.socket,16);/* use 16-bits */
flSetWindowSpeed(vol.socket,120); /* 120 nsec. */
flSetWindowSize(vol.socket, TFLASH_SIZE>>12);
vol.chipSize = TFLASH_SIZE;
vol.map = lv6401MTDMap;
vol.mtdVars = &mtdVars[flSocketNoOf(vol.socket)];
baseFlashPtr = (FlashWPTR)vol.map (&vol, (CardAddress)0, vol.interleaving);
/* printf("\nthe baseFlashPtr is %x\n",baseFlashPtr);*/
/*UNLOCK_ADDR為字地址, 賦值轉換x2*/
thisVars->unlockAddr1 = (FlashWPTR)((long)baseFlashPtr) + UNLOCK_ADDR1;
thisVars->unlockAddr2 = (FlashWPTR)((long)baseFlashPtr) + UNLOCK_ADDR2;
/*get flash device ID.*/
i=intLock();/*close interrupt */
fllv6401Identify(&vol, 2);
intUnlock(i);/*release interrupt*/
/* printf("\nthe thisVars->unlockAddr1 is %x, thisVars->unlockAddr2 is %x\n",thisVars->unlockAddr1,thisVars->unlockAddr2);
printf("\nthe type is %x\n",vol.type);*/
if (vol.type != LV6401B_DEID)
{
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: can not identify SST39VF6401 media.\n");
#endif
return flUnknownMedia;
}
vol.noOfChips =0x1; /*one chip.*/
vol.erasableBlockSize = 0x10000; /* 64k bytes.*/
vol.flags |= SUSPEND_FOR_WRITE;
/* Register our flash handlers */
vol.write = lv6401MTDWrite;
vol.erase = lv6401MTDErase;
/* printf("\nidentify ok\n");*/
return flOK;
}
/*
void mount_tffs(void)
{
tffsDevFormat();
usrTffsConfig(0,0,"/tffs0");
}
void ftp_tffs(void)
{
if(ioDefPathSet("/tffs0")!=-1)
{
if(loginUserAdd("whl","RQcRcRSS9e")!=-1)
printf("ftp_tffs ok!!!!");
else printf("login error!!!!");
}
else printf("set ftp path error!!!!");
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -