os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/inc/lffsdev.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/inc/lffsdev.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,286 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// template\template_variant\inc\lffsdev.h
    1.18 +// Header file for a Logging Flash file system (LFFS) physical device driver 
    1.19 +// for a standard Common Flash Interface (CFI) based NOR flash chip.
    1.20 +// This file is part of the Template Base port
    1.21 +// 
    1.22 +//
    1.23 +
    1.24 +#ifndef __LFFSDEV_H__
    1.25 +#define __LFFSDEV_H__
    1.26 +
    1.27 +#include <drivers/flash_media.h>
    1.28 +#include <template_assp.h>
    1.29 +
    1.30 +#define FLASH_FAULT()	Kern::Fault("LFFSDEV",__LINE__)
    1.31 +
    1.32 +//
    1.33 +// TO DO: (mandatory)
    1.34 +//
    1.35 +// Define the bus width (typically this will be 16 or 32)
    1.36 +// and the number of devices spanning the bus (typically 1, 2 or 4).
    1.37 +//
    1.38 +// Possible value are :	FLASH_BUS_WIDTH	FLASH_BUS_DEVICES
    1.39 +//						32				1					1 x 32 bit device
    1.40 +//						32				2					2 x 16 bit devices
    1.41 +//						32				4					4 x 8  bit devices
    1.42 +//						16				1					1 x 16 bit device
    1.43 +//						16				2					2 x 8  bit devices
    1.44 +//
    1.45 +//
    1.46 +#define FLASH_BUS_WIDTH 32		// EXAMPLE_ONLY
    1.47 +#define FLASH_BUS_DEVICES 2		// EXAMPLE_ONLY
    1.48 +
    1.49 +
    1.50 +
    1.51 +#if FLASH_BUS_WIDTH == 32
    1.52 +	#define TFLASHWORD TUint32
    1.53 +	#define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 2)
    1.54 +	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 2)
    1.55 +	#define FLASH_ERASE_WORD_VALUE 0xFFFFFFFF
    1.56 +#elif FLASH_BUS_WIDTH == 16
    1.57 +	#define TFLASHWORD TUint16
    1.58 +	#define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 1)
    1.59 +	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 1)
    1.60 +	#define FLASH_ERASE_WORD_VALUE 0xFFFF
    1.61 +#else	// FLASH_BUS_WIDTH == 8
    1.62 +	#define TFLASHWORD TUint8
    1.63 +	#define FLASH_BYTES_TO_WORDS(aNumBytes) aNumBytes
    1.64 +	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) aWordAddr
    1.65 +	#define FLASH_ERASE_WORD_VALUE 0xFF
    1.66 +#endif
    1.67 +
    1.68 +#define BUS_WIDTH_PER_DEVICE (FLASH_BUS_WIDTH / FLASH_BUS_DEVICES)
    1.69 +
    1.70 +/********************************************
    1.71 +Common Flash Interface (CFI) definitions for various
    1.72 +combinations of FLASH_BUS_WIDTH and FLASH_BUS_DEVICES
    1.73 + ********************************************/
    1.74 +//
    1.75 +// TO DO: (optional)
    1.76 +// Delete the definitions that are not applicable to your device
    1.77 +//
    1.78 +#if FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 1			// 1x32bit devices on 32bit bus
    1.79 +
    1.80 +const TFLASHWORD KCmdReadArray				= 0x000000FF;	// Set read array command
    1.81 +const TFLASHWORD KCmdReadStatusRegister		= 0x00000070;	// Read status register command
    1.82 +const TFLASHWORD KCmdClearStatusRegister	= 0x00000050;	// Clear status register error bits command
    1.83 +const TFLASHWORD KCmdWriteToBuffer			= 0x000000E8;	// Write to buffer setup command
    1.84 +const TFLASHWORD KCmdBlockErase				= 0x00000020;	// Block erase command
    1.85 +const TFLASHWORD KCmdEraseSuspend			= 0x000000B0;	// Erase suspend command
    1.86 +const TFLASHWORD KCmdEraseResume			= 0x000000D0;	// Erase resume command (actually a confirm)
    1.87 +const TFLASHWORD KCmdConfirm				= 0x000000D0;	// Confirm command
    1.88 +const TFLASHWORD KCmdReadIdentifiers		= 0x00000090;	// Read Flash identifiers command
    1.89 +const TFLASHWORD KCmdReadQuery				= 0x00000098;	// Read Flash Query info command
    1.90 +
    1.91 +const TFLASHWORD KStsReady					= 0x00000080;	// Ready bit
    1.92 +const TFLASHWORD KStsSuspended				= 0x00000040;	// Suspend bit
    1.93 +const TFLASHWORD KStsEraseError				= 0x00000020;	// Erase error bit
    1.94 +const TFLASHWORD KStsWriteError				= 0x00000010;	// Write error bit
    1.95 +const TFLASHWORD KStsVppLow					= 0x00000008;	// Vpp low bit
    1.96 +const TFLASHWORD KStsReserved				= 0x00000004;	// Reserved bit (not used)
    1.97 +const TFLASHWORD KStsLocked					= 0x00000002;	// Locked bit
    1.98 +const TFLASHWORD KStsReserved2				= 0x00000001;	// Reserved bit
    1.99 +
   1.100 +#elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 2		// 2x16bit devices on 32bit bus
   1.101 +
   1.102 +const TFLASHWORD KCmdReadArray				= 0x00FF00FF;	// Set read array command
   1.103 +const TFLASHWORD KCmdReadStatusRegister		= 0x00700070;	// Read status register command
   1.104 +const TFLASHWORD KCmdClearStatusRegister	= 0x00500050;	// Clear status register error bits command
   1.105 +const TFLASHWORD KCmdWriteToBuffer			= 0x00E800E8;	// Write to buffer setup command
   1.106 +const TFLASHWORD KCmdBlockErase				= 0x00200020;	// Block erase command
   1.107 +const TFLASHWORD KCmdEraseSuspend			= 0x00B000B0;	// Erase suspend command
   1.108 +const TFLASHWORD KCmdEraseResume			= 0x00D000D0;	// Erase resume command (actually a confirm)
   1.109 +const TFLASHWORD KCmdConfirm				= 0x00D000D0;	// Confirm command
   1.110 +const TFLASHWORD KCmdReadIdentifiers		= 0x00900090;	// Read Flash identifiers command
   1.111 +const TFLASHWORD KCmdReadQuery				= 0x00980098;	// Read Flash Query info command
   1.112 +
   1.113 +const TFLASHWORD KStsReady					= 0x00800080;	// Ready bit
   1.114 +const TFLASHWORD KStsSuspended				= 0x00400040;	// Suspend bit
   1.115 +const TFLASHWORD KStsEraseError				= 0x00200020;	// Erase error bit
   1.116 +const TFLASHWORD KStsWriteError				= 0x00100010;	// Write error bit
   1.117 +const TFLASHWORD KStsVppLow					= 0x00080008;	// Vpp low bit
   1.118 +const TFLASHWORD KStsReserved				= 0x00040004;	// Reserved bit (not used)
   1.119 +const TFLASHWORD KStsLocked					= 0x00020002;	// Locked bit
   1.120 +const TFLASHWORD KStsReserved2				= 0x00010001;	// Reserved bit
   1.121 +
   1.122 +#elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 4		// 4x8bit devices on 32bit bus
   1.123 +
   1.124 +const TFLASHWORD KCmdReadArray				= 0xFFFFFFFF;	// Set read array command
   1.125 +const TFLASHWORD KCmdReadStatusRegister		= 0x70707070;	// Read status register command
   1.126 +const TFLASHWORD KCmdClearStatusRegister	= 0x50505050;	// Clear status register error bits command
   1.127 +const TFLASHWORD KCmdWriteToBuffer			= 0xE8E8E8E8;	// Write to buffer setup command
   1.128 +const TFLASHWORD KCmdBlockErase				= 0x20202020;	// Block erase command
   1.129 +const TFLASHWORD KCmdEraseSuspend			= 0xB0B0B0B0;	// Erase suspend command
   1.130 +const TFLASHWORD KCmdEraseResume			= 0xD0D0D0D0;	// Erase resume command (actually a confirm)
   1.131 +const TFLASHWORD KCmdConfirm				= 0xD0D0D0D0;	// Confirm command
   1.132 +const TFLASHWORD KCmdReadIdentifiers		= 0x90909090;	// Read Flash identifiers command
   1.133 +const TFLASHWORD KCmdReadQuery				= 0x98989898;	// Read Flash Query info command
   1.134 +
   1.135 +const TFLASHWORD KStsReady					= 0x80808080;	// Ready bit
   1.136 +const TFLASHWORD KStsSuspended				= 0x40404040;	// Suspend bit
   1.137 +const TFLASHWORD KStsEraseError				= 0x20202020;	// Erase error bit
   1.138 +const TFLASHWORD KStsWriteError				= 0x10101010;	// Write error bit
   1.139 +const TFLASHWORD KStsVppLow					= 0x08080808;	// Vpp low bit
   1.140 +const TFLASHWORD KStsReserved				= 0x04040404;	// Reserved bit (not used)
   1.141 +const TFLASHWORD KStsLocked					= 0x02020202;	// Locked bit
   1.142 +const TFLASHWORD KStsReserved2				= 0x01010101;	// Reserved bit
   1.143 +
   1.144 +#elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 1	// 1x16bit devices on 16bit bus
   1.145 +
   1.146 +const TFLASHWORD KCmdReadArray				= 0x00FF;	// Set read array command
   1.147 +const TFLASHWORD KCmdReadStatusRegister		= 0x0070;	// Read status register command
   1.148 +const TFLASHWORD KCmdClearStatusRegister	= 0x0050;	// Clear status register error bits command
   1.149 +const TFLASHWORD KCmdWriteToBuffer			= 0x00E8;	// Write to buffer setup command
   1.150 +const TFLASHWORD KCmdBlockErase				= 0x0020;	// Block erase command
   1.151 +const TFLASHWORD KCmdEraseSuspend			= 0x00B0;	// Erase suspend command
   1.152 +const TFLASHWORD KCmdEraseResume			= 0x00D0;	// Erase resume command (actually a confirm)
   1.153 +const TFLASHWORD KCmdConfirm				= 0x00D0;	// Confirm command
   1.154 +const TFLASHWORD KCmdReadIdentifiers		= 0x0090;	// Read Flash identifiers command
   1.155 +const TFLASHWORD KCmdReadQuery				= 0x0098;	// Read Flash Query info command
   1.156 +
   1.157 +const TFLASHWORD KStsReady					= 0x0080;	// Ready bit
   1.158 +const TFLASHWORD KStsSuspended				= 0x0040;	// Suspend bit
   1.159 +const TFLASHWORD KStsEraseError				= 0x0020;	// Erase error bit
   1.160 +const TFLASHWORD KStsWriteError				= 0x0010;	// Write error bit
   1.161 +const TFLASHWORD KStsVppLow					= 0x0008;	// Vpp low bit
   1.162 +const TFLASHWORD KStsReserved				= 0x0004;	// Reserved bit (not used)
   1.163 +const TFLASHWORD KStsLocked					= 0x0002;	// Locked bit
   1.164 +const TFLASHWORD KStsReserved2				= 0x0001;	// Reserved bit
   1.165 +
   1.166 +#elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 2	// 2x8bit devices on 16bit bus
   1.167 +const TFLASHWORD KCmdReadArray				= 0xFFFF;	// Set read array command
   1.168 +const TFLASHWORD KCmdReadStatusRegister		= 0x7070;	// Read status register command
   1.169 +const TFLASHWORD KCmdClearStatusRegister	= 0x5050;	// Clear status register error bits command
   1.170 +const TFLASHWORD KCmdWriteToBuffer			= 0xE8E8;	// Write to buffer setup command
   1.171 +const TFLASHWORD KCmdBlockErase				= 0x2020;	// Block erase command
   1.172 +const TFLASHWORD KCmdEraseSuspend			= 0xB0B0;	// Erase suspend command
   1.173 +const TFLASHWORD KCmdEraseResume			= 0xD0D0;	// Erase resume command (actually a confirm)
   1.174 +const TFLASHWORD KCmdConfirm				= 0xD0D0;	// Confirm command
   1.175 +const TFLASHWORD KCmdReadIdentifiers		= 0x9090;	// Read Flash identifiers command
   1.176 +const TFLASHWORD KCmdReadQuery				= 0x9898;	// Read Flash Query info command
   1.177 +
   1.178 +const TFLASHWORD KStsReady					= 0x8080;	// Ready bit
   1.179 +const TFLASHWORD KStsSuspended				= 0x4040;	// Suspend bit
   1.180 +const TFLASHWORD KStsEraseError				= 0x2020;	// Erase error bit
   1.181 +const TFLASHWORD KStsWriteError				= 0x1010;	// Write error bit
   1.182 +const TFLASHWORD KStsVppLow					= 0x0808;	// Vpp low bit
   1.183 +const TFLASHWORD KStsReserved				= 0x0404;	// Reserved bit (not used)
   1.184 +const TFLASHWORD KStsLocked					= 0x0202;	// Locked bit
   1.185 +const TFLASHWORD KStsReserved2				= 0x0101;	// Reserved bit
   1.186 +
   1.187 +#endif
   1.188 +
   1.189 +// address at which to issue the Query command
   1.190 +const TUint32 KCmdReadQueryOffset				= 0x55;	
   1.191 +
   1.192 +const TUint32 KQueryOffsetQRY					= 0x10;
   1.193 +const TUint32 KQueryOffsetSizePower				= 0x27;
   1.194 +const TUint32 KQueryOffsetWriteBufferSizePower	= 0x2A;
   1.195 +const TUint32 KQueryOffsetErasePartitions		= 0x2C;
   1.196 +const TUint32 KQueryOffsetEraseBlockCount		= 0x2D;
   1.197 +const TUint32 KQueryOffsetEraseBlockSize		= 0x2F;
   1.198 +
   1.199 +/********************************************
   1.200 + * Driver definitions
   1.201 + ********************************************/
   1.202 +const TInt KMaxWriteSetupAttempts		= 8;
   1.203 +const TInt KMaxEraseResumeAttempts		= 32;
   1.204 +
   1.205 +const TInt KDataBufSize=1024;
   1.206 +
   1.207 +
   1.208 +// TO DO: (mandatory)
   1.209 +// Define the following timeouts in terms of timer ticks
   1.210 +// This is only example code... you may need to modify it for your hardware
   1.211 +// The examples given here assume a timer clock frequency of 3.6864MHz
   1.212 +const TUint32 KFlashWriteTimerPeriod =		1500;	// 1500 ticks @ 3.6864MHz = 406us
   1.213 +const TUint32 KFlashWriteTimerRetries =		3;		// total 1.2ms
   1.214 +const TUint32 KFlashSuspendTimerPeriod =	1500;	// 1500 ticks @ 3.6864MHz = 406us
   1.215 +const TUint32 KFlashSuspendTimerRetries =	3;		// total 1.2ms
   1.216 +const TUint32 KFlashEraseTimerPeriod =		100000;	// 100000 ticks @ 3.6864MHz = 27ms
   1.217 +const TUint32 KFlashEraseTimerRetries =		100;	// total 2.7sec
   1.218 +const TInt	  KEraseSuspendHoldOffTime =	130;	// 130ms
   1.219 +
   1.220 +/********************************************
   1.221 + * Media driver class
   1.222 + ********************************************/
   1.223 +//
   1.224 +// TO DO: (optional)
   1.225 +//
   1.226 +// Add any private functions and data you require
   1.227 +//
   1.228 +class DMediaDriverFlashTemplate : public DMediaDriverFlash
   1.229 +	{
   1.230 +public:
   1.231 +	enum TWriteState {EWriteIdle=0,EWriting=1};
   1.232 +	enum TEraseState {EEraseIdle=0,EErase=1,EEraseNoSuspend=2,ESuspendPending=3,ESuspending=4,ESuspended=5};
   1.233 +	enum TEvent {EPollTimer=1,ETimeout=2,EHoldOffEnd=4};
   1.234 +
   1.235 +	DMediaDriverFlashTemplate(TInt aMediaId);
   1.236 +
   1.237 +	// replacing pure virtual - FLASH device specific stuff
   1.238 +	virtual TInt Initialise();
   1.239 +	virtual TUint32 EraseBlockSize();
   1.240 +	virtual TUint32 TotalSize();
   1.241 +	virtual TInt DoRead();
   1.242 +	virtual TInt DoWrite();
   1.243 +	virtual TInt DoErase();
   1.244 +
   1.245 +private:
   1.246 +	void IPostEvents(TUint32 aEvents);
   1.247 +	void HandleEvents(TUint32 aEvents);
   1.248 +	void ClearEvents(TUint32 aEvents);
   1.249 +	void StartPollTimer(TUint32 aPeriod, TUint32 aRetries);
   1.250 +	void StartPollTimer();
   1.251 +	void StartHoldOffTimer();
   1.252 +	void CancelHoldOffTimer();
   1.253 +	void StartErase();
   1.254 +	void SuspendErase();
   1.255 +	void WriteStep();
   1.256 +	void DoFlashReady(TUint32 aStatus);
   1.257 +	void DoFlashTimeout();
   1.258 +	void StartPendingRW();
   1.259 +	TUint32 ReadQueryData8(TUint32 aOffset);
   1.260 +	TUint32 ReadQueryData16(TUint32 aOffset);
   1.261 +	void ReadFlashParameters();
   1.262 +	static void Isr(TAny* aPtr);
   1.263 +	static void HoldOffTimerFn(TAny* aPtr);
   1.264 +	static void EventDfc(TAny* aPtr);
   1.265 +
   1.266 +private:
   1.267 +	TWriteState iWriteState;
   1.268 +	TEraseState iEraseState;
   1.269 +	TLinAddr iBase;
   1.270 +	TUint32 iEraseBlockSize;
   1.271 +	TUint32 iTotalSize;
   1.272 +	TUint32 iWriteBufferSize;
   1.273 +	TUint32 iWritePos;
   1.274 +	TInt iDataBufPos;
   1.275 +	TInt iDataBufRemain;
   1.276 +	TUint8* iData;		// data being written
   1.277 +	TUint32 iErasePos;
   1.278 +	NTimer iHoldOffTimer;
   1.279 +	TUint32 iEvents;
   1.280 +	TDfc iEventDfc;
   1.281 +	TUint32 iPollPeriod;
   1.282 +	TUint32 iPollRetries;
   1.283 +	TUint32 iEraseError;
   1.284 +	TInt iWriteError;
   1.285 +	TInt iEraseAttempt;
   1.286 +	DPlatChunkHw* iFlashChunk;
   1.287 +	};
   1.288 +
   1.289 +#endif