application.c 3.4 KB

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