freertos(6216).c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 = 256 * 4,
  60. .priority = (osPriority_t) osPriorityBelowNormal1,
  61. };
  62. /* Definitions for handleData */
  63. osThreadId_t handleDataHandle;
  64. const osThreadAttr_t handleData_attributes = {
  65. .name = "handleData",
  66. .stack_size = 128 * 4,
  67. .priority = (osPriority_t) osPriorityLow7,
  68. };
  69. /* Definitions for Time2_ */
  70. osTimerId_t Time2_Handle;
  71. const osTimerAttr_t Time2__attributes = {
  72. .name = "Time2_"
  73. };
  74. /* Definitions for mutex_rs485RecDate */
  75. osMutexId_t mutex_rs485RecDateHandle;
  76. const osMutexAttr_t mutex_rs485RecDate_attributes = {
  77. .name = "mutex_rs485RecDate"
  78. };
  79. /* Definitions for mutex_ec800Date */
  80. osMutexId_t mutex_ec800DateHandle;
  81. const osMutexAttr_t mutex_ec800Date_attributes = {
  82. .name = "mutex_ec800Date"
  83. };
  84. /* Definitions for s_messageDate_location */
  85. osMutexId_t s_messageDate_locationHandle;
  86. const osMutexAttr_t s_messageDate_location_attributes = {
  87. .name = "s_messageDate_location"
  88. };
  89. /* Definitions for semphore_ */
  90. osSemaphoreId_t semphore_Handle;
  91. const osSemaphoreAttr_t semphore__attributes = {
  92. .name = "semphore_"
  93. };
  94. /* Definitions for count_semphore_ */
  95. osSemaphoreId_t count_semphore_Handle;
  96. const osSemaphoreAttr_t count_semphore__attributes = {
  97. .name = "count_semphore_"
  98. };
  99. /* Private function prototypes -----------------------------------------------*/
  100. /* USER CODE BEGIN FunctionPrototypes */
  101. /* USER CODE END FunctionPrototypes */
  102. void StartDefaultTask(void *argument);
  103. void Task_ec800_upload(void *argument);
  104. void Task_communication(void *argument);
  105. void Task_handleData(void *argument);
  106. void Time2_Callback(void *argument);
  107. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  108. /* Hook prototypes */
  109. void configureTimerForRunTimeStats(void);
  110. unsigned long getRunTimeCounterValue(void);
  111. /* USER CODE BEGIN 1 */
  112. /* Functions needed when configGENERATE_RUN_TIME_STATS is on */
  113. __weak void configureTimerForRunTimeStats(void)
  114. {
  115. }
  116. __weak unsigned long getRunTimeCounterValue(void)
  117. {
  118. return 0;
  119. }
  120. /* USER CODE END 1 */
  121. /* USER CODE BEGIN PREPOSTSLEEP */
  122. __weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
  123. {
  124. /* place for user code */
  125. }
  126. __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
  127. {
  128. /* place for user code */
  129. }
  130. /* USER CODE END PREPOSTSLEEP */
  131. /**
  132. * @brief FreeRTOS initialization
  133. * @param None
  134. * @retval None
  135. */
  136. void MX_FREERTOS_Init(void) {
  137. /* USER CODE BEGIN Init */
  138. /* USER CODE END Init */
  139. /* Create the mutex(es) */
  140. /* creation of mutex_rs485RecDate */
  141. mutex_rs485RecDateHandle = osMutexNew(&mutex_rs485RecDate_attributes);
  142. /* creation of mutex_ec800Date */
  143. mutex_ec800DateHandle = osMutexNew(&mutex_ec800Date_attributes);
  144. /* creation of s_messageDate_location */
  145. s_messageDate_locationHandle = osMutexNew(&s_messageDate_location_attributes);
  146. /* USER CODE BEGIN RTOS_MUTEX */
  147. /* add mutexes, ... */
  148. /* USER CODE END RTOS_MUTEX */
  149. /* Create the semaphores(s) */
  150. /* creation of semphore_ */
  151. semphore_Handle = osSemaphoreNew(1, 1, &semphore__attributes);
  152. /* creation of count_semphore_ */
  153. count_semphore_Handle = osSemaphoreNew(1, 1, &count_semphore__attributes);
  154. /* USER CODE BEGIN RTOS_SEMAPHORES */
  155. /* add semaphores, ... */
  156. /* USER CODE END RTOS_SEMAPHORES */
  157. /* Create the timer(s) */
  158. /* creation of Time2_ */
  159. Time2_Handle = osTimerNew(Time2_Callback, osTimerPeriodic, NULL, &Time2__attributes);
  160. /* USER CODE BEGIN RTOS_TIMERS */
  161. /* start timers, add new ones, ... */
  162. /* USER CODE END RTOS_TIMERS */
  163. /* USER CODE BEGIN RTOS_QUEUES */
  164. /* add queues, ... */
  165. /* USER CODE END RTOS_QUEUES */
  166. /* Create the thread(s) */
  167. /* creation of defaultTask */
  168. defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
  169. /* creation of ec800_dataUploa */
  170. ec800_dataUploaHandle = osThreadNew(Task_ec800_upload, NULL, &ec800_dataUploa_attributes);
  171. /* creation of communication */
  172. communicationHandle = osThreadNew(Task_communication, NULL, &communication_attributes);
  173. /* creation of handleData */
  174. handleDataHandle = osThreadNew(Task_handleData, NULL, &handleData_attributes);
  175. /* USER CODE BEGIN RTOS_THREADS */
  176. /* add threads, ... */
  177. /* USER CODE END RTOS_THREADS */
  178. /* USER CODE BEGIN RTOS_EVENTS */
  179. /* add events, ... */
  180. /* USER CODE END RTOS_EVENTS */
  181. }
  182. /* USER CODE BEGIN Header_StartDefaultTask */
  183. /**
  184. * @brief Function implementing the defaultTask thread.
  185. * @param argument: Not used
  186. * @retval None
  187. */
  188. /* USER CODE END Header_StartDefaultTask */
  189. void StartDefaultTask(void *argument)
  190. {
  191. /* USER CODE BEGIN StartDefaultTask */
  192. /* Infinite loop */
  193. for(;;)
  194. {
  195. osDelay(1);
  196. }
  197. /* USER CODE END StartDefaultTask */
  198. }
  199. /* USER CODE BEGIN Header_Task_ec800_upload */
  200. /**
  201. * @brief Function implementing the ec800_dataUploa thread.
  202. * @param argument: Not used
  203. * @retval None
  204. */
  205. /* USER CODE END Header_Task_ec800_upload */
  206. void Task_ec800_upload(void *argument)
  207. {
  208. /* USER CODE BEGIN Task_ec800_upload */
  209. /* Infinite loop */
  210. for(;;)
  211. {
  212. task_ec800_content();
  213. osDelay(1);
  214. }
  215. /* USER CODE END Task_ec800_upload */
  216. }
  217. /* USER CODE BEGIN Header_Task_communication */
  218. /**
  219. * @brief Function implementing the communication thread.
  220. * @param argument: Not used
  221. * @retval None
  222. */
  223. /* USER CODE END Header_Task_communication */
  224. void Task_communication(void *argument)
  225. {
  226. /* USER CODE BEGIN Task_communication */
  227. /* Infinite loop */
  228. for(;;)
  229. {
  230. task_communication_content();
  231. osDelay(1);
  232. }
  233. /* USER CODE END Task_communication */
  234. }
  235. /* USER CODE BEGIN Header_Task_handleData */
  236. /**
  237. * @brief Function implementing the handleData thread.
  238. * @param argument: Not used
  239. * @retval None
  240. */
  241. /* USER CODE END Header_Task_handleData */
  242. void Task_handleData(void *argument)
  243. {
  244. /* USER CODE BEGIN Task_handleData */
  245. /* Infinite loop */
  246. for(;;)
  247. {
  248. osDelay(1);
  249. }
  250. /* USER CODE END Task_handleData */
  251. }
  252. /* Time2_Callback function */
  253. void Time2_Callback(void *argument)
  254. {
  255. /* USER CODE BEGIN Time2_Callback */
  256. /* USER CODE END Time2_Callback */
  257. }
  258. /* Private application code --------------------------------------------------*/
  259. /* USER CODE BEGIN Application */
  260. /* USER CODE END Application */