-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSdInfo.h
286 lines (285 loc) · 7.88 KB
/
SdInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* Arduino Sd2Card Library
* Copyright (C) 2009 by William Greiman
*
* This file is part of the Arduino Sd2Card Library
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the Arduino Sd2Card Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef SdInfo_h
#define SdInfo_h
#include <stdint.h>
/** Based on the document: **/
//
/** SD Specifications **/
/** Part 1 **/
/** Physical Layer **/
/** Simplified Specification **/
/** Version 2.00 **/
/** September 25, 2006 **/
//
/** www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
* **/
//------------------------------------------------------------------------------
/** SD card commands **/
/** GO_IDLE_STATE - init card in spi mode if CS low */
#define CMD0 0X00
/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
#define CMD8 0X08
/** SEND_CSD - read the Card Specific Data (CSD register) */
#define CMD9 0X09
/** SEND_CID - read the card identification information (CID register) */
#define CMD10 0X0A
/** SEND_STATUS - read the card status register */
#define CMD13 0X0D
/** READ_BLOCK - read a single data block from the card */
#define CMD17 0X11
/** WRITE_BLOCK - write a single data block to the card */
#define CMD24 0X18
/** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
#define CMD25 0X19
/** ERASE_WR_BLK_START - sets the address of the first block to be erased */
#define CMD32 0X20
/** ERASE_WR_BLK_END - sets the address of the last block of the continuous
* range to be erased*/
#define CMD33 0X21
/** ERASE - erase all previously selected blocks */
#define CMD38 0X26
/** APP_CMD - escape for application specific command */
#define CMD55 0X37
/** READ_OCR - read the OCR register of a card */
#define CMD58 0X3A
/** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be pre-erased
* before writing */
#define ACMD23 0X17
/** SD_SEND_OP_COMD - Sends host capacity support information and activates the
* card's initialization process */
#define ACMD41 0X29
//------------------------------------------------------------------------------
/** status for card in the ready state */
#define R1_READY_STATE 0
/** status for card in the idle state */
#define R1_IDLE_STATE 1
/** status bit for illegal command */
#define R1_ILLEGAL_COMMAND 4
/** start data token for read or write single block*/
#define DATA_START_BLOCK 0XFE
/** stop token for write multiple blocks*/
#define STOP_TRAN_TOKEN 0XFD
/** start data token for write multiple blocks*/
#define WRITE_MULTIPLE_TOKEN 0XFC
/** mask for data response tokens after a write block operation */
#define DATA_RES_MASK 0X1F
/** write data accepted token */
#define DATA_RES_ACCEPTED 0X05
//------------------------------------------------------------------------------
///< CID typedef struct
typedef struct CID {
/** byte 0 Manufacturer ID **/
uint8_t mid;
/** byte 1-2 OEM/Application ID **/
char oid[2];
/** byte 3-7 Product name **/
char pnm[5];
/** byte 8 Product revision n.m **/
unsigned prv_m : 4;
/** byte 8 Product revision n.m **/
unsigned prv_n : 4;
/** byte 9-12 Product serial number **/
uint32_t psn;
/** byte 13 Manufacturing date **/
unsigned mdt_year_high : 4;
/** byte 13 Manufacturing date **/
unsigned reserved : 4;
/** byte 14 **/
unsigned mdt_month : 4;
/** byte 14 **/
unsigned mdt_year_low : 4;
/** byte 15 **/
unsigned always1 : 1;
/** byte 15 **/
unsigned crc : 7;
} cid_t;
//------------------------------------------------------------------------------
///< CSD for version 1.00 cards
typedef struct CSDV1 {
/** byte 0 **/
unsigned reserved1 : 6;
/** byte 0 **/
unsigned csd_ver : 2;
/** byte 1 **/
uint8_t taac;
/** byte 2 **/
uint8_t nsac;
/** byte 3 **/
uint8_t tran_speed;
/** byte 4 **/
uint8_t ccc_high;
/** byte 5 **/
unsigned read_bl_len : 4;
/** byte 5 **/
unsigned ccc_low : 4;
// unsigned read_bl_len : 4;
/** byte 6 **/
unsigned c_size_high : 2;
/** byte 6 **/
unsigned reserved2 : 2;
/** byte 6 **/
unsigned dsr_imp : 1;
/** byte 6 **/
unsigned read_blk_misalign : 1;
/** byte 6 **/
unsigned write_blk_misalign : 1;
/** byte 6 **/
unsigned read_bl_partial : 1;
/** byte 7 **/
uint8_t c_size_mid;
/** byte 8 **/
unsigned vdd_r_curr_max : 3;
/** byte 8 **/
unsigned vdd_r_curr_min : 3;
/** byte 8 **/
unsigned c_size_low : 2;
/** byte 9 **/
unsigned c_size_mult_high : 2;
/** byte 9 **/
unsigned vdd_w_cur_max : 3;
/** byte 9 **/
unsigned vdd_w_curr_min : 3;
/** byte 10 **/
unsigned sector_size_high : 6;
/** byte 10 **/
unsigned erase_blk_en : 1;
/** byte 10 **/
unsigned c_size_mult_low : 1;
/** byte 11 **/
unsigned wp_grp_size : 7;
/** byte 11 **/
unsigned sector_size_low : 1;
/** byte 12 **/
unsigned write_bl_len_high : 2;
/** byte 12 **/
unsigned r2w_factor : 3;
/** byte 12 **/
unsigned reserved3 : 2;
/** byte 12 **/
unsigned wp_grp_enable : 1;
/** byte 13 **/
unsigned reserved4 : 5;
/** byte 13 **/
unsigned write_partial : 1;
/** byte 13 **/
unsigned write_bl_len_low : 2;
/** byte 14 **/
unsigned reserved5 : 2;
/** byte 14 **/
unsigned file_format : 2;
/** byte 14 **/
unsigned tmp_write_protect : 1;
/** byte 14 **/
unsigned perm_write_protect : 1;
/** byte 14 **/
unsigned copy : 1;
/** byte 14 **/
unsigned file_format_grp : 1;
/** byte 15 **/
unsigned always1 : 1;
/** byte 15 **/
unsigned crc : 7;
} csd1_t;
//------------------------------------------------------------------------------
///< CSD for version 2.00 cards
typedef struct CSDV2 {
/** byte 0 **/
unsigned reserved1 : 6;
/** byte 0 **/
unsigned csd_ver : 2;
/** byte 1 **/
uint8_t taac;
/** byte 2 **/
uint8_t nsac;
/** byte 3 **/
uint8_t tran_speed;
/** byte 4 **/
uint8_t ccc_high;
/** byte 5 **/
unsigned read_bl_len : 4;
/** byte 5 **/
unsigned ccc_low : 4;
/** byte 6 **/
unsigned reserved2 : 4;
/** byte 6 **/
unsigned dsr_imp : 1;
/** byte 6 **/
unsigned read_blk_misalign : 1;
/** byte 6 **/
unsigned write_blk_misalign : 1;
/** byte 6 **/
unsigned read_bl_partial : 1;
/** byte 7 **/
unsigned reserved3 : 2;
/** byte 7 **/
unsigned c_size_high : 6;
/** byte 8 **/
uint8_t c_size_mid;
/** byte 9 **/
uint8_t c_size_low;
/** byte 10 **/
unsigned sector_size_high : 6;
/** byte 10 **/
unsigned erase_blk_en : 1;
/** byte 10 **/
unsigned reserved4 : 1;
/** byte 11 **/
unsigned wp_grp_size : 7;
/** byte 11 **/
unsigned sector_size_low : 1;
/** byte 12 **/
unsigned write_bl_len_high : 2;
/** byte 12 **/
unsigned r2w_factor : 3;
/** byte 12 **/
unsigned reserved5 : 2;
/** byte 12 **/
unsigned wp_grp_enable : 1;
/** byte 13 **/
unsigned reserved6 : 5;
/** byte 13 **/
unsigned write_partial : 1;
/** byte 13 **/
unsigned write_bl_len_low : 2;
/** byte 14 **/
unsigned reserved7 : 2;
/** byte 14 **/
unsigned file_format : 2;
/** byte 14 **/
unsigned tmp_write_protect : 1;
/** byte 14 **/
unsigned perm_write_protect : 1;
/** byte 14 **/
unsigned copy : 1;
/** byte 14 **/
unsigned file_format_grp : 1;
/** byte 15 **/
unsigned always1 : 1;
/** byte 15 **/
unsigned crc : 7;
} csd2_t;
//------------------------------------------------------------------------------
///< union of old and new style CSD register
union csd_t {
csd1_t v1; ///< v1 CSD register
csd2_t v2; ///< v2 CSD register
};
#endif /** SdInfo_h **/