application.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. * 2011-01-13 weety first version
  13. */
  14. /**
  15. * @addtogroup at91sam9260
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #ifdef RT_USING_DFS
  20. /* dfs init */
  21. #include <dfs_init.h>
  22. /* dfs filesystem:ELM FatFs filesystem init */
  23. #include <dfs_elm.h>
  24. /* dfs Filesystem APIs */
  25. #include <dfs_fs.h>
  26. #ifdef RT_USING_DFS_UFFS
  27. /* dfs filesystem:UFFS filesystem init */
  28. #include <dfs_uffs.h>
  29. #endif
  30. #endif
  31. #if defined(RT_USING_DFS_DEVFS)
  32. #include <devfs.h>
  33. #endif
  34. #ifdef RT_USING_LWIP
  35. #include <netif/ethernetif.h>
  36. #include <arch/sys_arch_init.h>
  37. #include "macb.h"
  38. #endif
  39. #ifdef RT_USING_LED
  40. #include "led.h"
  41. #endif
  42. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  43. #ifdef RT_USING_DFS_ROMFS
  44. #include <dfs_romfs.h>
  45. #endif
  46. void rt_init_thread_entry(void* parameter)
  47. {
  48. /* Filesystem Initialization */
  49. #ifdef RT_USING_DFS
  50. {
  51. /* init the device filesystem */
  52. dfs_init();
  53. #if defined(RT_USING_DFS_ELMFAT)
  54. /* init the elm chan FatFs filesystam*/
  55. elm_init();
  56. #endif
  57. #if defined(RT_USING_DFS_ROMFS)
  58. dfs_romfs_init();
  59. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  60. {
  61. rt_kprintf("ROM File System initialized!\n");
  62. }
  63. else
  64. rt_kprintf("ROM File System initialzation failed!\n");
  65. #endif
  66. #if defined(RT_USING_DFS_DEVFS)
  67. devfs_init();
  68. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  69. rt_kprintf("Device File System initialized!\n");
  70. else
  71. rt_kprintf("Device File System initialzation failed!\n");
  72. #ifdef RT_USING_NEWLIB
  73. /* init libc */
  74. libc_system_init("uart0");
  75. #endif
  76. #endif
  77. #if defined(RT_USING_DFS_UFFS)
  78. {
  79. /* init the uffs filesystem */
  80. dfs_uffs_init();
  81. /* mount flash device as flash directory */
  82. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  83. rt_kprintf("UFFS File System initialized!\n");
  84. else
  85. rt_kprintf("UFFS File System initialzation failed!\n");
  86. }
  87. #endif
  88. }
  89. #endif
  90. #ifdef RT_USING_LWIP
  91. {
  92. /* register ethernetif device */
  93. eth_system_device_init();
  94. rt_hw_macb_init();
  95. /* init lwip system */
  96. lwip_sys_init();
  97. rt_kprintf("TCP/IP initialized!\n");
  98. }
  99. #endif
  100. }
  101. #ifdef RT_USING_LED
  102. void rt_led_thread_entry(void* parameter)
  103. {
  104. rt_uint8_t cnt = 0;
  105. led_init();
  106. while(1)
  107. {
  108. /* light on leds for one second */
  109. rt_thread_delay(40);
  110. cnt++;
  111. if (cnt&0x01)
  112. led_on(1);
  113. else
  114. led_off(1);
  115. if (cnt&0x02)
  116. led_on(2);
  117. else
  118. led_off(2);
  119. if (cnt&0x04)
  120. led_on(3);
  121. else
  122. led_off(3);
  123. }
  124. }
  125. #endif
  126. int rt_application_init()
  127. {
  128. rt_thread_t init_thread;
  129. #ifdef RT_USING_LED
  130. rt_thread_t led_thread;
  131. #endif
  132. #if (RT_THREAD_PRIORITY_MAX == 32)
  133. init_thread = rt_thread_create("init",
  134. rt_init_thread_entry, RT_NULL,
  135. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  136. #ifdef RT_USING_LED
  137. led_thread = rt_thread_create("led",
  138. rt_led_thread_entry, RT_NULL,
  139. 512, 20, 20);
  140. #endif
  141. #else
  142. init_thread = rt_thread_create("init",
  143. rt_init_thread_entry, RT_NULL,
  144. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  145. #ifdef RT_USING_LED
  146. led_thread = rt_thread_create("led",
  147. rt_led_thread_entry, RT_NULL,
  148. 512, 200, 20);
  149. #endif
  150. #endif
  151. if (init_thread != RT_NULL)
  152. rt_thread_startup(init_thread);
  153. #ifdef RT_USING_LED
  154. if(led_thread != RT_NULL)
  155. rt_thread_startup(led_thread);
  156. #endif
  157. return 0;
  158. }
  159. /* NFSv3 Initialization */
  160. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  161. #include <dfs_nfs.h>
  162. void nfs_start(void)
  163. {
  164. nfs_init();
  165. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  166. {
  167. rt_kprintf("NFSv3 File System initialized!\n");
  168. }
  169. else
  170. rt_kprintf("NFSv3 File System initialzation failed!\n");
  171. }
  172. #include "finsh.h"
  173. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  174. #endif
  175. /*@}*/