1
0

application.c 5.2 KB

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