freertos(6801).c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : freertos.c
  5. * Description : Code for freertos applications
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2024 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "FreeRTOS.h"
  21. #include "task.h"
  22. #include "main.h"
  23. #include "cmsis_os.h"
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26. #include "task_ec800_upload.h"
  27. #include "task_communication.h"
  28. /* USER CODE END Includes */
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* USER CODE BEGIN PTD */
  31. /* USER CODE END PTD */
  32. /* Private define ------------------------------------------------------------*/
  33. /* USER CODE BEGIN PD */
  34. /* USER CODE END PD */
  35. /* Private macro -------------------------------------------------------------*/
  36. /* USER CODE BEGIN PM */
  37. /* USER CODE END PM */
  38. /* Private variables ---------------------------------------------------------*/
  39. /* USER CODE BEGIN Variables */
  40. /* USER CODE END Variables */
  41. /* Definitions for defaultTask */
  42. osThreadId_t defaultTaskHandle;
  43. const osThreadAttr_t defaultTask_attributes = {
  44. .name = "defaultTask",
  45. .stack_size = 128 * 4,
  46. .priority = (osPriority_t) osPriorityNormal,
  47. };
  48. /* Definitions for ec800_dataUploa */
  49. osThreadId_t ec800_dataUploaHandle;
  50. const osThreadAttr_t ec800_dataUploa_attributes = {
  51. .name = "ec800_dataUploa",
  52. .stack_size = 256 * 4,
  53. .priority = (osPriority_t) osPriorityBelowNormal,
  54. };
  55. /* Definitions for communication */
  56. osThreadId_t communicationHandle;
  57. const osThreadAttr_t communication_attributes = {
  58. .name = "communication",
  59. .stack_size = 128 * 4,
  60. .priority = (osPriority_t) osPriorityBelowNormal1,
  61. };
  62. /* Definitions for Time2_ */
  63. osTimerId_t Time2_Handle;
  64. const osTimerAttr_t Time2__attributes = {
  65. .name = "Time2_"
  66. };
  67. /* Definitions for semphore_ */
  68. osSemaphoreId_t semphore_Handle;
  69. const osSemaphoreAttr_t semphore__attributes = {
  70. .name = "semphore_"
  71. };
  72. /* Definitions for count_semphore_ */
  73. osSemaphoreId_t count_semphore_Handle;
  74. const osSemaphoreAttr_t count_semphore__attributes = {
  75. .name = "count_semphore_"
  76. };
  77. /* Private function prototypes -----------------------------------------------*/
  78. /* USER CODE BEGIN FunctionPrototypes */
  79. /* USER CODE END FunctionPrototypes */
  80. void StartDefaultTask(void *argument);
  81. void Task_ec800_upload(void *argument);
  82. void Task_communication(void *argument);
  83. void Time2_Callback(void *argument);
  84. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  85. /* Hook prototypes */
  86. void configureTimerForRunTimeStats(void);
  87. unsigned long getRunTimeCounterValue(void);
  88. /* USER CODE BEGIN 1 */
  89. /* Functions needed when configGENERATE_RUN_TIME_STATS is on */
  90. __weak void configureTimerForRunTimeStats(void)
  91. {
  92. }
  93. __weak unsigned long getRunTimeCounterValue(void)
  94. {
  95. return 0;
  96. }
  97. /* USER CODE END 1 */
  98. /* USER CODE BEGIN PREPOSTSLEEP */
  99. __weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
  100. {
  101. /* place for user code */
  102. }
  103. __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
  104. {
  105. /* place for user code */
  106. }
  107. /* USER CODE END PREPOSTSLEEP */
  108. /**
  109. * @brief FreeRTOS initialization
  110. * @param None
  111. * @retval None
  112. */
  113. void MX_FREERTOS_Init(void) {
  114. /* USER CODE BEGIN Init */
  115. /* USER CODE END Init */
  116. /* USER CODE BEGIN RTOS_MUTEX */
  117. /* add mutexes, ... */
  118. /* USER CODE END RTOS_MUTEX */
  119. /* Create the semaphores(s) */
  120. /* creation of semphore_ */
  121. semphore_Handle = osSemaphoreNew(1, 1, &semphore__attributes);
  122. /* creation of count_semphore_ */
  123. count_semphore_Handle = osSemaphoreNew(1, 1, &count_semphore__attributes);
  124. /* USER CODE BEGIN RTOS_SEMAPHORES */
  125. /* add semaphores, ... */
  126. /* USER CODE END RTOS_SEMAPHORES */
  127. /* Create the timer(s) */
  128. /* creation of Time2_ */
  129. Time2_Handle = osTimerNew(Time2_Callback, osTimerPeriodic, NULL, &Time2__attributes);
  130. /* USER CODE BEGIN RTOS_TIMERS */
  131. /* start timers, add new ones, ... */
  132. /* USER CODE END RTOS_TIMERS */
  133. /* USER CODE BEGIN RTOS_QUEUES */
  134. /* add queues, ... */
  135. /* USER CODE END RTOS_QUEUES */
  136. /* Create the thread(s) */
  137. /* creation of defaultTask */
  138. defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  139. /* creation of ec800_dataUploa */
  140. ec800_dataUploaHandle = osThreadNew(Task_ec800_upload, NULL, &ec800_dataUploa_attributes);
  141. /* creation of communication */
  142. communicationHandle = osThreadNew(Task_communication, NULL, &communication_attributes);
  143. /* USER CODE BEGIN RTOS_THREADS */
  144. /* add threads, ... */
  145. /* USER CODE END RTOS_THREADS */
  146. /* USER CODE BEGIN RTOS_EVENTS */
  147. /* add events, ... */
  148. /* USER CODE END RTOS_EVENTS */
  149. }
  150. /* USER CODE BEGIN Header_StartDefaultTask */
  151. /**
  152. * @brief Function implementing the defaultTask thread.
  153. * @param argument: Not used
  154. * @retval None
  155. */
  156. /* USER CODE END Header_StartDefaultTask */
  157. void StartDefaultTask(void *argument)
  158. {
  159. /* USER CODE BEGIN StartDefaultTask */
  160. /* Infinite loop */
  161. for(;;)
  162. {
  163. osDelay(1);
  164. }
  165. /* USER CODE END StartDefaultTask */
  166. }
  167. /* USER CODE BEGIN Header_Task_ec800_upload */
  168. /**
  169. * @brief Function implementing the ec800_dataUploa thread.
  170. * @param argument: Not used
  171. * @retval None
  172. */
  173. /* USER CODE END Header_Task_ec800_upload */
  174. void Task_ec800_upload(void *argument)
  175. {
  176. /* USER CODE BEGIN Task_ec800_upload */
  177. atk_ms6050_init();
  178. printf("ATK-MS6050 init\r\n");
  179. atk_ms6050_dmp_init();
  180. printf("ATK-MS6050 DMP init!\r\n");
  181. /* Infinite loop */
  182. for(;;)
  183. {
  184. task_ec800_content();
  185. osDelay(1);
  186. }
  187. /* USER CODE END Task_ec800_upload */
  188. }
  189. /* USER CODE BEGIN Header_Task_communication */
  190. /**
  191. * @brief Function implementing the communication thread.
  192. * @param argument: Not used
  193. * @retval None
  194. */
  195. /* USER CODE END Header_Task_communication */
  196. void Task_communication(void *argument)
  197. {
  198. /* USER CODE BEGIN Task_communication */
  199. /* Infinite loop */
  200. for(;;)
  201. {
  202. task_communication_content();
  203. osDelay(1);
  204. }
  205. /* USER CODE END Task_communication */
  206. }
  207. /* Time2_Callback function */
  208. void Time2_Callback(void *argument)
  209. {
  210. /* USER CODE BEGIN Time2_Callback */
  211. /* USER CODE END Time2_Callback */
  212. }
  213. /* Private application code --------------------------------------------------*/
  214. /* USER CODE BEGIN Application */
  215. /* USER CODE END Application */