Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions freertos/FreeRTOSConfig_examples_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t

/* Memory allocation related definitions. */
#ifndef configSUPPORT_STATIC_ALLOCATION
#define configSUPPORT_STATIC_ALLOCATION 0
#endif
#ifndef configSUPPORT_DYNAMIC_ALLOCATION
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#endif
#define configTOTAL_HEAP_SIZE (128*1024)
#define configAPPLICATION_ALLOCATED_HEAP 0

Expand Down
29 changes: 28 additions & 1 deletion freertos/hello_freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Example running FreeRTOS on 1 core
set(TARGET_NAME hello_freertos1)
add_executable(${TARGET_NAME}
hello_freertos.c
Expand All @@ -14,13 +15,14 @@ if(PICO_CYW43_SUPPORTED)
# For led support on pico_w
target_link_libraries(${TARGET_NAME} PRIVATE
pico_cyw43_arch_none
)
)
endif()
target_compile_definitions(${TARGET_NAME} PRIVATE
configNUMBER_OF_CORES=1
)
pico_add_extra_outputs(${TARGET_NAME})

# Example running FreeRTOS on 2 cores
set(TARGET_NAME hello_freertos2)
add_executable(${TARGET_NAME}
hello_freertos.c
Expand All @@ -37,6 +39,31 @@ if(PICO_CYW43_SUPPORTED)
# For led support on pico_w
target_link_libraries(${TARGET_NAME} PRIVATE
pico_cyw43_arch_none
)
endif()
pico_add_extra_outputs(${TARGET_NAME})

# Example running FreeRTOS on 2 cores with static RAM allocation
set(TARGET_NAME hello_freertos_static)
add_executable(${TARGET_NAME}
hello_freertos.c
)
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/..
)
target_link_libraries(${TARGET_NAME} PRIVATE
pico_async_context_freertos
FreeRTOS-Kernel-Static
pico_stdlib
)
target_compile_definitions(${TARGET_NAME} PRIVATE
configSUPPORT_STATIC_ALLOCATION=1
configSUPPORT_DYNAMIC_ALLOCATION=0
)
if(PICO_CYW43_SUPPORTED)
# For led support on pico_w
target_link_libraries(${TARGET_NAME} PRIVATE
pico_cyw43_arch_none
)
endif()
pico_add_extra_outputs(${TARGET_NAME})
23 changes: 21 additions & 2 deletions freertos/hello_freertos/hello_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ static async_context_t *example_async_context(void) {
async_context_freertos_config_t config = async_context_freertos_default_config();
config.task_priority = WORKER_TASK_PRIORITY; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY
config.task_stack_size = WORKER_TASK_STACK_SIZE; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE
#if configSUPPORT_STATIC_ALLOCATION
static StackType_t async_context_freertos_task_stack[WORKER_TASK_STACK_SIZE];
config.task_stack = async_context_freertos_task_stack;
#endif
if (!async_context_freertos_init(&async_context_instance, &config))
return NULL;
return &async_context_instance.core;
Expand Down Expand Up @@ -127,8 +131,15 @@ void main_task(__unused void *params) {
async_context_add_at_time_worker_in_ms(context, &worker_timeout, 0);
#if USE_LED
// start the led blinking
#if configSUPPORT_STATIC_ALLOCATION
static StackType_t blink_stack[BLINK_TASK_STACK_SIZE];
static StaticTask_t blink_buf;
xTaskCreateStatic(blink_task, "BlinkThread", BLINK_TASK_STACK_SIZE, NULL, BLINK_TASK_PRIORITY, blink_stack, &blink_buf);
#else
static_assert(configSUPPORT_DYNAMIC_ALLOCATION, "");
xTaskCreate(blink_task, "BlinkThread", BLINK_TASK_STACK_SIZE, NULL, BLINK_TASK_PRIORITY, NULL);
#endif
#endif // configSUPPORT_STATIC_ALLOCATION
#endif // USE_LED
int count = 0;
while(true) {
#if configNUMBER_OF_CORES > 1
Expand All @@ -146,11 +157,19 @@ void main_task(__unused void *params) {

void vLaunch( void) {
TaskHandle_t task;
#if configSUPPORT_STATIC_ALLOCATION
static StackType_t main_stack[MAIN_TASK_STACK_SIZE];
static StaticTask_t main_buf;
task = xTaskCreateStatic(main_task, "MainThread", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, main_stack, &main_buf);
#else
static_assert(configSUPPORT_DYNAMIC_ALLOCATION, "");
xTaskCreate(main_task, "MainThread", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &task);

#endif // configSUPPORT_STATIC_ALLOCATION
#if configUSE_CORE_AFFINITY && configNUMBER_OF_CORES > 1
// we must bind the main task to one core (well at least while the init is called)
vTaskCoreAffinitySet(task, 1);
#else
(void)task;
#endif

/* Start the tasks and timer running. */
Expand Down