diff --git a/bsp/imx6ull-artpi-smart/applications/filesystem.c b/bsp/imx6ull-artpi-smart/applications/filesystem.c new file mode 100644 index 0000000000000000000000000000000000000000..7fc7d47739d6fedc3c451ca0c500bacf1446d605 --- /dev/null +++ b/bsp/imx6ull-artpi-smart/applications/filesystem.c @@ -0,0 +1,92 @@ +#include + +#include + +#define DBG_TAG "app.filesystem" +#define DBG_LVL DBG_INFO +#include + +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; +} + diff --git a/bsp/imx6ull-artpi-smart/applications/mnt.c b/bsp/imx6ull-artpi-smart/applications/mnt.c index b85f5b032e689e9d80cc23a03ca02434993eb09d..278ecadfd8c49fc467585d7f9f9b7ffe4e1be6ab 100644 --- a/bsp/imx6ull-artpi-smart/applications/mnt.c +++ b/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; } diff --git a/bsp/imx6ull-artpi-smart/applications/romfs.c b/bsp/imx6ull-artpi-smart/applications/romfs.c new file mode 100644 index 0000000000000000000000000000000000000000..f098a76572cad3c0d6bdb688b5d54515f83c98ec --- /dev/null +++ b/bsp/imx6ull-artpi-smart/applications/romfs.c @@ -0,0 +1,11 @@ +#include + +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])}; + diff --git a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c b/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c index ed0ebe05495bd25ea88e76b6eaf3514cf9b7d5e0..10fe3ed3f77cc799891c7b5fe0e6b07a122755c6 100644 --- a/bsp/imx6ull-artpi-smart/drivers/drv_sdio.c +++ b/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); +} +