application.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. }
  117. #endif
  118. }
  119. #ifdef RT_USING_LED
  120. void rt_led_thread_entry(void* parameter)
  121. {
  122. rt_uint8_t cnt = 0;
  123. led_init();
  124. while(1)
  125. {
  126. /* light on leds for one second */
  127. rt_thread_delay(40);
  128. cnt++;
  129. if (cnt&0x01)
  130. led_on(1);
  131. else
  132. led_off(1);
  133. if (cnt&0x02)
  134. led_on(2);
  135. else
  136. led_off(2);
  137. if (cnt&0x04)
  138. led_on(3);
  139. else
  140. led_off(3);
  141. }
  142. }
  143. #endif
  144. int rt_application_init()
  145. {
  146. rt_thread_t init_thread;
  147. #ifdef RT_USING_LED
  148. rt_thread_t led_thread;
  149. #endif
  150. #if (RT_THREAD_PRIORITY_MAX == 32)
  151. init_thread = rt_thread_create("init",
  152. rt_init_thread_entry, RT_NULL,
  153. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  154. #ifdef RT_USING_LED
  155. led_thread = rt_thread_create("led",
  156. rt_led_thread_entry, RT_NULL,
  157. 512, 20, 20);
  158. #endif
  159. #else
  160. init_thread = rt_thread_create("init",
  161. rt_init_thread_entry, RT_NULL,
  162. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  163. #ifdef RT_USING_LED
  164. led_thread = rt_thread_create("led",
  165. rt_led_thread_entry, RT_NULL,
  166. 512, 200, 20);
  167. #endif
  168. #endif
  169. if (init_thread != RT_NULL)
  170. rt_thread_startup(init_thread);
  171. #ifdef RT_USING_LED
  172. if(led_thread != RT_NULL)
  173. rt_thread_startup(led_thread);
  174. #endif
  175. return 0;
  176. }
  177. /* NFSv3 Initialization */
  178. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  179. #include <dfs_nfs.h>
  180. void nfs_start(void)
  181. {
  182. nfs_init();
  183. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  184. {
  185. rt_kprintf("NFSv3 File System initialized!\n");
  186. }
  187. else
  188. rt_kprintf("NFSv3 File System initialzation failed!\n");
  189. }
  190. #include "finsh.h"
  191. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  192. #endif
  193. /*@}*/