[DeviceDrivers] Add MMC/SD change support.

Add MMC/SD change support, which patched by FH.
This commit is contained in:
Bernard Xiong 2016-05-20 12:20:35 +08:00
parent 4d45dc45bd
commit 02a5cebc6d
2 changed files with 32 additions and 2 deletions

View File

@ -220,6 +220,10 @@ rt_inline rt_uint32_t fls(rt_uint32_t val)
return bit; 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_lock(struct rt_mmcsd_host *host);
void mmcsd_host_unlock(struct rt_mmcsd_host *host); void mmcsd_host_unlock(struct rt_mmcsd_host *host);
void mmcsd_req_complete(struct rt_mmcsd_host *host); void mmcsd_req_complete(struct rt_mmcsd_host *host);

View File

@ -44,6 +44,8 @@ static struct rt_thread mmcsd_detect_thread;
static rt_uint8_t mmcsd_stack[RT_MMCSD_STACK_SIZE]; static rt_uint8_t mmcsd_stack[RT_MMCSD_STACK_SIZE];
static struct rt_mailbox mmcsd_detect_mb; static struct rt_mailbox mmcsd_detect_mb;
static rt_uint32_t mmcsd_detect_mb_pool[4]; 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) 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); 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) void mmcsd_change(struct rt_mmcsd_host *host)
{ {
rt_mb_send(&mmcsd_detect_mb, (rt_uint32_t)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)) if (init_mmc(host, ocr))
mmcsd_power_off(host); mmcsd_power_off(host);
mmcsd_host_unlock(host); mmcsd_host_unlock(host);
rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host);
continue; continue;
} }
mmcsd_host_unlock(host); mmcsd_host_unlock(host);
@ -667,6 +688,7 @@ void mmcsd_detect(void *param)
host->card = RT_NULL; host->card = RT_NULL;
} }
mmcsd_host_unlock(host); mmcsd_host_unlock(host);
rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host);
} }
} }
} }
@ -711,10 +733,14 @@ void rt_mmcsd_core_init(void)
/* initialize detect SD cart thread */ /* initialize detect SD cart thread */
/* initialize mailbox and create detect SD card thread */ /* initialize mailbox and create detect SD card thread */
ret = rt_mb_init(&mmcsd_detect_mb, "mmcsdmb", 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_IPC_FLAG_FIFO);
RT_ASSERT(ret == RT_EOK); RT_ASSERT(ret == RT_EOK);
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, 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); &mmcsd_stack[0], RT_MMCSD_STACK_SIZE, RT_MMCSD_THREAD_PREORITY, 20);
if (ret == RT_EOK) if (ret == RT_EOK)