application.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. * 2007-11-20 Yi.Qiu add rtgui application
  13. * 2008-6-28 Bernard no rtgui init
  14. */
  15. /**
  16. * @addtogroup mini2440
  17. */
  18. /*@{*/
  19. #include <rtthread.h>
  20. #include "touch.h"
  21. #include "lcd.h"
  22. #include "led.h"
  23. #include "dm9000.h"
  24. #ifdef RT_USING_DFS
  25. /* dfs init */
  26. #include <dfs_init.h>
  27. /* dfs filesystem:ELM FatFs filesystem init */
  28. #include <dfs_elm.h>
  29. /* dfs Filesystem APIs */
  30. #include <dfs_fs.h>
  31. #ifdef RT_USING_DFS_UFFS
  32. /* dfs filesystem:UFFS filesystem init */
  33. #include <dfs_uffs.h>
  34. #endif
  35. #endif
  36. #ifdef RT_USING_LWIP
  37. #include <netif/ethernetif.h>
  38. #endif
  39. #ifdef RT_USING_RTGUI
  40. #include <rtgui/rtgui.h>
  41. extern void rt_hw_touch_init(void);
  42. #endif
  43. #ifdef RT_USING_FTK
  44. #include "ftk.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. #ifdef RT_USING_FTK
  51. static int argc = 1;
  52. static char* argv[] = {"ftk", NULL};
  53. void rt_ftk_thread_entry(void* parameter)
  54. {
  55. int FTK_MAIN(int argc, char* argv[]);
  56. FTK_MAIN(argc, argv);
  57. return;
  58. }
  59. #endif
  60. void rt_init_thread_entry(void* parameter)
  61. {
  62. /* Filesystem Initialization */
  63. #ifdef RT_USING_DFS
  64. {
  65. /* init the device filesystem */
  66. dfs_init();
  67. #if defined(RT_USING_DFS_ELMFAT)
  68. /* init the elm chan FatFs filesystam*/
  69. elm_init();
  70. /* mount sd card fat partition 1 as root directory */
  71. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  72. {
  73. rt_kprintf("File System initialized!\n");
  74. }
  75. else
  76. rt_kprintf("File System initialzation failed!\n");
  77. #endif
  78. #if defined(RT_USING_DFS_ROMFS)
  79. dfs_romfs_init();
  80. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  81. {
  82. rt_kprintf("ROM File System initialized!\n");
  83. }
  84. else
  85. rt_kprintf("ROM File System initialzation failed!\n");
  86. #endif
  87. #if defined(RT_USING_DFS_DEVFS)
  88. devfs_init();
  89. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  90. rt_kprintf("Device File System initialized!\n");
  91. else
  92. rt_kprintf("Device File System initialzation failed!\n");
  93. #ifdef RT_USING_NEWLIB
  94. /* init libc */
  95. libc_system_init("uart0");
  96. #endif
  97. #endif
  98. #if defined(RT_USING_DFS_UFFS)
  99. {
  100. /* init the uffs filesystem */
  101. dfs_uffs_init();
  102. /* mount flash device as flash directory */
  103. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  104. rt_kprintf("UFFS File System initialized!\n");
  105. else
  106. rt_kprintf("UFFS File System initialzation failed!\n");
  107. }
  108. #endif
  109. }
  110. #endif
  111. #ifdef RT_USING_RTGUI
  112. {
  113. /* init lcd */
  114. rt_hw_lcd_init();
  115. /* init touch panel */
  116. rtgui_touch_hw_init();
  117. /* init keypad */
  118. rt_hw_key_init();
  119. /* re-init device driver */
  120. rt_device_init_all();
  121. /* startup rtgui */
  122. rtgui_startup();
  123. }
  124. #endif
  125. /* LwIP Initialization */
  126. #ifdef RT_USING_LWIP
  127. {
  128. extern void lwip_sys_init(void);
  129. eth_system_device_init();
  130. /* register ethernetif device */
  131. rt_hw_dm9000_init();
  132. /* re-init device driver */
  133. rt_device_init_all();
  134. /* init lwip system */
  135. lwip_sys_init();
  136. rt_kprintf("TCP/IP initialized!\n");
  137. }
  138. #endif
  139. #ifdef RT_USING_FTK
  140. {
  141. rt_thread_t ftk_thread;
  142. /* init lcd */
  143. rt_hw_lcd_init();
  144. /* init touch panel */
  145. rtgui_touch_hw_init();
  146. /* init keypad */
  147. rt_hw_key_init();
  148. /* re-init device driver */
  149. rt_device_init_all();
  150. /* create ftk thread */
  151. ftk_thread = rt_thread_create("ftk",
  152. rt_ftk_thread_entry, RT_NULL,
  153. 10 * 1024, 8, 20);
  154. /* startup ftk thread */
  155. if(ftk_thread != RT_NULL)
  156. rt_thread_startup(ftk_thread);
  157. }
  158. #endif
  159. }
  160. void rt_led_thread_entry(void* parameter)
  161. {
  162. while(1)
  163. {
  164. /* light on leds for one second */
  165. rt_hw_led_on(LED2|LED3);
  166. rt_hw_led_off(LED1|LED4);
  167. rt_thread_delay(100);
  168. /* light off leds for one second */
  169. rt_hw_led_off(LED2|LED3);
  170. rt_hw_led_on(LED1|LED4);
  171. rt_thread_delay(100);
  172. }
  173. }
  174. int rt_application_init()
  175. {
  176. rt_thread_t init_thread;
  177. rt_thread_t led_thread;
  178. #if (RT_THREAD_PRIORITY_MAX == 32)
  179. init_thread = rt_thread_create("init",
  180. rt_init_thread_entry, RT_NULL,
  181. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  182. led_thread = rt_thread_create("led",
  183. rt_led_thread_entry, RT_NULL,
  184. 512, 20, 20);
  185. #else
  186. init_thread = rt_thread_create("init",
  187. rt_init_thread_entry, RT_NULL,
  188. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  189. led_thread = rt_thread_create("led",
  190. rt_led_thread_entry, RT_NULL,
  191. 512, 200, 20);
  192. #endif
  193. if (init_thread != RT_NULL)
  194. rt_thread_startup(init_thread);
  195. if(led_thread != RT_NULL)
  196. rt_thread_startup(led_thread);
  197. return 0;
  198. }
  199. /* NFSv3 Initialization */
  200. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  201. #include <dfs_nfs.h>
  202. void nfs_start(void)
  203. {
  204. nfs_init();
  205. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  206. {
  207. rt_kprintf("NFSv3 File System initialized!\n");
  208. }
  209. else
  210. rt_kprintf("NFSv3 File System initialzation failed!\n");
  211. }
  212. #include "finsh.h"
  213. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  214. #endif
  215. /*@}*/