application.c 5.0 KB

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