Skip to content

Commit 981850d

Browse files
committed
Fix some code review issues
1 parent 6207c40 commit 981850d

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ These examples require you to set the `FREERTOS_KERNEL_PATH` to point to the Fre
115115

116116
App|Description
117117
---|---
118-
[hello_freertos](freertos/hello_freertos) | Examples that demonstrate how run FreeRTOS and tasks on 1 or 2 cores.
118+
[hello_freertos_one_core](freertos/hello_freertos) | Demonstrates how run FreeRTOS and tasks on one core
119+
[hello_freertos_two_cores](freertos/hello_freertos) | Demonstrates how run FreeRTOS and tasks on two cores.
120+
[hello_freertos_static_allocation](freertos/hello_freertos) | Demonstrates how run FreeRTOS on two cores with static RAM allocation.
119121

120122
### GPIO
121123

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,74 @@
11
# Example running FreeRTOS on 1 core
2-
set(TARGET_NAME hello_freertos1)
3-
add_executable(${TARGET_NAME}
2+
add_executable(hello_freertos_one_core
43
hello_freertos.c
54
)
6-
target_include_directories(${TARGET_NAME} PRIVATE
5+
target_include_directories(hello_freertos_one_core PRIVATE
76
${CMAKE_CURRENT_LIST_DIR}/..
87
)
9-
target_link_libraries(${TARGET_NAME} PRIVATE
8+
# Linking to FreeRTOS-Kernel-Heap4 means we use a dynamic heap for allocations
9+
target_link_libraries(hello_freertos_one_core PRIVATE
1010
pico_async_context_freertos
1111
FreeRTOS-Kernel-Heap4
1212
pico_stdlib
1313
)
14+
# Set the nunber of cores to 1.
15+
# This defaults to 2 in FreeRTOSConfig_examples_common.h if not defined in here
16+
target_compile_definitions(hello_freertos_one_core PRIVATE
17+
configNUMBER_OF_CORES=1
18+
)
1419
if(PICO_CYW43_SUPPORTED)
1520
# For led support on pico_w
16-
target_link_libraries(${TARGET_NAME} PRIVATE
21+
target_link_libraries(hello_freertos_one_core PRIVATE
1722
pico_cyw43_arch_none
1823
)
1924
endif()
20-
target_compile_definitions(${TARGET_NAME} PRIVATE
21-
configNUMBER_OF_CORES=1
22-
)
23-
pico_add_extra_outputs(${TARGET_NAME})
25+
pico_add_extra_outputs(hello_freertos_one_core)
2426

2527
# Example running FreeRTOS on 2 cores
26-
set(TARGET_NAME hello_freertos2)
27-
add_executable(${TARGET_NAME}
28+
add_executable(hello_freertos_two_cores
2829
hello_freertos.c
2930
)
30-
target_include_directories(${TARGET_NAME} PRIVATE
31+
target_include_directories(hello_freertos_two_cores PRIVATE
3132
${CMAKE_CURRENT_LIST_DIR}/..
3233
)
33-
target_link_libraries(${TARGET_NAME} PRIVATE
34+
# Linking to FreeRTOS-Kernel-Heap4 to use a dynamic heap for allocations
35+
target_link_libraries(hello_freertos_two_cores PRIVATE
3436
pico_async_context_freertos
3537
FreeRTOS-Kernel-Heap4
3638
pico_stdlib
3739
)
3840
if(PICO_CYW43_SUPPORTED)
3941
# For led support on pico_w
40-
target_link_libraries(${TARGET_NAME} PRIVATE
42+
target_link_libraries(hello_freertos_two_cores PRIVATE
4143
pico_cyw43_arch_none
4244
)
4345
endif()
44-
pico_add_extra_outputs(${TARGET_NAME})
46+
pico_add_extra_outputs(hello_freertos_two_cores)
4547

4648
# Example running FreeRTOS on 2 cores with static RAM allocation
47-
set(TARGET_NAME hello_freertos_static)
48-
add_executable(${TARGET_NAME}
49+
add_executable(hello_freertos_static_allocation
4950
hello_freertos.c
5051
)
51-
target_include_directories(${TARGET_NAME} PRIVATE
52+
target_include_directories(hello_freertos_static_allocation PRIVATE
5253
${CMAKE_CURRENT_LIST_DIR}/..
5354
)
54-
target_link_libraries(${TARGET_NAME} PRIVATE
55+
# Linking to FreeRTOS-Kernel-Static to use static memory instead of a dynamic heap for allocations
56+
target_link_libraries(hello_freertos_static_allocation PRIVATE
5557
pico_async_context_freertos
5658
FreeRTOS-Kernel-Static
5759
pico_stdlib
5860
)
59-
target_compile_definitions(${TARGET_NAME} PRIVATE
61+
# Change the configuration to just use static RAM allocation
62+
# If configSUPPORT_DYNAMIC_ALLOCATION is left undefined it will default to 1
63+
# If configSUPPORT_STATIC_ALLOCATION is left undefined it will default to 0
64+
target_compile_definitions(hello_freertos_static_allocation PRIVATE
6065
configSUPPORT_STATIC_ALLOCATION=1
6166
configSUPPORT_DYNAMIC_ALLOCATION=0
6267
)
6368
if(PICO_CYW43_SUPPORTED)
6469
# For led support on pico_w
65-
target_link_libraries(${TARGET_NAME} PRIVATE
70+
target_link_libraries(hello_freertos_static_allocation PRIVATE
6671
pico_cyw43_arch_none
6772
)
6873
endif()
69-
pico_add_extra_outputs(${TARGET_NAME})
74+
pico_add_extra_outputs(hello_freertos_static_allocation)

freertos/hello_freertos/hello_freertos.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
static async_context_freertos_t async_context_instance;
4949

5050
// Create an async context
51-
static async_context_t *example_async_context(void) {
51+
static async_context_t *create_async_context(void) {
5252
async_context_freertos_config_t config = async_context_freertos_default_config();
5353
config.task_priority = WORKER_TASK_PRIORITY; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_PRIORITY
5454
config.task_stack_size = WORKER_TASK_STACK_SIZE; // defaults to ASYNC_CONTEXT_DEFAULT_FREERTOS_TASK_STACK_SIZE
@@ -63,7 +63,7 @@ static async_context_t *example_async_context(void) {
6363

6464
#if USE_LED
6565
// Turn led on or off
66-
static void pico_set_led(bool led_on) {
66+
static void set_led(bool led_on) {
6767
#if defined PICO_DEFAULT_LED_PIN
6868
gpio_put(PICO_DEFAULT_LED_PIN, led_on);
6969
#elif defined(CYW43_WL_GPIO_LED_PIN)
@@ -72,20 +72,20 @@ static void pico_set_led(bool led_on) {
7272
}
7373

7474
// Initialise led
75-
static void pico_init_led(void) {
75+
static void init_led(void) {
7676
#if defined PICO_DEFAULT_LED_PIN
7777
gpio_init(PICO_DEFAULT_LED_PIN);
7878
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
7979
#elif defined(CYW43_WL_GPIO_LED_PIN)
8080
hard_assert(cyw43_arch_init() == PICO_OK);
81-
pico_set_led(false); // make sure cyw43 is started
81+
set_led(false); // make sure cyw43 is started
8282
#endif
8383
}
8484

8585
void blink_task(__unused void *params) {
8686
bool on = false;
8787
printf("blink_task starts\n");
88-
pico_init_led();
88+
init_led();
8989
while (true) {
9090
#if configNUMBER_OF_CORES > 1
9191
static int last_core_id = -1;
@@ -94,7 +94,7 @@ void blink_task(__unused void *params) {
9494
printf("blink task is on core %d\n", last_core_id);
9595
}
9696
#endif
97-
pico_set_led(on);
97+
set_led(on);
9898
on = !on;
9999

100100
#if LED_BUSY_WAIT
@@ -126,7 +126,7 @@ static void do_work(async_context_t *context, async_at_time_worker_t *worker) {
126126
async_at_time_worker_t worker_timeout = { .do_work = do_work };
127127

128128
void main_task(__unused void *params) {
129-
async_context_t *context = example_async_context();
129+
async_context_t *context = create_async_context();
130130
// start the worker running
131131
async_context_add_at_time_worker_in_ms(context, &worker_timeout, 0);
132132
#if USE_LED

0 commit comments

Comments
 (0)