sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // template\template_variant\inc\lffsdev.h sl@0: // Header file for a Logging Flash file system (LFFS) physical device driver sl@0: // for a standard Common Flash Interface (CFI) based NOR flash chip. sl@0: // This file is part of the Template Base port sl@0: // sl@0: // sl@0: sl@0: #ifndef __LFFSDEV_H__ sl@0: #define __LFFSDEV_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #define FLASH_FAULT() Kern::Fault("LFFSDEV",__LINE__) sl@0: sl@0: // sl@0: // TO DO: (mandatory) sl@0: // sl@0: // Define the bus width (typically this will be 16 or 32) sl@0: // and the number of devices spanning the bus (typically 1, 2 or 4). sl@0: // sl@0: // Possible value are : FLASH_BUS_WIDTH FLASH_BUS_DEVICES sl@0: // 32 1 1 x 32 bit device sl@0: // 32 2 2 x 16 bit devices sl@0: // 32 4 4 x 8 bit devices sl@0: // 16 1 1 x 16 bit device sl@0: // 16 2 2 x 8 bit devices sl@0: // sl@0: // sl@0: #define FLASH_BUS_WIDTH 32 // EXAMPLE_ONLY sl@0: #define FLASH_BUS_DEVICES 2 // EXAMPLE_ONLY sl@0: sl@0: sl@0: sl@0: #if FLASH_BUS_WIDTH == 32 sl@0: #define TFLASHWORD TUint32 sl@0: #define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 2) sl@0: #define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 2) sl@0: #define FLASH_ERASE_WORD_VALUE 0xFFFFFFFF sl@0: #elif FLASH_BUS_WIDTH == 16 sl@0: #define TFLASHWORD TUint16 sl@0: #define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 1) sl@0: #define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 1) sl@0: #define FLASH_ERASE_WORD_VALUE 0xFFFF sl@0: #else // FLASH_BUS_WIDTH == 8 sl@0: #define TFLASHWORD TUint8 sl@0: #define FLASH_BYTES_TO_WORDS(aNumBytes) aNumBytes sl@0: #define FLASH_ADDRESS_IN_BYTES(aWordAddr) aWordAddr sl@0: #define FLASH_ERASE_WORD_VALUE 0xFF sl@0: #endif sl@0: sl@0: #define BUS_WIDTH_PER_DEVICE (FLASH_BUS_WIDTH / FLASH_BUS_DEVICES) sl@0: sl@0: /******************************************** sl@0: Common Flash Interface (CFI) definitions for various sl@0: combinations of FLASH_BUS_WIDTH and FLASH_BUS_DEVICES sl@0: ********************************************/ sl@0: // sl@0: // TO DO: (optional) sl@0: // Delete the definitions that are not applicable to your device sl@0: // sl@0: #if FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 1 // 1x32bit devices on 32bit bus sl@0: sl@0: const TFLASHWORD KCmdReadArray = 0x000000FF; // Set read array command sl@0: const TFLASHWORD KCmdReadStatusRegister = 0x00000070; // Read status register command sl@0: const TFLASHWORD KCmdClearStatusRegister = 0x00000050; // Clear status register error bits command sl@0: const TFLASHWORD KCmdWriteToBuffer = 0x000000E8; // Write to buffer setup command sl@0: const TFLASHWORD KCmdBlockErase = 0x00000020; // Block erase command sl@0: const TFLASHWORD KCmdEraseSuspend = 0x000000B0; // Erase suspend command sl@0: const TFLASHWORD KCmdEraseResume = 0x000000D0; // Erase resume command (actually a confirm) sl@0: const TFLASHWORD KCmdConfirm = 0x000000D0; // Confirm command sl@0: const TFLASHWORD KCmdReadIdentifiers = 0x00000090; // Read Flash identifiers command sl@0: const TFLASHWORD KCmdReadQuery = 0x00000098; // Read Flash Query info command sl@0: sl@0: const TFLASHWORD KStsReady = 0x00000080; // Ready bit sl@0: const TFLASHWORD KStsSuspended = 0x00000040; // Suspend bit sl@0: const TFLASHWORD KStsEraseError = 0x00000020; // Erase error bit sl@0: const TFLASHWORD KStsWriteError = 0x00000010; // Write error bit sl@0: const TFLASHWORD KStsVppLow = 0x00000008; // Vpp low bit sl@0: const TFLASHWORD KStsReserved = 0x00000004; // Reserved bit (not used) sl@0: const TFLASHWORD KStsLocked = 0x00000002; // Locked bit sl@0: const TFLASHWORD KStsReserved2 = 0x00000001; // Reserved bit sl@0: sl@0: #elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 2 // 2x16bit devices on 32bit bus sl@0: sl@0: const TFLASHWORD KCmdReadArray = 0x00FF00FF; // Set read array command sl@0: const TFLASHWORD KCmdReadStatusRegister = 0x00700070; // Read status register command sl@0: const TFLASHWORD KCmdClearStatusRegister = 0x00500050; // Clear status register error bits command sl@0: const TFLASHWORD KCmdWriteToBuffer = 0x00E800E8; // Write to buffer setup command sl@0: const TFLASHWORD KCmdBlockErase = 0x00200020; // Block erase command sl@0: const TFLASHWORD KCmdEraseSuspend = 0x00B000B0; // Erase suspend command sl@0: const TFLASHWORD KCmdEraseResume = 0x00D000D0; // Erase resume command (actually a confirm) sl@0: const TFLASHWORD KCmdConfirm = 0x00D000D0; // Confirm command sl@0: const TFLASHWORD KCmdReadIdentifiers = 0x00900090; // Read Flash identifiers command sl@0: const TFLASHWORD KCmdReadQuery = 0x00980098; // Read Flash Query info command sl@0: sl@0: const TFLASHWORD KStsReady = 0x00800080; // Ready bit sl@0: const TFLASHWORD KStsSuspended = 0x00400040; // Suspend bit sl@0: const TFLASHWORD KStsEraseError = 0x00200020; // Erase error bit sl@0: const TFLASHWORD KStsWriteError = 0x00100010; // Write error bit sl@0: const TFLASHWORD KStsVppLow = 0x00080008; // Vpp low bit sl@0: const TFLASHWORD KStsReserved = 0x00040004; // Reserved bit (not used) sl@0: const TFLASHWORD KStsLocked = 0x00020002; // Locked bit sl@0: const TFLASHWORD KStsReserved2 = 0x00010001; // Reserved bit sl@0: sl@0: #elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 4 // 4x8bit devices on 32bit bus sl@0: sl@0: const TFLASHWORD KCmdReadArray = 0xFFFFFFFF; // Set read array command sl@0: const TFLASHWORD KCmdReadStatusRegister = 0x70707070; // Read status register command sl@0: const TFLASHWORD KCmdClearStatusRegister = 0x50505050; // Clear status register error bits command sl@0: const TFLASHWORD KCmdWriteToBuffer = 0xE8E8E8E8; // Write to buffer setup command sl@0: const TFLASHWORD KCmdBlockErase = 0x20202020; // Block erase command sl@0: const TFLASHWORD KCmdEraseSuspend = 0xB0B0B0B0; // Erase suspend command sl@0: const TFLASHWORD KCmdEraseResume = 0xD0D0D0D0; // Erase resume command (actually a confirm) sl@0: const TFLASHWORD KCmdConfirm = 0xD0D0D0D0; // Confirm command sl@0: const TFLASHWORD KCmdReadIdentifiers = 0x90909090; // Read Flash identifiers command sl@0: const TFLASHWORD KCmdReadQuery = 0x98989898; // Read Flash Query info command sl@0: sl@0: const TFLASHWORD KStsReady = 0x80808080; // Ready bit sl@0: const TFLASHWORD KStsSuspended = 0x40404040; // Suspend bit sl@0: const TFLASHWORD KStsEraseError = 0x20202020; // Erase error bit sl@0: const TFLASHWORD KStsWriteError = 0x10101010; // Write error bit sl@0: const TFLASHWORD KStsVppLow = 0x08080808; // Vpp low bit sl@0: const TFLASHWORD KStsReserved = 0x04040404; // Reserved bit (not used) sl@0: const TFLASHWORD KStsLocked = 0x02020202; // Locked bit sl@0: const TFLASHWORD KStsReserved2 = 0x01010101; // Reserved bit sl@0: sl@0: #elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 1 // 1x16bit devices on 16bit bus sl@0: sl@0: const TFLASHWORD KCmdReadArray = 0x00FF; // Set read array command sl@0: const TFLASHWORD KCmdReadStatusRegister = 0x0070; // Read status register command sl@0: const TFLASHWORD KCmdClearStatusRegister = 0x0050; // Clear status register error bits command sl@0: const TFLASHWORD KCmdWriteToBuffer = 0x00E8; // Write to buffer setup command sl@0: const TFLASHWORD KCmdBlockErase = 0x0020; // Block erase command sl@0: const TFLASHWORD KCmdEraseSuspend = 0x00B0; // Erase suspend command sl@0: const TFLASHWORD KCmdEraseResume = 0x00D0; // Erase resume command (actually a confirm) sl@0: const TFLASHWORD KCmdConfirm = 0x00D0; // Confirm command sl@0: const TFLASHWORD KCmdReadIdentifiers = 0x0090; // Read Flash identifiers command sl@0: const TFLASHWORD KCmdReadQuery = 0x0098; // Read Flash Query info command sl@0: sl@0: const TFLASHWORD KStsReady = 0x0080; // Ready bit sl@0: const TFLASHWORD KStsSuspended = 0x0040; // Suspend bit sl@0: const TFLASHWORD KStsEraseError = 0x0020; // Erase error bit sl@0: const TFLASHWORD KStsWriteError = 0x0010; // Write error bit sl@0: const TFLASHWORD KStsVppLow = 0x0008; // Vpp low bit sl@0: const TFLASHWORD KStsReserved = 0x0004; // Reserved bit (not used) sl@0: const TFLASHWORD KStsLocked = 0x0002; // Locked bit sl@0: const TFLASHWORD KStsReserved2 = 0x0001; // Reserved bit sl@0: sl@0: #elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 2 // 2x8bit devices on 16bit bus sl@0: const TFLASHWORD KCmdReadArray = 0xFFFF; // Set read array command sl@0: const TFLASHWORD KCmdReadStatusRegister = 0x7070; // Read status register command sl@0: const TFLASHWORD KCmdClearStatusRegister = 0x5050; // Clear status register error bits command sl@0: const TFLASHWORD KCmdWriteToBuffer = 0xE8E8; // Write to buffer setup command sl@0: const TFLASHWORD KCmdBlockErase = 0x2020; // Block erase command sl@0: const TFLASHWORD KCmdEraseSuspend = 0xB0B0; // Erase suspend command sl@0: const TFLASHWORD KCmdEraseResume = 0xD0D0; // Erase resume command (actually a confirm) sl@0: const TFLASHWORD KCmdConfirm = 0xD0D0; // Confirm command sl@0: const TFLASHWORD KCmdReadIdentifiers = 0x9090; // Read Flash identifiers command sl@0: const TFLASHWORD KCmdReadQuery = 0x9898; // Read Flash Query info command sl@0: sl@0: const TFLASHWORD KStsReady = 0x8080; // Ready bit sl@0: const TFLASHWORD KStsSuspended = 0x4040; // Suspend bit sl@0: const TFLASHWORD KStsEraseError = 0x2020; // Erase error bit sl@0: const TFLASHWORD KStsWriteError = 0x1010; // Write error bit sl@0: const TFLASHWORD KStsVppLow = 0x0808; // Vpp low bit sl@0: const TFLASHWORD KStsReserved = 0x0404; // Reserved bit (not used) sl@0: const TFLASHWORD KStsLocked = 0x0202; // Locked bit sl@0: const TFLASHWORD KStsReserved2 = 0x0101; // Reserved bit sl@0: sl@0: #endif sl@0: sl@0: // address at which to issue the Query command sl@0: const TUint32 KCmdReadQueryOffset = 0x55; sl@0: sl@0: const TUint32 KQueryOffsetQRY = 0x10; sl@0: const TUint32 KQueryOffsetSizePower = 0x27; sl@0: const TUint32 KQueryOffsetWriteBufferSizePower = 0x2A; sl@0: const TUint32 KQueryOffsetErasePartitions = 0x2C; sl@0: const TUint32 KQueryOffsetEraseBlockCount = 0x2D; sl@0: const TUint32 KQueryOffsetEraseBlockSize = 0x2F; sl@0: sl@0: /******************************************** sl@0: * Driver definitions sl@0: ********************************************/ sl@0: const TInt KMaxWriteSetupAttempts = 8; sl@0: const TInt KMaxEraseResumeAttempts = 32; sl@0: sl@0: const TInt KDataBufSize=1024; sl@0: sl@0: sl@0: // TO DO: (mandatory) sl@0: // Define the following timeouts in terms of timer ticks sl@0: // This is only example code... you may need to modify it for your hardware sl@0: // The examples given here assume a timer clock frequency of 3.6864MHz sl@0: const TUint32 KFlashWriteTimerPeriod = 1500; // 1500 ticks @ 3.6864MHz = 406us sl@0: const TUint32 KFlashWriteTimerRetries = 3; // total 1.2ms sl@0: const TUint32 KFlashSuspendTimerPeriod = 1500; // 1500 ticks @ 3.6864MHz = 406us sl@0: const TUint32 KFlashSuspendTimerRetries = 3; // total 1.2ms sl@0: const TUint32 KFlashEraseTimerPeriod = 100000; // 100000 ticks @ 3.6864MHz = 27ms sl@0: const TUint32 KFlashEraseTimerRetries = 100; // total 2.7sec sl@0: const TInt KEraseSuspendHoldOffTime = 130; // 130ms sl@0: sl@0: /******************************************** sl@0: * Media driver class sl@0: ********************************************/ sl@0: // sl@0: // TO DO: (optional) sl@0: // sl@0: // Add any private functions and data you require sl@0: // sl@0: class DMediaDriverFlashTemplate : public DMediaDriverFlash sl@0: { sl@0: public: sl@0: enum TWriteState {EWriteIdle=0,EWriting=1}; sl@0: enum TEraseState {EEraseIdle=0,EErase=1,EEraseNoSuspend=2,ESuspendPending=3,ESuspending=4,ESuspended=5}; sl@0: enum TEvent {EPollTimer=1,ETimeout=2,EHoldOffEnd=4}; sl@0: sl@0: DMediaDriverFlashTemplate(TInt aMediaId); sl@0: sl@0: // replacing pure virtual - FLASH device specific stuff sl@0: virtual TInt Initialise(); sl@0: virtual TUint32 EraseBlockSize(); sl@0: virtual TUint32 TotalSize(); sl@0: virtual TInt DoRead(); sl@0: virtual TInt DoWrite(); sl@0: virtual TInt DoErase(); sl@0: sl@0: private: sl@0: void IPostEvents(TUint32 aEvents); sl@0: void HandleEvents(TUint32 aEvents); sl@0: void ClearEvents(TUint32 aEvents); sl@0: void StartPollTimer(TUint32 aPeriod, TUint32 aRetries); sl@0: void StartPollTimer(); sl@0: void StartHoldOffTimer(); sl@0: void CancelHoldOffTimer(); sl@0: void StartErase(); sl@0: void SuspendErase(); sl@0: void WriteStep(); sl@0: void DoFlashReady(TUint32 aStatus); sl@0: void DoFlashTimeout(); sl@0: void StartPendingRW(); sl@0: TUint32 ReadQueryData8(TUint32 aOffset); sl@0: TUint32 ReadQueryData16(TUint32 aOffset); sl@0: void ReadFlashParameters(); sl@0: static void Isr(TAny* aPtr); sl@0: static void HoldOffTimerFn(TAny* aPtr); sl@0: static void EventDfc(TAny* aPtr); sl@0: sl@0: private: sl@0: TWriteState iWriteState; sl@0: TEraseState iEraseState; sl@0: TLinAddr iBase; sl@0: TUint32 iEraseBlockSize; sl@0: TUint32 iTotalSize; sl@0: TUint32 iWriteBufferSize; sl@0: TUint32 iWritePos; sl@0: TInt iDataBufPos; sl@0: TInt iDataBufRemain; sl@0: TUint8* iData; // data being written sl@0: TUint32 iErasePos; sl@0: NTimer iHoldOffTimer; sl@0: TUint32 iEvents; sl@0: TDfc iEventDfc; sl@0: TUint32 iPollPeriod; sl@0: TUint32 iPollRetries; sl@0: TUint32 iEraseError; sl@0: TInt iWriteError; sl@0: TInt iEraseAttempt; sl@0: DPlatChunkHw* iFlashChunk; sl@0: }; sl@0: sl@0: #endif