os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/inc/lffsdev.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// template\template_variant\inc\lffsdev.h
sl@0
    15
// Header file for a Logging Flash file system (LFFS) physical device driver 
sl@0
    16
// for a standard Common Flash Interface (CFI) based NOR flash chip.
sl@0
    17
// This file is part of the Template Base port
sl@0
    18
// 
sl@0
    19
//
sl@0
    20
sl@0
    21
#ifndef __LFFSDEV_H__
sl@0
    22
#define __LFFSDEV_H__
sl@0
    23
sl@0
    24
#include <drivers/flash_media.h>
sl@0
    25
#include <template_assp.h>
sl@0
    26
sl@0
    27
#define FLASH_FAULT()	Kern::Fault("LFFSDEV",__LINE__)
sl@0
    28
sl@0
    29
//
sl@0
    30
// TO DO: (mandatory)
sl@0
    31
//
sl@0
    32
// Define the bus width (typically this will be 16 or 32)
sl@0
    33
// and the number of devices spanning the bus (typically 1, 2 or 4).
sl@0
    34
//
sl@0
    35
// Possible value are :	FLASH_BUS_WIDTH	FLASH_BUS_DEVICES
sl@0
    36
//						32				1					1 x 32 bit device
sl@0
    37
//						32				2					2 x 16 bit devices
sl@0
    38
//						32				4					4 x 8  bit devices
sl@0
    39
//						16				1					1 x 16 bit device
sl@0
    40
//						16				2					2 x 8  bit devices
sl@0
    41
//
sl@0
    42
//
sl@0
    43
#define FLASH_BUS_WIDTH 32		// EXAMPLE_ONLY
sl@0
    44
#define FLASH_BUS_DEVICES 2		// EXAMPLE_ONLY
sl@0
    45
sl@0
    46
sl@0
    47
sl@0
    48
#if FLASH_BUS_WIDTH == 32
sl@0
    49
	#define TFLASHWORD TUint32
sl@0
    50
	#define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 2)
sl@0
    51
	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 2)
sl@0
    52
	#define FLASH_ERASE_WORD_VALUE 0xFFFFFFFF
sl@0
    53
#elif FLASH_BUS_WIDTH == 16
sl@0
    54
	#define TFLASHWORD TUint16
sl@0
    55
	#define FLASH_BYTES_TO_WORDS(aNumBytes) (aNumBytes >> 1)
sl@0
    56
	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) (aWordAddr << 1)
sl@0
    57
	#define FLASH_ERASE_WORD_VALUE 0xFFFF
sl@0
    58
#else	// FLASH_BUS_WIDTH == 8
sl@0
    59
	#define TFLASHWORD TUint8
sl@0
    60
	#define FLASH_BYTES_TO_WORDS(aNumBytes) aNumBytes
sl@0
    61
	#define FLASH_ADDRESS_IN_BYTES(aWordAddr) aWordAddr
sl@0
    62
	#define FLASH_ERASE_WORD_VALUE 0xFF
sl@0
    63
#endif
sl@0
    64
sl@0
    65
#define BUS_WIDTH_PER_DEVICE (FLASH_BUS_WIDTH / FLASH_BUS_DEVICES)
sl@0
    66
sl@0
    67
/********************************************
sl@0
    68
Common Flash Interface (CFI) definitions for various
sl@0
    69
combinations of FLASH_BUS_WIDTH and FLASH_BUS_DEVICES
sl@0
    70
 ********************************************/
sl@0
    71
//
sl@0
    72
// TO DO: (optional)
sl@0
    73
// Delete the definitions that are not applicable to your device
sl@0
    74
//
sl@0
    75
#if FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 1			// 1x32bit devices on 32bit bus
sl@0
    76
sl@0
    77
const TFLASHWORD KCmdReadArray				= 0x000000FF;	// Set read array command
sl@0
    78
const TFLASHWORD KCmdReadStatusRegister		= 0x00000070;	// Read status register command
sl@0
    79
const TFLASHWORD KCmdClearStatusRegister	= 0x00000050;	// Clear status register error bits command
sl@0
    80
const TFLASHWORD KCmdWriteToBuffer			= 0x000000E8;	// Write to buffer setup command
sl@0
    81
