application.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #endif
  42. #ifdef RT_USING_FTK
  43. #include "ftk.h"
  44. #endif
  45. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  46. #ifdef RT_USING_DFS_ROMFS
  47. #include <dfs_romfs.h>
  48. #endif
  49. #ifdef RT_USING_FTK
  50. static int argc = 1;
  51. static char* argv[] = {"ftk", NULL};
  52. void rt_ftk_thread_entry(void *parameter)
  53. {
  54. int FTK_MAIN(int argc, char *argv[]);
  55. FTK_MAIN(argc, argv);
  56. return;
  57. }
  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. /* mount sd card fat partition 1 as root directory */
  70. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  71. {
  72. rt_kprintf("File System initialized!\n");
  73. }
  74. else
  75. rt_kprintf("File System initialzation failed!\n");
  76. #endif
  77. #if defined(RT_USING_DFS_ROMFS)
  78. dfs_romfs_init();
  79. if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
  80. {
  81. rt_kprintf("ROM File System initialized!\n");
  82. }
  83. else
  84. rt_kprintf("ROM File System initialzation failed!\n");
  85. #endif
  86. #if defined(RT_USING_DFS_DEVFS)
  87. devfs_init();
  88. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  89. rt_kprintf("Device File System initialized!\n");
  90. else
  91. rt_kprintf("Device File System initialzation failed!\n");
  92. #ifdef RT_USING_NEWLIB
  93. /* init libc */
  94. libc_system_init("uart0");
  95. #endif
  96. #endif
  97. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  98. /* NFSv3 Initialization */
  99. nfs_init();
  100. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  101. rt_kprintf("NFSv3 File System initialized!\n");
  102. else
  103. rt_kprintf("NFSv3 File System initialzation failed!\n");
  104. #endif
  105. #if defined(RT_USING_DFS_UFFS)
  106. /* init the uffs filesystem */
  107. dfs_uffs_init();
  108. /* mount flash device as flash directory */
  109. if (dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  110. rt_kprintf("UFFS File System initialized!\n");
  111. else
  112. rt_kprintf("UFFS File System initialzation failed!\n");
  113. #endif
  114. }
  115. #endif
  116. #ifdef RT_USING_RTGUI
  117. {
  118. rt_device_t lcd;
  119. /* init lcd */
  120. rt_hw_lcd_init();
  121. /* init touch panel */
  122. rtgui_touch_hw_init();
  123. /* init keypad */
  124. rt_hw_key_init();
  125. /* re-init device driver */
  126. rt_device_init_all();
  127. /* find lcd device */
  128. lcd = rt_device_find("lcd");
  129. /* set lcd device as rtgui graphic driver */
  130. rtgui_graphic_set_device(lcd);
  131. /* initalize rtgui system server */
  132. rtgui_system_server_init();
  133. }
  134. #endif
  135. /* LwIP Initialization */
  136. #ifdef RT_USING_LWIP
  137. {
  138. extern void lwip_sys_init(void);
  139. eth_system_device_init();
  140. /* register ethernetif device */
  141. rt_hw_dm9000_init();
  142. /* re-init device driver */
  143. rt_device_init_all();
  144. /* init lwip system */
  145. lwip_sys_init();
  146. rt_kprintf("TCP/IP initialized!\n");
  147. }
  148. #endif
  149. #ifdef RT_USING_FTK
  150. {
  151. rt_thread_t ftk_thread;
  152. /* init lcd */
  153. rt_hw_lcd_init();
  154. /* init touch panel */
  155. rtgui_touch_hw_init();
  156. /* init keypad */
  157. rt_hw_key_init();
  158. /* re-init device driver */
  159. rt_device_init_all();
  160. /* create ftk thread */
  161. ftk_thread = rt_thread_create("ftk",
  162. rt_ftk_thread_entry, RT_NULL,
  163. 10 * 1024, 8, 20);
  164. /* startup ftk thread */
  165. if (ftk_thread != RT_NULL)
  166. rt_thread_startup(ftk_thread);
  167. }
  168. #endif
  169. }
  170. void rt_led_thread_entry(void *parameter)
  171. {
  172. while (1)
  173. {
  174. /* light on leds for one second */
  175. rt_hw_led_on(LED2|LED3);
  176. rt_hw_led_off(LED1|LED4);
  177. rt_thread_delay(100);
  178. /* light off leds for one second */
  179. rt_hw_led_off(LED2|LED3);
  180. rt_hw_led_on(LED1|LED4);
  181. rt_thread_delay(100);
  182. }
  183. }
  184. int rt_application_init(void)
  185. {
  186. rt_thread_t init_thread;
  187. rt_thread_t led_thread;
  188. #if (RT_THREAD_PRIORITY_MAX == 32)
  189. init_thread = rt_thread_create("init",
  190. rt_init_thread_entry, RT_NULL,
  191. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  192. led_thread = rt_thread_create("led",
  193. rt_led_thread_entry, RT_NULL,
  194. 512, 20, 20);
  195. #else
  196. init_thread = rt_thread_create("init",
  197. rt_init_thread_entry, RT_NULL,
  198. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  199. led_thread = rt_thread_create("led",
  200. rt_led_thread_entry, RT_NULL,
  201. 512, 200, 20);
  202. #endif
  203. if (init_thread != RT_NULL)
  204. rt_thread_startup(init_thread);
  205. if (led_thread != RT_NULL)
  206. rt_thread_startup(led_thread);
  207. return 0;
  208. }
  209. /*@}*/