我的arm系列的32位芯片,flash2片是16位的,在加载tffs驱动的时候使用28f016的时候写入总是不正确,
static FLStatus i28f016Write(FLFlash vol,
CardAddress address,
const void FAR1 *buffer,
int length,
FLBoolean overwrite)应该如何改?
/*----------------------------------------------------------------------*/
/* 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;
}
/*----------------------------------------------------------------------*/
/* 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 */
}
}
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 |