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) 2025 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 | |
---|
20 | /* Includes ------------------------------------------------------------------*/ |
---|
21 | #include "FreeRTOS.h" |
---|
22 | #include "task.h" |
---|
23 | #include "main.h" |
---|
24 | #include "cmsis_os.h" |
---|
25 | |
---|
26 | /* Private includes ----------------------------------------------------------*/ |
---|
27 | /* USER CODE BEGIN Includes */ |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | |
---|
31 | #include "queue.h" |
---|
32 | |
---|
33 | #include "keys_task.h" |
---|
34 | #include "eth_task.h" |
---|
35 | #include "mb_slave_task.h" |
---|
36 | #include "beeper_task.h" |
---|
37 | #include "onewire_task.h" |
---|
38 | #include "bme_task.h" |
---|
39 | #include "gui_task.h" |
---|
40 | #include "fan_task.h" |
---|
41 | |
---|
42 | /* USER CODE END Includes */ |
---|
43 | |
---|
44 | /* Private typedef -----------------------------------------------------------*/ |
---|
45 | typedef StaticTask_t osStaticThreadDef_t; |
---|
46 | /* USER CODE BEGIN PTD */ |
---|
47 | |
---|
48 | /* USER CODE END PTD */ |
---|
49 | |
---|
50 | /* Private define ------------------------------------------------------------*/ |
---|
51 | /* USER CODE BEGIN PD */ |
---|
52 | |
---|
53 | #define KEYS_TASK_STACK_DEPTH_WORDS (128U) |
---|
54 | #define ETH_TASK_STACK_DEPTH_WORDS (2048U) |
---|
55 | #define MB_SLAVE_TASK_STACK_DEPTH_WORDS (1024U) |
---|
56 | #define BEEPER_TASK_STACK_DEPTH_WORDS (128U) |
---|
57 | #define ONEWIRE_TASK_STACK_DEPTH_WORDS (128U) |
---|
58 | #define BME_TASK_STACK_DEPTH_WORDS (256U) |
---|
59 | #define GUI_TASK_STACK_DEPTH_WORDS (2048U) |
---|
60 | #define FAN_TASK_STACK_DEPTH_WORDS (256U) |
---|
61 | |
---|
62 | /* USER CODE END PD */ |
---|
63 | |
---|
64 | /* Private macro -------------------------------------------------------------*/ |
---|
65 | /* USER CODE BEGIN PM */ |
---|
66 | |
---|
67 | /* USER CODE END PM */ |
---|
68 | |
---|
69 | /* Private variables ---------------------------------------------------------*/ |
---|
70 | /* USER CODE BEGIN Variables */ |
---|
71 | |
---|
72 | static StackType_t keysTaskStackBuffer[KEYS_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
73 | static StackType_t ethTaskStackBuffer[ETH_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
74 | static StackType_t mbSlaveTaskStackBuffer[MB_SLAVE_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
75 | static StackType_t beeperTaskStackBuffer[BEEPER_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
76 | static StackType_t onewireTaskStackBuffer[ONEWIRE_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
77 | static StackType_t bmeTaskStackBuffer[BME_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
78 | static StackType_t guiTaskStackBuffer[GUI_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
79 | static StackType_t fanTaskStackBuffer[FAN_TASK_STACK_DEPTH_WORDS] __attribute__((section(".DTCM_RAM"))); |
---|
80 | |
---|
81 | static uint8_t beeperQueueStorageArea[BEEPER_QUEUE_SIZE * BEEPER_QUEUE_ITEM_SIZE] __attribute__((section(".DTCM_RAM"))); |
---|
82 | static uint8_t onewireQueueStorageArea[ONEWIRE_QUEUE_SIZE * ONEWIRE_QUEUE_ITEM_SIZE] __attribute__((section(".DTCM_RAM"))); |
---|
83 | |
---|
84 | static StaticTask_t keysTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
85 | static StaticTask_t ethTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
86 | static StaticTask_t mbSlaveTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
87 | static StaticTask_t beeperTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
88 | static StaticTask_t onewireTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
89 | static StaticTask_t bmeTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
90 | static StaticTask_t guiTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
91 | static StaticTask_t fanTaskBuffer __attribute__((section(".DTCM_RAM"))); |
---|
92 | |
---|
93 | static StaticQueue_t beeperQueueBuffer __attribute__((section(".DTCM_RAM"))); |
---|
94 | static StaticQueue_t onewireQueueBuffer __attribute__((section(".DTCM_RAM"))); |
---|
95 | |
---|
96 | static const char* const keysTaskName = "ScanKeysTask"; |
---|
97 | static const char* const ethTaskName = "EthTask"; |
---|
98 | static const char* const mbSlaveTaskName = "MBSlaveTask"; |
---|
99 | static const char* const beeperTaskName = "BeeperTask"; |
---|
100 | static const char* const onewireTaskName = "1WireTask"; |
---|
101 | static const char* const bmeTaskName = "BMETask"; |
---|
102 | static const char* const guiTaskName = "GUITask"; |
---|
103 | static const char* const fanTaskName = "GUITask"; |
---|
104 | |
---|
105 | /* USER CODE END Variables */ |
---|
106 | /* Definitions for mainTask */ |
---|
107 | osThreadId_t mainTaskHandle; |
---|
108 | uint32_t mainTaskBuffer[ 512 ]; |
---|
109 | osStaticThreadDef_t mainTaskControlBlock; |
---|
110 | const osThreadAttr_t mainTask_attributes = { |
---|
111 | .name = "mainTask", |
---|
112 | .cb_mem = &mainTaskControlBlock, |
---|
113 | .cb_size = sizeof(mainTaskControlBlock), |
---|
114 | .stack_mem = &mainTaskBuffer[0], |
---|
115 | .stack_size = sizeof(mainTaskBuffer), |
---|
116 | .priority = (osPriority_t) osPriorityNormal, |
---|
117 | }; |
---|
118 | |
---|
119 | /* Private function prototypes -----------------------------------------------*/ |
---|
120 | /* USER CODE BEGIN FunctionPrototypes */ |
---|
121 | |
---|
122 | /* USER CODE END FunctionPrototypes */ |
---|
123 | |
---|
124 | void mainTaskStart(void *argument); |
---|
125 | |
---|
126 | void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ |
---|
127 | |
---|
128 | /* Hook prototypes */ |
---|
129 | void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName); |
---|
130 | |
---|
131 | /* USER CODE BEGIN 4 */ |
---|
132 | void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName) |
---|
133 | { |
---|
134 | /* Run time stack overflow checking is performed if |
---|
135 | configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is |
---|
136 | called if a stack overflow is detected. */ |
---|
137 | } |
---|
138 | /* USER CODE END 4 */ |
---|
139 | |
---|
140 | /* USER CODE BEGIN PREPOSTSLEEP */ |
---|
141 | __weak void PreSleepProcessing(uint32_t ulExpectedIdleTime) |
---|
142 | { |
---|
143 | /* place for user code */ |
---|
144 | } |
---|
145 | |
---|
146 | __weak void PostSleepProcessing(uint32_t ulExpectedIdleTime) |
---|
147 | { |
---|
148 | /* place for user code */ |
---|
149 | } |
---|
150 | /* USER CODE END PREPOSTSLEEP */ |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief FreeRTOS initialization |
---|
154 | * @param None |
---|
155 | * @retval None |
---|
156 | */ |
---|
157 | void MX_FREERTOS_Init(void) { |
---|
158 | /* USER CODE BEGIN Init */ |
---|
159 | |
---|
160 | /* USER CODE END Init */ |
---|
161 | |
---|
162 | /* USER CODE BEGIN RTOS_MUTEX */ |
---|
163 | /* add mutexes, ... */ |
---|
164 | /* USER CODE END RTOS_MUTEX */ |
---|
165 | |
---|
166 | /* USER CODE BEGIN RTOS_SEMAPHORES */ |
---|
167 | /* add semaphores, ... */ |
---|
168 | /* USER CODE END RTOS_SEMAPHORES */ |
---|
169 | |
---|
170 | /* USER CODE BEGIN RTOS_TIMERS */ |
---|
171 | /* start timers, add new ones, ... */ |
---|
172 | /* USER CODE END RTOS_TIMERS */ |
---|
173 | |
---|
174 | /* USER CODE BEGIN RTOS_QUEUES */ |
---|
175 | |
---|
176 | beeperQueue = xQueueCreateStatic(BEEPER_QUEUE_SIZE, BEEPER_QUEUE_ITEM_SIZE, beeperQueueStorageArea, &beeperQueueBuffer); |
---|
177 | if (beeperQueue == NULL) printf("Cannot create Beeper Queue!\n"); |
---|
178 | |
---|
179 | onewireQueue = xQueueCreateStatic(ONEWIRE_QUEUE_SIZE, ONEWIRE_QUEUE_ITEM_SIZE, onewireQueueStorageArea, &onewireQueueBuffer); |
---|
180 | if (onewireQueue == NULL) printf("Cannot create 1-Wire Queue!\n"); |
---|
181 | |
---|
182 | /* USER CODE END RTOS_QUEUES */ |
---|
183 | |
---|
184 | /* Create the thread(s) */ |
---|
185 | /* creation of mainTask */ |
---|
186 | mainTaskHandle = osThreadNew(mainTaskStart, NULL, &mainTask_attributes); |
---|
187 | |
---|
188 | /* USER CODE BEGIN RTOS_THREADS */ |
---|
189 | /* add threads, ... */ |
---|
190 | |
---|
191 | TaskHandle_t r = xTaskCreateStatic(keysTaskStart, keysTaskName, KEYS_TASK_STACK_DEPTH_WORDS, NULL, 24, keysTaskStackBuffer, &keysTaskBuffer); |
---|
192 | if (r == NULL) printf("Cannot create %s!\n", keysTaskName); |
---|
193 | |
---|
194 | r = xTaskCreateStatic(ethTaskStart, ethTaskName, ETH_TASK_STACK_DEPTH_WORDS, NULL, 24, ethTaskStackBuffer, ðTaskBuffer); |
---|
195 | if (r == NULL) printf("Cannot create %s!\n", ethTaskName); |
---|
196 | |
---|
197 | r = xTaskCreateStatic(mbSlaveTaskStart, mbSlaveTaskName, MB_SLAVE_TASK_STACK_DEPTH_WORDS, NULL, 24, mbSlaveTaskStackBuffer, &mbSlaveTaskBuffer); |
---|
198 | if (r == NULL) printf("Cannot create %s!\n", mbSlaveTaskName); |
---|
199 | |
---|
200 | r = xTaskCreateStatic(beeperTaskStart, beeperTaskName, BEEPER_TASK_STACK_DEPTH_WORDS, NULL, 24, beeperTaskStackBuffer, &beeperTaskBuffer); |
---|
201 | if (r == NULL) printf("Cannot create %s!\n", beeperTaskName); |
---|
202 | |
---|
203 | r = xTaskCreateStatic(onewireTaskStart, onewireTaskName, ONEWIRE_TASK_STACK_DEPTH_WORDS, NULL, 24, onewireTaskStackBuffer, &onewireTaskBuffer); |
---|
204 | if (r == NULL) printf("Cannot create %s!\n", onewireTaskName); |
---|
205 | |
---|
206 | r = xTaskCreateStatic(bmeTaskStart, bmeTaskName, BME_TASK_STACK_DEPTH_WORDS, NULL, 24, bmeTaskStackBuffer, &bmeTaskBuffer); |
---|
207 | if (r == NULL) printf("Cannot create %s!\n", bmeTaskName); |
---|
208 | |
---|
209 | r = xTaskCreateStatic(guiTaskStart, guiTaskName, GUI_TASK_STACK_DEPTH_WORDS, NULL, 24, guiTaskStackBuffer, &guiTaskBuffer); |
---|
210 | if (r == NULL) printf("Cannot create %s!\n", guiTaskName); |
---|
211 | |
---|
212 | r = xTaskCreateStatic(fanTaskStart, fanTaskName, FAN_TASK_STACK_DEPTH_WORDS, NULL, 24, fanTaskStackBuffer, &fanTaskBuffer); |
---|
213 | if (r == NULL) printf("Cannot create %s!\n", fanTaskName); |
---|
214 | |
---|
215 | /* USER CODE END RTOS_THREADS */ |
---|
216 | |
---|
217 | /* USER CODE BEGIN RTOS_EVENTS */ |
---|
218 | /* add events, ... */ |
---|
219 | /* USER CODE END RTOS_EVENTS */ |
---|
220 | |
---|
221 | } |
---|
222 | |
---|
223 | /* USER CODE BEGIN Header_mainTaskStart */ |
---|
224 | /** |
---|
225 | * @brief Function implementing the mainTask thread. |
---|
226 | * @param argument: Not used |
---|
227 | * @retval None |
---|
228 | */ |
---|
229 | /* USER CODE END Header_mainTaskStart */ |
---|
230 | __weak void mainTaskStart(void *argument) |
---|
231 | { |
---|
232 | /* USER CODE BEGIN mainTaskStart */ |
---|
233 | |
---|
234 | UNUSED(argument); |
---|
235 | |
---|
236 | /* Infinite loop */ |
---|
237 | for(;;) |
---|
238 | { |
---|
239 | osDelay(1); |
---|
240 | } |
---|
241 | /* USER CODE END mainTaskStart */ |
---|
242 | } |
---|
243 | |
---|
244 | /* Private application code --------------------------------------------------*/ |
---|
245 | /* USER CODE BEGIN Application */ |
---|
246 | |
---|
247 | /* USER CODE END Application */ |
---|
248 | |
---|