drv_sdcard.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-13 balanceTWK add sdcard port file
  9. * 2021-05-10 Meco Man fix a bug that cannot use fatfs in the main thread at starting up
  10. */
  11. #include <rtthread.h>
  12. #ifdef BSP_USING_SDCARD
  13. #include <dfs_elm.h>
  14. #include <dfs_fs.h>
  15. #include <dfs_posix.h>
  16. #define DBG_TAG "app.card"
  17. #define DBG_LVL DBG_INFO
  18. #include <rtdbg.h>
  19. static void sd_mount(void *parameter)
  20. {
  21. while (1)
  22. {
  23. rt_thread_mdelay(500);
  24. if(rt_device_find("sd0") != RT_NULL)
  25. {
  26. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  27. {
  28. LOG_I("sd card mount to '/'");
  29. break;
  30. }
  31. else
  32. {
  33. LOG_W("sd card mount to '/' failed!");
  34. }
  35. }
  36. }
  37. }
  38. static int onboard_sdcard_mount(void)
  39. {
  40. rt_thread_t tid;
  41. if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
  42. {
  43. LOG_I("sd card mount to '/'");
  44. }
  45. else
  46. {
  47. tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
  48. 1024, RT_THREAD_PRIORITY_MAX - 2, 20);
  49. if (tid != RT_NULL)
  50. {
  51. rt_thread_startup(tid);
  52. }
  53. else
  54. {
  55. LOG_E("create sd_mount thread err!");
  56. }
  57. }
  58. return RT_EOK;
  59. }
  60. INIT_APP_EXPORT(onboard_sdcard_mount);
  61. #endif /* BSP_USING_SDCARD */