1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - CARD - libraries
3   File:     card_spi.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-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16 
17  *---------------------------------------------------------------------------*/
18 #ifndef NITRO_LIBRARIES_CARD_SPI_H__
19 #define NITRO_LIBRARIES_CARD_SPI_H__
20 
21 
22 #ifdef __cplusplus
23 extern  "C"
24 {
25 #endif
26 
27 
28 /*---------------------------------------------------------------------------*/
29 /* Constants */
30 
31 #define	CSPI_CONTINUOUS_ON	0x0040
32 #define	CSPI_CONTINUOUS_OFF	0x0000
33 
34 /* Commands */
35 #define COMM_WRITE_STATUS	0x01   /* Write status */
36 #define COMM_PROGRAM_PAGE	0x02   /* Page program */
37 #define COMM_READ_ARRAY		0x03   /* Read */
38 #define COMM_WRITE_DISABLE	0x04   /* Disable writing (not used) */
39 #define COMM_READ_STATUS	0x05   /* Read status */
40 #define COMM_WRITE_ENABLE	0x06   /* Enable writing */
41 
42 /* FLASH */
43 #define COMM_PAGE_WRITE		0x0A
44 #define COMM_PAGE_ERASE		0xDB
45 #define COMM_SECTOR_ERASE	0xD8
46 #define COMM_SUBSECTOR_ERASE	0x20
47 #define COMM_CHIP_ERASE		0xC7
48 #define CARDFLASH_READ_BYTES_FAST	0x0B    /* Unused */
49 #define CARDFLASH_DEEP_POWDOWN		0xB9    /* Unused */
50 #define CARDFLASH_WAKEUP			0xAB    /* Unused */
51 
52 /* Status register bits */
53 #define	COMM_STATUS_WIP_BIT		0x01    /* WriteInProgress (bufy) */
54 #define	COMM_STATUS_WEL_BIT		0x02    /* WriteEnableLatch */
55 #define	COMM_STATUS_BP0_BIT		0x04
56 #define	COMM_STATUS_BP1_BIT		0x08
57 #define	COMM_STATUS_BP2_BIT		0x10
58 #define COMM_STATUS_WPBEN_BIT	0x80
59 
60 
61 /*---------------------------------------------------------------------------*/
62 /* functions */
63 
64 /*---------------------------------------------------------------------------*
65   Name:         CARDi_InitStatusRegister
66 
67   Description:  Corrects status registers at startup for FRAM and EEPROM.
68                 (Because FRAM write protection settings may change when the power is turned on)
69                 (Because there may be invalid values initially in EEPROM when it is delivered)
70 
71   Arguments:    None.
72 
73   Returns:      None.
74  *---------------------------------------------------------------------------*/
75 void    CARDi_InitStatusRegister(void);
76 
77 /*---------------------------------------------------------------------------*
78   Name:         CARDi_CommandReadStatus
79 
80   Description:  Read status.
81 
82   Arguments:    None.
83 
84   Returns:      Status value.
85  *---------------------------------------------------------------------------*/
86 u8 CARDi_CommandReadStatus(void);
87 
88 /*---------------------------------------------------------------------------*
89   Name:         CARDi_ReadBackupCore
90 
91   Description:  The entire read command to the device.
92 
93   Arguments:    src         Device offset to read from
94                 dst         Memory address to read to
95                 len         Read size
96 
97   Returns:      None.
98  *---------------------------------------------------------------------------*/
99 void    CARDi_ReadBackupCore(u32 src, void *dst, u32 len);
100 
101 /*---------------------------------------------------------------------------*
102   Name:         CARDi_ProgramBackupCore
103 
104   Description:  The entire program (non-deleting write) command to the device.
105 
106   Arguments:    dst             Device offset to write to
107                 src             Memory address to write from
108                 len             Write size
109 
110   Returns:      None.
111  *---------------------------------------------------------------------------*/
112 void    CARDi_ProgramBackupCore(u32 dst, const void *src, u32 len);
113 
114 /*---------------------------------------------------------------------------*
115   Name:         CARDi_WriteBackupCore
116 
117   Description:  The entire write (delete and program) command to the device.
118 
119   Arguments:    dst             Device offset to write to
120                 src             Memory address to write from
121                 len             Write size
122 
123   Returns:      None.
124  *---------------------------------------------------------------------------*/
125 void    CARDi_WriteBackupCore(u32 dst, const void *src, u32 len);
126 
127 /*---------------------------------------------------------------------------*
128   Name:         CARDi_VerifyBackupCore
129 
130   Description:  The entire verify (actually read and compare) command to the device.
131 
132   Arguments:    dst        Device offset to compare
133                 src        Memory address to compare against
134                 len        Comparison size
135 
136   Returns:      None.
137  *---------------------------------------------------------------------------*/
138 void    CARDi_VerifyBackupCore(u32 dst, const void *src, u32 len);
139 
140 /*---------------------------------------------------------------------------*
141   Name:         CARDi_EraseBackupSectorCore
142 
143   Description:  The entire sector delete command to the device.
144 
145   Arguments:    dst        Device offset to delete
146                 len        Deletion size
147 
148   Returns:      None.
149  *---------------------------------------------------------------------------*/
150 void    CARDi_EraseBackupSectorCore(u32 dst, u32 len);
151 
152 /*---------------------------------------------------------------------------*
153   Name:         CARDi_EraseBackupSubSectorCore
154 
155   Description:  The entire sub-sector deletion command to the device.
156 
157   Arguments:    dst               Deletion target device offset
158                 len               Deletion size
159 
160   Returns:      None.
161  *---------------------------------------------------------------------------*/
162 void    CARDi_EraseBackupSubSectorCore(u32 dst, u32 len);
163 
164 /*---------------------------------------------------------------------------*
165   Name:         CARDi_EraseChipCore
166 
167   Description:  The entire chip delete command to the device.
168 
169   Arguments:    None.
170 
171   Returns:      None.
172  *---------------------------------------------------------------------------*/
173 void    CARDi_EraseChipCore(void);
174 
175 /*---------------------------------------------------------------------------*
176   Name:         CARDi_SetWriteProtectCore
177 
178   Description:  The entire write-protect command to the device.
179 
180   Arguments:    stat              Protect flag to set
181 
182   Returns:      None.
183  *---------------------------------------------------------------------------*/
184 void    CARDi_SetWriteProtectCore(u16 stat);
185 
186 
187 #ifdef __cplusplus
188 } // extern "C"
189 #endif
190 
191 
192 
193 #endif // NITRO_LIBRARIES_CARD_SPI_H__
194