application.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #ifdef RT_USING_DFS
  20. /* dfs init */
  21. #include <dfs_init.h>
  22. /* dfs filesystem:FAT filesystem init */
  23. #include <dfs_fat.h>
  24. /* dfs filesystem:EFS filesystem init */
  25. #include <dfs_efs.h>
  26. /* dfs Filesystem APIs */
  27. #include <dfs_fs.h>
  28. #endif
  29. /* filesystem test */
  30. #include <dfs_posix.h>
  31. static char fullpath[256 + 1];
  32. void ls_root()
  33. {
  34. DIR *dir;
  35. dir = opendir("/");
  36. if (dir != RT_NULL)
  37. {
  38. struct dfs_dirent* dirent;
  39. struct dfs_stat s;
  40. do
  41. {
  42. dirent = readdir(dir);
  43. if (dirent == RT_NULL) break;
  44. rt_memset(&s, 0, sizeof(struct dfs_stat));
  45. /* build full path for each file */
  46. rt_sprintf(fullpath, "/%s", dirent->d_name);
  47. stat(fullpath, &s);
  48. if ( s.st_mode & DFS_S_IFDIR )
  49. {
  50. rt_kprintf("%s\t\t<DIR>\n", dirent->d_name);
  51. }
  52. else
  53. {
  54. rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size);
  55. }
  56. } while (dirent != RT_NULL);
  57. closedir(dir);
  58. }
  59. else rt_kprintf("open root directory failed\n");
  60. }
  61. void rt_init_thread_entry(void* parameter)
  62. {
  63. /* Filesystem Initialization */
  64. #ifdef RT_USING_DFS
  65. {
  66. /* init the device filesystem */
  67. dfs_init();
  68. /* init the efsl filesystam*/
  69. efsl_init();
  70. /* mount sd card fat partition 1 as root directory */
  71. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  72. {
  73. rt_kprintf("File System initialized!\n");
  74. ls_root();
  75. }
  76. else
  77. rt_kprintf("File System init failed!\n");
  78. }
  79. #endif
  80. }
  81. int rt_application_init()
  82. {
  83. rt_thread_t init_thread;
  84. #if (RT_THREAD_PRIORITY_MAX == 32)
  85. init_thread = rt_thread_create("init",
  86. rt_init_thread_entry, RT_NULL,
  87. 2048, 8, 20);
  88. #else
  89. init_thread = rt_thread_create("init",
  90. rt_init_thread_entry, RT_NULL,
  91. 2048, 80, 20);
  92. #endif
  93. if (init_thread != RT_NULL)
  94. rt_thread_startup(init_thread);
  95. return 0;
  96. }
  97. /*@}*/