const TFLASHWORD KCmdBlockErase				= 0x00000020;	// Block erase command
sl@0
    82
const TFLASHWORD KCmdEraseSuspend			= 0x000000B0;	// Erase suspend command
sl@0
    83
const TFLASHWORD KCmdEraseResume			= 0x000000D0;	// Erase resume command (actually a confirm)
sl@0
    84
const TFLASHWORD KCmdConfirm				= 0x000000D0;	// Confirm command
sl@0
    85
const TFLASHWORD KCmdReadIdentifiers		= 0x00000090;	// Read Flash identifiers command
sl@0
    86
const TFLASHWORD KCmdReadQuery				= 0x00000098;	// Read Flash Query info command
sl@0
    87
sl@0
    88
const TFLASHWORD KStsReady					= 0x00000080;	// Ready bit
sl@0
    89
const TFLASHWORD KStsSuspended				= 0x00000040;	// Suspend bit
sl@0
    90
const TFLASHWORD KStsEraseError				= 0x00000020;	// Erase error bit
sl@0
    91
const TFLASHWORD KStsWriteError				= 0x00000010;	// Write error bit
sl@0
    92
const TFLASHWORD KStsVppLow					= 0x00000008;	// Vpp low bit
sl@0
    93
const TFLASHWORD KStsReserved				= 0x00000004;	// Reserved bit (not used)
sl@0
    94
const TFLASHWORD KStsLocked					= 0x00000002;	// Locked bit
sl@0
    95
const TFLASHWORD KStsReserved2				= 0x00000001;	// Reserved bit
sl@0
    96
sl@0
    97
#elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 2		// 2x16bit devices on 32bit bus
sl@0
    98
sl@0
    99
const TFLASHWORD KCmdReadArray				= 0x00FF00FF;	// Set read array command
sl@0
   100
const TFLASHWORD KCmdReadStatusRegister		= 0x00700070;	// Read status register command
sl@0
   101
const TFLASHWORD KCmdClearStatusRegister	= 0x00500050;	// Clear status register error bits command
sl@0
   102
const TFLASHWORD KCmdWriteToBuffer			= 0x00E800E8;	// Write to buffer setup command
sl@0
   103
const TFLASHWORD KCmdBlockErase				= 0x00200020;	// Block erase command
sl@0
   104
const TFLASHWORD KCmdEraseSuspend			= 0x00B000B0;	// Erase suspend command
sl@0
   105
const TFLASHWORD KCmdEraseResume			= 0x00D000D0;	// Erase resume command (actually a confirm)
sl@0
   106
const TFLASHWORD KCmdConfirm				= 0x00D000D0;	// Confirm command
sl@0
   107
const TFLASHWORD KCmdReadIdentifiers		= 0x00900090;	// Read Flash identifiers command
sl@0
   108
const TFLASHWORD KCmdReadQuery				= 0x00980098;	// Read Flash Query info command
sl@0
   109
sl@0
   110
const TFLASHWORD KStsReady					= 0x00800080;	// Ready bit
sl@0
   111
const TFLASHWORD KStsSuspended				= 0x00400040;	// Suspend bit
sl@0
   112
const TFLASHWORD KStsEraseError				= 0x00200020;	// Erase error bit
sl@0
   113
const TFLASHWORD KStsWriteError				= 0x00100010;	// Write error bit
sl@0
   114
const TFLASHWORD KStsVppLow					= 0x00080008;	// Vpp low bit
sl@0
   115
const TFLASHWORD KStsReserved				= 0x00040004;	// Reserved bit (not used)
sl@0
   116
const TFLASHWORD KStsLocked					= 0x00020002;	// Locked bit
sl@0
   117
const TFLASHWORD KStsReserved2				= 0x00010001;	// Reserved bit
sl@0
   118
sl@0
   119
#elif FLASH_BUS_WIDTH == 32 && FLASH_BUS_DEVICES == 4		// 4x8bit devices on 32bit bus
sl@0
   120
sl@0
   121
const TFLASHWORD KCmdReadArray				= 0xFFFFFFFF;	// Set read array command
sl@0
   122
