mnt.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2020-2021, Bluetrum Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021/01/21 greedyhao The first version
  9. */
  10. #include <rtthread.h>
  11. #if defined (BSP_USING_SDCARD)
  12. #include <dfs_elm.h>
  13. #include <dfs_fs.h>
  14. #include <dfs_file.h>
  15. #include <unistd.h>
  16. #include <stdio.h>
  17. #include <sys/stat.h>
  18. #include <sys/statfs.h>
  19. #include "drv_gpio.h"
  20. // #define DRV_DEBUG
  21. #define DBG_TAG "app.card"
  22. #include <rtdbg.h>
  23. void sd_mount(void *parameter)
  24. {
  25. while (1)
  26. {
  27. rt_thread_mdelay(500);
  28. if (rt_device_find("sd0") != RT_NULL)
  29. {
  30. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  31. {
  32. LOG_I("sd card mount to '/'");
  33. break;
  34. }
  35. else
  36. {
  37. LOG_W("sd card mount to '/' failed!");
  38. }
  39. }
  40. }
  41. }
  42. int ab32_sdcard_mount(void)
  43. {
  44. rt_thread_t tid;
  45. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  46. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  47. if (tid != RT_NULL)
  48. {
  49. rt_thread_startup(tid);
  50. }
  51. else
  52. {
  53. LOG_E("create sd_mount thread err!");
  54. }
  55. return RT_EOK;
  56. }
  57. INIT_APP_EXPORT(ab32_sdcard_mount);
  58. #elif defined (RT_USING_DFS_ROMFS)
  59. #include <dfs_fs.h>
  60. #include "dfs_romfs.h"
  61. int ab32_romfs_mount(void)
  62. {
  63. if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0)
  64. {
  65. rt_kprintf("ROM file system initializated!\n");
  66. }
  67. else
  68. {
  69. rt_kprintf("ROM file system initializate failed!\n");
  70. }
  71. return 0;
  72. }
  73. INIT_ENV_EXPORT(ab32_romfs_mount);
  74. #endif