hal_mmcsd.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_mmcsd.h
  15. * @brief MMC/SD cards common header.
  16. * @details This header defines an abstract interface useful to access MMC/SD
  17. * I/O block devices in a standardized way.
  18. *
  19. * @addtogroup MMCSD
  20. * @{
  21. */
  22. #ifndef HAL_MMCSD_H
  23. #define HAL_MMCSD_H
  24. #if (HAL_USE_MMC_SPI == TRUE) || (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
  25. /*===========================================================================*/
  26. /* Driver constants. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief Fixed block size for MMC/SD block devices.
  30. */
  31. #define MMCSD_BLOCK_SIZE 512U
  32. /**
  33. * @brief Mask of error bits in R1 responses.
  34. */
  35. #define MMCSD_R1_ERROR_MASK 0xFDFFE008U
  36. /**
  37. * @brief Fixed pattern for CMD8.
  38. */
  39. #define MMCSD_CMD8_PATTERN 0x000001AAU
  40. /**
  41. * @name SD/MMC status conditions
  42. * @{
  43. */
  44. #define MMCSD_STS_IDLE 0U
  45. #define MMCSD_STS_READY 1U
  46. #define MMCSD_STS_IDENT 2U
  47. #define MMCSD_STS_STBY 3U
  48. #define MMCSD_STS_TRAN 4U
  49. #define MMCSD_STS_DATA 5U
  50. #define MMCSD_STS_RCV 6U
  51. #define MMCSD_STS_PRG 7U
  52. #define MMCSD_STS_DIS 8U
  53. /** @} */
  54. /**
  55. * @name SD/MMC commands
  56. * @{
  57. */
  58. #define MMCSD_CMD_GO_IDLE_STATE 0U
  59. #define MMCSD_CMD_INIT 1U
  60. #define MMCSD_CMD_ALL_SEND_CID 2U
  61. #define MMCSD_CMD_SEND_RELATIVE_ADDR 3U
  62. #define MMCSD_CMD_SET_BUS_WIDTH 6U
  63. #define MMCSD_CMD_SWITCH MMCSD_CMD_SET_BUS_WIDTH
  64. #define MMCSD_CMD_SEL_DESEL_CARD 7U
  65. #define MMCSD_CMD_SEND_IF_COND 8U
  66. #define MMCSD_CMD_SEND_EXT_CSD MMCSD_CMD_SEND_IF_COND
  67. #define MMCSD_CMD_SEND_CSD 9U
  68. #define MMCSD_CMD_SEND_CID 10U
  69. #define MMCSD_CMD_STOP_TRANSMISSION 12U
  70. #define MMCSD_CMD_SEND_STATUS 13U
  71. #define MMCSD_CMD_SET_BLOCKLEN 16U
  72. #define MMCSD_CMD_READ_SINGLE_BLOCK 17U
  73. #define MMCSD_CMD_READ_MULTIPLE_BLOCK 18U
  74. #define MMCSD_CMD_SET_BLOCK_COUNT 23U
  75. #define MMCSD_CMD_WRITE_BLOCK 24U
  76. #define MMCSD_CMD_WRITE_MULTIPLE_BLOCK 25U
  77. #define MMCSD_CMD_ERASE_RW_BLK_START 32U
  78. #define MMCSD_CMD_ERASE_RW_BLK_END 33U
  79. #define MMCSD_CMD_ERASE 38U
  80. #define MMCSD_CMD_APP_OP_COND 41U
  81. #define MMCSD_CMD_LOCK_UNLOCK 42U
  82. #define MMCSD_CMD_APP_CMD 55U
  83. #define MMCSD_CMD_READ_OCR 58U
  84. /** @} */
  85. /**
  86. * @name CSD record offsets
  87. */
  88. /**
  89. * @brief Slice position of values in CSD register.
  90. */
  91. /* CSD for MMC */
  92. #define MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE 127U,126U
  93. #define MMCSD_CSD_MMC_SPEC_VERS_SLICE 125U,122U
  94. #define MMCSD_CSD_MMC_TAAC_SLICE 119U,112U
  95. #define MMCSD_CSD_MMC_NSAC_SLICE 111U,104U
  96. #define MMCSD_CSD_MMC_TRAN_SPEED_SLICE 103U,96U
  97. #define MMCSD_CSD_MMC_CCC_SLICE 95U,84U
  98. #define MMCSD_CSD_MMC_READ_BL_LEN_SLICE 83U,80U
  99. #define MMCSD_CSD_MMC_READ_BL_PARTIAL_SLICE 79U,79U
  100. #define MMCSD_CSD_MMC_WRITE_BLK_MISALIGN_SLICE 78U,78U
  101. #define MMCSD_CSD_MMC_READ_BLK_MISALIGN_SLICE 77U,77U
  102. #define MMCSD_CSD_MMC_DSR_IMP_SLICE 76U,76U
  103. #define MMCSD_CSD_MMC_C_SIZE_SLICE 73U,62U
  104. #define MMCSD_CSD_MMC_VDD_R_CURR_MIN_SLICE 61U,59U
  105. #define MMCSD_CSD_MMC_VDD_R_CURR_MAX_SLICE 58U,56U
  106. #define MMCSD_CSD_MMC_VDD_W_CURR_MIN_SLICE 55U,53U
  107. #define MMCSD_CSD_MMC_VDD_W_CURR_MAX_SLICE 52U,50U
  108. #define MMCSD_CSD_MMC_C_SIZE_MULT_SLICE 49U,47U
  109. #define MMCSD_CSD_MMC_ERASE_GRP_SIZE_SLICE 46U,42U
  110. #define MMCSD_CSD_MMC_ERASE_GRP_MULT_SLICE 41U,37U
  111. #define MMCSD_CSD_MMC_WP_GRP_SIZE_SLICE 36U,32U
  112. #define MMCSD_CSD_MMC_WP_GRP_ENABLE_SLICE 31U,31U
  113. #define MMCSD_CSD_MMC_DEFAULT_ECC_SLICE 30U,29U
  114. #define MMCSD_CSD_MMC_R2W_FACTOR_SLICE 28U,26U
  115. #define MMCSD_CSD_MMC_WRITE_BL_LEN_SLICE 25U,22U
  116. #define MMCSD_CSD_MMC_WRITE_BL_PARTIAL_SLICE 21U,21U
  117. #define MMCSD_CSD_MMC_CONTENT_PROT_APP_SLICE 16U,16U
  118. #define MMCSD_CSD_MMC_FILE_FORMAT_GRP_SLICE 15U,15U
  119. #define MMCSD_CSD_MMC_COPY_SLICE 14U,14U
  120. #define MMCSD_CSD_MMC_PERM_WRITE_PROTECT_SLICE 13U,13U
  121. #define MMCSD_CSD_MMC_TMP_WRITE_PROTECT_SLICE 12U,12U
  122. #define MMCSD_CSD_MMC_FILE_FORMAT_SLICE 11U,10U
  123. #define MMCSD_CSD_MMC_ECC_SLICE 9U,8U
  124. #define MMCSD_CSD_MMC_CRC_SLICE 7U,1U
  125. /* CSD version 2.0 */
  126. #define MMCSD_CSD_20_CRC_SLICE 7U,1U
  127. #define MMCSD_CSD_20_FILE_FORMAT_SLICE 11U,10U
  128. #define MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE 12U,12U
  129. #define MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE 13U,13U
  130. #define MMCSD_CSD_20_COPY_SLICE 14U,14U
  131. #define MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE 15U,15U
  132. #define MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE 21U,21U
  133. #define MMCSD_CSD_20_WRITE_BL_LEN_SLICE 25U,12U
  134. #define MMCSD_CSD_20_R2W_FACTOR_SLICE 28U,26U
  135. #define MMCSD_CSD_20_WP_GRP_ENABLE_SLICE 31U,31U
  136. #define MMCSD_CSD_20_WP_GRP_SIZE_SLICE 38U,32U
  137. #define MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE 45U,39U
  138. #define MMCSD_CSD_20_ERASE_BLK_EN_SLICE 46U,46U
  139. #define MMCSD_CSD_20_C_SIZE_SLICE 69U,48U
  140. #define MMCSD_CSD_20_DSR_IMP_SLICE 76U,76U
  141. #define MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE 77U,77U
  142. #define MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE 78U,78U
  143. #define MMCSD_CSD_20_READ_BL_PARTIAL_SLICE 79U,79U
  144. #define MMCSD_CSD_20_READ_BL_LEN_SLICE 83U,80U
  145. #define MMCSD_CSD_20_CCC_SLICE 95U,84U
  146. #define MMCSD_CSD_20_TRANS_SPEED_SLICE 103U,96U
  147. #define MMCSD_CSD_20_NSAC_SLICE 111U,104U
  148. #define MMCSD_CSD_20_TAAC_SLICE 119U,112U
  149. #define MMCSD_CSD_20_CSD_STRUCTURE_SLICE 127U,126U
  150. /* CSD version 1.0 */
  151. #define MMCSD_CSD_10_CRC_SLICE MMCSD_CSD_20_CRC_SLICE
  152. #define MMCSD_CSD_10_FILE_FORMAT_SLICE MMCSD_CSD_20_FILE_FORMAT_SLICE
  153. #define MMCSD_CSD_10_TMP_WRITE_PROTECT_SLICE MMCSD_CSD_20_TMP_WRITE_PROTECT_SLICE
  154. #define MMCSD_CSD_10_PERM_WRITE_PROTECT_SLICE MMCSD_CSD_20_PERM_WRITE_PROTECT_SLICE
  155. #define MMCSD_CSD_10_COPY_SLICE MMCSD_CSD_20_COPY_SLICE
  156. #define MMCSD_CSD_10_FILE_FORMAT_GRP_SLICE MMCSD_CSD_20_FILE_FORMAT_GRP_SLICE
  157. #define MMCSD_CSD_10_WRITE_BL_PARTIAL_SLICE MMCSD_CSD_20_WRITE_BL_PARTIAL_SLICE
  158. #define MMCSD_CSD_10_WRITE_BL_LEN_SLICE MMCSD_CSD_20_WRITE_BL_LEN_SLICE
  159. #define MMCSD_CSD_10_R2W_FACTOR_SLICE MMCSD_CSD_20_R2W_FACTOR_SLICE
  160. #define MMCSD_CSD_10_WP_GRP_ENABLE_SLICE MMCSD_CSD_20_WP_GRP_ENABLE_SLICE
  161. #define MMCSD_CSD_10_WP_GRP_SIZE_SLICE MMCSD_CSD_20_WP_GRP_SIZE_SLICE
  162. #define MMCSD_CSD_10_ERASE_SECTOR_SIZE_SLICE MMCSD_CSD_20_ERASE_SECTOR_SIZE_SLICE
  163. #define MMCSD_CSD_10_ERASE_BLK_EN_SLICE MMCSD_CSD_20_ERASE_BLK_EN_SLICE
  164. #define MMCSD_CSD_10_C_SIZE_MULT_SLICE 49U,47U
  165. #define MMCSD_CSD_10_VDD_W_CURR_MAX_SLICE 52U,50U
  166. #define MMCSD_CSD_10_VDD_W_CURR_MIN_SLICE 55U,53U
  167. #define MMCSD_CSD_10_VDD_R_CURR_MAX_SLICE 58U,56U
  168. #define MMCSD_CSD_10_VDD_R_CURR_MIX_SLICE 61U,59U
  169. #define MMCSD_CSD_10_C_SIZE_SLICE 73U,62U
  170. #define MMCSD_CSD_10_DSR_IMP_SLICE MMCSD_CSD_20_DSR_IMP_SLICE
  171. #define MMCSD_CSD_10_READ_BLK_MISALIGN_SLICE MMCSD_CSD_20_READ_BLK_MISALIGN_SLICE
  172. #define MMCSD_CSD_10_WRITE_BLK_MISALIGN_SLICE MMCSD_CSD_20_WRITE_BLK_MISALIGN_SLICE
  173. #define MMCSD_CSD_10_READ_BL_PARTIAL_SLICE MMCSD_CSD_20_READ_BL_PARTIAL_SLICE
  174. #define MMCSD_CSD_10_READ_BL_LEN_SLICE 83U,80U
  175. #define MMCSD_CSD_10_CCC_SLICE MMCSD_CSD_20_CCC_SLICE
  176. #define MMCSD_CSD_10_TRANS_SPEED_SLICE MMCSD_CSD_20_TRANS_SPEED_SLICE
  177. #define MMCSD_CSD_10_NSAC_SLICE MMCSD_CSD_20_NSAC_SLICE
  178. #define MMCSD_CSD_10_TAAC_SLICE MMCSD_CSD_20_TAAC_SLICE
  179. #define MMCSD_CSD_10_CSD_STRUCTURE_SLICE MMCSD_CSD_20_CSD_STRUCTURE_SLICE
  180. /** @} */
  181. /**
  182. * @name CID record offsets
  183. */
  184. /**
  185. * @brief Slice position of values in CID register.
  186. */
  187. /* CID for SDC */
  188. #define MMCSD_CID_SDC_CRC_SLICE 7U,1U
  189. #define MMCSD_CID_SDC_MDT_M_SLICE 11U,8U
  190. #define MMCSD_CID_SDC_MDT_Y_SLICE 19U,12U
  191. #define MMCSD_CID_SDC_PSN_SLICE 55U,24U
  192. #define MMCSD_CID_SDC_PRV_M_SLICE 59U,56U
  193. #define MMCSD_CID_SDC_PRV_N_SLICE 63U,60U
  194. #define MMCSD_CID_SDC_PNM0_SLICE 71U,64U
  195. #define MMCSD_CID_SDC_PNM1_SLICE 79U,72U
  196. #define MMCSD_CID_SDC_PNM2_SLICE 87U,80U
  197. #define MMCSD_CID_SDC_PNM3_SLICE 95U,88U
  198. #define MMCSD_CID_SDC_PNM4_SLICE 103U,96U
  199. #define MMCSD_CID_SDC_OID_SLICE 119U,104U
  200. #define MMCSD_CID_SDC_MID_SLICE 127U,120U
  201. /* CID for MMC */
  202. #define MMCSD_CID_MMC_CRC_SLICE 7U,1U
  203. #define MMCSD_CID_MMC_MDT_Y_SLICE 11U,8U
  204. #define MMCSD_CID_MMC_MDT_M_SLICE 15U,12U
  205. #define MMCSD_CID_MMC_PSN_SLICE 47U,16U
  206. #define MMCSD_CID_MMC_PRV_M_SLICE 51U,48U
  207. #define MMCSD_CID_MMC_PRV_N_SLICE 55U,52U
  208. #define MMCSD_CID_MMC_PNM0_SLICE 63U,56U
  209. #define MMCSD_CID_MMC_PNM1_SLICE 71U,64U
  210. #define MMCSD_CID_MMC_PNM2_SLICE 79U,72U
  211. #define MMCSD_CID_MMC_PNM3_SLICE 87U,80U
  212. #define MMCSD_CID_MMC_PNM4_SLICE 95U,88U
  213. #define MMCSD_CID_MMC_PNM5_SLICE 103U,96U
  214. #define MMCSD_CID_MMC_OID_SLICE 119U,104U
  215. #define MMCSD_CID_MMC_MID_SLICE 127U,120U
  216. /** @} */
  217. /*===========================================================================*/
  218. /* Driver pre-compile time settings. */
  219. /*===========================================================================*/
  220. /*===========================================================================*/
  221. /* Derived constants and error checks. */
  222. /*===========================================================================*/
  223. /*===========================================================================*/
  224. /* Driver data structures and types. */
  225. /*===========================================================================*/
  226. /**
  227. * @brief @p MMCSDBlockDevice specific methods.
  228. */
  229. #define _mmcsd_block_device_methods \
  230. _base_block_device_methods
  231. /**
  232. * @brief @p MMCSDBlockDevice specific data.
  233. * @note It is empty because @p MMCSDBlockDevice is only an interface
  234. * without implementation.
  235. */
  236. #define _mmcsd_block_device_data \
  237. _base_block_device_data \
  238. /* Card CID.*/ \
  239. uint32_t cid[4]; \
  240. /* Card CSD.*/ \
  241. uint32_t csd[4]; \
  242. /* Total number of blocks in card.*/ \
  243. uint32_t capacity;
  244. /**
  245. * @extends BaseBlockDeviceVMT
  246. *
  247. * @brief @p MMCSDBlockDevice virtual methods table.
  248. */
  249. struct MMCSDBlockDeviceVMT {
  250. _base_block_device_methods
  251. };
  252. /**
  253. * @extends BaseBlockDevice
  254. *
  255. * @brief MCC/SD block device class.
  256. * @details This class represents a, block-accessible, MMC/SD device.
  257. */
  258. typedef struct {
  259. /** @brief Virtual Methods Table.*/
  260. const struct MMCSDBlockDeviceVMT *vmt;
  261. _mmcsd_block_device_data
  262. } MMCSDBlockDevice;
  263. /**
  264. * @brief Unpacked CID register from SDC.
  265. */
  266. typedef struct {
  267. uint8_t mid;
  268. uint16_t oid;
  269. char pnm[5];
  270. uint8_t prv_n;
  271. uint8_t prv_m;
  272. uint32_t psn;
  273. uint8_t mdt_m;
  274. uint16_t mdt_y;
  275. uint8_t crc;
  276. } unpacked_sdc_cid_t;
  277. /**
  278. * @brief Unpacked CID register from MMC.
  279. */
  280. typedef struct {
  281. uint8_t mid;
  282. uint16_t oid;
  283. char pnm[6];
  284. uint8_t prv_n;
  285. uint8_t prv_m;
  286. uint32_t psn;
  287. uint8_t mdt_m;
  288. uint16_t mdt_y;
  289. uint8_t crc;
  290. } unpacked_mmc_cid_t;
  291. /**
  292. * @brief Unpacked CSD v1.0 register from SDC.
  293. */
  294. typedef struct {
  295. uint8_t csd_structure;
  296. uint8_t taac;
  297. uint8_t nsac;
  298. uint8_t tran_speed;
  299. uint16_t ccc;
  300. uint8_t read_bl_len;
  301. uint8_t read_bl_partial;
  302. uint8_t write_blk_misalign;
  303. uint8_t read_blk_misalign;
  304. uint8_t dsr_imp;
  305. uint16_t c_size;
  306. uint8_t vdd_r_curr_min;
  307. uint8_t vdd_r_curr_max;
  308. uint8_t vdd_w_curr_min;
  309. uint8_t vdd_w_curr_max;
  310. uint8_t c_size_mult;
  311. uint8_t erase_blk_en;
  312. uint8_t erase_sector_size;
  313. uint8_t wp_grp_size;
  314. uint8_t wp_grp_enable;
  315. uint8_t r2w_factor;
  316. uint8_t write_bl_len;
  317. uint8_t write_bl_partial;
  318. uint8_t file_format_grp;
  319. uint8_t copy;
  320. uint8_t perm_write_protect;
  321. uint8_t tmp_write_protect;
  322. uint8_t file_format;
  323. uint8_t crc;
  324. } unpacked_sdc_csd_10_t;
  325. /**
  326. * @brief Unpacked CSD v2.0 register from SDC.
  327. */
  328. typedef struct {
  329. uint8_t csd_structure;
  330. uint8_t taac;
  331. uint8_t nsac;
  332. uint8_t tran_speed;
  333. uint16_t ccc;
  334. uint8_t read_bl_len;
  335. uint8_t read_bl_partial;
  336. uint8_t write_blk_misalign;
  337. uint8_t read_blk_misalign;
  338. uint8_t dsr_imp;
  339. uint32_t c_size;
  340. uint8_t erase_blk_en;
  341. uint8_t erase_sector_size;
  342. uint8_t wp_grp_size;
  343. uint8_t wp_grp_enable;
  344. uint8_t r2w_factor;
  345. uint8_t write_bl_len;
  346. uint8_t write_bl_partial;
  347. uint8_t file_format_grp;
  348. uint8_t copy;
  349. uint8_t perm_write_protect;
  350. uint8_t tmp_write_protect;
  351. uint8_t file_format;
  352. uint8_t crc;
  353. } unpacked_sdc_csd_20_t;
  354. /**
  355. * @brief Unpacked CSD register from MMC.
  356. */
  357. typedef struct {
  358. uint8_t csd_structure;
  359. uint8_t spec_vers;
  360. uint8_t taac;
  361. uint8_t nsac;
  362. uint8_t tran_speed;
  363. uint16_t ccc;
  364. uint8_t read_bl_len;
  365. uint8_t read_bl_partial;
  366. uint8_t write_blk_misalign;
  367. uint8_t read_blk_misalign;
  368. uint8_t dsr_imp;
  369. uint16_t c_size;
  370. uint8_t vdd_r_curr_min;
  371. uint8_t vdd_r_curr_max;
  372. uint8_t vdd_w_curr_min;
  373. uint8_t vdd_w_curr_max;
  374. uint8_t c_size_mult;
  375. uint8_t erase_grp_size;
  376. uint8_t erase_grp_mult;
  377. uint8_t wp_grp_size;
  378. uint8_t wp_grp_enable;
  379. uint8_t default_ecc;
  380. uint8_t r2w_factor;
  381. uint8_t write_bl_len;
  382. uint8_t write_bl_partial;
  383. uint8_t content_prot_app;
  384. uint8_t file_format_grp;
  385. uint8_t copy;
  386. uint8_t perm_write_protect;
  387. uint8_t tmp_write_protect;
  388. uint8_t file_format;
  389. uint8_t ecc;
  390. uint8_t crc;
  391. } unpacked_mmc_csd_t;
  392. /*===========================================================================*/
  393. /* Driver macros. */
  394. /*===========================================================================*/
  395. /**
  396. * @name R1 response utilities
  397. * @{
  398. */
  399. /**
  400. * @brief Evaluates to @p true if the R1 response contains error flags.
  401. *
  402. * @param[in] r1 the r1 response
  403. */
  404. #define MMCSD_R1_ERROR(r1) (((r1) & MMCSD_R1_ERROR_MASK) != 0U)
  405. /**
  406. * @brief Returns the status field of an R1 response.
  407. *
  408. * @param[in] r1 the r1 response
  409. */
  410. #define MMCSD_R1_STS(r1) (((r1) >> 9U) & 15U)
  411. /**
  412. * @brief Evaluates to @p true if the R1 response indicates a locked card.
  413. *
  414. * @param[in] r1 the r1 response
  415. */
  416. #define MMCSD_R1_IS_CARD_LOCKED(r1) ((((r1) >> 21U) & 1U) != 0U)
  417. /** @} */
  418. /**
  419. * @name Macro Functions
  420. * @{
  421. */
  422. /**
  423. * @brief Returns the card capacity in blocks.
  424. *
  425. * @param[in] ip pointer to a @p MMCSDBlockDevice or derived class
  426. *
  427. * @return The card capacity.
  428. *
  429. * @api
  430. */
  431. #define mmcsdGetCardCapacity(ip) ((ip)->capacity)
  432. /** @} */
  433. /*===========================================================================*/
  434. /* External declarations. */
  435. /*===========================================================================*/
  436. #ifdef __cplusplus
  437. extern "C" {
  438. #endif
  439. uint32_t _mmcsd_get_slice(const uint32_t *data,
  440. uint32_t end,
  441. uint32_t start);
  442. uint32_t _mmcsd_get_capacity(const uint32_t *csd);
  443. uint32_t _mmcsd_get_capacity_ext(const uint8_t *ext_csd);
  444. void _mmcsd_unpack_sdc_cid(const MMCSDBlockDevice *sdcp,
  445. unpacked_sdc_cid_t *cidsdc);
  446. void _mmcsd_unpack_mmc_cid(const MMCSDBlockDevice *sdcp,
  447. unpacked_mmc_cid_t *cidmmc);
  448. void _mmcsd_unpack_csd_mmc(const MMCSDBlockDevice *sdcp,
  449. unpacked_mmc_csd_t *csdmmc);
  450. void _mmcsd_unpack_csd_v10(const MMCSDBlockDevice *sdcp,
  451. unpacked_sdc_csd_10_t *csd10);
  452. void _mmcsd_unpack_csd_v20(const MMCSDBlockDevice *sdcp,
  453. unpacked_sdc_csd_20_t *csd20);
  454. #ifdef __cplusplus
  455. }
  456. #endif
  457. #endif /* HAL_USE_MMC_SPI == TRUE || HAL_USE_MMC_SDC == TRUE */
  458. #endif /* HAL_MMCSD_H */
  459. /** @} */