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

Function sdio_host_create

bsp/at32/libraries/rt_drivers/drv_sdio.c:616–679  ·  view source on GitHub ↗

* @brief this function create mmcsd host. * @param sdio_des at32_sdio_des * @retval rt_mmcsd_host */

Source from the content-addressed store, hash-verified

614 * @retval rt_mmcsd_host
615 */
616struct rt_mmcsd_host *sdio_host_create(struct at32_sdio_des *sdio_des)
617{
618 struct rt_mmcsd_host *host;
619 struct rt_hw_sdio *sdio = RT_NULL;
620
621 if ((sdio_des == RT_NULL) || (sdio_des->txconfig == RT_NULL) || (sdio_des->rxconfig == RT_NULL))
622 {
623 LOG_E("L:%d F:%s %s %s %s",
624 (sdio_des == RT_NULL ? "sdio_des is NULL" : ""),
625 (sdio_des ? (sdio_des->txconfig ? "txconfig is NULL" : "") : ""),
626 (sdio_des ? (sdio_des->rxconfig ? "rxconfig is NULL" : "") : "")
627 );
628 return RT_NULL;
629 }
630
631 sdio = rt_malloc(sizeof(struct rt_hw_sdio));
632 if (sdio == RT_NULL)
633 {
634 LOG_E("L:%d F:%s malloc rt_hw_sdio fail");
635 return RT_NULL;
636 }
637 rt_memset(sdio, 0, sizeof(struct rt_hw_sdio));
638
639 host = mmcsd_alloc_host();
640 if (host == RT_NULL)
641 {
642 LOG_E("L:%d F:%s mmcsd alloc host fail");
643 rt_free(sdio);
644 return RT_NULL;
645 }
646
647 rt_memcpy(&sdio->sdio_des, sdio_des, sizeof(struct at32_sdio_des));
648 sdio->sdio_des.hw_sdio = (sdio_des->hw_sdio == RT_NULL ? (struct at32_sdio *)SDIO_BASE_ADDRESS : sdio_des->hw_sdio);
649 sdio->sdio_des.clk_get = (sdio_des->clk_get == RT_NULL ? at32_sdio_clk_get : sdio_des->clk_get);
650
651 rt_event_init(&sdio->event, "sdio", RT_IPC_FLAG_FIFO);
652 rt_mutex_init(&sdio->mutex, "sdio", RT_IPC_FLAG_PRIO);
653
654 /* set host defautl attributes */
655 host->ops = &ops;
656 host->freq_min = 400 * 1000;
657 host->freq_max = SDIO_MAX_FREQ;
658 host->valid_ocr = 0X00FFFF80;/* the voltage range supported is 1.65v-3.6v */
659#ifndef SDIO_USING_1_BIT
660 host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
661#else
662 host->flags = MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
663#endif
664 host->max_seg_size = SDIO_BUFF_SIZE;
665 host->max_dma_segs = 1;
666 host->max_blk_size = 512;
667 host->max_blk_count = 512;
668
669 /* link up host and sdio */
670 sdio->host = host;
671 host->private_data = sdio;
672
673 rt_hw_sdio_irq_update(host, 1);

Callers 1

rt_hw_sdio_initFunction · 0.70

Calls 9

rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
mmcsd_alloc_hostFunction · 0.85
rt_freeFunction · 0.85
rt_memcpyFunction · 0.85
rt_event_initFunction · 0.85
rt_mutex_initFunction · 0.85
mmcsd_changeFunction · 0.85
rt_hw_sdio_irq_updateFunction · 0.70

Tested by

no test coverage detected