⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amdmtd.c

📁 vxworks tffs for x86
💻 C
📖 第 1 页 / 共 2 页
字号:
      dFlashPtr++;      while ((dFlashPtr[-1] != dBuffer[-1]) && (flMsecCounter < writeTimeout)) {        if (((dFlashPtr[-1] &  D5               ) && ((dFlashPtr[-1]  ^ dBuffer[-1]) &         0xff))                               ||            ((dFlashPtr[-1] & (D5 *       0x100)) && ((dFlashPtr[-1]  ^ dBuffer[-1]) &       0xff00))                               ||            ((dFlashPtr[-1] & (D5 *   0x10000lu)) && ((dFlashPtr[-1]  ^ dBuffer[-1]) &   0xff0000lu))                               ||            ((dFlashPtr[-1] & (D5 * 0x1000000lu)) && ((dFlashPtr[-1]  ^ dBuffer[-1]) & 0xff000000lu))) {	  dFlashPtr[-1] = READ_ARRAY * 0x1010101lu;	#ifdef DEBUG_PRINT	  DEBUG_PRINT("Debug: write failed in AMD MTD.\n");	#endif	  return flWriteFault;	}      }    }    if (cLength > 0)      goto lastWord;  }  flashPtr -= length;  bBuffer -= length;  if (tffscmp((void FAR0 *) flashPtr,buffer,length)) {    /* verify the data */	#ifdef DEBUG_PRINT	  DEBUG_PRINT("Debug: write failed in AMD MTD on verification.\n");	#endif    return flWriteFault;  }  return flOK;}/*----------------------------------------------------------------------*//*               e r a s e F i r s t B l o c k L V 0 0 8		*//*									*//* Erase the first block in LV008 chip. This block is devided into four *//* subblocks 16, 8, 8, and 32 kbytes in size.  				*//*									*//* Parameters:                                                          *//*	vol		: Pointer identifying drive			*//*      firstErasableBlock : Number of block to erase			*//*                                                                      *//* Returns:                                                             *//*	FLStatus	: 0 on success, failed otherwise		*//*----------------------------------------------------------------------*/static FLStatus eraseFirstBlockLV008(FLFlash vol, int firstErasableBlock){  int iSubBlock;  long subBlockSize = 0;  for (iSubBlock = 0; iSubBlock < 4; iSubBlock++) {    int i;    FlashPTR flashPtr;    FLBoolean finished;    switch (iSubBlock) {      case 1:	subBlockSize = 0x4000;	break;      case 2:      case 3:	subBlockSize = 0x2000;	break;    }    flashPtr = (FlashPTR)	  vol.map(&vol,		    firstErasableBlock + subBlockSize * vol.interleaving,		    vol.interleaving);    for (i = 0; i < vol.interleaving; i++) {      amdCommand(&vol, i,SETUP_ERASE, flashPtr);      *((FlashPTR) flAddLongToFarPointer((void FAR0 *)flashPtr,                                          i + thisVars->unlockAddr1)) = UNLOCK_1;      *((FlashPTR) flAddLongToFarPointer((void FAR0 *)flashPtr,                                          i + thisVars->unlockAddr2)) = UNLOCK_2;      flashPtr[i] = SECTOR_ERASE;    }    do {#ifdef BACKGROUND      while (flForeground(1) == BG_SUSPEND) {		/* suspend */	for (i = 0; i < vol.interleaving; i++) {	  flashPtr[i] = SUSPEND_ERASE;	  /* Wait for D6 to stop toggling */	  while ((flashPtr[i] ^ flashPtr[i]) & D6)	    ;	}      }#endif      finished = TRUE;      for (i = 0; i < vol.interleaving; i++) {	flashPtr[i] = RESUME_ERASE;	if (flashPtr[i] != 0xff) {	  if ((flashPtr[i] & D5) && flashPtr[i] != 0xff) {	    flashPtr[i] = READ_ARRAY;	    return flWriteFault;	  }	  finished = FALSE;	}      }    } while (!finished);  }  return flOK;}/*----------------------------------------------------------------------*//*                     a m d M T D E r a s e				*//*									*//* Erase one or more contiguous Flash erasable blocks			*//*									*//* This routine will be registered as the MTD vol.erase routine	*//*									*//* 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		*//*----------------------------------------------------------------------*/static FLStatus amdMTDErase(FLFlash vol,			  int firstErasableBlock,			  int numOfErasableBlocks){  int iBlock;  if (flWriteProtected(vol.socket))    return flWriteProtect;  for (iBlock = 0; iBlock < numOfErasableBlocks; iBlock++) {    int i;    FLBoolean finished;    FlashPTR flashPtr;    /* The first block in an LV008 chip requires special care.*/    if ((vol.type == Am29LV008_FLASH) || (vol.type == Fuj29LV008_FLASH))      if ((firstErasableBlock + iBlock) % (vol.chipSize / 0x10000l) == 0) {	checkStatus(eraseFirstBlockLV008(&vol, firstErasableBlock + iBlock));	continue;      }    /* No need to call mapBase because we know we are on a unit boundary */    flashPtr = (FlashPTR)	  vol.map(&vol,		    (firstErasableBlock + iBlock) * vol.erasableBlockSize,		    vol.interleaving);    for (i = 0; i < vol.interleaving; i++) {      amdCommand(&vol, i,SETUP_ERASE, flashPtr);      *((FlashPTR) flAddLongToFarPointer((void FAR0 *)flashPtr,                                          i + thisVars->unlockAddr1)) = UNLOCK_1;      *((FlashPTR) flAddLongToFarPointer((void FAR0 *)flashPtr,                                          i + thisVars->unlockAddr2)) = UNLOCK_2;      flashPtr[i] = SECTOR_ERASE;    }    do {#ifdef BACKGROUND      FLBoolean eraseSuspended = FALSE;      while (flForeground(1) == BG_SUSPEND) {		/* suspend */        eraseSuspended = TRUE;	for (i = 0; i < vol.interleaving; i++) {	  flashPtr[i] = SUSPEND_ERASE;	  /* Wait for D6 to stop toggling */	  while ((flashPtr[i] ^ flashPtr[i]) & D6)	    ;	}      }      if (eraseSuspended) {  				/* resume */        eraseSuspended = FALSE;        for(i = 0; i < vol.interleaving; i++)          flashPtr[i] = RESUME_ERASE;      }#endif      finished = TRUE;      for (i = 0; i < vol.interleaving; i++) {	if (flashPtr[i] != 0xff) {	  if ((flashPtr[i] & D5) && flashPtr[i] != 0xff) {	    flashPtr[i] = READ_ARRAY;	  #ifdef DEBUG_PRINT	    DEBUG_PRINT("Debug: erase failed in AMD MTD.\n");	  #endif	    return flWriteFault;	  }	  finished = FALSE;	}      }    } while (!finished);  }  return flOK;}/*----------------------------------------------------------------------*//*                    a m d M T D I d e n t i f y			*//*									*//* Identifies AMD and Fujitsu flash media and registers as an MTD for   *//* such.								*//*									*//* 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 amdMTDIdentify(FLFlash vol){  int inlv;  #ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: entering AMD MTD identification routine.\n");  #endif  flSetWindowBusWidth(vol.socket,16);/* use 16-bits */  flSetWindowSpeed(vol.socket,120);  /* 120 nsec. */  flSetWindowSize(vol.socket,2);	/* 8 KBytes */  vol.mtdVars = &mtdVars[flSocketNoOf(vol.socket)];  thisVars->unlockAddr1 = NO_UNLOCK_ADDR;  /* try different interleavings */  for (inlv = 4; inlv > 0; inlv >>= 1) {    if (inlv == 1)      flSetWindowBusWidth(vol.socket,8); /* use 8-bits */    vol.interleaving = inlv;    flIntelIdentify(&vol, amdCommand,0);    if (vol.type == Am29F016_FLASH ||	vol.type == Fuj29F016_FLASH ||	vol.type == Am29F016C_FLASH ||	vol.type == Fuj29F016C_FLASH ||	vol.type == Am29F080_FLASH ||	vol.type == Fuj29F080_FLASH ||	vol.type == Am29LV080_FLASH ||	vol.type == Fuj29LV080_FLASH ||	vol.type == Am29LV008_FLASH ||	vol.type == Fuj29LV008_FLASH ||	vol.type == Am29F040_FLASH ||	vol.type == Fuj29F040_FLASH ||	vol.type == Am29LV017_FLASH ||	vol.type == Fuj29LV017_FLASH)      break;  }  if (vol.type == Am29F016_FLASH ||      vol.type == Fuj29F016_FLASH ||      vol.type == Am29F016C_FLASH ||      vol.type == Fuj29F016C_FLASH ||      vol.type == Am29LV017_FLASH ||      vol.type == Fuj29LV017_FLASH)    vol.chipSize = 0x200000l;  else if (vol.type == Fuj29F080_FLASH ||	   vol.type == Am29F080_FLASH ||	   vol.type == Fuj29LV080_FLASH ||	   vol.type == Am29LV080_FLASH ||	   vol.type == Fuj29LV008_FLASH ||	   vol.type == Am29LV008_FLASH)    vol.chipSize = 0x100000l;  else if (vol.type == Fuj29F040_FLASH ||	   vol.type == Am29F040_FLASH)    vol.chipSize = 0x80000l;  else {  #ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: did not identify AMD or Fujitsu flash media.\n");  #endif    return flUnknownMedia;  }  if ((vol.type == Am29F016C_FLASH) || (vol.type == Fuj29F016C_FLASH)) {    thisVars->unlockAddr1 = thisVars->unlockAddr2 = 0L;    thisVars->baseMask = 0xfffff800L * vol.interleaving;  }  else if ((vol.type == Am29F040_FLASH) || (vol.type == Fuj29F040_FLASH)){    flSetWindowSize(vol.socket,8 * vol.interleaving);    thisVars->unlockAddr1 = 0x5555u * vol.interleaving;    thisVars->unlockAddr2 = 0x2aaau * vol.interleaving;    thisVars->baseMask = 0xffff8000L * vol.interleaving;  }  else {    thisVars->unlockAddr1 = 0x555 * vol.interleaving;    thisVars->unlockAddr2 = 0x2aa * vol.interleaving;    thisVars->baseMask = 0xfffff800L * vol.interleaving;  }  checkStatus(flIntelSize(&vol,amdCommand,0));  vol.erasableBlockSize = 0x10000l * vol.interleaving;  vol.flags |= SUSPEND_FOR_WRITE;  /* Register our flash handlers */  vol.write = amdMTDWrite;  vol.erase = amdMTDErase;#ifdef DEBUG_PRINT  DEBUG_PRINT("Debug: Identified AMD or Fujitsu flash media.\n");#endif  return flOK;}#if	FALSE/*----------------------------------------------------------------------*//*                   f l R e g i s t e r A M D M T D			*//*									*//* Registers this MTD for use						*//*									*//* Parameters:                                                          *//*	None								*//*                                                                      *//* Returns:								*//*	FLStatus	: 0 on success, otherwise failure		*//*----------------------------------------------------------------------*/FLStatus flRegisterAMDMTD(void){  if (noOfMTDs >= MTDS)    return flTooManyComponents;  mtdTable[noOfMTDs++] = amdMTDIdentify;  return flOK;}#endif	/* FALSE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -