1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - CARD - include
3   File:     eeprom.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_EEPROM_H_
19 #define NITRO_CARD_EEPROM_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_IsBackupEeprom
36 
37   Description:  Determines whether the backup device type is currently configured to be EEPROM.
38 
39   Arguments:    None.
40 
41   Returns:      TRUE if the backup device type is currently configured to be EEPROM.
42  *---------------------------------------------------------------------------*/
CARD_IsBackupEeprom(void)43 SDK_INLINE BOOL CARD_IsBackupEeprom(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_EEPROM);
48 }
49 
50 /*---------------------------------------------------------------------------*
51   Name:         CARD_ReadEeprom
52 
53   Description:  Performs a synchronous EEPROM read (equivalent to the "read" chip command).
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_ReadEeprom(u32 src,void * dst,u32 len)61 SDK_INLINE BOOL CARD_ReadEeprom(u32 src, void *dst, u32 len)
62 {
63     return CARD_ReadBackup(src, dst, len);
64 }
65 
66 /*---------------------------------------------------------------------------*
67   Name:         CARD_ReadEepromAsync
68 
69   Description:  Performs an asynchronous EEPROM read (equivalent to the "read" chip command).
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_ReadEepromAsync(u32 src,void * dst,u32 len,MIDmaCallback callback,void * arg)79 SDK_INLINE void CARD_ReadEepromAsync(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_WriteEeprom
87 
88   Description:  Performs a synchronous EEPROM write (equivalent to the "program" chip command).
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_WriteEeprom(u32 dst,const void * src,u32 len)96 SDK_INLINE BOOL CARD_WriteEeprom(u32 dst, const void *src, u32 len)
97 {
98     return CARD_ProgramBackup(dst, src, len);
99 }
100 
101 /*---------------------------------------------------------------------------*
102   Name:         CARD_WriteFlashAsync
103 
104   Description:  Performs an asynchronous EEPROM write (equivalent to the "write" chip command).
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_WriteEepromAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)114 SDK_INLINE void CARD_WriteEepromAsync(u32 dst, const void *src, u32 len,
115                                       MIDmaCallback callback, void *arg)
116 {
117     CARD_ProgramBackupAsync(dst, src, len, callback, arg);
118 }
119 
120 /*---------------------------------------------------------------------------*
121   Name:         CARD_VerifyEeprom
122 
123   Description:  Synchronously verifies an EEPROM.
124 
125   Arguments:    dst        Offset of the comparison destination.
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_VerifyEeprom(u32 dst,const void * src,u32 len)131 SDK_INLINE BOOL CARD_VerifyEeprom(u32 dst, const void *src, u32 len)
132 {
133     return CARD_VerifyBackup(dst, src, len);
134 }
135 
136 /*---------------------------------------------------------------------------*
137   Name:         CARD_VerifyEepromAsync
138 
139   Description:  Asynchronously verifies an EEPROM.
140 
141   Arguments:    dst        Offset of the comparison destination
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_VerifyEepromAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)149 SDK_INLINE void CARD_VerifyEepromAsync(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_WriteAndVerifyEeprom
157 
158   Description:  Synchronously performs an EEPROM 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_WriteAndVerifyEeprom(u32 dst,const void * src,u32 len)166 SDK_INLINE BOOL CARD_WriteAndVerifyEeprom(u32 dst, const void *src, u32 len)
167 {
168     return CARD_ProgramAndVerifyBackup(dst, src, len);
169 }
170 
171 /*---------------------------------------------------------------------------*
172   Name:         CARD_WriteAndVerifyEepromAsync
173 
174   Description:  Asynchronously performs an EEPROM 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_WriteAndVerifyEepromAsync(u32 dst,const void * src,u32 len,MIDmaCallback callback,void * arg)184 SDK_INLINE void CARD_WriteAndVerifyEepromAsync(u32 dst, const void *src, u32 len,
185                                                MIDmaCallback callback, void *arg)
186 {
187     CARD_ProgramAndVerifyBackupAsync(dst, src, len, callback, arg);
188 }
189 
190 
191 #ifdef __cplusplus
192 } // extern "C"
193 #endif
194 
195 
196 #endif // NITRO_CARD_EEPROM_H_
197