const TFLASHWORD KCmdReadStatusRegister		= 0x70707070;	// Read status register command
sl@0
   123
const TFLASHWORD KCmdClearStatusRegister	= 0x50505050;	// Clear status register error bits command
sl@0
   124
const TFLASHWORD KCmdWriteToBuffer			= 0xE8E8E8E8;	// Write to buffer setup command
sl@0
   125
const TFLASHWORD KCmdBlockErase				= 0x20202020;	// Block erase command
sl@0
   126
const TFLASHWORD KCmdEraseSuspend			= 0xB0B0B0B0;	// Erase suspend command
sl@0
   127
const TFLASHWORD KCmdEraseResume			= 0xD0D0D0D0;	// Erase resume command (actually a confirm)
sl@0
   128
const TFLASHWORD KCmdConfirm				= 0xD0D0D0D0;	// Confirm command
sl@0
   129
const TFLASHWORD KCmdReadIdentifiers		= 0x90909090;	// Read Flash identifiers command
sl@0
   130
const TFLASHWORD KCmdReadQuery				= 0x98989898;	// Read Flash Query info command
sl@0
   131
sl@0
   132
const TFLASHWORD KStsReady					= 0x80808080;	// Ready bit
sl@0
   133
const TFLASHWORD KStsSuspended				= 0x40404040;	// Suspend bit
sl@0
   134
const TFLASHWORD KStsEraseError				= 0x20202020;	// Erase error bit
sl@0
   135
const TFLASHWORD KStsWriteError				= 0x10101010;	// Write error bit
sl@0
   136
const TFLASHWORD KStsVppLow					= 0x08080808;	// Vpp low bit
sl@0
   137
const TFLASHWORD KStsReserved				= 0x04040404;	// Reserved bit (not used)
sl@0
   138
const TFLASHWORD KStsLocked					= 0x02020202;	// Locked bit
sl@0
   139
const TFLASHWORD KStsReserved2				= 0x01010101;	// Reserved bit
sl@0
   140
sl@0
   141
#elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 1	// 1x16bit devices on 16bit bus
sl@0
   142
sl@0
   143
const TFLASHWORD KCmdReadArray				= 0x00FF;	// Set read array command
sl@0
   144
const TFLASHWORD KCmdReadStatusRegister		= 0x0070;	// Read status register command
sl@0
   145
const TFLASHWORD KCmdClearStatusRegister	= 0x0050;	// Clear status register error bits command
sl@0
   146
const TFLASHWORD KCmdWriteToBuffer			= 0x00E8;	// Write to buffer setup command
sl@0
   147
const TFLASHWORD KCmdBlockErase				= 0x0020;	// Block erase command
sl@0
   148
const TFLASHWORD KCmdEraseSuspend			= 0x00B0;	// Erase suspend command
sl@0
   149
const TFLASHWORD KCmdEraseResume			= 0x00D0;	// Erase resume command (actually a confirm)
sl@0
   150
const TFLASHWORD KCmdConfirm				= 0x00D0;	// Confirm command
sl@0
   151
const TFLASHWORD KCmdReadIdentifiers		= 0x0090;	// Read Flash identifiers command
sl@0
   152
const TFLASHWORD KCmdReadQuery				= 0x0098;	// Read Flash Query info command
sl@0
   153
sl@0
   154
const TFLASHWORD KStsReady					= 0x0080;	// Ready bit
sl@0
   155
const TFLASHWORD KStsSuspended				= 0x0040;	// Suspend bit
sl@0
   156
const TFLASHWORD KStsEraseError				= 0x0020;	// Erase error bit
sl@0
   157
const TFLASHWORD KStsWriteError				= 0x0010;	// Write error bit
sl@0
   158
const TFLASHWORD KStsVppLow					= 0x0008;	// Vpp low bit
sl@0
   159
const TFLASHWORD KStsReserved				= 0x0004;	// Reserved bit (not used)
sl@0
   160
const TFLASHWORD KStsLocked					= 0x0002;	// Locked bit
sl@0
   161
const TFLASHWORD KStsReserved2				= 0x0001;	// Reserved bit
sl@0
   162
sl@0
   163
