application.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. * 2013-07-12 aozima update for auto initial.
  14. */
  15. /**
  16. * @addtogroup STM32
  17. */
  18. /*@{*/
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #ifdef RT_USING_COMPONENTS_INIT
  22. #include <components.h>
  23. #endif /* RT_USING_COMPONENTS_INIT */
  24. #ifdef RT_USING_DFS
  25. /* dfs filesystem:ELM filesystem init */
  26. #include <dfs_elm.h>
  27. /* dfs Filesystem APIs */
  28. #include <dfs_fs.h>
  29. #endif
  30. #ifdef RT_USING_RTGUI
  31. #include <rtgui/rtgui.h>
  32. #include <rtgui/rtgui_server.h>
  33. #include <rtgui/rtgui_system.h>
  34. #include <rtgui/driver.h>
  35. #include <rtgui/calibration.h>
  36. #endif
  37. #ifdef RT_USING_RTGUI
  38. rt_bool_t cali_setup(void)
  39. {
  40. rt_kprintf("cali setup entered\n");
  41. return RT_FALSE;
  42. }
  43. void cali_store(struct calibration_data *data)
  44. {
  45. rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
  46. data->min_x,
  47. data->max_x,
  48. data->min_y,
  49. data->max_y);
  50. }
  51. #endif /* RT_USING_RTGUI */
  52. void rt_init_thread_entry(void* parameter)
  53. {
  54. #ifdef RT_USING_MODULE
  55. rt_system_module_init();
  56. #endif
  57. #ifdef RT_USING_FINSH
  58. /* initialize finsh */
  59. finsh_system_init();
  60. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  61. #endif
  62. #ifdef RT_USING_LWIP
  63. /* initialize lwip stack */
  64. /* register ethernetif device */
  65. eth_system_device_init();
  66. /* initialize lwip system */
  67. lwip_system_init();
  68. rt_kprintf("TCP/IP initialized!\n");
  69. #endif
  70. #ifdef RT_USING_DFS
  71. /* initialize the device file system */
  72. dfs_init();
  73. #ifdef RT_USING_DFS_ELMFAT
  74. /* initialize the elm chan FatFS file system*/
  75. elm_init();
  76. #endif
  77. #if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP)
  78. /* initialize NFSv3 client file system */
  79. nfs_init();
  80. #endif
  81. #ifdef RT_USING_DFS_YAFFS2
  82. dfs_yaffs2_init();
  83. #endif
  84. #ifdef RT_USING_DFS_UFFS
  85. dfs_uffs_init();
  86. #endif
  87. #ifdef RT_USING_DFS_JFFS2
  88. dfs_jffs2_init();
  89. #endif
  90. #ifdef RT_USING_DFS_ROMFS
  91. dfs_romfs_init();
  92. #endif
  93. #ifdef RT_USING_DFS_RAMFS
  94. dfs_ramfs_init();
  95. #endif
  96. #ifdef RT_USING_DFS_DEVFS
  97. devfs_init();
  98. #endif
  99. #endif /* end of RT_USING_DFS */
  100. #ifdef RT_USING_NEWLIB
  101. libc_system_init(RT_CONSOLE_DEVICE_NAME);
  102. #else
  103. /* the pthread system initialization will be initiallized in libc */
  104. #ifdef RT_USING_PTHREADS
  105. pthread_system_init();
  106. #endif
  107. #endif
  108. #ifdef RT_USING_RTGUI
  109. rtgui_system_server_init();
  110. #endif
  111. #ifdef RT_USING_USB_HOST
  112. rt_usb_host_init();
  113. #endif
  114. #ifdef RT_USING_FINSH
  115. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  116. #endif /* RT_USING_FINSH */
  117. /* Filesystem Initialization */
  118. #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
  119. /* mount sd card fat partition 1 as root directory */
  120. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  121. {
  122. rt_kprintf("File System initialized!\n");
  123. }
  124. else
  125. rt_kprintf("File System initialzation failed!\n");
  126. #endif /* RT_USING_DFS */
  127. #ifdef RT_USING_RTGUI
  128. {
  129. extern void rt_hw_lcd_init();
  130. extern void rtgui_touch_hw_init(void);
  131. rt_device_t lcd;
  132. /* init lcd */
  133. rt_hw_lcd_init();
  134. /* init touch panel */
  135. rtgui_touch_hw_init();
  136. /* find lcd device */
  137. lcd = rt_device_find("lcd");
  138. /* set lcd device as rtgui graphic driver */
  139. rtgui_graphic_set_device(lcd);
  140. #ifndef RT_USING_COMPONENTS_INIT
  141. /* init rtgui system server */
  142. rtgui_system_server_init();
  143. #endif
  144. calibration_set_restore(cali_setup);
  145. calibration_set_after(cali_store);
  146. calibration_init();
  147. }
  148. #endif /* #ifdef RT_USING_RTGUI */
  149. }
  150. ALIGN(RT_ALIGN_SIZE)
  151. static rt_uint8_t led_stack[ 512 ];
  152. static struct rt_thread led_thread;
  153. static void led_thread_entry(void* parameter)
  154. {
  155. unsigned int count=0;
  156. // rt_hw_led_init();
  157. while (1)
  158. {
  159. /* led1 on */
  160. #ifndef RT_USING_FINSH
  161. rt_kprintf("led on, count : %d\r\n",count);
  162. #endif
  163. count++;
  164. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  165. /* led1 off */
  166. #ifndef RT_USING_FINSH
  167. rt_kprintf("led off\r\n");
  168. #endif
  169. rt_thread_delay( RT_TICK_PER_SECOND/2 );
  170. }
  171. }
  172. int rt_application_init(void)
  173. {
  174. rt_thread_t init_thread;
  175. #if 1
  176. rt_err_t result;
  177. /* init led thread */
  178. result = rt_thread_init(&led_thread,
  179. "led",
  180. led_thread_entry,
  181. RT_NULL,
  182. (rt_uint8_t*)&led_stack[0],
  183. sizeof(led_stack),
  184. 20,
  185. 5);
  186. if (result == RT_EOK)
  187. {
  188. rt_thread_startup(&led_thread);
  189. }
  190. #endif
  191. #if (RT_THREAD_PRIORITY_MAX == 32)
  192. init_thread = rt_thread_create("init",
  193. rt_init_thread_entry, RT_NULL,
  194. 1024, 8, 20);
  195. #else
  196. init_thread = rt_thread_create("init",
  197. rt_init_thread_entry, RT_NULL,
  198. 2048, 80, 20);
  199. #endif
  200. if (init_thread != RT_NULL)
  201. rt_thread_startup(init_thread);
  202. return 0;
  203. }
  204. /*@}*/