1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - CARD - include
3 File: flash.h
4
5 Copyright 2007-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16
17 *---------------------------------------------------------------------------*/
18 #ifndef NITRO_CARD_FLASH_H_
19 #define NITRO_CARD_FLASH_H_
20
21
22 #include <nitro/card/backup.h>
23
24
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29
30
31 /*---------------------------------------------------------------------------*/
32 /* Functions */
33
34 /*---------------------------------------------------------------------------*
35 Name: CARD_IsBackupFlash
36
37 Description: Determines whether the backup device type is currently configured to be FLASH.
38
39 Arguments: None.
40
41 Returns: TRUE if the backup device type is currently configured to be FLASH.
42 *---------------------------------------------------------------------------*/
CARD_IsBackupFlash(void)43 SDK_INLINE BOOL CARD_IsBackupFlash(void)
44 {
45 const CARDBackupType t = CARD_GetCurrentBackupType();
46 return (((t >> CARD_BACKUP_TYPE_DEVICE_SHIFT) &
47 CARD_BACKUP_TYPE_DEVICE_MASK) == CARD_BACKUP_TYPE_DEVICE_FLASH);
48 }
49
50 /*---------------------------------------------------------------------------*
51 Name: CARD_ReadFlash
52
53 Description: Synchronous FLASH read (equivalent to the chip command "read").
54
55 Arguments: src Transfer source offset
56 dst Transfer destination memory address
57 len Transfer size
58
59 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
60 *---------------------------------------------------------------------------*/
CARD_ReadFlash(u32 src,void * dst,u32 len)61 SDK_INLINE BOOL CARD_ReadFlash(u32 src, void *dst, u32 len)
62 {
63 return CARD_ReadBackup(src, dst, len);
64 }
65
66 /*---------------------------------------------------------------------------*
67 Name: CARD_ReadFlashAsync
68
69 Description: Asynchronous FLASH read (equivalent to the chip command "read").
70
71 Arguments: src Transfer source offset
72 dst Transfer destination memory address
73 len Transfer size
74 callback Completion callback (NULL if not used)
75 arg Argument of completion callback (ignored if not used)
76
77 Returns: None.
78 *---------------------------------------------------------------------------*/
CARD_ReadFlashAsync(u32 src,void * dst,u32 len,MIDmaCallback callback,void * arg)79 SDK_INLINE void CARD_ReadFlashAsync(u32 src, void *dst, u32 len,
80 MIDmaCallback callback, void *arg)
81 {
82 CARD_ReadBackupAsync(src, dst, len, callback, arg);
83 }
84
85 /*---------------------------------------------------------------------------*
86 Name: CARD_WriteFlash
87
88 Description: Synchronous FLASH write (equivalent to the chip command "write").
89
90 Arguments: dst Transfer destination offset
91 src Transfer source memory address
92 len Transfer size
93
94 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
95 *---------------------------------------------------------------------------*/
CARD_WriteFlash(u32 dst,const void * src,u32 len)96 SDK_INLINE BOOL CARD_WriteFlash(u32 dst, const void *src, u32 len)
97 {
98 return CARD_WriteBackup(dst, src, len);
99 }
100
101 /*---------------------------------------------------------------------------*
102 Name: CARD_WriteFlashAsync
103
104 Description: Asynchronous FLASH write (equivalent to the chip command "write").
105
106 Arguments: dst Transfer destination offset
107 src Transfer source memory address
108 len Transfer size
109 callback Completion callback (NULL if not used)
110 arg Argument of completion callback (ignored if not used)
111
112 Returns: None.
113 *---------------------------------------------------------------------------*/
CARD_WriteFlashAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)114 SDK_INLINE void CARD_WriteFlashAsync(u32 dst, const void *src, u32 len,
115 MIDmaCallback callback, void *arg)
116 {
117 CARD_WriteBackupAsync(dst, src, len, callback, arg);
118 }
119
120 /*---------------------------------------------------------------------------*
121 Name: CARD_VerifyFlash
122
123 Description: Synchronous FLASH verify.
124
125 Arguments: dst Offset of the comparison target
126 src Memory address of the comparison source
127 len Comparison size
128
129 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
130 *---------------------------------------------------------------------------*/
CARD_VerifyFlash(u32 dst,const void * src,u32 len)131 SDK_INLINE BOOL CARD_VerifyFlash(u32 dst, const void *src, u32 len)
132 {
133 return CARD_VerifyBackup(dst, src, len);
134 }
135
136 /*---------------------------------------------------------------------------*
137 Name: CARD_VerifyFlashAsync
138
139 Description: Asynchronous FLASH verify.
140
141 Arguments: dst Offset of the comparison target
142 src Memory address of the comparison source
143 len Comparison size
144 callback Completion callback (NULL if not used)
145 arg Argument of completion callback (ignored if not used)
146
147 Returns: None.
148 *---------------------------------------------------------------------------*/
CARD_VerifyFlashAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)149 SDK_INLINE void CARD_VerifyFlashAsync(u32 dst, const void *src, u32 len,
150 MIDmaCallback callback, void *arg)
151 {
152 CARD_VerifyBackupAsync(dst, src, len, callback, arg);
153 }
154
155 /*---------------------------------------------------------------------------*
156 Name: CARD_WriteAndVerifyFlash
157
158 Description: Synchronous FLASH write and verification.
159
160 Arguments: dst Transfer destination offset
161 src Transfer source memory address
162 len Transfer size
163
164 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
165 *---------------------------------------------------------------------------*/
CARD_WriteAndVerifyFlash(u32 dst,const void * src,u32 len)166 SDK_INLINE BOOL CARD_WriteAndVerifyFlash(u32 dst, const void *src, u32 len)
167 {
168 return CARD_WriteAndVerifyBackup(dst, src, len);
169 }
170
171 /*---------------------------------------------------------------------------*
172 Name: CARD_WriteAndVerifyFlashAsync
173
174 Description: Synchronous FLASH write and verification.
175
176 Arguments: dst Transfer destination offset
177 src Transfer source memory address
178 len Transfer size
179 callback Completion callback (NULL if not used)
180 arg Argument of completion callback (ignored if not used)
181
182 Returns: None.
183 *---------------------------------------------------------------------------*/
CARD_WriteAndVerifyFlashAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)184 SDK_INLINE void CARD_WriteAndVerifyFlashAsync(u32 dst, const void *src, u32 len,
185 MIDmaCallback callback, void *arg)
186 {
187 CARD_WriteAndVerifyBackupAsync(dst, src, len, callback, arg);
188 }
189
190 /*---------------------------------------------------------------------------*
191 Name: CARD_EraseFlashSector
192
193 Description: Synchronous sector deletion.
194
195 Arguments: dst Deletion target offset
196 Must be an integer multiple of the sector size.
197 len Deletion size
198 Must be an integer multiple of the sector size.
199
200 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
201 *---------------------------------------------------------------------------*/
CARD_EraseFlashSector(u32 dst,u32 len)202 SDK_INLINE BOOL CARD_EraseFlashSector(u32 dst, u32 len)
203 {
204 return CARD_EraseBackupSector(dst, len);
205 }
206
207 /*---------------------------------------------------------------------------*
208 Name: CARD_EraseFlashSectorAsync
209
210 Description: Asynchronous sector deletion.
211
212 Arguments: dst Deletion target offset
213 Must be an integer multiple of the sector size.
214 len the deletion size
215 Must be an integer multiple of the sector size.
216 callback Completion callback (NULL if not used)
217 arg Argument of completion callback (ignored if not used)
218
219 Returns: None.
220 *---------------------------------------------------------------------------*/
CARD_EraseFlashSectorAsync(u32 dst,u32 len,MIDmaCallback callback,void * arg)221 SDK_INLINE void CARD_EraseFlashSectorAsync(u32 dst, u32 len,
222 MIDmaCallback callback, void *arg)
223 {
224 CARD_EraseBackupSectorAsync(dst, len, callback, arg);
225 }
226
227 /*---------------------------------------------------------------------------*
228 Name: CARD_ProgramFlash
229
230 Description: Synchronous FLASH program (equivalent to the chip command "program").
231
232 Arguments: dst Transfer destination offset
233 src Transfer source memory address
234 len Transfer size
235
236 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
237 *---------------------------------------------------------------------------*/
CARD_ProgramFlash(u32 dst,const void * src,u32 len)238 SDK_INLINE BOOL CARD_ProgramFlash(u32 dst, const void *src, u32 len)
239 {
240 return CARD_ProgramBackup(dst, src, len);
241 }
242
243 /*---------------------------------------------------------------------------*
244 Name: CARD_ProgramFlashAsync
245
246 Description: Asynchronous FLASH program (equivalent to the chip command "program").
247
248 Arguments: dst Transfer destination offset
249 src Transfer source memory address
250 len Transfer size
251 callback Completion callback (NULL if not used)
252 arg Argument of completion callback (ignored if not used)
253
254 Returns: None.
255 *---------------------------------------------------------------------------*/
CARD_ProgramFlashAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)256 SDK_INLINE void CARD_ProgramFlashAsync(u32 dst, const void *src, u32 len,
257 MIDmaCallback callback, void *arg)
258 {
259 CARD_ProgramBackupAsync(dst, src, len, callback, arg);
260 }
261
262 /*---------------------------------------------------------------------------*
263 Name: CARD_ProgramAndVerifyFlash
264
265 Description: Synchronous FLASH program and verification.
266
267 Arguments: dst Transfer destination offset
268 src Transfer source memory address
269 len Transfer size
270
271 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
272 *---------------------------------------------------------------------------*/
CARD_ProgramAndVerifyFlash(u32 dst,const void * src,u32 len)273 SDK_INLINE BOOL CARD_ProgramAndVerifyFlash(u32 dst, const void *src, u32 len)
274 {
275 return CARD_ProgramAndVerifyBackup(dst, src, len);
276 }
277
278 /*---------------------------------------------------------------------------*
279 Name: CARD_ProgramAndVerifyFlashAsync
280
281 Description: Asynchronous FLASH program and verification.
282
283 Arguments: dst Transfer destination offset
284 src Transfer source memory address
285 len Transfer size
286 callback Completion callback (NULL if not used)
287 arg Argument of completion callback (ignored if not used)
288
289 Returns: None.
290 *---------------------------------------------------------------------------*/
CARD_ProgramAndVerifyFlashAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)291 SDK_INLINE void CARD_ProgramAndVerifyFlashAsync(u32 dst, const void *src, u32 len,
292 MIDmaCallback callback, void *arg)
293 {
294 CARD_ProgramAndVerifyBackupAsync(dst, src, len, callback, arg);
295 }
296
297 /*---------------------------------------------------------------------------*
298 Name: CARD_WriteFlashSector
299
300 Description: Sector erasure and program.
301
302 Arguments: dst Transfer destination offset
303 Must be an integer multiple of the sector size.
304 src Transfer source memory address
305 len Transfer size
306 Must be an integer multiple of the sector size.
307
308 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
309 *---------------------------------------------------------------------------*/
CARD_WriteFlashSector(u32 dst,const void * src,u32 len)310 SDK_INLINE BOOL CARD_WriteFlashSector(u32 dst, const void *src, u32 len)
311 {
312 return CARD_WriteBackupSector(dst, src, len);
313 }
314
315 /*---------------------------------------------------------------------------*
316 Name: CARD_WriteFlashSectorAsync
317
318 Description: Sector erasure and program.
319
320 Arguments: dst Transfer destination offset
321 Must be an integer multiple of the sector size.
322 src Transfer source memory address
323 len Transfer size
324 Must be an integer multiple of the sector size.
325 callback Completion callback (NULL if not used)
326 arg Argument of completion callback (ignored if not used)
327
328 Returns: None.
329 *---------------------------------------------------------------------------*/
CARD_WriteFlashSectorAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)330 SDK_INLINE void CARD_WriteFlashSectorAsync(u32 dst, const void *src, u32 len,
331 MIDmaCallback callback, void *arg)
332 {
333 CARD_WriteBackupSectorAsync(dst, src, len, callback, arg);
334 }
335
336 /*---------------------------------------------------------------------------*
337 Name: CARD_WriteAndVerifyFlashSector
338
339 Description: Sector erasure, program, and verification.
340
341 Arguments: dst Transfer destination offset
342 Must be an integer multiple of the sector size.
343 src Transfer source memory address
344 len Transfer size
345 Must be an integer multiple of the sector size.
346
347 Returns: TRUE on completion with CARD_RESULT_SUCCESS and FALSE otherwise.
348 *---------------------------------------------------------------------------*/
CARD_WriteAndVerifyFlashSector(u32 dst,const void * src,u32 len)349 SDK_INLINE BOOL CARD_WriteAndVerifyFlashSector(u32 dst, const void *src, u32 len)
350 {
351 return CARD_WriteAndVerifyBackupSector(dst, src, len);
352 }
353
354 /*---------------------------------------------------------------------------*
355 Name: CARD_WriteAndVerifyFlashSectorAsync
356
357 Description: Sector erasure, program, and verification.
358
359 Arguments: dst Transfer destination offset
360 Must be an integer multiple of the sector size.
361 src Transfer source memory address
362 len Transfer size
363 Must be an integer multiple of the sector size.
364 callback Completion callback (NULL if not used)
365 arg Argument of completion callback (ignored if not used)
366
367 Returns: None.
368 *---------------------------------------------------------------------------*/
CARD_WriteAndVerifyFlashSectorAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)369 SDK_INLINE void CARD_WriteAndVerifyFlashSectorAsync(u32 dst, const void *src, u32 len,
370 MIDmaCallback callback, void *arg)
371 {
372 CARD_WriteAndVerifyBackupSectorAsync(dst, src, len, callback, arg);
373 }
374
375
376 #ifdef __cplusplus
377 } /* extern "C" */
378 #endif
379
380
381 #endif /* NITRO_CARD_EEPROM_H_ */
382