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