8000 async_context_freertos: Add support for configSUPPORT_STATIC_ALLOCATION by mbrase · Pull Request #2436 · raspberrypi/pico-sdk · GitHub
[go: up one dir, main page]

Skip to content

async_context_freertos: Add support for configSUPPORT_STATIC_ALLOCATION #2436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mbrase
Copy link
@mbrase mbrase commented Apr 22, 2025

The implementation of async_context_freertos currently assumes that FreeRTOS has been configured with configSUPPORT_DYNAMIC_ALLOCATION, which causes it to allocate semaphores, timers and tasks from the heap. However, some projects may prefer configSUPPORT_STATIC_ALLOCATION, which requires memory to be alloc 8000 ated ahead of time. This change allows async_context_freertos to support either static or dynamic allocation.

The way this works is when configSUPPORT_STATIC_ALLOCATION is enabled, async_context_freertos struct will reserve extra space for the static objects (e.g. StaticSemaphore_t) and it will prefer to use the static creation functions (e.g. xSemaphoreCreateBinaryStatic()). For the task creation, the user will be responsible for allocating the stack memory and passing it in through the config. If a stack is not provided, then it will fallback to using dynamic allocation for the stack (e.g. xTaskCreate()).

@kilograham kilograham added this to the 2.1.2 milestone Apr 23, 2025
@kilograham kilograham self-assigned this Apr 23, 2025
@mbrase mbrase force-pushed the freertos-static-task branch 2 times, most recently from 968d67b to 636f390 Compare April 29, 2025 19:40
@mbrase
Copy link
Author
mbrase commented Apr 29, 2025

I pushed a new change that does not try to fall back to xTaskCreate() if no stack is provided. I also modified the cyw43_arch_init_default_async_context() function to statically allocate a stack when configSUPPORT_STATIC_ALLOCATION is enabled.

The implementation of async_context_freertos currently assumes that
FreeRTOS has been configured with `configSUPPORT_DYNAMIC_ALLOCATION`,
which causes it to allocate semaphores, timers and tasks from the heap.
However, some projects may prefer `configSUPPORT_STATIC_ALLOCATION`,
which requires memory to be allocated ahead of time. This change allows
async_context_freertos to support either static or dynamic allocation.

The way this works is when `configSUPPORT_STATIC_ALLOCATION` is enabled,
`async_context_freertos` struct will reserve extra space for the static
objects (e.g. `StaticSemaphore_t`) and it will prefer to use the static
creation functions (e.g. `xSemaphoreCreateBinaryStatic()`). For the task
creation, the user will be responsible for allocating the stack memory
and setting the task_stack field in `async_context_freertos_config_t`.
For convenience, The `cyw43_arch_init_default_async_context()` function
will reserve `CYW43_TASK_STACK_SIZE` words of stack space in static
memory.
/**
* \brief Pointer to stack memory for the async_context task.
* If this is not provided, then a stack will be allocated from the
* freertos heap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment still true?

@peterharperuk
Copy link
Contributor
peterharperuk commented May 30, 2025

LwIP NO_SYS=0 requires configSUPPORT_DYNAMIC_ALLOCATION so that's one use case for having both (it works fine) although I'm not sure why you'd bother?

In theory you can use your own async context therefore bypassing
cyw43_arch_init_default_async_context, which would leave
cyw43_async_context_freertos_task_stack unused.

Add a #define for this rare situation.
7215 Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0