components.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * File : components.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012 - 2013, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-09-20 Bernard Change the name to components.c
  23. * And all components related header files.
  24. * 2012-12-23 Bernard fix the pthread initialization issue.
  25. * 2013-06-23 Bernard Add the init_call for components initialization.
  26. * 2013-07-05 Bernard Remove initialization feature for MS VC++ compiler
  27. */
  28. #include "components.h"
  29. static int rti_start(void)
  30. {
  31. return 0;
  32. }
  33. INIT_EXPORT(rti_start, "0");
  34. static int rti_board_end(void)
  35. {
  36. return 0;
  37. }
  38. INIT_EXPORT(rti_board_end, "1.post");
  39. static int rti_end(void)
  40. {
  41. return 0;
  42. }
  43. INIT_EXPORT(rti_end,"7");
  44. /**
  45. * RT-Thread Components Initialization for board
  46. */
  47. void rt_components_board_init(void)
  48. {
  49. #ifndef _MSC_VER
  50. #if RT_DEBUG_INIT
  51. int result;
  52. const struct rt_init_desc *desc;
  53. for (desc = &__rt_init_desc_rti_start; desc < &__rt_init_desc_rti_board_end; desc ++)
  54. {
  55. rt_kprintf("initialize %s", desc->fn_name);
  56. result = desc->fn();
  57. rt_kprintf(":%d done\n", result);
  58. }
  59. #else
  60. const init_fn_t *fn_ptr;
  61. for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++)
  62. {
  63. (*fn_ptr)();
  64. }
  65. #endif
  66. #endif
  67. }
  68. /**
  69. * RT-Thread Components Initialization
  70. */
  71. void rt_components_init(void)
  72. {
  73. #ifndef _MSC_VER
  74. #if RT_DEBUG_INIT
  75. int result;
  76. const struct rt_init_desc *desc;
  77. rt_kprintf("do components intialization.\n");
  78. for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc ++)
  79. {
  80. rt_kprintf("initialize %s", desc->fn_name);
  81. result = desc->fn();
  82. rt_kprintf(":%d done\n", result);
  83. }
  84. #else
  85. const init_fn_t *fn_ptr;
  86. for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; fn_ptr ++)
  87. {
  88. (*fn_ptr)();
  89. }
  90. #endif
  91. #else
  92. #ifdef RT_USING_MODULE
  93. rt_system_module_init();
  94. #endif
  95. #ifdef RT_USING_FINSH
  96. /* initialize finsh */
  97. finsh_system_init();
  98. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  99. #endif
  100. #ifdef RT_USING_LWIP
  101. /* initialize lwip stack */
  102. /* register ethernetif device */
  103. eth_system_device_init();
  104. /* initialize lwip system */
  105. lwip_system_init();
  106. rt_kprintf("TCP/IP initialized!\n");
  107. #endif
  108. #ifdef RT_USING_DFS
  109. /* initialize the device file system */
  110. dfs_init();
  111. #ifdef RT_USING_DFS_ELMFAT
  112. /* initialize the elm chan FatFS file system*/
  113. elm_init();
  114. #endif
  115. #if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP)
  116. /* initialize NFSv3 client file system */
  117. nfs_init();
  118. #endif
  119. #ifdef RT_USING_DFS_YAFFS2
  120. dfs_yaffs2_init();
  121. #endif
  122. #ifdef RT_USING_DFS_UFFS
  123. dfs_uffs_init();
  124. #endif
  125. #ifdef RT_USING_DFS_JFFS2
  126. dfs_jffs2_init();
  127. #endif
  128. #ifdef RT_USING_DFS_ROMFS
  129. dfs_romfs_init();
  130. #endif
  131. #ifdef RT_USING_DFS_RAMFS
  132. dfs_ramfs_init();
  133. #endif
  134. #ifdef RT_USING_DFS_DEVFS
  135. devfs_init();
  136. #endif
  137. #endif /* end of RT_USING_DFS */
  138. #ifdef RT_USING_NEWLIB
  139. libc_system_init(RT_CONSOLE_DEVICE_NAME);
  140. #else
  141. /* the pthread system initialization will be initiallized in libc */
  142. #ifdef RT_USING_PTHREADS
  143. pthread_system_init();
  144. #endif
  145. #endif
  146. #ifdef RT_USING_RTGUI
  147. rtgui_system_server_init();
  148. #endif
  149. #ifdef RT_USING_USB_HOST
  150. rt_usb_host_init();
  151. #endif
  152. #endif
  153. }