application.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 "dm9000.h"
  21. #include "touch.h"
  22. #include "led.h"
  23. #ifdef RT_USING_DFS
  24. /* dfs init */
  25. #include <dfs_init.h>
  26. /* dfs filesystem:ELM FatFs filesystem init */
  27. #include <dfs_elm.h>
  28. /* dfs Filesystem APIs */
  29. #include <dfs_fs.h>
  30. #endif
  31. #ifdef RT_USING_LWIP
  32. #include <netif/ethernetif.h>
  33. #endif
  34. #ifdef RT_USING_RTGUI
  35. #include <rtgui/rtgui.h>
  36. extern void rt_hw_touch_init(void);
  37. #endif
  38. #ifdef RT_USING_FTK
  39. #include "ftk.h"
  40. #endif
  41. #ifdef RT_USING_FTK
  42. #define RT_INIT_THREAD_STACK_SIZE (10*1024)
  43. #else
  44. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  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_DEVFS)
  65. devfs_init();
  66. if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
  67. rt_kprintf("Device File System initialized!\n");
  68. else
  69. rt_kprintf("Device File System initialzation failed!\n");
  70. /* init libc */
  71. libc_system_init("uart0");
  72. #endif
  73. }
  74. #endif
  75. #ifdef RT_USING_RTGUI
  76. {
  77. /* init touch panel */
  78. rtgui_touch_hw_init();
  79. /* re-init device driver */
  80. rt_device_init_all();
  81. /* startup rtgui */
  82. rtgui_startup();
  83. }
  84. #endif
  85. /* LwIP Initialization */
  86. #ifdef RT_USING_LWIP
  87. {
  88. extern void lwip_sys_init(void);
  89. eth_system_device_init();
  90. /* register ethernetif device */
  91. rt_hw_dm9000_init();
  92. /* re-init device driver */
  93. rt_device_init_all();
  94. /* init lwip system */
  95. lwip_sys_init();
  96. rt_kprintf("TCP/IP initialized!\n");
  97. }
  98. #endif
  99. #ifdef RT_USING_FTK
  100. {
  101. void rt_hw_lcd_init();
  102. int FTK_MAIN(int argc, char* argv[]);
  103. /* init lcd */
  104. rt_hw_lcd_init();
  105. /* init touch panel */
  106. rtgui_touch_hw_init();
  107. /* re-init device driver */
  108. rt_device_init_all();
  109. /* enter ftk main */
  110. FTK_MAIN(0, NULL);
  111. }
  112. #endif
  113. }
  114. void rt_led_thread_entry(void* parameter)
  115. {
  116. while(1)
  117. {
  118. /* light on leds for one second */
  119. rt_hw_led_on(LED2|LED3);
  120. rt_hw_led_off(LED1|LED4);
  121. rt_thread_delay(100);
  122. /* light off leds for one second */
  123. rt_hw_led_off(LED2|LED3);
  124. rt_hw_led_on(LED1|LED4);
  125. rt_thread_delay(100);
  126. }
  127. }
  128. int rt_application_init()
  129. {
  130. rt_thread_t init_thread;
  131. rt_thread_t led_thread;
  132. #if (RT_THREAD_PRIORITY_MAX == 32)
  133. init_thread = rt_thread_create("init",
  134. rt_init_thread_entry, RT_NULL,
  135. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  136. led_thread = rt_thread_create("led",
  137. rt_led_thread_entry, RT_NULL,
  138. 512, 20, 20);
  139. #else
  140. init_thread = rt_thread_create("init",
  141. rt_init_thread_entry, RT_NULL,
  142. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  143. led_thread = rt_thread_create("led",
  144. rt_led_thread_entry, RT_NULL,
  145. 512, 200, 20);
  146. #endif
  147. if (init_thread != RT_NULL)
  148. rt_thread_startup(init_thread);
  149. if(led_thread != RT_NULL)
  150. rt_thread_startup(led_thread);
  151. return 0;
  152. }
  153. /* NFSv3 Initialization */
  154. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  155. #include <dfs_nfs.h>
  156. void nfs_start(void)
  157. {
  158. nfs_init();
  159. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  160. {
  161. rt_kprintf("NFSv3 File System initialized!\n");
  162. }
  163. else
  164. rt_kprintf("NFSv3 File System initialzation failed!\n");
  165. }
  166. #include "finsh.h"
  167. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  168. #endif
  169. /*@}*/