这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 请问:关于28f016tffs文件系统

共8条 1/1 1 跳转至

请问:关于28f016tffs文件系统

菜鸟
2007-04-05 00:05:36     打赏

我的arm系列的32位芯片,flash2片是16位的,在加载tffs驱动的时候使用28f016的时候写入总是不正确,

static FLStatus i28f016Write(FLFlash vol,
CardAddress address,
const void FAR1 *buffer,
int length,
FLBoolean overwrite)应该如何改?




关键词: 请问     关于     28f016tffs     文件     系统    

菜鸟
2007-04-05 17:46:00     打赏
2楼

1、overwrite不需要处理

2、buffer的地址传进来的时候是相对于base address的偏移,write函数内部需要调用map做映射。


院士
2007-04-05 17:55:00     打赏
3楼
这叫风范~

菜鸟
2007-04-05 18:13:00     打赏
4楼
woodhead,如何映射?

菜鸟
2007-04-06 16:07:00     打赏
5楼

用flash的基地址加偏移,基地址需要自己配置,偏移是函数传入的参数CardAddress address,


菜鸟
2007-04-07 00:22:00     打赏
6楼

/*----------------------------------------------------------------------*/
/* i 2 8 f 0 1 6 W r i t e */
/* */
/* Write a block of bytes to Flash */
/* */
/* This routine will be registered as the MTD flash.write routine */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* address : Card address to write to */
/* buffer : Address of data to write */
/* length : Number of bytes to write */
/* overwrite : TRUE if overwriting old Flash contents */
/* FALSE if old contents are known to be erased */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/

static FLStatus i28f016Write(FLFlash vol,
CardAddress address,
const void FAR1 *buffer,
int length,
FLBoolean overwrite)
{
/* Set timeout ot 5 seconds from now */
unsigned long writeTimeout = flMsecCounter + 5000;



int iInterleaving;

FLStatus status;
int i, cLength;
unsigned long *tempBuffer;
FlashPTR flashPtr;
FlashWPTR wordFlashPtr; /*donleo for 16 bit*/
FlashDPTR dwordFlashPtr;/*fxf for 32 bit*/

#ifdef DEBUG_PRINT
DEBUG_PRINT("----->i28f016Write() start.\n");
DEBUG_PRINT("vol=0x%x address=0x%x buffer=%s length=%d overwrite=%d.\n",&vol,address,buffer,length,overwrite);
#endif
sysFlashWriteEnable();
sysFlashWriteEnable1();
if (flWriteProtected(vol.socket)) {
sysFlashWriteDisable();
sysFlashWriteDisable1();
return flWriteProtect;
}

flashPtr = (FlashPTR) vol.map(&vol, address,length);
cLength = length;

iInterleaving=vol.interleaving;

vol.interleaving = 2;
if (vol.interleaving == 1) {
lastByte:
#ifdef __cplusplus
#define bFlashPtr flashPtr
#define bBuffer ((const unsigned char FAR1 * &) buffer)
#else
#define bFlashPtr flashPtr
#define bBuffer ((const unsigned char FAR1 *) buffer)
#endif
while (cLength >= 1) {
*bFlashPtr = (UINT8)SETUP_WRITE;
*bFlashPtr = *bBuffer;
do
{
*bFlashPtr = (UINT8)READ_STATUS;
}
while ((*bFlashPtr & WSM_READY) != (unsigned char)WSM_READY);

cLength--;
bBuffer++;
bFlashPtr++;
while (!(bFlashPtr[-1] & WSM_READY) && flMsecCounter < writeTimeout)
;
}
}
else if (vol.interleaving == 2) {
lastWord:
#ifdef __cplusplus
#define wFlashPtr ((FlashWPTR &) flashPtr)
#define wBuffer ((const unsigned short FAR1 * &) buffer)
#else
#define wFlashPtr ((FlashWPTR) flashPtr)
#define wBuffer ((const unsigned short FAR1 *) buffer)
#endif
while (cLength >= 2) {
*wFlashPtr = 0x40404040; flDelayLoop(2); /* HOOK for VME-177 */
*tempBuffer = *wBuffer;
*tempBuffer = ((*tempBuffer&0xff00)>>8)|((*tempBuffer&0x00ff)<<8);
/* flDelayLoop(5); */
*wFlashPtr = *tempBuffer; flDelayLoop(2); /* HOOK for VME-177 */

do
{
*wFlashPtr = 0x70707070;
}
while ((*wFlashPtr & 0x0080) != (unsigned short)0x0080);

cLength -= 2;
wBuffer++;
wFlashPtr++;
while (!(wFlashPtr[-1] & (0x0080)) && flMsecCounter < writeTimeout)
;
}
if (cLength > 0)
goto lastByte;
}
else /* if (vol.interleaving >= 4) */ {
#ifdef __cplusplus
#define dFlashPtr ((FlashDPTR &) flashPtr)
#define dBuffer ((const unsigned long FAR1 * &) buffer)
#else
#define dFlashPtr ((FlashDPTR) flashPtr)
#define dBuffer ((const unsigned long FAR1 *) buffer)
#endif
while (cLength >= 4) {
*dFlashPtr = SETUP_WRITE; /*by fxf =SETUP_WRITE*/ flDelayLoop(2); /* HOOK for VME-177 */
*tempBuffer = *dBuffer;
*tempBuffer = ((*tempBuffer&0xff000000)>>8)|((*tempBuffer&0x00ff0000)<<8)|((*tempBuffer&0xff00)>>8)|((*tempBuffer&0x00ff)<<8);

flDelayLoop(2);
*dFlashPtr = *dBuffer; flDelayLoop(2); /* HOOK for VME-177 */

do
{
*dFlashPtr = READ_STATUS;

}
while ((*dFlashPtr & WSM_READY) != (unsigned int)WSM_READY);
/* Check Byte Write Error Status */
cLength -= 4;
dBuffer++;
dFlashPtr++;
while (!(dFlashPtr[-1] & (WSM_READY)) && flMsecCounter < writeTimeout)
;
}
if (cLength > 0)
goto lastWord;
}

vol.interleaving = iInterleaving;

flashPtr -= length;
bBuffer -= length;

dwordFlashPtr = (FlashDPTR)flashPtr;

DEBUG_PRINT("fxf :flashPtr[0]=%x,(flashPtr[0] & WSM_ERROR)=%x\n",flashPtr[0],(flashPtr[0] & WSM_ERROR));/*by fxf */

status = flOK;
for (i = 0; i < vol.interleaving && i < length; i++) {
if (flashPtr[i] & WSM_ERROR) {


#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: write failed for 8-bit Intel media.\n");
DEBUG_PRINT("Debug: flashPtr[%d]=0x%x &flashPtr[%d]=0x%x.\n",i,flashPtr[i],i,&flashPtr[i]);
#endif
status = (flashPtr[i] & WSM_VPP_ERROR) ? flVppFailure : flWriteFault;
flashPtr[i] = CLEAR_STATUS;
}
flashPtr[i] = READ_ARRAY;
}

/* we need this to switch to the read window */


flashPtr = (FlashWPTR) vol.map(&vol, address,length);

DEBUG_PRINT("fxf:flashPtr=%s,buffer=%s,length=%s\n",flashPtr,buffer,length);
/* verify the data */
if (status == flOK && tffscmp((void FAR0 *) flashPtr,buffer,length)) {
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: write failed for 8-bit Intel media in verification.\n");

#endif
status = flWriteFault;
}
sysFlashWriteDisable();
sysFlashWriteDisable1();
return status;
}


