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

Function sdio_host_create

bsp/ht32/libraries/ht32_drivers/drv_sdio.c:542–606  ·  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

540 * @retval rt_mmcsd_host
541 */
542struct rt_mmcsd_host *sdio_host_create(struct ht32_sdio_des *sdio_des)
543{
544 struct rt_mmcsd_host *host;
545 struct rt_hw_sdio *sdio = RT_NULL;
546 /* effective parameter */
547 if ((sdio_des == RT_NULL) || (sdio_des->txconfig == RT_NULL) || (sdio_des->rxconfig == RT_NULL))
548 {
549 LOG_E("L:%d F:%s %s %s %s",
550 (sdio_des == RT_NULL ? "sdio_des is NULL" : ""),
551 (sdio_des ? (sdio_des->txconfig ? "txconfig is NULL" : "") : ""),
552 (sdio_des ? (sdio_des->rxconfig ? "rxconfig is NULL" : "") : "")
553 );
554 return RT_NULL;
555 }
556
557 sdio = rt_malloc(sizeof(struct rt_hw_sdio));
558 if (sdio == RT_NULL)
559 {
560 LOG_E("L:%d F:%s malloc rt_hw_sdio fail");
561 return RT_NULL;
562 }
563 rt_memset(sdio, 0, sizeof(struct rt_hw_sdio));
564
565 host = mmcsd_alloc_host();
566 if (host == RT_NULL)
567 {
568 LOG_E("L:%d F:%s mmcsd alloc host fail");
569 rt_free(sdio);
570 return RT_NULL;
571 }
572
573 rt_memcpy(&sdio->sdio_des, sdio_des, sizeof(struct ht32_sdio_des));
574 sdio->sdio_des.hw_sdio = (sdio_des->hw_sdio == RT_NULL ? (HT_SDIO_TypeDef *)SDIO_BASE_ADDRESS : sdio_des->hw_sdio);
575 sdio->sdio_des.clk_get = (sdio_des->clk_get == RT_NULL ? ht32_sdio_clk_get : sdio_des->clk_get);
576 /* Initialising events and mutexes */
577 rt_event_init(&sdio->dat_event, "sdio", RT_IPC_FLAG_FIFO);
578 rt_event_init(&sdio->cmd_event, "sdio_cmd", RT_IPC_FLAG_FIFO);
579 rt_mutex_init(&sdio->mutex, "sdio", RT_IPC_FLAG_PRIO);
580
581 /* set host defautl attributes */
582 host->ops = &ops;
583 host->freq_min = 400 * 1000;
584 host->freq_max = SDIO_MAX_FREQ;
585 host->valid_ocr = 0X00FFFF80;
586#ifndef SDIO_USING_1_BIT
587 host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
588#else
589 host->flags = MMCSD_MUTBLKWRITE | MMCSD_SUP_SDIO_IRQ;
590#endif
591 host->max_seg_size = SDIO_BUFF_SIZE;
592 host->max_dma_segs = 1;
593 host->max_blk_size = 512;
594 host->max_blk_count = 512;
595
596 /* link up host and sdio */
597 sdio->host = host;
598 host->private_data = sdio;
599

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