freertos.c 7.4 KB

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