application.c 5.2 KB

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