MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / mmc_get_ext_csd

Function mmc_get_ext_csd

components/drivers/sdio/dev_mmc.c:119–181  ·  view source on GitHub ↗

* Read extended CSD. */

Source from the content-addressed store, hash-verified

117 * Read extended CSD.
118 */
119static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd)
120{
121 void *ext_csd;
122 struct rt_mmcsd_req req;
123 struct rt_mmcsd_cmd cmd;
124 struct rt_mmcsd_data data;
125
126 *new_ext_csd = RT_NULL;
127 if (GET_BITS(card->resp_csd, 122, 4) < 4)
128 return 0;
129
130 /*
131 * As the ext_csd is so large and mostly unused, we don't store the
132 * raw block in mmc_card.
133 */
134 ext_csd = rt_malloc(512);
135 if (!ext_csd)
136 {
137 LOG_E("alloc memory failed when get ext csd!");
138 return -RT_ENOMEM;
139 }
140
141 rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
142 rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
143 rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
144
145 req.cmd = &cmd;
146 req.data = &data;
147
148 cmd.cmd_code = SEND_EXT_CSD;
149 cmd.arg = 0;
150
151 /* NOTE HACK: the RESP_SPI_R1 is always correct here, but we
152 * rely on callers to never use this with "native" calls for reading
153 * CSD or CID. Native versions of those commands use the R2 type,
154 * not R1 plus a data block.
155 */
156 cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
157
158 data.blksize = 512;
159 data.blks = 1;
160 data.flags = DATA_DIR_READ;
161 data.buf = ext_csd;
162
163 /*
164 * Some cards require longer data read timeout than indicated in CSD.
165 * Address this by setting the read timeout to a "reasonably high"
166 * value. For the cards tested, 300ms has proven enough. If necessary,
167 * this value can be increased if other problematic cards require this.
168 */
169 data.timeout_ns = 300000000;
170 data.timeout_clks = 0;
171
172 mmcsd_send_request(card->host, &req);
173
174 if (cmd.err)
175 return cmd.err;
176 if (data.err)

Callers 2

mmc_compare_ext_csdsFunction · 0.85
mmcsd_mmc_init_cardFunction · 0.85

Calls 4

rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
mmcsd_send_requestFunction · 0.85
GET_BITSFunction · 0.70

Tested by

no test coverage detected