freertos(6998).c 7.1 KB

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