application.c 4.1 KB

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