application.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_SDIO
  35. #include <mmcsd_core.h>
  36. #include "at91_mci.h"
  37. #endif
  38. #ifdef RT_USING_LWIP
  39. #include <netif/ethernetif.h>
  40. #include <arch/sys_arch_init.h>
  41. #include "macb.h"
  42. #endif
  43. #ifdef RT_USING_LED
  44. #include "led.h"
  45. #endif
  46. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  47. #ifdef RT_USING_DFS_ROMFS
  48. #include <dfs_romfs.h>
  49. #endif
  50. void rt_init_thread_entry(void* parameter)
  51. {
  52. /* Filesystem Initialization */
  53. #ifdef RT_USING_DFS
  54. {
  55. /* init the device filesystem */
  56. dfs_init();
  57. #if defined(RT_USING_DFS_ELMFAT)
  58. /* init the elm chan FatFs filesystam*/
  59. elm_init();
  60. #endif
  61. #if defined(RT_USING_DFS_ROMFS)
  62. dfs_romfs_init();
  63. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  64. {
  65. rt_kprintf("ROM File System initialized!\n");
  66. }
  67. else
  68. rt_kprintf("ROM File System initialzation failed!\n");
  69. #endif
  70. #if defined(RT_USING_DFS_DEVFS)
  71. devfs_init();
  72. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  73. rt_kprintf("Device File System initialized!\n");
  74. else
  75. rt_kprintf("Device File System initialzation failed!\n");
  76. #ifdef RT_USING_NEWLIB
  77. /* init libc */
  78. libc_system_init("uart0");
  79. #endif
  80. #endif
  81. #if defined(RT_USING_DFS_UFFS)
  82. {
  83. /* init the uffs filesystem */
  84. dfs_uffs_init();
  85. /* mount flash device as flash directory */
  86. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  87. rt_kprintf("UFFS File System initialized!\n");
  88. else
  89. rt_kprintf("UFFS File System initialzation failed!\n");
  90. }
  91. #endif
  92. #ifdef RT_USING_SDIO
  93. rt_mmcsd_core_init();
  94. rt_mmcsd_blk_init();
  95. at91_mci_init();
  96. rt_thread_delay(RT_TICK_PER_SECOND*2);
  97. /* mount sd card fat partition 1 as root directory */
  98. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  99. {
  100. rt_kprintf("File System initialized!\n");
  101. }
  102. else
  103. rt_kprintf("File System initialzation failed!\n");
  104. #endif
  105. }
  106. #endif
  107. #ifdef RT_USING_LWIP
  108. {
  109. /* register ethernetif device */
  110. eth_system_device_init();
  111. rt_hw_macb_init();
  112. /* re-init device driver */
  113. //rt_device_init_all();
  114. /* init lwip system */
  115. lwip_sys_init();
  116. rt_kprintf("TCP/IP initialized!\n");
  117. }
  118. #endif
  119. }
  120. #ifdef RT_USING_LED
  121. void rt_led_thread_entry(void* parameter)
  122. {
  123. rt_uint8_t cnt = 0;
  124. led_init();
  125. while(1)
  126. {
  127. /* light on leds for one second */
  128. rt_thread_delay(40);
  129. cnt++;
  130. if (cnt&0x01)
  131. led_on(1);
  132. else
  133. led_off(1);
  134. if (cnt&0x02)
  135. led_on(2);
  136. else
  137. led_off(2);
  138. if (cnt&0x04)
  139. led_on(3);
  140. else
  141. led_off(3);
  142. }
  143. }
  144. #endif
  145. int rt_application_init()
  146. {
  147. rt_thread_t init_thread;
  148. #ifdef RT_USING_LED
  149. rt_thread_t led_thread;
  150. #endif
  151. #if (RT_THREAD_PRIORITY_MAX == 32)
  152. init_thread = rt_thread_create("init",
  153. rt_init_thread_entry, RT_NULL,
  154. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  155. #ifdef RT_USING_LED
  156. led_thread = rt_thread_create("led",
  157. rt_led_thread_entry, RT_NULL,
  158. 512, 20, 20);
  159. #endif
  160. #else
  161. init_thread = rt_thread_create("init",
  162. rt_init_thread_entry, RT_NULL,
  163. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  164. #ifdef RT_USING_LED
  165. led_thread = rt_thread_create("led",
  166. rt_led_thread_entry, RT_NULL,
  167. 512, 200, 20);
  168. #endif
  169. #endif
  170. if (init_thread != RT_NULL)
  171. rt_thread_startup(init_thread);
  172. #ifdef RT_USING_LED
  173. if(led_thread != RT_NULL)
  174. rt_thread_startup(led_thread);
  175. #endif
  176. return 0;
  177. }
  178. /* NFSv3 Initialization */
  179. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  180. #include <dfs_nfs.h>
  181. void nfs_start(void)
  182. {
  183. nfs_init();
  184. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  185. {
  186. rt_kprintf("NFSv3 File System initialized!\n");
  187. }
  188. else
  189. rt_kprintf("NFSv3 File System initialzation failed!\n");
  190. }
  191. #include "finsh.h"
  192. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  193. #endif
  194. /*@}*/