application.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. * 2011-01-13 weety first version
  23. */
  24. /**
  25. * @addtogroup dm365
  26. */
  27. /*@{*/
  28. #include <rtthread.h>
  29. //#include <rtdevice.h>
  30. #ifdef RT_USING_DFS
  31. /* dfs init */
  32. #include <dfs_init.h>
  33. /* dfs filesystem:ELM FatFs filesystem init */
  34. #include <dfs_elm.h>
  35. /* dfs Filesystem APIs */
  36. #include <dfs_fs.h>
  37. #ifdef RT_USING_DFS_UFFS
  38. /* dfs filesystem:UFFS filesystem init */
  39. #include <dfs_uffs.h>
  40. #endif
  41. #endif
  42. #if defined(RT_USING_DFS_DEVFS)
  43. #include <devfs.h>
  44. #endif
  45. #ifdef RT_USING_SDIO
  46. #include <drivers/mmcsd_core.h>
  47. #endif
  48. #ifdef RT_USING_LWIP
  49. #include <netif/ethernetif.h>
  50. #endif
  51. #ifdef RT_USING_SPI
  52. #include <spi-davinci.h>
  53. #endif
  54. #ifdef RT_USING_LED
  55. #include "led.h"
  56. #endif
  57. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  58. #ifdef RT_USING_DFS_ROMFS
  59. #include <dfs_romfs.h>
  60. #endif
  61. void rt_init_thread_entry(void* parameter)
  62. {
  63. platform_init();
  64. /* Filesystem Initialization */
  65. #ifdef RT_USING_DFS
  66. {
  67. /* init the device filesystem */
  68. dfs_init();
  69. #if defined(RT_USING_DFS_ELMFAT)
  70. /* init the elm chan FatFs filesystam*/
  71. elm_init();
  72. #endif
  73. #if defined(RT_USING_DFS_ROMFS)
  74. dfs_romfs_init();
  75. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  76. {
  77. rt_kprintf("ROM File System initialized!\n");
  78. }
  79. else
  80. rt_kprintf("ROM File System initialzation failed!\n");
  81. #endif
  82. #if defined(RT_USING_DFS_DEVFS)
  83. devfs_init();
  84. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  85. rt_kprintf("Device File System initialized!\n");
  86. else
  87. rt_kprintf("Device File System initialzation failed!\n");
  88. #ifdef RT_USING_NEWLIB
  89. /* init libc */
  90. libc_system_init(RT_CONSOLE_DEVICE_NAME);
  91. #endif
  92. #endif
  93. #if defined(RT_USING_DFS_UFFS)
  94. {
  95. /* init the uffs filesystem */
  96. dfs_uffs_init();
  97. /* mount flash device as flash directory */
  98. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  99. rt_kprintf("UFFS File System initialized!\n");
  100. else
  101. rt_kprintf("UFFS File System initialzation failed!\n");
  102. }
  103. #endif
  104. #ifdef RT_USING_I2C
  105. {
  106. rt_i2c_core_init();
  107. davinci_i2c_init("I2C1");
  108. }
  109. #endif
  110. #ifdef RT_USING_SPI
  111. {
  112. rt_hw_spi_init();
  113. }
  114. #endif
  115. #ifdef RT_USING_SDIO
  116. rt_mmcsd_core_init();
  117. rt_mmcsd_blk_init();
  118. rt_hw_mmcsd_init();
  119. rt_thread_delay(RT_TICK_PER_SECOND*2);
  120. /* mount sd card fat partition 1 as root directory */
  121. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  122. {
  123. rt_kprintf("File System initialized!\n");
  124. }
  125. else
  126. rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
  127. #endif
  128. }
  129. #endif
  130. #ifdef RT_USING_LWIP
  131. {
  132. /* register ethernetif device */
  133. eth_system_device_init();
  134. rt_hw_davinci_emac_init();
  135. /* init lwip system */
  136. lwip_system_init();
  137. }
  138. #endif
  139. }
  140. void rt_led_thread_entry(void* parameter)
  141. {
  142. while(1)
  143. {
  144. /* light on leds for one second */
  145. rt_thread_delay(100);
  146. /* light off leds for one second */
  147. rt_thread_delay(100);
  148. }
  149. }
  150. int rt_application_init()
  151. {
  152. rt_thread_t init_thread;
  153. #ifdef RT_USING_LED
  154. rt_thread_t led_thread;
  155. #endif
  156. #if (RT_THREAD_PRIORITY_MAX == 32)
  157. init_thread = rt_thread_create("init",
  158. rt_init_thread_entry, RT_NULL,
  159. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  160. #ifdef RT_USING_LED
  161. led_thread = rt_thread_create("led",
  162. rt_led_thread_entry, RT_NULL,
  163. 512, 20, 20);
  164. #endif
  165. #else
  166. init_thread = rt_thread_create("init",
  167. rt_init_thread_entry, RT_NULL,
  168. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  169. #ifdef RT_USING_LED
  170. led_thread = rt_thread_create("led",
  171. rt_led_thread_entry, RT_NULL,
  172. 512, 200, 20);
  173. #endif
  174. #endif
  175. if (init_thread != RT_NULL)
  176. rt_thread_startup(init_thread);
  177. #ifdef RT_USING_LED
  178. if(led_thread != RT_NULL)
  179. rt_thread_startup(led_thread);
  180. #endif
  181. return 0;
  182. }
  183. /* NFSv3 Initialization */
  184. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  185. #include <dfs_nfs.h>
  186. void nfs_start(void)
  187. {
  188. nfs_init();
  189. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  190. {
  191. rt_kprintf("NFSv3 File System initialized!\n");
  192. }
  193. else
  194. rt_kprintf("NFSv3 File System initialzation failed!\n");
  195. }
  196. #include "finsh.h"
  197. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  198. #endif
  199. /*@}*/