1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author            Notes
8  * 2023-03-18     luobeihai         first version
9  */
10 
11 #include <rtthread.h>
12 
13 #ifdef BSP_USING_SDCARD
14 
15 #include <dfs_elm.h>
16 #include <dfs_fs.h>
17 #include <dfs_file.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <sys/stat.h>
21 #include <sys/statfs.h>
22 
23 #define DBG_TAG "app.card"
24 #define DBG_LVL DBG_INFO
25 #include <rtdbg.h>
26 
sd_mount(void * parameter)27 void sd_mount(void *parameter)
28 {
29     while (1)
30     {
31         rt_thread_mdelay(500);
32         if(rt_device_find("sd0") != RT_NULL)
33         {
34             if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
35             {
36                 LOG_I("sd card mount to '/'");
37                 break;
38             }
39             else
40             {
41                 LOG_W("sd card mount to '/' failed!");
42             }
43         }
44     }
45 }
46 
apm32_sdcard_mount(void)47 int apm32_sdcard_mount(void)
48 {
49     rt_thread_t tid;
50 
51     tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
52                            2048, RT_THREAD_PRIORITY_MAX - 2, 20);
53     if (tid != RT_NULL)
54     {
55         rt_thread_startup(tid);
56     }
57     else
58     {
59         LOG_E("create sd_mount thread err!");
60     }
61     return RT_EOK;
62 }
63 INIT_APP_EXPORT(apm32_sdcard_mount);
64 
65 #endif /* BSP_USING_SDCARD */
66 
67