我的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 */
  }
}
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |