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