My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SdInfo.h 8.3KB

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