SdInfo.h

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

mercurial