application.c 4.7 KB

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