这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » [请教]tffsDevFormat的参数

共9条 1/1 1 跳转至

[请教]tffsDevFormat的参数

菜鸟
2006-08-03 19:17:57     打赏

请教各位大侠:

请问调用tffDevFormat时,函数参数是怎样确定的,***Erase(),***Write(),函数的参数又是怎样确定的,参数的传递过程又是怎样的?[em06]




关键词: 请教     tffsDevFormat     参数    

菜鸟
2006-08-04 21:56:00     打赏
2楼
根据你的芯片的手册呀!

菜鸟
2006-08-04 21:59:00     打赏
3楼

tffsDevFormatParams params =
{
#undef HALF_FORMAT /* lower 512KB for bootimage, upper for TFFS */
#ifdef HALF_FORMAT
{0x00080000l, 99, 1, 0x40000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},
#else
{0x00000000l, 99, 1, 0x40000l, NULL, {0,0,0,0}, NULL, 2, 0, NULL},
#endif /* HALF_FORMAT */
FTL_FORMAT_IF_NEEDED
};
status = tffsDevFormat (1, (int)&params); /* 设备1 */

0x00080000l是前面保留的大小;0x00000000l就是不保留!

0x40000l是一个扇区(SECTOR)的大小!(具体看你的芯片而定)


菜鸟
2006-08-04 22:59:00     打赏
4楼

谢谢大家的回复。

to maomaotr: 0x40000l 好像不是指一个扇区的大小,文档上说:/* FTL 在RAM中映射的大小,默认为 64Kbytes*/ (我也不明白到底是什么意义。)

问题继续:

举例***Write()来说:

***Write (FLFlash vol, CardAddress address, const void FAR1 *buffer, int length, int modes)中的address、buffer、length是根据那些宏定义来确定的呢?


菜鸟
2006-08-05 07:34:00     打赏
5楼

to maomaotr: 0x40000l 好像不是指一个扇区的大小,文档上说:/* FTL 在RAM中映射的大小,默认为 64Kbytes*/ (我也不明白到底是什么意义。) 64Kbytes=64*1024=0x10000;格式化一般是以扇区来进行,一般的扇区都是64Kbytes,但我的AM29PL160C是256Kbytes=0x40000,所以这么说!


菜鸟
2006-08-05 07:42:00     打赏
6楼

/*------------------------------------------------------------------------
Procedure: lv160MTDWrite ID:1
Purpose: MTD写Flash函数
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static FLStatus lv160MTDWrite(FLFlash vol, CardAddress address, const void FAR1 *buffer, int length, FLBoolean overwrite)
{
int cLength;
FlashWPTR flashPtr, flashTmp;
volatile UINT16 *gBuffer;

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(lv160OpOverDetect((void *)flashPtr, 0x1000000));
if(*flashPtr != *gBuffer)
{
*flashPtr = READ_ARRAY;
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: lv160MTDWrite timeout.\n");
#endif
return flWriteFault;
}
cLength--;
flashPtr++;
gBuffer++;
}
if (tffscmp((void FAR0 *) flashTmp, buffer,length))
{
/* verify the data */
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: lv160MTDWrite fail.\n");
#endif
return flWriteFault;
}

return flOK;
}
/*------------------------------------------------------------------------
Procedure: lv160MTDWrite ID:1
Purpose: MTD擦除Flash函数
Input:
Output:
Errors:
------------------------------------------------------------------------*/
static FLStatus lv160MTDErase(FLFlash vol, int firstErasableBlock, int numOfErasableBlocks)
{
int iBlock; FlashWPTR flashPtr;
unsigned int offset;

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;

lv160OpOverDetect((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: lv160MTDErase fail.\n");
#endif
return flWriteFault;
}
}

printf("\Erase ok\n");
return flOK;
}


菜鸟
2006-08-05 07:45:00     打赏
7楼

看看他们是怎样调用的:

