application.c 5.0 KB

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