freertos.c 8.2 KB

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