application.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. void rt_init_thread_entry(void* parameter)
  42. {
  43. /* Filesystem Initialization */
  44. #ifdef RT_USING_DFS
  45. {
  46. /* init the device filesystem */
  47. dfs_init();
  48. #if defined(RT_USING_DFS_ELMFAT)
  49. /* init the elm chan FatFs filesystam*/
  50. elm_init();
  51. /* mount sd card fat partition 1 as root directory */
  52. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  53. {
  54. rt_kprintf("File System initialized!\n");
  55. }
  56. else
  57. rt_kprintf("File System initialzation failed!\n");
  58. #endif
  59. }
  60. #endif
  61. #ifdef RT_USING_RTGUI
  62. {
  63. /* init touch panel */
  64. rtgui_touch_hw_init();
  65. /* re-init device driver */
  66. rt_device_init_all();
  67. /* startup rtgui */
  68. rtgui_startup();
  69. }
  70. #endif
  71. /* LwIP Initialization */
  72. #ifdef RT_USING_LWIP
  73. {
  74. extern void lwip_sys_init(void);
  75. eth_system_device_init();
  76. /* register ethernetif device */
  77. rt_hw_dm9000_init();
  78. /* re-init device driver */
  79. rt_device_init_all();
  80. /* init lwip system */
  81. lwip_sys_init();
  82. rt_kprintf("TCP/IP initialized!\n");
  83. }
  84. #endif
  85. #ifdef RT_USING_FTK
  86. {
  87. void rt_hw_lcd_init();
  88. int FTK_MAIN(int argc, char* argv[]);
  89. rt_hw_lcd_init();
  90. FTK_MAIN(0, NULL);
  91. }
  92. #endif
  93. }
  94. void rt_led_thread_entry(void* parameter)
  95. {
  96. while(1)
  97. {
  98. /* light on leds for one second */
  99. rt_hw_led_on(LED2|LED3);
  100. rt_hw_led_off(LED1|LED4);
  101. rt_thread_delay(100);
  102. /* light off leds for one second */
  103. rt_hw_led_off(LED2|LED3);
  104. rt_hw_led_on(LED1|LED4);
  105. rt_thread_delay(100);
  106. }
  107. }
  108. int rt_application_init()
  109. {
  110. rt_thread_t init_thread;
  111. rt_thread_t led_thread;
  112. #if (RT_THREAD_PRIORITY_MAX == 32)
  113. init_thread = rt_thread_create("init",
  114. rt_init_thread_entry, RT_NULL,
  115. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  116. led_thread = rt_thread_create("led",
  117. rt_led_thread_entry, RT_NULL,
  118. 512, 20, 20);
  119. #else
  120. init_thread = rt_thread_create("init",
  121. rt_init_thread_entry, RT_NULL,
  122. RT_INIT_THREAD_STACK_SIZE, 80, 20);
  123. led_thread = rt_thread_create("led",
  124. rt_led_thread_entry, RT_NULL,
  125. 512, 200, 20);
  126. #endif
  127. if (init_thread != RT_NULL)
  128. rt_thread_startup(init_thread);
  129. if(led_thread != RT_NULL)
  130. rt_thread_startup(led_thread);
  131. return 0;
  132. }
  133. /* NFSv3 Initialization */
  134. #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
  135. #include <dfs_nfs.h>
  136. void nfs_start(void)
  137. {
  138. nfs_init();
  139. if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
  140. {
  141. rt_kprintf("NFSv3 File System initialized!\n");
  142. }
  143. else
  144. rt_kprintf("NFSv3 File System initialzation failed!\n");
  145. }
  146. #include "finsh.h"
  147. FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
  148. #endif
  149. /*@}*/