#elif FLASH_BUS_WIDTH == 16 && FLASH_BUS_DEVICES == 2	// 2x8bit devices on 16bit bus
sl@0
   164
const TFLASHWORD KCmdReadArray				= 0xFFFF;	// Set read array command
sl@0
   165
const TFLASHWORD KCmdReadStatusRegister		= 0x7070;	// Read status register command
sl@0
   166
const TFLASHWORD KCmdClearStatusRegister	= 0x5050;	// Clear status register error bits command
sl@0
   167
const TFLASHWORD KCmdWriteToBuffer			= 0xE8E8;	// Write to buffer setup command
sl@0
   168
const TFLASHWORD KCmdBlockErase				= 0x2020;	// Block erase command
sl@0
   169
const TFLASHWORD KCmdEraseSuspend			= 0xB0B0;	// Erase suspend command
sl@0
   170
const TFLASHWORD KCmdEraseResume			= 0xD0D0;	// Erase resume command (actually a confirm)
sl@0
   171
const TFLASHWORD KCmdConfirm				= 0xD0D0;	// Confirm command
sl@0
   172
const TFLASHWORD KCmdReadIdentifiers		= 0x9090;	// Read Flash identifiers command
sl@0
   173
const TFLASHWORD KCmdReadQuery				= 0x9898;	// Read Flash Query info command
sl@0
   174
sl@0
   175
const TFLASHWORD KStsReady					= 0x8080;	// Ready bit
sl@0
   176
const TFLASHWORD KStsSuspended				= 0x4040;	// Suspend bit
sl@0
   177
const TFLASHWORD KStsEraseError				= 0x2020;	// Erase error bit
sl@0
   178
const TFLASHWORD KStsWriteError				= 0x1010;	// Write error bit
sl@0
   179
const TFLASHWORD KStsVppLow					= 0x0808;	// Vpp low bit
sl@0
   180
const TFLASHWORD KStsReserved				= 0x0404;	// Reserved bit (not used)
sl@0
   181
const TFLASHWORD KStsLocked					= 0x0202;	// Locked bit
sl@0
   182
const TFLASHWORD KStsReserved2				= 0x0101;	// Reserved bit
sl@0
   183
sl@0
   184
#endif
sl@0
   185
sl@0
   186
// address at which to issue the Query command
sl@0
   187
const TUint32 KCmdReadQueryOffset				= 0x55;	
sl@0
   188
sl@0
   189
const TUint32 KQueryOffsetQRY					= 0x10;
sl@0
   190
const TUint32 KQueryOffsetSizePower				= 0x27;
sl@0
   191
const TUint32 KQueryOffsetWriteBufferSizePower	= 0x2A;
sl@0
   192
const TUint32 KQueryOffsetErasePartitions		= 0x2C;
sl@0
   193
const TUint32 KQueryOffsetEraseBlockCount		= 0x2D;
sl@0
   194
const TUint32 KQueryOffsetEraseBlockSize		= 0x2F;
sl@0
   195
sl@0
   196
/********************************************
sl@0
   197
 * Driver definitions
sl@0
   198
 ********************************************/
sl@0
   199
const TInt KMaxWriteSetupAttempts		= 8;
sl@0
   200
const TInt KMaxEraseResumeAttempts		= 32;
sl@0
   201
sl@0
   202
const TInt KDataBufSize=1024;
sl@0
   203
sl@0
   204
sl@0
   205
// TO DO: (mandatory)
sl@0
   206
// Define the following timeouts in terms of timer ticks
sl@0
   207
// This is only example code... you may need to modify it for your hardware
sl@0
   208
// The examples given here assume a timer clock frequency of 3.6864MHz
sl@0
   209
const TUint32 KFlashWriteTimerPeriod =		1500;	// 1500 ticks @ 3.6864MHz = 406us
sl@0
   210
const TUint32 KFlashWriteTimerRetries =		3;		// total 1.2ms
sl@0
   211
const TUint32 KFlashSuspendTimerPeriod =	1500;	// 1500 ticks @ 3.6864MHz = 406us
sl@0
   212
const TUint32 KFlashSuspendTimerRetries =	3;		// total 1.2ms
sl@0
   213
