xref: /aosp_15_r20/external/pigweed/third_party/freertos/static_task_allocation.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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 /// Allocates static memory for the idle task. Provides a
42 /// `configMINIMAL_STACK_SIZE` stack.
vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize)43 void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
44                                    StackType_t** ppxIdleTaskStackBuffer,
45                                    uint32_t* pulIdleTaskStackSize) {
46   static StackType_t idle_stack[configMINIMAL_STACK_SIZE];
47   static StaticTask_t idle_tcb;
48 
49   *ppxIdleTaskTCBBuffer = &idle_tcb;
50   *ppxIdleTaskStackBuffer = idle_stack;
51   *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
52 }
53 
54 #if configUSE_TIMERS == 1
55 
56 /// Allocates static memory for the timer task. Provides a
57 /// `configTIMER_TASK_STACK_DEPTH` stack.
vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBuffer,StackType_t ** ppxTimerTaskStackBuffer,uint32_t * pulTimerTaskStackSize)58 void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
59                                     StackType_t** ppxTimerTaskStackBuffer,
60                                     uint32_t* pulTimerTaskStackSize) {
61   static StackType_t timer_stack[configTIMER_TASK_STACK_DEPTH];
62   static StaticTask_t timer_tcb;
63 
64   *ppxTimerTaskTCBBuffer = &timer_tcb;
65   *ppxTimerTaskStackBuffer = timer_stack;
66   *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
67 }
68 
69 #endif  // configUSE_TIMERS == 1
70 #endif  // configSUPPORT_STATIC_ALLOCATION == 1
71 
72 }  // extern "C"
73 
74 /// @}
75