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

Function init_sd

components/drivers/sdio/dev_sd.c:816–869  ·  view source on GitHub ↗

* Starting point for SD card init. */

Source from the content-addressed store, hash-verified

814 * Starting point for SD card init.
815 */
816rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr)
817{
818 rt_int32_t err = -RT_EINVAL;
819 rt_uint32_t current_ocr;
820 /*
821 * We need to get OCR a different way for SPI.
822 */
823 if (controller_is_spi(host))
824 {
825 mmcsd_go_idle(host);
826
827 err = mmcsd_spi_read_ocr(host, 0, &ocr);
828 if (err)
829 goto _err;
830 }
831
832 current_ocr = mmcsd_select_voltage(host, ocr);
833
834 /*
835 * Can we support the voltage(s) of the card(s)?
836 */
837 if (!current_ocr)
838 {
839 err = -RT_ERROR;
840 goto _err;
841 }
842
843 /*
844 * Detect and init the card.
845 */
846 err = mmcsd_sd_init_card(host, current_ocr);
847 if (err)
848 goto _err;
849
850 mmcsd_host_unlock(host);
851
852 err = rt_mmcsd_blk_probe(host->card);
853 if (err)
854 goto remove_card;
855 mmcsd_host_lock(host);
856
857 return 0;
858
859remove_card:
860 mmcsd_host_lock(host);
861 rt_mmcsd_blk_remove(host->card);
862 rt_free(host->card);
863 host->card = RT_NULL;
864_err:
865
866 LOG_D("init SD card failed!");
867
868 return err;
869}

Callers 1

mmcsd_detectFunction · 0.85

Calls 9

mmcsd_go_idleFunction · 0.85
mmcsd_spi_read_ocrFunction · 0.85
mmcsd_select_voltageFunction · 0.85
mmcsd_sd_init_cardFunction · 0.85
mmcsd_host_unlockFunction · 0.85
rt_mmcsd_blk_probeFunction · 0.85
mmcsd_host_lockFunction · 0.85
rt_mmcsd_blk_removeFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected