PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
sdcard.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
51 #ifndef __SDCARD_H__
52 #define __SDCARD_H__
53 
54 /******************************************************************************/
55 /* Include files */
56 /******************************************************************************/
57 #include "sdcmd.h"
58 
59 #if (defined(PDL_PERIPHERAL_SD_ACTIVE))
60 
61 /* C binding of definitions if building with C++ compiler */
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66 
73 
74 /******************************************************************************
75  * Global definitions
76  ******************************************************************************/
77 #define E_SD_OK 0
78 #define E_SD_NO_CARD -1
79 #define E_SD_INIT -2
80 #define E_SD_PARAMETER -3
81 #define E_SD_READ -4
82 #define E_SD_PROTECT -5
83 #define E_SD_WRITE -6
84 #define E_SD_DEVICE_TYPE -7
85 #define E_SD_ACTIVE -8
86 
87 #define E_SD_CMD_ERR -11
88 #define E_SD_CMD_TIMEOUT -13
89 #define E_SD_CMD_CRC_ERR -14
90 #define E_SD_CMD_WR_ERR -15
91 #define E_SD_CMD_IDLE -16
92 #define E_SD_CMD_CARD_ERR -20
93 
94 #define BLOCK_SIZE 512
95 #define CMD8_WAIT (0x00001000)
96 //#define ARG_CMD8 0xFF000AAF //CRC7 --0x38
97 #define ARG_CMD8 0x000001AA
98 //#define ARG_ACMD41_HCS_OFF 0x00000000//lower version before 2.0
99 #define ARG_ACMD41_HCS_OFF 0x003C0000
100 #define ARG_ACMD41_HCS_ON 0x403C0000 //High speed support by higher version 2.0 or later
101 #define ARG_ACMD41_BUSY 0x80000000 //Card Busy status
102 
103 #define CSD_VERSION_MASK 3
104 #define CSD_STRUCT_OFFSET 14
105 #define OCR_CAPACITY_OFFSET 30
106 #define OCR_CAPACITY_MASK 0x40000000
107 #define SD_VERSION_1_0 0
108 #define SD_VERSION_2_0 1 //version 2.0 or later
109 #define SD_CAPACITY_STANDARD 0
110 #define SD_CAPACITY_HIGH 1
111 
112 /******************************************************************************
113  * Global type definitions
114  ******************************************************************************/
115 typedef struct stc_sdcard_type
116 {
117  uint8_t u8Capacity : 4;
118  uint8_t u8Version : 4;
120 
121 // CSD Register ver1.0(for Standard Capacity Card)
122 typedef struct stc_csdver1
123 {
124  uint8_t u8Reserved1 : 6;
125  uint8_t u8Csd_structure : 2;
126 
127  uint8_t u8Taac : 8;
128  uint8_t u8Nsac : 8;
129  uint8_t u8Tran_speed : 8;
130  uint8_t u8Ccc1 : 8;
131 
132  uint8_t u8Read_bl_len : 4;
133  uint8_t u8Ccc2 : 4;
134 
135  uint8_t u8C_size1 : 2;
136  uint8_t u8Reserved2 : 2;
137  uint8_t u8Dsr_imp : 1;
138  uint8_t u8Read_blk_misaligh : 1;
139  uint8_t u8Write_blk_misalign : 1;
140  uint8_t u8Read_bl_partial : 1;
141 
142  uint8_t u8C_size2 : 8;
143 
144  uint8_t u8Vdd_r_curr_max : 3;
145  uint8_t u8Vdd_r_curr_min : 3;
146  uint8_t u8C_size3 : 2;
147 
148  uint8_t u8C_size_multi1 : 2;
149  uint8_t u8Cdd_w_curr_max : 3;
150  uint8_t u8Cdd_w_curr_min : 3;
151 
152  uint8_t u8Sector_size1 : 6;
153  uint8_t u8Erase_blk_en : 1;
154  uint8_t u8C_size_multi2 : 1;
155 
156  uint8_t u8Wp_grp_size : 7;
157  uint8_t u8Sector_size2 : 1;
158 
159  uint8_t u8Write_bl_len1 : 2;
160  uint8_t u8R2w_factor : 3;
161  uint8_t u8Reserved3 : 2;
162  uint8_t u8Wp_grp_enable : 1;
163 
164  uint8_t u8Reserved4 : 5;
165  uint8_t u8Write_bl_partial : 1;
166  uint8_t u8Write_bl_len2 : 2;
167 
168  uint8_t u8Reserved5 : 2;
169  uint8_t u8File_format : 2;
170  uint8_t u8Tmp_write_protect : 1;
171  uint8_t u8Perm_write_protect : 1;
172  uint8_t u8Copy : 1;
173  uint8_t u8File_format_grp : 1;
174 
175  uint8_t u8No_use : 1;
176  uint8_t u8Crc : 7;
178 
179 // CSD Register ver2.0(for High Capacity Card)
180 typedef struct stc_csdver2
181 {
182  uint8_t u8Reserved1 : 6;
183  uint8_t u8Csd_structure : 2;
184 
185  uint8_t u8Taac : 8;
186  uint8_t u8Nsac : 8;
187  uint8_t u8Tran_speed : 8;
188  uint8_t u8Ccc1 : 8;
189 
190  uint8_t u8Read_bl_len : 4;
191  uint8_t u8Ccc2 : 4;
192 
193  uint8_t u8Reserved2_U : 4;
194  uint8_t u8Dsr_imp : 1;
195  uint8_t u8Read_blk_misaligh : 1;
196  uint8_t u8Write_blk_misalign : 1;
197  uint8_t u8Read_bl_partial : 1;
198 
199  uint8_t u8C_size1 : 6;
200  uint8_t u8Reserved2_L : 2;
201 
202  uint8_t u8C_size2 : 8;
203  uint8_t u8C_size3 : 8;
204 
205  uint8_t u8Sector_size1 : 6;
206  uint8_t u8Erase_blk_en : 1;
207  uint8_t u8Reserved3 : 1;
208 
209  uint8_t u8Wp_grp_size : 7;
210  uint8_t u8Sector_size2 : 1;
211 
212  uint8_t u8Write_bl_len1 : 2;
213  uint8_t u8R2w_factor : 3;
214  uint8_t u8Reserved4 : 2;
215  uint8_t u8Wp_grp_enable : 1;
216 
217  uint8_t u8Reserved5 : 5;
218  uint8_t u8Write_bl_partial : 1;
219  uint8_t u8Write_bl_len2 : 2;
220 
221  uint8_t u8Reserved6 : 2;
222  uint8_t u8File_format : 2;
223  uint8_t u8Tmp_write_protect : 1;
224  uint8_t u8Perm_write_protect : 1;
225  uint8_t u8Copy : 1;
226  uint8_t u8File_format_grp : 1;
227 
228  uint8_t u8No_use : 1;
229  uint8_t u8Crc : 7;
235 typedef struct stc_sdcard_info
236 {
237  uint32_t OCR ;
238  uint8_t CID[16];
239  uint8_t CSD[16];
240  uint16_t RCA ;
242  uint32_t u32MaxSectorNum;
244 
245 /******************************************************************************/
246 /* Global variable declarations ('extern', definition in C source) */
247 /******************************************************************************/
248 
249 /******************************************************************************/
250 /* Global function prototypes ('extern', definition in C source) */
251 /******************************************************************************/
252 extern int32_t Sdcard_Init(stc_sdcard_info_t *pstcSdcardInfo);
253 extern int32_t Sdcard_ReadSector(stc_sdcard_info_t *pstcSdcardInfo, uint32_t u32start, uint16_t u16count, uint8_t *pu8buf);
254 extern int32_t Sdcard_WriteSector(stc_sdcard_info_t *pstcSdcardInfo, uint32_t u32start, uint16_t u16count, const uint8_t *pu8buf);
255 extern boolean_t Sdcard_Detect(void);
256 
257 /***ToDo for second release
258 
259 **///ToDo for second release
260 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif // #if (defined(PDL_PERIPHERAL_SD_ACTIVE))
267 
268 #endif /* __SDCARD_H__ */
269 /******************************************************************************/
270 /* EOF (not truncated) */
271 /******************************************************************************/
272