/*------------------------------------------------------------------------
Procedure: lv160MTDIdentify ID:1
Purpose: MTD读Flash标识[extern]
Input:
Output:
Errors:
------------------------------------------------------------------------*/
FLStatus lv160MTDIdentify(FLFlash vol)
{
FlashWPTR baseFlashPtr;

vol.interleaving = 1;

flSetWindowBusWidth(vol.socket,16);/* use 16-bits */
flSetWindowSpeed(vol.socket,120); /* 120 nsec. */
if (vol.socket->serialNo == 0){
flSetWindowSize(vol.socket, FLASH_SIZE>>12);
vol.chipSize =0x001c0000; /* FLASH_SIZE;*/
vol.map = lv160MTDMap0;
}
else if(vol.socket->serialNo == 1){
flSetWindowSize(vol.socket, FLASH_BOOT_SIZE>>12);
vol.chipSize = FLASH_BOOT_SIZE;
vol.map = lv160MTDMap1;
}
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;

fllv160Identify(&vol, 2); /*get flash device ID.*/

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 != AM29LV160D_DEID)
{
#ifdef DEBUG_PRINT
DEBUG_PRINT("Debug: can not identify SST39VF160 media.\n");
#endif
return flUnknownMedia;
}

vol.noOfChips =0x1; /*one chip.*/
vol.erasableBlockSize = 0x40000; /* 256k bytes.*/
vol.flags |= SUSPEND_FOR_WRITE;

/* Register our flash handlers */
vol.write = lv160MTDWrite;
vol.erase = lv160MTDErase;

printf("\nidentify ok\n");
return flOK;
}

