From 02a5cebc6dd19f0f209d75ca2f79aa6384450434 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 20 May 2016 12:20:35 +0800 Subject: [PATCH] [DeviceDrivers] Add MMC/SD change support. Add MMC/SD change support, which patched by FH. --- .../drivers/include/drivers/mmcsd_core.h | 4 +++ components/drivers/sdio/mmcsd_core.c | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/drivers/include/drivers/mmcsd_core.h b/components/drivers/include/drivers/mmcsd_core.h index 1e5560b893..e474fa28a8 100644 --- a/components/drivers/include/drivers/mmcsd_core.h +++ b/components/drivers/include/drivers/mmcsd_core.h @@ -220,6 +220,10 @@ rt_inline rt_uint32_t fls(rt_uint32_t val) return bit; } +#define MMCSD_HOST_PLUGED 0 +#define MMCSD_HOST_UNPLUGED 1 + +int mmcsd_wait_cd_changed(rt_int32_t timeout); void mmcsd_host_lock(struct rt_mmcsd_host *host); void mmcsd_host_unlock(struct rt_mmcsd_host *host); void mmcsd_req_complete(struct rt_mmcsd_host *host); diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index 0cbf8f1892..adda6a4910 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -44,6 +44,8 @@ static struct rt_thread mmcsd_detect_thread; static rt_uint8_t mmcsd_stack[RT_MMCSD_STACK_SIZE]; static struct rt_mailbox mmcsd_detect_mb; static rt_uint32_t mmcsd_detect_mb_pool[4]; +static struct rt_mailbox mmcsd_hotpluge_mb; +static rt_uint32_t mmcsd_hotpluge_mb_pool[4]; void mmcsd_host_lock(struct rt_mmcsd_host *host) { @@ -594,6 +596,24 @@ static void mmcsd_power_off(struct rt_mmcsd_host *host) mmcsd_set_iocfg(host); } +int mmcsd_wait_cd_changed(rt_int32_t timeout) +{ + struct rt_mmcsd_host *host; + if (rt_mb_recv(&mmcsd_hotpluge_mb, (rt_uint32_t*)&host, timeout) == RT_EOK) + { + if(host->card == RT_NULL) + { + return MMCSD_HOST_UNPLUGED; + } + else + { + return MMCSD_HOST_PLUGED; + } + } + return -RT_ETIMEOUT; +} +RTM_EXPORT(mmcsd_wait_cd_changed); + void mmcsd_change(struct rt_mmcsd_host *host) { rt_mb_send(&mmcsd_detect_mb, (rt_uint32_t)host); @@ -647,6 +667,7 @@ void mmcsd_detect(void *param) if (init_mmc(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); continue; } mmcsd_host_unlock(host); @@ -667,6 +688,7 @@ void mmcsd_detect(void *param) host->card = RT_NULL; } mmcsd_host_unlock(host); + rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); } } } @@ -711,11 +733,15 @@ void rt_mmcsd_core_init(void) /* initialize detect SD cart thread */ /* initialize mailbox and create detect SD card thread */ ret = rt_mb_init(&mmcsd_detect_mb, "mmcsdmb", - &mmcsd_detect_mb_pool[0], sizeof(mmcsd_detect_mb_pool), + &mmcsd_detect_mb_pool[0], sizeof(mmcsd_detect_mb_pool) / sizeof(mmcsd_detect_mb_pool[0]), RT_IPC_FLAG_FIFO); RT_ASSERT(ret == RT_EOK); - ret = rt_thread_init(&mmcsd_detect_thread, "mmcsd_detect", mmcsd_detect, RT_NULL, + ret = rt_mb_init(&mmcsd_hotpluge_mb, "mmcsdhotplugmb", + &mmcsd_hotpluge_mb_pool[0], sizeof(mmcsd_hotpluge_mb_pool) / sizeof(mmcsd_hotpluge_mb_pool[0]), + RT_IPC_FLAG_FIFO); + RT_ASSERT(ret == RT_EOK); + ret = rt_thread_init(&mmcsd_detect_thread, "mmcsd_detect", mmcsd_detect, RT_NULL, &mmcsd_stack[0], RT_MMCSD_STACK_SIZE, RT_MMCSD_THREAD_PREORITY, 20); if (ret == RT_EOK) { -- GitLab