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

Function mmcsd_sd_init_card

components/drivers/sdio/dev_sd.c:657–811  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

655}
656
657static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host,
658 rt_uint32_t ocr)
659{
660 struct rt_mmcsd_card *card;
661 rt_int32_t err;
662 rt_uint32_t resp[4];
663 rt_uint32_t max_data_rate;
664
665 mmcsd_go_idle(host);
666
667 /*
668 * If SD_SEND_IF_COND indicates an SD 2.0
669 * compliant card and we should set bit 30
670 * of the ocr to indicate that we can handle
671 * block-addressed SDHC cards.
672 */
673 err = mmcsd_send_if_cond(host, ocr);
674 if (!err)
675 ocr |= 1 << 30;
676
677 /* Switch to UHS voltage if both Host and the Card support this feature */
678 if (((host->valid_ocr & VDD_165_195) != 0) && (host->ops->switch_uhs_voltage != RT_NULL))
679 {
680 ocr |= OCR_S18R;
681 }
682 err = mmcsd_send_app_op_cond(host, ocr, &ocr);
683 if (err)
684 goto err2;
685
686 /* Select voltage */
687 if (ocr & OCR_S18R)
688 {
689 ocr = VDD_165_195;
690 err = sd_switch_voltage(host);
691 if (err)
692 goto err2;
693 err = sd_switch_uhs_voltage(host);
694 if (err)
695 goto err2;
696 }
697
698 if (controller_is_spi(host))
699 err = mmcsd_get_cid(host, resp);
700 else
701 err = mmcsd_all_get_cid(host, resp);
702 if (err)
703 goto err2;
704
705 card = rt_malloc(sizeof(struct rt_mmcsd_card));
706 if (!card)
707 {
708 LOG_E("malloc card failed!");
709 err = -RT_ENOMEM;
710 goto err2;
711 }
712 rt_memset(card, 0, sizeof(struct rt_mmcsd_card));
713
714 card->card_type = CARD_TYPE_SD;

Callers 1

init_sdFunction · 0.85

Calls 15

mmcsd_go_idleFunction · 0.85
mmcsd_send_if_condFunction · 0.85
mmcsd_send_app_op_condFunction · 0.85
sd_switch_voltageFunction · 0.85
sd_switch_uhs_voltageFunction · 0.85
mmcsd_get_cidFunction · 0.85
mmcsd_all_get_cidFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
rt_memcpyFunction · 0.85
mmcsd_get_card_addrFunction · 0.85
mmcsd_set_bus_modeFunction · 0.85

Tested by

no test coverage detected