[align=right][color=#000066][此贴子已经被作者于2006-8-4 23:46:08编辑过][/color][/align]

菜鸟
2006-08-05 07:56:00     打赏
8楼

"tffs/flflash.h"

/************************************************************************/
/* */
/* FAT-FTL Lite Software Development Kit */
/* Copyright (C) M-Systems Ltd. 1995-1996 */
/* */
/************************************************************************/


#ifndef FLFLASH_H
#define FLFLASH_H

#ifdef __cplusplus
extern "C" {
#endif

#include "flsocket.h"

/* Some useful types for mapped Flash locations */

typedef volatile unsigned char FAR0 * FlashPTR;
typedef volatile unsigned short int FAR0 * FlashWPTR;
typedef volatile unsigned long FAR0 * FlashDPTR;

typedef unsigned short FlashType; /* JEDEC id */

#define NOT_FLASH 0

/* page characteristics flags */
#define BIG_PAGE 0x0100 /* page size > 100H*/
#define FULL_PAGE 0x0200 /* no partial page programming*/

/* MTD write routine mode flags */
#define OVERWRITE 1 /* Overwriting non-erased area */
#define EDC 2 /* Activate ECC/EDC */
#define EXTRA 4 /* Read/write spare area */


/*----------------------------------------------------------------------*/
/* Flash array identification structure */
/* */
/* This structure contains a description of the Flash array and */
/* routine pointers for the map, read, write & erase functions. */
/* */
/* The structure is initialized by the MTD that identifies the Flash */
/* array. */
/* On entry to an MTD, the Flash structure contains default routines */
/* for all operations. This routines are sufficient forread-only access */
/* to NOR Flash on a memory-mapped socket. The MTD should override the */
/* default routines with MTD specific ones when appropriate. */
/*----------------------------------------------------------------------*/

/* Flash array identification structure */

typedef struct tFlash FLFlash; /* Forward definition */

struct tFlash {
FlashType type; /* Flash device type (JEDEC id) */
long int erasableBlockSize; /* Smallest physically erasable size
(with interleaving taken in account) */
long int chipSize; /* chip size */
int noOfChips; /* no of chips in array */
int interleaving; /* chip interleaving
(The interleaving is defined as
the address difference between
two consecutive bytes on a chip) */
unsigned flags; /* Special capabilities & options
Bits 0-7 may be used by FLite.
Bits 8-15 are not used bt FLite
and may be used by MTD's for MTD-
specific purposes. */
void * mtdVars; /* Points to MTD private area for
this socket.
This field, if used by the MTD, is
initialized by the MTD identification
routine */
FLSocket * socket; /* Socket of this drive */


/* Flag bit values */

#define SUSPEND_FOR_WRITE 1 /* MTD provides suspend for write */
#define NFTL_ENABLED 2 /* Flash can run NFTL */


/*----------------------------------------------------------------------*/
/* f l a s h . m a p */
/* */
/* MTD specific map routine */
/* */
/* The default routine maps by socket mapping, and is suitable for all */
/* NOR Flash. */
/* NAND or other type Flash should use map-through-copy emulation: Read */
/* a block of Flash to an internal buffer and return a pointer to that */
/* buffer. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* address : Card address to map */
/* length : Length to map */
/* */
/* Returns: */
/* Pointer to required card address */
/*----------------------------------------------------------------------*/
void FAR0 * (*map)(FLFlash *, CardAddress, int);

/*----------------------------------------------------------------------*/
/* f l a s h . r e a d */
/* */
/* MTD specific Flash read routine */
/* */
/* The default routine reads by copying from a mapped window, and is */
/* suitable for all NOR Flash. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* address : Card address to read */
/* buffer : Area to read into */
/* length : Length to read */
/* */
/*----------------------------------------------------------------------*/
FLStatus (*read)(FLFlash *, CardAddress, void FAR1 *, int, int);

/*----------------------------------------------------------------------*/
/* f l a s h . w r i t e */
/* */
/* MTD specific Flash write routine */
/* */
/* The default routine returns a write-protect error. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* address : Card address to write to */
/* buffer : Address of data to write */
/* length : Number of bytes to write */
/* modes : See write mode flags definition above */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus (*write)(FLFlash *, CardAddress, const void FAR1 *, int, int);

/*----------------------------------------------------------------------*/
/* f l a s h . e r a s e */
/* */
/* Erase one or more contiguous Flash erasable blocks */
/* */
/* The default routine returns a write-protect error. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* firstErasableBlock : Number of first block to erase */
/* numOfErasableBlocks: Number of blocks to erase */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus (*erase)(FLFlash *, int, int);

/*----------------------------------------------------------------------*/
/* f l a s h . s e t P o w e r O n C a l l b a c k */
/* */
/* Register power on callback routine. Default: no routine is */
/* registered. */
/* */
/* Parameters: */
/* vol : Pointer identifying drive */
/* */
/*----------------------------------------------------------------------*/
void (*setPowerOnCallback)(FLFlash *);
};

/* MTD registration information */

extern int noOfMTDs; /* No. of MTDs actually registered */

typedef FLStatus (*MTDidentifyRoutine) (FLFlash vol);

extern MTDidentifyRoutine mtdTable[];


/* See interface documentation of functions in flash.c */

extern void flIntelIdentify(FLFlash *,
void (*)(FLFlash *, CardAddress, unsigned char, FlashPTR),
CardAddress);

extern FLStatus flIntelSize(FLFlash *,
void (*)(FLFlash *, CardAddress, unsigned char, FlashPTR),
CardAddress);

extern FLStatus flIdentifyFlash(FLSocket *socket, FLFlash *flash);

#ifdef __cplusplus
}
#endif

#endif


菜鸟
2006-08-05 19:44:00     打赏
9楼

谢谢 maomaotr的回答。

我根据maoamotr的回复对照了自己的代码,然后调试中出现了这样的问题:

-> tffsDevFormat
Debug:i28f128MTDIdentify: entering 16-bit Intel media identification routine.
Debug:i28f128MTDIdentify: entering 16-bit Intel media identification routine.
Debug: i28f128Erase - firstErasableBlock=0, iBlock=0, vol.erasableBlockSize=0x20000, offset=0x0.
Debug: i28f128Erase - flashPtr=0x10140000, first=0, number=1.

i28f128Write: dest=0x10140000, src=0x21fff070 , size=0x50, start_sect=0x0, i28f128Write:start_sect=0x0,end_sect=0x0
************erase sector 0x0***********
----------program sector 0x0---------

Data abort

我发现src=0x21fff070 , size=0x50,都不是我想要的值,但是也不知道这些值系统是根据什么配置来确定的。

[em06][em06]

共9条 1/1 1 跳转至

回复

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