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

📄 am29lv160bt.c

📁 vxworks中am29lv160bt的mtd驱动。
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "flflash.h"#include "backgrnd.h"#define INCLUDE_ONE_FlASH/*#undef  INCLUDE_ONE_FlASH*//* JEDEC ids for this MTD */#define am29lv160bt_FLASH	    0x22c4 /* zhan add*/  #ifdef INCLUDE_ONE_FlASH /* zhan add */#define	FLASH_BASE_ADRS	            0x01000000#define	FLASH_SIZE		              0x0400000			#define FLASH_START_ADDR            0x01000000    #else#define	FLASH_BASE_ADRS		          0x02000000	#define	FLASH_SIZE		              0x0200000#define FLASH_START_ADDR            0x02000000#endif#define FLASH_ADDR_UNLOCK1     	    0x555#define FLASH_ADDR_UNLOCK2     	    0x2aa#define FLASH_ADDR_UNLOCK3          0x555#define FLASH_DATA_UNLOCK1     	    0xaa#define FLASH_DATA_UNLOCK2     	    0x55#define FLASH_DATA_UNLOCK3     	    0xa0#define AMD_ID                      0x01        /* AM29LV160BT Manufacture ID code */#define AMD_29LV160                 0x22c4      /* AMD AM29LV160BT device code */#define ADDRESS_ID1                 0x00000000#define ADDRESS_ID2                 0x00000001/*#ifdef DEBUG_PRINT#undef DEBUG_PRINT#define DEBUG_PRINT  printf#endif*/#define DEBUG_PRINT  printf#undef DEBUG_PRINT/*----------------------------------------------------------------------*//*                      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 am29lv160btWrite(FLFlash vol,			   CardAddress address,			   const void FAR1 *buffer,			   int length,			   FLBoolean overwrite ){  /* Set timeout ot 5 seconds from now */  /*unsigned long writeTimeout = flMsecCounter + 5000;*/  FLStatus status = flOK;  FlashWPTR flashPtr;  /*int maxLength, i, from;  */UINT16 *pData;  UINT32 k;  int j;    UINT32 startAddr;  if (address  >= 0x200000){  	 startAddr = 0x1200000;         address = address - 0x200000;  }  else startAddr = 0x1000000;   /*  if (flWriteProtected(vol.socket))    return flWriteProtect;*/    #ifdef DEBUG_PRINT  /*  flashPtr = (FlashWPTR) flMap(vol.socket, address);*/     flashPtr =(FlashWPTR)(address + startAddr);     DEBUG_PRINT("write addr:%x\nmaped address:%x\nlength:%d\noverwrite value is %d\n\n",address,flashPtr,length,overwrite);  #endif      /*  if ((length %2 )!=0) length = length + 1;    */        if (length & 1)	/* Only write words on word-boundary */    return flBadParameter;    pData=(UINT16 *)buffer;    k=address/2 ; /* there should /2 */    for(j=0x0 ; j<length/2; j++){               *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK1) = FLASH_DATA_UNLOCK1;              *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK2) = FLASH_DATA_UNLOCK2;       *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK3) = FLASH_DATA_UNLOCK3;          *((volatile UINT16 *) startAddr + k) = *pData++;                             /*need wait 11us */                flDelayLoop(150);                  k++;    }  /* tffsFlashWrite(buffer, length, address+0x100000, 0xc4,0);*/#if 0  if ((length & 1) || (address & 1))	/* Only write words on word-boundary */    return flBadParameter;#ifdef SOCKET_12_VOLTS  checkStatus(flNeedVpp(vol.socket));#endif  maxLength = 256 * vol.interleaving;  for (from = 0; from < length && status == flOK; from += maxLength) {    FlashWPTR currPtr;    unsigned lengthWord;    int tailBytes;    int thisLength = length - from;    if (thisLength > maxLength)      thisLength = maxLength;    lengthWord = (thisLength + vol.interleaving - 1) /		 (vol.interleaving == 1 ? 2 : vol.interleaving) - 1;    if (vol.interleaving != 1)      lengthWord |= (lengthWord << 8);    flashPtr = (FlashWPTR) flMap(vol.socket,address + from);    tailBytes = ((thisLength - 1) & (vol.interleaving - 1)) + 1;    for (i = 0, currPtr = flashPtr;	 i < vol.interleaving && i < thisLength;	 i += 2, currPtr++) {      *currPtr = LOAD_PAGE_BUFFER;      *currPtr = i < tailBytes ? lengthWord : lengthWord - 1;      *currPtr = 0;    }    tffscpyWords((unsigned long FAR0 *) flashPtr,	    (const char FAR1 *) buffer + from,	    thisLength);    for (i = 0, currPtr = flashPtr;	 i < vol.interleaving && i < thisLength;	 i += 2, currPtr++) {      *currPtr = WRITE_PAGE_BUFFER;      if (!((address + from + i) & vol.interleaving)) {	/* Even address */	*currPtr = lengthWord;	*currPtr = 0;      }      else {	/* Odd address */	*currPtr = 0;	*currPtr = lengthWord;      }    }    /* map to the GSR & BSR */    flashPtr = (FlashWPTR) flMap(vol.socket,			       ((address + from) & -vol.erasableBlockSize) +			       4 * vol.interleaving);    for (i = 0, currPtr = flashPtr;	 i < vol.interleaving && i < thisLength;	 i += 2, currPtr++) {      *currPtr = READ_EXTENDED_REGS;      while (!(both(*currPtr) & WSM_READY) && flMsecCounter < writeTimeout)	;      if ((any(*currPtr) & GSR_ERROR) || !(both(*currPtr) & WSM_READY)) {      #ifdef DEBUG_PRINT	DEBUG_PRINT("Debug: write failed for 16-bit Intel media.\n");      #endif	status = flWriteFault;	*currPtr = CLEAR_STATUS;      }      *currPtr = READ_ARRAY;    }  }#ifdef SOCKET_12_VOLTS  flDontNeedVpp(vol.socket);#endif  flashPtr = (FlashWPTR) flMap(vol.socket, address);  /* verify the data */  if (status == flOK && tffscmpWords((void FAR0 *) flashPtr, (void FAR1 *) buffer,length)) {  #ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: write failed for 16-bit Intel media in verification.\n");  #endif    status = flWriteFault;  }#endifreturn status;}static void sectorErase(UINT32 sectorAdr,UINT32 startAddr) {    *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK1) = FLASH_DATA_UNLOCK1;           *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK2) = FLASH_DATA_UNLOCK2;    *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK3) = 0x80;    *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK3) = FLASH_DATA_UNLOCK1;           *((volatile UINT16 *) startAddr + FLASH_ADDR_UNLOCK2) = FLASH_DATA_UNLOCK2;     /* sectorAdr range is 0x00000~0x1f0000,0x1f0000,0x1f8000,0x1fa000,0x1fc000==>byte mode */    *((volatile UINT16 *)  (startAddr + sectorAdr)) = 0x30; }static void lastSectorErase(UINT32 startAddr) /* word mode */{	int i;		#ifdef DEBUG_PRINT	     DEBUG_PRINT("****Enter erase last four sectors****\n" );        #endif		sectorErase (0x1f0000,startAddr);	for (i=0; i<43; i++ ) flDelayLoop (0x21000); /* delay 0.7s */	sectorErase (0x1f8000,startAddr);	for (i=0; i<43; i++ ) flDelayLoop (0x21000);	sectorErase (0x1fa000,startAddr);	for (i=0; i<43; i++ ) flDelayLoop (0x21000);	sectorErase (0x1fc000,startAddr);	for (i=0; i<43; i++ ) flDelayLoop (0x21000);		#ifdef DEBUG_PRINT	     DEBUG_PRINT("****End erase last four sectors****\n" );        #endif}/*----------------------------------------------------------------------*//*                      i 2 8 f 0 1 6 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 am29lv160btErase(FLFlash vol,			   int firstErasableBlock,			   int numOfErasableBlocks){  FLStatus status = flOK;	/* unless proven otherwise */  int iBlock,i;/*  if (flWriteProtected(vol.socket))    return flWriteProtect;#ifdef SOCKET_12_VOLTS  checkStatus(flNeedVpp(vol.socket));#endif*/

⌨️ 快捷键说明

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