const TUint32 KFlashEraseTimerPeriod =		100000;	// 100000 ticks @ 3.6864MHz = 27ms
sl@0
   214
const TUint32 KFlashEraseTimerRetries =		100;	// total 2.7sec
sl@0
   215
const TInt	  KEraseSuspendHoldOffTime =	130;	// 130ms
sl@0
   216
sl@0
   217
/********************************************
sl@0
   218
 * Media driver class
sl@0
   219
 ********************************************/
sl@0
   220
//
sl@0
   221
// TO DO: (optional)
sl@0
   222
//
sl@0
   223
// Add any private functions and data you require
sl@0
   224
//
sl@0
   225
class DMediaDriverFlashTemplate : public DMediaDriverFlash
sl@0
   226
	{
sl@0
   227
public:
sl@0
   228
	enum TWriteState {EWriteIdle=0,EWriting=1};
sl@0
   229
	enum TEraseState {EEraseIdle=0,EErase=1,EEraseNoSuspend=2,ESuspendPending=3,ESuspending=4,ESuspended=5};
sl@0
   230
	enum TEvent {EPollTimer=1,ETimeout=2,EHoldOffEnd=4};
sl@0
   231
sl@0
   232
	DMediaDriverFlashTemplate(TInt aMediaId);
sl@0
   233
sl@0
   234
	// replacing pure virtual - FLASH device specific stuff
sl@0
   235
	virtual TInt Initialise();
sl@0
   236
	virtual TUint32 EraseBlockSize();
sl@0
   237
	virtual TUint32 TotalSize();
sl@0
   238
	virtual TInt DoRead();
sl@0
   239
	virtual TInt DoWrite();
sl@0
   240
	virtual TInt DoErase();
sl@0
   241
sl@0
   242
private:
sl@0
   243
	void IPostEvents(TUint32 aEvents);
sl@0
   244
	void HandleEvents(TUint32 aEvents);
sl@0
   245
	void ClearEvents(TUint32 aEvents);
sl@0
   246
	void StartPollTimer(TUint32 aPeriod, TUint32 aRetries);
sl@0
   247
	void StartPollTimer();
sl@0
   248
	void StartHoldOffTimer();
sl@0
   249
	void CancelHoldOffTimer();
sl@0
   250
	void StartErase();
sl@0
   251
	void SuspendErase();
sl@0
   252
	void WriteStep();
sl@0
   253
	void DoFlashReady(TUint32 aStatus);
sl@0
   254
	void DoFlashTimeout();
sl@0
   255
	void StartPendingRW();
sl@0
   256
	TUint32 ReadQueryData8(TUint32 aOffset);
sl@0
   257
	TUint32 ReadQueryData16(TUint32 aOffset);
sl@0
   258
	void ReadFlashParameters();
sl@0
   259
	static void Isr(TAny* aPtr);
sl@0
   260
	static void HoldOffTimerFn(TAny* aPtr);
sl@0
   261
	static void EventDfc(TAny* aPtr);
sl@0
   262
sl@0
   263
private:
sl@0
   264
	TWriteState iWriteState;
sl@0
   265
	TEraseState iEraseState;
sl@0
   266
	TLinAddr iBase;
sl@0
   267
	TUint32 iEraseBlockSize;
sl@0
   268
	TUint32 iTotalSize;
sl@0
   269
	TUint32 iWriteBufferSize;
sl@0
   270
	TUint32 iWritePos;
sl@0
   271
	TInt iDataBufPos;
sl@0
   272
	TInt iDataBufRemain;
sl@0
   273
	TUint8* iData;		// data being written
sl@0
   274
	TUint32 iErasePos;
sl@0
   275
	NTimer iHoldOffTimer;
sl@0
   276
	TUint32 iEvents;
sl@0
   277
	TDfc iEventDfc;
sl@0
   278
	TUint32 iPollPeriod;
sl@0
   279
	TUint32 iPollRetries;
sl@0
   280
	TUint32 iEraseError;
sl@0
   281
	TInt iWriteError;
sl@0
   282
	TInt iEraseAttempt;
sl@0
   283
	DPlatChunkHw* iFlashChunk;
sl@0
   284
	};
sl@0
   285
sl@0
   286
#endif