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. 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) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  99. /* NFSv3 Initialization */
  100. nfs_init();
  101. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  102. rt_kprintf("NFSv3 File System initialized!\n");
  103. else
  104. rt_kprintf("NFSv3 File System initialzation failed!\n");
  105. #endif
  106. #if defined(RT_USING_DFS_UFFS)
  107. /* init the uffs filesystem */
  108. dfs_uffs_init();
  109. /* mount flash device as flash directory */
  110. if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
  111. rt_kprintf("UFFS File System initialized!\n");
  112. else
  113. rt_kprintf("UFFS File System initialzation failed!\n");
  114. #endif
  115. }
  116. #endif
  117. #ifdef RT_USING_RTGUI
  118. {
  119. rt_device_t lcd;
  120. /* init lcd */
  121. rt_hw_lcd_init();
  122. /* init touch panel */
  123. rtgui_touch_hw_init();
  124. /* init keypad */
  125. rt_hw_key_init();
  126. /* re-init device driver */
  127. rt_device_init_all();
  128. /* find lcd device */
  129. lcd = rt_device_find("lcd");
  130. /* set lcd device as rtgui graphic driver */
  131. rtgui_graphic_set_device(lcd);
  132. /* startup rtgui */
  133. rtgui_startup();
  134. }
  135. #endif
  136. /* LwIP Initialization */
  137. #ifdef RT_USING_LWIP
  138. {
  139. extern void lwip_sys_init(void);
  140. eth_system_device_init();
  141. /* register ethernetif device */
  142. rt_hw_dm9000_init();
  143. /* re-init device driver */
  144. rt_device_init_all();
  145. /* init lwip system */
  146. lwip_sys_init();
  147. rt_kprintf("TCP/IP initialized!\n");
  148. }
  149. #endif
  150. #ifdef RT_USING_FTK
  151. {
  152. rt_thread_t ftk_thread;
  153. /* init lcd */
  154. rt_hw_lcd_init();
  155. /* init touch panel */
  156. rtgui_touch_hw_init();
  157. /* init keypad */
  158. rt_hw_key_init();
  159. /* re-init device driver */
  160. rt_device_init_all();
  161. /* create ftk thread */
  162. ftk_thread = rt_thread_create("ftk",
  163. rt_ftk_thread_entry, RT_NULL,
  164. 10 * 1024, 8, 20);
  165. /* startup ftk thread */
  166. if(ftk_thread != RT_NULL)
  167. rt_thread_startup(ftk_thread);
  168. }
  169. #endif
  170. }
  171. void rt_led_thread_entry(void* parameter)
  172. {
  173. while(1)
  174. {
  175. /* light on leds for one second */
  176. rt_hw_led_on(LED2|LED3);
  177. rt_hw_led_off(LED1|LED4);
  178. rt_thread_delay(100);
  179. /* light off leds for one second */
  180. rt_hw_led_off(LED2|LED3);
  181. rt_hw_led_on(LED1|LED4);
  182. rt_thread_delay(100);
  183. }
  184. }
  185. int rt_application_init()
  186. {
  187. rt_thread_t init_thread;
  188. rt_thread_t led_thread;
  189. #if (RT_THREAD_PRIORITY_MAX == 32)
  190. init_thread = rt_thread_create("init",
  191. rt_init_thread_entry, RT_NULL,
  192. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  193. led_thread = rt_thread_create("led",
  194. rt_led_thread_entry, RT_NULL,
  195. 512, 20, 20);
  196. #else
  197. init_thread = rt_thread_create("init",
  198. rt_init_thread_entry, RT_NULL,
  199. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  200. led_thread = rt_thread_create("led",
  201. rt_led_thread_entry, RT_NULL,
  202. 512, 200, 20);
  203. #endif
  204. if (init_thread != RT_NULL)
  205. rt_thread_startup(init_thread);
  206. if(led_thread != RT_NULL)
  207. rt_thread_startup(led_thread);
  208. return 0;
  209. }
  210. /*@}*/