application.c 4.9 KB

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