application.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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:EFS filesystem init */
  23. #include <dfs_efs.h>
  24. /* dfs Filesystem APIs */
  25. #include <dfs_fs.h>
  26. #endif
  27. /* filesystem test */
  28. #include <dfs_posix.h>
  29. static char fullpath[256 + 1];
  30. void ls_root()
  31. {
  32. DIR *dir;
  33. dir = opendir("/");
  34. if (dir != RT_NULL)
  35. {
  36. struct dfs_dirent* dirent;
  37. struct dfs_stat s;
  38. do
  39. {
  40. dirent = readdir(dir);
  41. if (dirent == RT_NULL) break;
  42. rt_memset(&s, 0, sizeof(struct dfs_stat));
  43. /* build full path for each file */
  44. rt_sprintf(fullpath, "/%s", dirent->d_name);
  45. stat(fullpath, &s);
  46. if ( s.st_mode & DFS_S_IFDIR )
  47. {
  48. rt_kprintf("%s\t\t<DIR>\n", dirent->d_name);
  49. }
  50. else
  51. {
  52. rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size);
  53. }
  54. } while (dirent != RT_NULL);
  55. closedir(dir);
  56. }
  57. else rt_kprintf("open root directory failed\n");
  58. }
  59. void rt_init_thread_entry(void* parameter)
  60. {
  61. /* Filesystem Initialization */
  62. #ifdef RT_USING_DFS
  63. {
  64. /* init the device filesystem */
  65. dfs_init();
  66. /* init the efsl filesystam*/
  67. efsl_init();
  68. /* mount sd card fat partition 1 as root directory */
  69. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  70. {
  71. rt_kprintf("File System initialized!\n");
  72. ls_root();
  73. }
  74. else
  75. rt_kprintf("File System init failed!\n");
  76. }
  77. #endif
  78. }
  79. int rt_application_init()
  80. {
  81. rt_thread_t init_thread;
  82. #if (RT_THREAD_PRIORITY_MAX == 32)
  83. init_thread = rt_thread_create("init",
  84. rt_init_thread_entry, RT_NULL,
  85. 2048, 8, 20);
  86. #else
  87. init_thread = rt_thread_create("init",
  88. rt_init_thread_entry, RT_NULL,
  89. 2048, 80, 20);
  90. #endif
  91. if (init_thread != RT_NULL)
  92. rt_thread_startup(init_thread);
  93. return 0;
  94. }
  95. /*@}*/