-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: develop
Are you sure you want to change the base?
Conversation
src/rp2_common/pico_async_context/include/pico/async_context_freertos.h
Outdated
Show resolved
Hide resolved
968d67b
to
636f390
Compare
I pushed a new change that does not try to fall back to |
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.
636f390
to
456856f
Compare
/** | ||
* \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. |
There was a problem hiding this comment.
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?
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.
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 preferconfigSUPPORT_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()
).