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