📄 am29lv160bt.c
字号:
UINT32 startAddr; #ifdef DEBUG_PRINT DEBUG_PRINT("erase block size:%x first:%d NUM:%d\n",vol.erasableBlockSize,firstErasableBlock,numOfErasableBlocks); #endif #ifdef DEBUG_PRINT DEBUG_PRINT("erase adress:%x\n", (firstErasableBlock + iBlock) * vol.erasableBlockSize); #endif if (firstErasableBlock >= 32){ startAddr = 0x1200000; firstErasableBlock = firstErasableBlock - 32; } else startAddr = 0x1000000; for (iBlock = 0; iBlock < numOfErasableBlocks ; iBlock++) { if ((firstErasableBlock + iBlock) == 31) { lastSectorErase( startAddr); break; } *((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; *((volatile UINT16 *) (startAddr + (firstErasableBlock + iBlock) * vol.erasableBlockSize)) = 0x30; /* need wait 0.7s */ for (i=0; i<43; i++) flDelayLoop(0x21000); } /* for (iBlock = 0; iBlock < numOfErasableBlocks && status == flOK; iBlock++) { FlashWPTR currPtr; int i; FLBoolean finished; FlashWPTR flashPtr = (FlashWPTR) flMap(vol.socket,(firstErasableBlock + iBlock) * vol.erasableBlockSize); #ifdef DEBUG_PRINT DEBUG_PRINT("erase adress:%d\n",(firstErasableBlock + iBlock) * vol.erasableBlockSize); #endif for (i = 0, currPtr = flashPtr; i < vol.interleaving; i += 2, currPtr++) { *currPtr = SETUP_ERASE; *currPtr = CONFIRM_ERASE; } tffsFlashEraseSector(0xc4,(firstErasableBlock + iBlock) * vol.erasableBlockSize);#if 0 do {#ifdef BACKGROUND while (flForeground(1) == BG_SUSPEND) { for (i = 0, currPtr = flashPtr; i < vol.interleaving; i += 2, currPtr++) { *currPtr = READ_STATUS; if (!(both(*currPtr) & WSM_READY)) { *currPtr = SUSPEND_ERASE; *currPtr = READ_STATUS; while (!(both(*currPtr) & WSM_READY)) ; } *currPtr = READ_ARRAY; } }#endif finished = TRUE; for (i = 0, currPtr = flashPtr; i < vol.interleaving; i += 2, currPtr++) { *currPtr = READ_STATUS; if (any(*currPtr) & WSM_SUSPENDED) { *currPtr = RESUME_ERASE; finished = FALSE; } else if (!(both(*currPtr) & WSM_READY)) finished = FALSE; else { if (any(*currPtr) & WSM_ERROR) { #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: erase failed for 16-bit Intel media.\n"); #endif status = (any(*currPtr) & WSM_VPP_ERROR) ? flVppFailure : flWriteFault; *currPtr = CLEAR_STATUS; } *currPtr = READ_ARRAY; } } } while (!finished); #endif }#ifdef SOCKET_12_VOLTS flDontNeedVpp(vol.socket);#endif */ return status;}/* zhan add */static void FAR0 * am29lv160btMTDMap(FLFlash *vol, CardAddress addr, int length) { UINT32 ret; ret = FLASH_BASE_ADRS + addr; return (void FAR0 *)ret; }/*----------------------------------------------------------------------*//* 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 am29lv160btIdentify(FLFlash vol){ /*FlashWPTR flashPtr; */ unsigned long amd_id1; unsigned long amd_id2; #ifdef DEBUG_PRINT DEBUG_PRINT("\nDebug: entering 16-bit am29lv160bt identification routine.\n"); #endif flSetWindowBusWidth(vol.socket,16); /* use 16-bits */ flSetWindowSpeed(vol.socket,120); /* 120 nsec. */ /*flSetWindowSize(vol.socket,2);*/ /* 8 KBytes */ /* zhan added */ vol.interleaving = 1; flSetWindowSize(vol.socket, FLASH_SIZE>>12); vol.chipSize = FLASH_SIZE; vol.noOfChips = 0x1; /*one chip.*/ vol.erasableBlockSize = 0x10000; /* 64k bytes.*/ *((volatile UINT16 *) FLASH_START_ADDR + FLASH_ADDR_UNLOCK1) = FLASH_DATA_UNLOCK1; *((volatile UINT16 *) FLASH_START_ADDR + FLASH_ADDR_UNLOCK2) = FLASH_DATA_UNLOCK2; *((volatile UINT16 *) FLASH_START_ADDR + FLASH_ADDR_UNLOCK3) = 0x90; amd_id1 = *(volatile UINT16 *) (ADDRESS_ID1 + FLASH_START_ADDR); amd_id2 = *(volatile UINT16 *) (ADDRESS_ID2*2 + FLASH_START_ADDR); /* there must be ADDRESS_ID2*2 */ *((volatile UINT16 *) FLASH_START_ADDR + 0) = 0xF0; if ((amd_id1 == AMD_ID) && (amd_id2 == AMD_29LV160)) { vol.type = am29lv160bt_FLASH; vol.write = am29lv160btWrite; vol.erase = am29lv160btErase; vol.map = am29lv160btMTDMap; #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: am29lv160bt identified 16-bit Intel media.\n"); #endif return flOK; } else { #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: failed to am29lv160bt identify 16-bit Intel media.\n"); #endif return flUnknownMedia; /* not ours */ }/* zhan added end *//* flashPtr = (FlashWPTR) flMap(vol.socket,0); vol.noOfChips = 0; vol.interleaving = 1; vol.type = sst39vf160_FLASH; #if 0 flashPtr[0] = READ_ID; if (flashPtr[0] == 0x0089 && flashPtr[1] == 0x66a0) { Word mode */ /* vol.type = sst39vf160_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; We cannot handle byte-mode interleaving-1 *//* } #endif if (vol.type == sst39vf160_FLASH) { vol.chipSize = 0x200000L; vol.erasableBlockSize = 0x8000L * vol.interleaving; checkStatus(vol.interleaving == 1 ? sst39vf160WordSize(&vol) : flIntelSize(&vol, NULL,0)); Register our flash handlers */ /* vol.write = sst39vf160Write; vol.erase = sst39vf160Erase; #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: identified 16-bit Intel media.\n"); #endif return flOK; } else { #ifdef DEBUG_PRINT DEBUG_PRINT("Debug: failed to identify 16-bit Intel media.\n"); #endif return flUnknownMedia; not ours */ /*}*/ }#if FALSE/*----------------------------------------------------------------------*//* f l R e g i s t e r I 2 8 F 0 1 6 *//* *//* Registers this MTD for use *//* *//* Parameters: *//* None *//* *//* Returns: *//* FLStatus : 0 on success, otherwise failure *//*----------------------------------------------------------------------*/FLStatus flRegisteram29lv160bt(void){ if (noOfMTDs >= MTDS) return flTooManyComponents; mtdTable[noOfMTDs++] = am29lv160btIdentify; return flOK;}#endif /* FALSE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -