application.c 4.9 KB

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