application.c 5.0 KB

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