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

Function mmcsd_send_app_op_cond

components/drivers/sdio/dev_sd.c:432–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host,
433 rt_uint32_t ocr,
434 rt_uint32_t *rocr)
435{
436 struct rt_mmcsd_cmd cmd;
437 rt_uint32_t i;
438 rt_err_t err = RT_EOK;
439
440 rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
441
442 cmd.cmd_code = SD_APP_OP_COND;
443 if (controller_is_spi(host))
444 cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
445 else
446 cmd.arg = ocr;
447 cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR;
448
449 for (i = 1000; i; i--)
450 {
451 err = mmcsd_send_app_cmd(host, RT_NULL, &cmd, 3);
452 if (err)
453 break;
454
455 /* if we're just probing, do a single pass */
456 if (ocr == 0)
457 break;
458
459 /* otherwise wait until reset completes */
460 if (controller_is_spi(host))
461 {
462 if (!(cmd.resp[0] & R1_SPI_IDLE))
463 break;
464 }
465 else
466 {
467 if (cmd.resp[0] & CARD_BUSY)
468 break;
469 }
470
471 err = -RT_ETIMEOUT;
472
473 rt_thread_mdelay(10); //delay 10ms
474 }
475
476 if (rocr && !controller_is_spi(host))
477 *rocr = cmd.resp[0];
478
479 return err;
480}
481
482/*
483 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND

Callers 2

mmcsd_sd_init_cardFunction · 0.85
mmcsd_detectFunction · 0.85

Calls 3

rt_memsetFunction · 0.85
mmcsd_send_app_cmdFunction · 0.85
rt_thread_mdelayFunction · 0.85

Tested by

no test coverage detected