application.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. extern void rtgui_system_server_init(void);
  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. /* find lcd device */
  127. lcd = rt_device_find("lcd");
  128. /* set lcd device as rtgui graphic driver */
  129. rtgui_graphic_set_device(lcd);
  130. /* initalize rtgui system server */
  131. rtgui_system_server_init();
  132. }
  133. #endif
  134. /* LwIP Initialization */
  135. #ifdef RT_USING_LWIP
  136. {
  137. extern void lwip_sys_init(void);
  138. eth_system_device_init();
  139. /* register ethernetif device */
  140. rt_hw_dm9000_init();
  141. /* init lwip system */
  142. lwip_sys_init();
  143. rt_kprintf("TCP/IP initialized!\n");
  144. }
  145. #endif
  146. #ifdef RT_USING_FTK
  147. {
  148. rt_thread_t ftk_thread;
  149. /* init lcd */
  150. rt_hw_lcd_init();
  151. /* init touch panel */
  152. rtgui_touch_hw_init();
  153. /* init keypad */
  154. rt_hw_key_init();
  155. /* create ftk thread */
  156. ftk_thread = rt_thread_create("ftk",
  157. rt_ftk_thread_entry, RT_NULL,
  158. 10 * 1024, 8, 20);
  159. /* startup ftk thread */
  160. if (ftk_thread != RT_NULL)
  161. rt_thread_startup(ftk_thread);
  162. }
  163. #endif
  164. }
  165. void rt_led_thread_entry(void *parameter)
  166. {
  167. while (1)
  168. {
  169. /* light on leds for one second */
  170. rt_hw_led_on(LED2|LED3);
  171. rt_hw_led_off(LED1|LED4);
  172. rt_thread_delay(100);
  173. /* light off leds for one second */
  174. rt_hw_led_off(LED2|LED3);
  175. rt_hw_led_on(LED1|LED4);
  176. rt_thread_delay(100);
  177. }
  178. }
  179. int rt_application_init(void)
  180. {
  181. rt_thread_t init_thread;
  182. rt_thread_t led_thread;
  183. #if (RT_THREAD_PRIORITY_MAX == 32)
  184. init_thread = rt_thread_create("init",
  185. rt_init_thread_entry, RT_NULL,
  186. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  187. led_thread = rt_thread_create("led",
  188. rt_led_thread_entry, RT_NULL,
  189. 512, 20, 20);
  190. #else
  191. init_thread = rt_thread_create("init",
  192. rt_init_thread_entry, RT_NULL,
  193. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  194. led_thread = rt_thread_create("led",
  195. rt_led_thread_entry, RT_NULL,
  196. 512, 200, 20);
  197. #endif
  198. if (init_thread != RT_NULL)
  199. rt_thread_startup(init_thread);
  200. if (led_thread != RT_NULL)
  201. rt_thread_startup(led_thread);
  202. return 0;
  203. }
  204. /*@}*/