application.c 5.6 KB

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