application.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. }
  65. #endif
  66. #ifdef RT_USING_RTGUI
  67. {
  68. /* init touch panel */
  69. rtgui_touch_hw_init();
  70. /* re-init device driver */
  71. rt_device_init_all();
  72. /* startup rtgui */
  73. rtgui_startup();
  74. }
  75. #endif
  76. /* LwIP Initialization */
  77. #ifdef RT_USING_LWIP
  78. {
  79. extern void lwip_sys_init(void);
  80. eth_system_device_init();
  81. /* register ethernetif device */
  82. rt_hw_dm9000_init();
  83. /* re-init device driver */
  84. rt_device_init_all();
  85. /* init lwip system */
  86. lwip_sys_init();
  87. rt_kprintf("TCP/IP initialized!\n");
  88. }
  89. #endif
  90. #ifdef RT_USING_FTK
  91. {
  92. void rt_hw_lcd_init();
  93. int FTK_MAIN(int argc, char* argv[]);
  94. /* init lcd */
  95. rt_hw_lcd_init();
  96. /* init touch panel */
  97. rtgui_touch_hw_init();
  98. /* re-init device driver */
  99. rt_device_init_all();
  100. /* enter ftk main */
  101. FTK_MAIN(0, NULL);
  102. }
  103. #endif
  104. }
  105. void rt_led_thread_entry(void* parameter)
  106. {
  107. while(1)
  108. {
  109. /* light on leds for one second */
  110. rt_hw_led_on(LED2|LED3);
  111. rt_hw_led_off(LED1|LED4);
  112. rt_thread_delay(100);
  113. /* light off leds for one second */
  114. rt_hw_led_off(LED2|LED3);
  115. rt_hw_led_on(LED1|LED4);
  116. rt_thread_delay(100);
  117. }
  118. }
  119. int rt_application_init()
  120. {
  121. rt_thread_t init_thread;
  122. rt_thread_t led_thread;
  123. #if (RT_THREAD_PRIORITY_MAX == 32)
  124. init_thread = rt_thread_create("init",
  125. rt_init_thread_entry, RT_NULL,
  126. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  127. led_thread = rt_thread_create("led",
  128. rt_led_thread_entry, RT_NULL,
  129. 512, 20, 20);
  130. #else
  131. init_thread = rt_thread_create("init",
  132. rt_init_thread_entry, RT_NULL,
  133. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  134. led_thread = rt_thread_create("led",
  135. rt_led_thread_entry, RT_NULL,
  136. 512, 200, 20);
  137. #endif
  138. if (init_thread != RT_NULL)
  139. rt_thread_startup(init_thread);
  140. if(led_thread != RT_NULL)
  141. rt_thread_startup(led_thread);
  142. return 0;
  143. }
  144. /* NFSv3 Initialization */
  145. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  146. #include <dfs_nfs.h>
  147. void nfs_start(void)
  148. {
  149. nfs_init();
  150. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  151. {
  152. rt_kprintf("NFSv3 File System initialized!\n");
  153. }
  154. else
  155. rt_kprintf("NFSv3 File System initialzation failed!\n");
  156. }
  157. #include "finsh.h"
  158. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  159. #endif
  160. /*@}*/