ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
freertos_static_alloc.c
Go to the documentation of this file.
1/*
2 * FreeRTOS static allocation callbacks for LibreTiny platforms.
3 *
4 * Required when configSUPPORT_STATIC_ALLOCATION is enabled. These callbacks
5 * provide memory for the idle and timer tasks. Following ESP-IDF's approach,
6 * we allocate from the FreeRTOS heap (pvPortMalloc) rather than using truly
7 * static buffers, to avoid assumptions about memory layout.
8 *
9 * This enables xQueueCreateStatic, xTaskCreateStatic, etc. throughout ESPHome,
10 * allowing queue storage to live in BSS with zero runtime heap allocation.
11 */
12
13#ifdef USE_BK72XX
14
15#include <FreeRTOS.h>
16#include <task.h>
17
18#if (configSUPPORT_STATIC_ALLOCATION == 1)
19
20void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer,
21 uint32_t *pulIdleTaskStackSize) {
22 /* Stack grows down on ARM — allocate stack first, then TCB,
23 * so the stack does not grow into the TCB. */
24 StackType_t *stack = (StackType_t *) pvPortMalloc(configMINIMAL_STACK_SIZE * sizeof(StackType_t));
25 StaticTask_t *tcb = (StaticTask_t *) pvPortMalloc(sizeof(StaticTask_t));
26 configASSERT(stack != NULL);
27 configASSERT(tcb != NULL);
28
29 *ppxIdleTaskTCBBuffer = tcb;
30 *ppxIdleTaskStackBuffer = stack;
31 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
32}
33
34#if (configUSE_TIMERS == 1)
35
36void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer,
37 uint32_t *pulTimerTaskStackSize) {
38 StackType_t *stack = (StackType_t *) pvPortMalloc(configTIMER_TASK_STACK_DEPTH * sizeof(StackType_t));
39 StaticTask_t *tcb = (StaticTask_t *) pvPortMalloc(sizeof(StaticTask_t));
40 configASSERT(stack != NULL);
41 configASSERT(tcb != NULL);
42
43 *ppxTimerTaskTCBBuffer = tcb;
44 *ppxTimerTaskStackBuffer = stack;
45 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
46}
47
48#endif /* configUSE_TIMERS */
49
50#endif /* configSUPPORT_STATIC_ALLOCATION */
51
52#endif /* USE_BK72XX */
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize)
static void uint32_t