application.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. * 2009-01-05 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <board.h>
  19. #include <rtthread.h>
  20. #ifdef RT_USING_DFS
  21. /* dfs init */
  22. #include <dfs_init.h>
  23. /* dfs filesystem:ELM filesystem init */
  24. #include <dfs_elm.h>
  25. /* dfs Filesystem APIs */
  26. #include <dfs_fs.h>
  27. #endif
  28. #ifdef RT_USING_LWIP
  29. #include <lwip/sys.h>
  30. #include <lwip/api.h>
  31. #include <netif/ethernetif.h>
  32. #endif
  33. #ifdef RT_USING_RTGUI
  34. #include <rtgui/rtgui.h>
  35. #include <rtgui/rtgui_server.h>
  36. #include <rtgui/rtgui_system.h>
  37. #include <rtgui/driver.h>
  38. #endif
  39. #include "led.h"
  40. ALIGN(RT_ALIGN_SIZE)
  41. static rt_uint8_t led_stack[ 512 ];
  42. static struct rt_thread led_thread;
  43. static void led_thread_entry(void* parameter)
  44. {
  45. unsigned int count=0;
  46. rt_hw_led_init();
  47. while (1)
  48. {
  49. /* led1 on */
  50. #ifndef RT_USING_FINSH
  51. rt_kprintf("led on, count : %d\r\n",count);
  52. #endif
  53. count++;
  54. rt_hw_led_on(0);
  55. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  56. /* led1 off */
  57. #ifndef RT_USING_FINSH
  58. rt_kprintf("led off\r\n");
  59. #endif
  60. rt_hw_led_off(0);
  61. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  62. }
  63. }
  64. void rt_init_thread_entry(void* parameter)
  65. {
  66. /* Filesystem Initialization */
  67. #ifdef RT_USING_DFS
  68. {
  69. /* init the device filesystem */
  70. dfs_init();
  71. #ifdef RT_USING_DFS_ELMFAT
  72. /* init the elm chan FatFs filesystam*/
  73. elm_init();
  74. /* mount sd card fat partition 1 as root directory */
  75. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  76. {
  77. rt_kprintf("File System initialized!\n");
  78. }
  79. else
  80. rt_kprintf("File System initialzation failed!\n");
  81. #endif
  82. }
  83. #endif
  84. /* LwIP Initialization */
  85. #ifdef RT_USING_LWIP
  86. {
  87. extern void lwip_sys_init(void);
  88. /* register ethernetif device */
  89. eth_system_device_init();
  90. #ifdef STM32F10X_CL
  91. rt_hw_stm32_eth_init();
  92. #else
  93. /* STM32F103 */
  94. #if STM32_ETH_IF == 0
  95. rt_hw_enc28j60_init();
  96. #elif STM32_ETH_IF == 1
  97. rt_hw_dm9000_init();
  98. #endif
  99. #endif
  100. /* re-init device driver */
  101. rt_device_init_all();
  102. /* init lwip system */
  103. lwip_sys_init();
  104. rt_kprintf("TCP/IP initialized!\n");
  105. }
  106. #endif
  107. #ifdef RT_USING_RTGUI
  108. {
  109. extern void rtgui_startup();
  110. extern void rt_hw_lcd_init();
  111. extern void rtgui_touch_hw_init(void);
  112. extern void rt_hw_key_init(void);
  113. rt_device_t lcd;
  114. /* init lcd */
  115. rt_hw_lcd_init();
  116. /* init touch panel */
  117. rtgui_touch_hw_init();
  118. /* init keypad */
  119. rt_hw_key_init();
  120. /* re-init device driver */
  121. rt_device_init_all();
  122. /* find lcd device */
  123. lcd = rt_device_find("lcd");
  124. /* set lcd device as rtgui graphic driver */
  125. rtgui_graphic_set_device(lcd);
  126. /* startup rtgui */
  127. rtgui_startup();
  128. }
  129. #endif /* #ifdef RT_USING_RTGUI */
  130. }
  131. int rt_application_init()
  132. {
  133. rt_thread_t init_thread;
  134. rt_err_t result;
  135. /* init led thread */
  136. result = rt_thread_init(&led_thread,
  137. "led",
  138. led_thread_entry, RT_NULL,
  139. (rt_uint8_t*)&led_stack[0], sizeof(led_stack), 20, 5);
  140. if (result == RT_EOK)
  141. {
  142. rt_thread_startup(&led_thread);
  143. }
  144. #if (RT_THREAD_PRIORITY_MAX == 32)
  145. init_thread = rt_thread_create("init",
  146. rt_init_thread_entry, RT_NULL,
  147. 2048, 8, 20);
  148. #else
  149. init_thread = rt_thread_create("init",
  150. rt_init_thread_entry, RT_NULL,
  151. 2048, 80, 20);
  152. #endif
  153. if (init_thread != RT_NULL)
  154. rt_thread_startup(init_thread);
  155. return 0;
  156. }
  157. /*@}*/