菜鸟
2007-04-07 00:37:00     打赏
7楼

我没有看太仔细,没有发现什么问题,这里强行把vol.interleaving指定为2不知道会不会引起TFFS的反感,把你的identify函数贴出来看看吧


菜鸟
2007-04-07 00:50:00     打赏
8楼

/*----------------------------------------------------------------------*/
/* i 2 8 f 0 1 6 I d e n t i f y */
/* */
/* Identifies media based on Intel 28F016 and registers as an MTD for */
/* such. */
/* */
/* This routine will be placed on the MTD list in custom.h. It must be */
/* 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 */
/*----------------------------------------------------------------------*/

FLStatus i28f016Identify(FLFlash vol)
{
/*FlashWPTR flashPtr;/*by fxf */
FlashDPTR flashPtr;

#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: entering 16-bit Intel media identification routine.\n");
#endif
sysFlashWriteEnable();
sysFlashWriteEnable1();

flSetWindowBusWidth(vol.socket,32);
flSetWindowSpeed(vol.socket,120); /* 120 nsec. */
flSetWindowSize(vol.socket,2);

flashPtr = (FlashDPTR) flMap(vol.socket,0);

vol.noOfChips = 1;
flashPtr[0] = READ_ID;

if (flashPtr[0] == 0x00890089) {

/* Word mode */
vol.type = I28F016_FLASH;
vol.interleaving = 1;
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;
}

if (vol.type == I28F016_FLASH) {
vol.chipSize = TFFS_SIZE;
vol.erasableBlockSize = 0x20000L;
checkStatus(vol.interleaving == 1 ?
i28f016WordSize(&vol) :
flIntelSize(&vol, NULL,0));

/* Register our flash handlers */
vol.write = i28f016Write;
vol.erase = i28f016Erase;

#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: identified 16-bit Intel media.\n");
#endif
sysFlashWriteDisable();
sysFlashWriteDisable1();
return flOK;
}
else {
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: failed to identify 16-bit Intel media.\n");
#endif
return flUnknownMedia; /* not ours */
}
}


共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]