?? wamdmtd.c
字號:
/************************************************************************//* *//* FAT-FTL Lite Software Development Kit *//* Copyright (C) M-Systems Ltd. 1995-1996 *//* *//************************************************************************//* *//* 16-bit AMD MTD *//* *//* This MTD is for flash media which is accessible in 16-bit mode only. *//* The following Flash technologies are supported: *//* *//* - AMD Am29F080 8-mbit devices *//* - AMD Am29LV080 8-mbit devices *//* - AMD Am29F016 16-mbit devices *//* - Fujitsu MBM29F080 8-mbit devices *//* *//************************************************************************//* * $Log: V:/wamdmtd.c_v $ * * Rev 1.1 07 Oct 1997 14:58:32 ANDRY * get rid of generic names, registration routine returns status * * Rev 1.0 25 Aug 1997 12:00:00 ANDRY * Initial revision. */#include "flflash.h"#include "backgrnd.h"/* JEDEC ids for this MTD */#define Am29F040_FLASH 0x01a4#define Am29F080_FLASH 0x01d5#define Am29LV080_FLASH 0x0138#define Am29LV008_FLASH 0x0137#define Am29F016_FLASH 0x01ad#define Am29F016C_FLASH 0x013d#define Am29LV017_FLASH 0x01c8#define Fuj29F040_FLASH 0x04a4#define Fuj29F080_FLASH 0x04d5#define Fuj29LV080_FLASH 0x0438#define Fuj29LV008_FLASH 0x0437#define Fuj29F016_FLASH 0x04ad#define Fuj29F016C_FLASH 0x043d#define Fuj29LV017_FLASH 0x04c8/* commands for AMD flash */#define SETUP_ERASE 0x8080#define SETUP_WRITE 0xa0a0#define READ_ID 0x9090#define SUSPEND_ERASE 0xb0b0#define SECTOR_ERASE 0x3030#define RESUME_ERASE 0x3030#define READ_ARRAY 0xf0f0#define INTEL_READ_ARRAY 0xffff/* AMD unlocking sequence */#define UNLOCK_1 0xaaaa#define UNLOCK_2 0x5555#define UNLOCK_ADDR1 0x5555#define UNLOCK_ADDR2 0x2aaa/* AMD flash status bits */#define D2 0x04 /* Toggles when erase suspended */#define D5 0x20 /* Set when programming timeout */#define D6 0x40 /* Toggles when programming */#ifdef __cplusplus #define wFlashPtr ((FlashWPTR &) flashPtr) #define wBuffer ((const unsigned short FAR1 * &) buffer) #define wUnlockAddr1 ((FlashWPTR &) unlockAddr1) #define wUnlockAddr2 ((FlashWPTR &) unlockAddr2)#else #define wFlashPtr ((FlashWPTR) flashPtr) #define wBuffer ((const unsigned short FAR1 *) buffer) #define wUnlockAddr1 ((FlashWPTR) unlockAddr1) #define wUnlockAddr2 ((FlashWPTR) unlockAddr2)#endif/* -------------------------------------------------------------------- *//* AMD Flash specific data. Pointed by FLFlash.mtdVars *//* -------------------------------------------------------------------- */typedef struct { FlashWPTR unlockAddr1; FlashWPTR unlockAddr2; } Vars;static Vars mtdVars[DRIVES];#define thisVars ((Vars *) vol.mtdVars)/* -------------------------------------------------------------------- *//* f l U p d a t e U n l o c k A d d r s *//* *//* Updates unlock addresses for AMD flash media. *//* *//* *//* Parameters: *//* vol : Pointer identifying drive *//* basePtr : flash pointer, could point anywhere in the *//* memory window *//* *//* -------------------------------------------------------------------- */static void flUpdateUnlockAddrs (FLFlash vol, FlashWPTR basePtr){ if ((vol.type == Am29F016C_FLASH) || (vol.type == Fuj29F016C_FLASH)) thisVars->unlockAddr1 = thisVars->unlockAddr2 = basePtr; else { thisVars->unlockAddr1 = (FlashWPTR)(((long)basePtr & -0x10000l)) + 0x555; thisVars->unlockAddr2 = (FlashWPTR)(((long)basePtr & -0x10000l)) + 0x2aa; }}/*----------------------------------------------------------------------*//* f l w A m d C o m m a n d *//* *//* Writes an AMD command with the required unlock sequence *//* *//* Parameters: *//* vol : Pointer identifying drive *//* address : Card address at which to write command *//* command : command to write *//* *//*----------------------------------------------------------------------*/static void flwAmdCommand (FLFlash vol, CardAddress address, unsigned short command){ if (thisVars->unlockAddr1) { thisVars->unlockAddr1[0] = UNLOCK_1; thisVars->unlockAddr2[0] = UNLOCK_2; thisVars->unlockAddr1[0] = command; } else { CardAddress baseAddress = address & (-0x10000l); /* write AMD unlock sequence */ *(FlashWPTR) vol.map (&vol, baseAddress + 2 * UNLOCK_ADDR1, vol.interleaving) = UNLOCK_1; *(FlashWPTR) vol.map (&vol, baseAddress + 2 * UNLOCK_ADDR2, vol.interleaving) = UNLOCK_2; /* write flash command */ *(FlashWPTR) vol.map (&vol, baseAddress + 2 * UNLOCK_ADDR1, vol.interleaving) = command; vol.map (&vol, address, vol.interleaving); }}/*----------------------------------------------------------------------*//* f l w A m d M T D W r i t e *//* *//* Write a block of bytes to Flash *//* *//* This routine will be registered as FLFlash.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 flwAmdMTDWrite (FLFlash vol, CardAddress address, const void FAR1 *buffer, int length, FLBoolean overwrite){ unsigned long writeTimeout; int cLength; FlashWPTR flashPtr, unlockAddr1 = thisVars->unlockAddr1, unlockAddr2 = thisVars->unlockAddr2; if ( flWriteProtected(vol.socket) ) return flWriteProtect; flashPtr = (FlashWPTR) vol.map (&vol, address, length); /* set addresses for AMD unlock sequence */ flUpdateUnlockAddrs (&vol, flashPtr); unlockAddr1 = thisVars->unlockAddr1; unlockAddr2 = thisVars->unlockAddr2; /* Set timeout to 5 seconds from now */ writeTimeout = flMsecCounter + 5000; /* write the data */ cLength = length; while (cLength >= 2) { /* AMD unlock sequence */ *wUnlockAddr1 = UNLOCK_1; *wUnlockAddr2 = UNLOCK_2; /* flash command */ *wUnlockAddr1 = SETUP_WRITE; /* write user data word */ *wFlashPtr = *wBuffer; /* wait for ready */ while ((*wFlashPtr != *wBuffer) && (flMsecCounter < writeTimeout)) { if( ((*wFlashPtr & D5) && ((*wFlashPtr ^ *wBuffer) & 0xff)) || ((*wFlashPtr & (0x100 * D5)) && ((*wFlashPtr ^ *wBuffer) & 0xff00)) ) { *wFlashPtr = READ_ARRAY; return flWriteFault; } } cLength -= 2; /* replaced wBuffer++; wFlashPtr++; */ buffer = (unsigned char *)buffer + sizeof(unsigned short); flashPtr = (FlashWPTR)flashPtr + 1; } /* verify the written data */ /* replaced: wFlashPtr -= length/2; wBuffer -= length/2; */ flashPtr -= length / 2; buffer = (unsigned short *)buffer - (length/2); if (tffscmp((void FAR0 *)flashPtr, buffer, length)) return flWriteFault; return flOK;}/*----------------------------------------------------------------------*//* f l w 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 FLFlash.erase routine */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -