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