1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 /// @defgroup FreeRTOS_application_functions
16 ///
17 /// FreeRTOS requires the application to implement certain functions, depending
18 /// on its configuration.
19 ///
20 /// If static allocation (`configSUPPORT_STATIC_ALLOCATION`) is enabled and
21 /// `configKERNEL_PROVIDED_STATIC_MEMORY` is disabled, FreeRTOS requires
22 /// applications to implement functions that provide static memory for the idle
23 /// task and timer task. See https://www.freertos.org/a00110.html for details.
24 ///
25 /// Link against `"//third_party/freertos:support"` to include these function
26 /// implementations.
27 /// @{
28
29 #include <cstdint>
30
31 #include "FreeRTOS.h"
32 #include "task.h"
33 #include "timers.h"
34
35 extern "C" {
36
37 #if configSUPPORT_STATIC_ALLOCATION == 1 && \
38 (!defined(configKERNEL_PROVIDED_STATIC_MEMORY) || \
39 configKERNEL_PROVIDED_STATIC_MEMORY == 0)
40
41 #if ((tskKERNEL_VERSION_MAJOR == 11) && (tskKERNEL_VERSION_MINOR >= 1)) || \
42 tskKERNEL_VERSION_MAJOR > 11
43 #define TASK_STACK_SIZE_TYPE configSTACK_DEPTH_TYPE
44 #else
45 #define TASK_STACK_SIZE_TYPE uint32_t
46 #endif // tskKERNEL_VERSION_MAJOR >= 11
47
48 /// Allocates static memory for the idle task. Provides a
49 /// `configMINIMAL_STACK_SIZE` stack.
vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,TASK_STACK_SIZE_TYPE * pulIdleTaskStackSize)50 void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
51 StackType_t** ppxIdleTaskStackBuffer,
52 TASK_STACK_SIZE_TYPE* pulIdleTaskStackSize) {
53 static StackType_t idle_stack[configMINIMAL_STACK_SIZE];
54 static StaticTask_t idle_tcb;
55
56 *ppxIdleTaskTCBBuffer = &idle_tcb;
57 *ppxIdleTaskStackBuffer = idle_stack;
58 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
59 }
60
61 #if configUSE_TIMERS == 1
62
63 /// Allocates static memory for the timer task. Provides a
64 /// `configTIMER_TASK_STACK_DEPTH` stack.
vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBuffer,StackType_t ** ppxTimerTaskStackBuffer,TASK_STACK_SIZE_TYPE * pulTimerTaskStackSize)65 void vApplicationGetTimerTaskMemory(
66 StaticTask_t** ppxTimerTaskTCBBuffer,
67 StackType_t** ppxTimerTaskStackBuffer,
68 TASK_STACK_SIZE_TYPE* pulTimerTaskStackSize) {
69 static StackType_t timer_stack[configTIMER_TASK_STACK_DEPTH];
70 static StaticTask_t timer_tcb;
71
72 *ppxTimerTaskTCBBuffer = &timer_tcb;
73 *ppxTimerTaskStackBuffer = timer_stack;
74 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
75 }
76
77 #endif // configUSE_TIMERS == 1
78 #endif // configSUPPORT_STATIC_ALLOCATION == 1
79
80 } // extern "C"
81
82 /// @}
83