mnt_diskfs.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <rtthread.h>
  7. #ifdef RT_USING_DFS
  8. #include <dfs_fs.h>
  9. #define DBG_TAG "app.filesystem"
  10. #define DBG_LVL DBG_LOG
  11. #include <rtdbg.h>
  12. static int _wait_device_ready(const char* devname)
  13. {
  14. int k;
  15. for(k = 0; k < 10; k++)
  16. {
  17. if (rt_device_find(devname) != RT_NULL)
  18. {
  19. return 1;
  20. }
  21. rt_thread_mdelay(50);
  22. }
  23. return 0;
  24. }
  25. static void sd_mount(const char *devname)
  26. {
  27. if (!_wait_device_ready(devname)) {
  28. LOG_W("Failed to find device: %s", devname);
  29. return;
  30. }
  31. if (dfs_mount(devname, "/", "ext", 0, 0) == RT_EOK)
  32. {
  33. LOG_I("device '%s' is mounted to '/' as EXT", devname);
  34. }
  35. else if (dfs_mount(devname, "/", "elm", 0, 0) == RT_EOK)
  36. {
  37. LOG_I("device '%s' is mounted to '/' as FAT", devname);
  38. }
  39. else
  40. {
  41. LOG_W("Failed to mount device '%s' to '/': %d\n", devname, rt_get_errno());
  42. }
  43. }
  44. int mount_init(void)
  45. {
  46. #ifdef BSP_USING_SDH
  47. sd_mount("sd1");
  48. #endif
  49. return RT_EOK;
  50. }
  51. INIT_ENV_EXPORT(mount_init);
  52. #endif /* RT_USING_DFS */