@lin12345678 4 лет назад
Родитель
Сommit
1049437683

+ 92 - 0
bsp/imx6ull-artpi-smart/applications/filesystem.c

@@ -0,0 +1,92 @@
+#include <rtthread.h>
+
+#include <dfs_fs.h>
+
+#define DBG_TAG "app.filesystem"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+static void _sdcard_mount(void)
+{
+    rt_device_t device;
+
+    device = rt_device_find("sd0");
+    if (device == NULL)
+    {
+        mmcsd_wait_cd_changed(0);
+        host_change();
+        mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
+        rt_thread_mdelay(10);
+        device = rt_device_find("sd0");
+    }
+    if (device != RT_NULL)
+    {
+        if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK)
+        {
+            LOG_I("sd card mount to '/mnt'");
+        }
+        else
+        {
+            LOG_W("sd card mount to '/mnt' failed!");
+        }
+    }
+}
+
+static void _sdcard_unmount(void)
+{
+    rt_thread_mdelay(200);
+    dfs_unmount("/mnt");
+    LOG_I("Unmount \"/mnt\"");
+
+    mmcsd_wait_cd_changed(0);
+    host_change();
+    mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
+}
+
+static void sd_mount(void *parameter)
+{
+    volatile unsigned int *IN_STATUS;
+	IN_STATUS = (volatile unsigned int *)rt_ioremap((void *)0x2190030, 4);
+    rt_thread_mdelay(20);
+	if (dfs_mount("sd0", "/mnt", "elm", 0, 0) == RT_EOK)
+	{
+		LOG_I("sd card mount to '/mnt'");
+	}
+	else
+	{
+		LOG_W("sd card mount to '/mnt' failed!");
+	}
+    while (1)
+    {
+        rt_thread_mdelay(200);
+        if (((*IN_STATUS >>6) & 0x1) == 1)
+        {
+        	*IN_STATUS = 0x40;
+            _sdcard_mount();
+        }
+
+        if (((*IN_STATUS >>7) & 0x1) == 1)
+        {
+        	*IN_STATUS = (0x80);
+            _sdcard_unmount();
+        }
+    }
+}
+
+int sd_task(void)
+{
+
+    rt_thread_t tid;
+    tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
+                           2048, RT_THREAD_PRIORITY_MAX - 2, 20);
+    if (tid != RT_NULL)
+    {
+        rt_thread_startup(tid);
+    }
+    else
+    {
+        LOG_E("create sd_mount thread err!");
+    }
+    return RT_EOK;
+}
+

+ 3 - 7
bsp/imx6ull-artpi-smart/applications/mnt.c

@@ -17,17 +17,13 @@
 int mnt_init(void)
 {
     rt_thread_mdelay(500);
-    if (dfs_mount("sd0", "/", "elm", 0, NULL) != 0)
+    if (dfs_mount(NULL, "/", "rom", 0, &romfs_root) != 0)
     {
         rt_kprintf("Dir / mount failed!\n");
         return -1;
     }
-    else
-    {
-        mkdir("/romfs", 777);
-        mkdir("/flash", 777);
-        mkdir("/download", 777);
-    }
+
+	sd_task();
     rt_kprintf("file system initialization done!\n");
     return 0;
 }

+ 11 - 0
bsp/imx6ull-artpi-smart/applications/romfs.c

@@ -0,0 +1,11 @@
+#include <dfs_romfs.h>
+
+static const struct romfs_dirent _romfs_root[] = {
+    {ROMFS_DIRENT_DIR, "etc", RT_NULL, 0},
+    {ROMFS_DIRENT_DIR, "mnt", RT_NULL, 0},
+    {ROMFS_DIRENT_DIR, "bin", RT_NULL, 0}
+};
+
+const struct romfs_dirent romfs_root = {
+    ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0])};
+

+ 5 - 0
bsp/imx6ull-artpi-smart/drivers/drv_sdio.c

@@ -695,4 +695,9 @@ err:
 }
 
 INIT_DEVICE_EXPORT(imxrt_mci_init);
+void host_change(void)
+{
+	mmcsd_change(host1);
+}
+