Prusa3d Marlin fork
SdInfo.h
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
39 uint8_t const CMD0 = 0X00;
41 uint8_t const CMD8 = 0X08;
43 uint8_t const CMD9 = 0X09;
45 uint8_t const CMD10 = 0X0A;
47 uint8_t const CMD12 = 0X0C;
49 uint8_t const CMD13 = 0X0D;
51 uint8_t const CMD17 = 0X11;
53 uint8_t const CMD18 = 0X12;
55 uint8_t const CMD24 = 0X18;
57 uint8_t const CMD25 = 0X19;
59 uint8_t const CMD32 = 0X20;
62 uint8_t const CMD33 = 0X21;
64 uint8_t const CMD38 = 0X26;
65 
67 uint8_t const CMD48 = 0x30;
69 uint8_t const CMD49 = 0x31;
70 
72 uint8_t const CMD55 = 0X37;
74 uint8_t const CMD58 = 0X3A;
77 uint8_t const ACMD23 = 0X17;
80 uint8_t const ACMD41 = 0X29;
81 //------------------------------------------------------------------------------
83 uint8_t const R1_READY_STATE = 0X00;
85 uint8_t const R1_IDLE_STATE = 0X01;
87 uint8_t const R1_ILLEGAL_COMMAND = 0X04;
89 uint8_t const DATA_START_BLOCK = 0XFE;
91 uint8_t const STOP_TRAN_TOKEN = 0XFD;
93 uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC;
95 uint8_t const DATA_RES_MASK = 0X1F;
97 uint8_t const DATA_RES_ACCEPTED = 0X05;
98 //------------------------------------------------------------------------------
100 typedef struct CID {
101  // byte 0
103  unsigned char mid;
104  // byte 1-2
106  char oid[2];
107  // byte 3-7
109  char pnm[5];
110  // byte 8
112  unsigned char prv_m : 4;
114  unsigned char prv_n : 4;
115  // byte 9-12
117  uint32_t psn;
118  // byte 13
120  unsigned char mdt_year_high : 4;
122  unsigned char reserved : 4;
123  // byte 14
125  unsigned char mdt_month : 4;
127  unsigned char mdt_year_low :4;
128  // byte 15
130  unsigned char always1 : 1;
132  unsigned char crc : 7;
133 }cid_t;
134 //------------------------------------------------------------------------------
136 typedef struct CSDV1 {
137  // byte 0
138  unsigned char reserved1 : 6;
139  unsigned char csd_ver : 2;
140  // byte 1
141  unsigned char taac;
142  // byte 2
143  unsigned char nsac;
144  // byte 3
145  unsigned char tran_speed;
146  // byte 4
147  unsigned char ccc_high;
148  // byte 5
149  unsigned char read_bl_len : 4;
150  unsigned char ccc_low : 4;
151  // byte 6
152  unsigned char c_size_high : 2;
153  unsigned char reserved2 : 2;
154  unsigned char dsr_imp : 1;
155  unsigned char read_blk_misalign :1;
156  unsigned char write_blk_misalign : 1;
157  unsigned char read_bl_partial : 1;
158  // byte 7
159  unsigned char c_size_mid;
160  // byte 8
161  unsigned char vdd_r_curr_max : 3;
162  unsigned char vdd_r_curr_min : 3;
163  unsigned char c_size_low :2;
164  // byte 9
165  unsigned char c_size_mult_high : 2;
166  unsigned char vdd_w_cur_max : 3;
167  unsigned char vdd_w_curr_min : 3;
168  // byte 10
169  unsigned char sector_size_high : 6;
170  unsigned char erase_blk_en : 1;
171  unsigned char c_size_mult_low : 1;
172  // byte 11
173  unsigned char wp_grp_size : 7;
174  unsigned char sector_size_low : 1;
175  // byte 12
176  unsigned char write_bl_len_high : 2;
177  unsigned char r2w_factor : 3;
178  unsigned char reserved3 : 2;
179  unsigned char wp_grp_enable : 1;
180  // byte 13
181  unsigned char reserved4 : 5;
182  unsigned char write_partial : 1;
183  unsigned char write_bl_len_low : 2;
184  // byte 14
185  unsigned char reserved5: 2;
186  unsigned char file_format : 2;
187  unsigned char tmp_write_protect : 1;
188  unsigned char perm_write_protect : 1;
189  unsigned char copy : 1;
191  unsigned char file_format_grp : 1;
192  // byte 15
193  unsigned char always1 : 1;
194  unsigned char crc : 7;
195 }csd1_t;
196 //------------------------------------------------------------------------------
198 typedef struct CSDV2 {
199  // byte 0
200  unsigned char reserved1 : 6;
201  unsigned char csd_ver : 2;
202  // byte 1
204  unsigned char taac;
205  // byte 2
207  unsigned char nsac;
208  // byte 3
209  unsigned char tran_speed;
210  // byte 4
211  unsigned char ccc_high;
212  // byte 5
214  unsigned char read_bl_len : 4;
215  unsigned char ccc_low : 4;
216  // byte 6
218  unsigned char reserved2 : 4;
219  unsigned char dsr_imp : 1;
221  unsigned char read_blk_misalign :1;
223  unsigned char write_blk_misalign : 1;
225  unsigned char read_bl_partial : 1;
226  // byte 7
228  unsigned char reserved3 : 2;
230  unsigned char c_size_high : 6;
231  // byte 8
233  unsigned char c_size_mid;
234  // byte 9
236  unsigned char c_size_low;
237  // byte 10
239  unsigned char sector_size_high : 6;
241  unsigned char erase_blk_en : 1;
243  unsigned char reserved4 : 1;
244  // byte 11
245  unsigned char wp_grp_size : 7;
247  unsigned char sector_size_low : 1;
248  // byte 12
250  unsigned char write_bl_len_high : 2;
252  unsigned char r2w_factor : 3;
254  unsigned char reserved5 : 2;
256  unsigned char wp_grp_enable : 1;
257  // byte 13
258  unsigned char reserved6 : 5;
260  unsigned char write_partial : 1;
262  unsigned char write_bl_len_low : 2;
263  // byte 14
264  unsigned char reserved7: 2;
266  unsigned char file_format : 2;
267  unsigned char tmp_write_protect : 1;
268  unsigned char perm_write_protect : 1;
269  unsigned char copy : 1;
271  unsigned char file_format_grp : 1;
272  // byte 15
274  unsigned char always1 : 1;
276  unsigned char crc : 7;
277 }csd2_t;
278 //------------------------------------------------------------------------------
280 union csd_t {
281  csd1_t v1;
282  csd2_t v2;
283 };
284 #endif // SdInfo_h
285 
286 #endif
Definition: SdInfo.h:100
char oid[2]
Definition: SdInfo.h:106
unsigned char prv_m
Definition: SdInfo.h:112
unsigned char mdt_month
Definition: SdInfo.h:125
char pnm[5]
Definition: SdInfo.h:109
unsigned char mdt_year_high
Definition: SdInfo.h:120
unsigned char reserved
Definition: SdInfo.h:122
unsigned char crc
Definition: SdInfo.h:132
unsigned char mid
Definition: SdInfo.h:103
uint32_t psn
Definition: SdInfo.h:117
unsigned char prv_n
Definition: SdInfo.h:114
unsigned char always1
Definition: SdInfo.h:130
unsigned char mdt_year_low
Definition: SdInfo.h:127
Definition: SdInfo.h:136
unsigned char file_format_grp
Definition: SdInfo.h:191
Definition: SdInfo.h:198
unsigned char reserved2
Definition: SdInfo.h:218
unsigned char reserved3
Definition: SdInfo.h:228
unsigned char sector_size_high
Definition: SdInfo.h:239
unsigned char c_size_mid
Definition: SdInfo.h:233
unsigned char c_size_high
Definition: SdInfo.h:230
unsigned char write_bl_len_low
Definition: SdInfo.h:262
unsigned char write_partial
Definition: SdInfo.h:260
unsigned char reserved4
Definition: SdInfo.h:243
unsigned char c_size_low
Definition: SdInfo.h:236
unsigned char read_bl_len
Definition: SdInfo.h:214
unsigned char r2w_factor
Definition: SdInfo.h:252
unsigned char erase_blk_en
Definition: SdInfo.h:241
unsigned char wp_grp_enable
Definition: SdInfo.h:256
unsigned char file_format
Definition: SdInfo.h:266
unsigned char nsac
Definition: SdInfo.h:207
unsigned char read_blk_misalign
Definition: SdInfo.h:221
unsigned char always1
Definition: SdInfo.h:274
unsigned char write_blk_misalign
Definition: SdInfo.h:223
unsigned char taac
Definition: SdInfo.h:204
unsigned char crc
Definition: SdInfo.h:276
unsigned char read_bl_partial
Definition: SdInfo.h:225
unsigned char reserved5
Definition: SdInfo.h:254
unsigned char sector_size_low
Definition: SdInfo.h:247
unsigned char file_format_grp
Definition: SdInfo.h:271
unsigned char write_bl_len_high
Definition: SdInfo.h:250
Definition: SdInfo.h:280