application.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #include <rtgui/calibration.h>
  39. #endif
  40. #include "led.h"
  41. ALIGN(RT_ALIGN_SIZE)
  42. static rt_uint8_t led_stack[ 512 ];
  43. static struct rt_thread led_thread;
  44. static void led_thread_entry(void* parameter)
  45. {
  46. unsigned int count=0;
  47. rt_hw_led_init();
  48. while (1)
  49. {
  50. /* led1 on */
  51. #ifndef RT_USING_FINSH
  52. rt_kprintf("led on, count : %d\r\n",count);
  53. #endif
  54. count++;
  55. rt_hw_led_on(0);
  56. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  57. /* led1 off */
  58. #ifndef RT_USING_FINSH
  59. rt_kprintf("led off\r\n");
  60. #endif
  61. rt_hw_led_off(0);
  62. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  63. }
  64. }
  65. #ifdef RT_USING_RTGUI
  66. rt_bool_t cali_setup(void)
  67. {
  68. rt_kprintf("cali setup entered\n");
  69. return RT_FALSE;
  70. }
  71. void cali_store(struct calibration_data *data)
  72. {
  73. rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
  74. data->min_x,
  75. data->max_x,
  76. data->min_y,
  77. data->max_y);
  78. }
  79. #endif
  80. void rt_init_thread_entry(void* parameter)
  81. {
  82. /* Filesystem Initialization */
  83. #ifdef RT_USING_DFS
  84. {
  85. /* init the device filesystem */
  86. dfs_init();
  87. #ifdef RT_USING_DFS_ELMFAT
  88. /* init the elm chan FatFs filesystam*/
  89. elm_init();
  90. /* mount sd card fat partition 1 as root directory */
  91. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  92. {
  93. rt_kprintf("File System initialized!\n");
  94. }
  95. else
  96. rt_kprintf("File System initialzation failed!\n");
  97. #endif
  98. }
  99. #endif
  100. /* LwIP Initialization */
  101. #ifdef RT_USING_LWIP
  102. {
  103. extern void lwip_sys_init(void);
  104. /* register ethernetif device */
  105. eth_system_device_init();
  106. #ifdef STM32F10X_CL
  107. rt_hw_stm32_eth_init();
  108. #else
  109. /* STM32F103 */
  110. #if STM32_ETH_IF == 0
  111. rt_hw_enc28j60_init();
  112. #elif STM32_ETH_IF == 1
  113. rt_hw_dm9000_init();
  114. #endif
  115. #endif
  116. /* re-init device driver */
  117. rt_device_init_all();
  118. /* init lwip system */
  119. lwip_sys_init();
  120. rt_kprintf("TCP/IP initialized!\n");
  121. }
  122. #endif
  123. #ifdef RT_USING_RTGUI
  124. {
  125. extern void rtgui_system_server_init(void);
  126. extern void rt_hw_lcd_init();
  127. extern void rtgui_touch_hw_init(void);
  128. rt_device_t lcd;
  129. /* init lcd */
  130. rt_hw_lcd_init();
  131. /* init touch panel */
  132. rtgui_touch_hw_init();
  133. /* re-init device driver */
  134. rt_device_init_all();
  135. /* find lcd device */
  136. lcd = rt_device_find("lcd");
  137. /* set lcd device as rtgui graphic driver */
  138. rtgui_graphic_set_device(lcd);
  139. /* init rtgui system server */
  140. rtgui_system_server_init();
  141. calibration_set_restore(cali_setup);
  142. calibration_set_after(cali_store);
  143. calibration_init();
  144. }
  145. #endif /* #ifdef RT_USING_RTGUI */
  146. }
  147. int rt_application_init()
  148. {
  149. rt_thread_t init_thread;
  150. rt_err_t result;
  151. /* init led thread */
  152. result = rt_thread_init(&led_thread,
  153. "led",
  154. led_thread_entry, RT_NULL,
  155. (rt_uint8_t*)&led_stack[0], sizeof(led_stack), 20, 5);
  156. if (result == RT_EOK)
  157. {
  158. rt_thread_startup(&led_thread);
  159. }
  160. #if (RT_THREAD_PRIORITY_MAX == 32)
  161. init_thread = rt_thread_create("init",
  162. rt_init_thread_entry, RT_NULL,
  163. 2048, 8, 20);
  164. #else
  165. init_thread = rt_thread_create("init",
  166. rt_init_thread_entry, RT_NULL,
  167. 2048, 80, 20);
  168. #endif
  169. if (init_thread != RT_NULL)
  170. rt_thread_startup(init_thread);
  171. return 0;
  172. }
  173. /*@}*/