From afe0ca0a9551f2673b94bb9049d89fdfc46fd88a Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Mon, 27 Jan 2025 19:12:07 +0100 Subject: [PATCH] Refactor task setup chapter11_07 --- examples/chapter11_07/src/os/os_task.h | 26 +++++++++---------- .../chapter11_07/src/sys/start/sys_start.cpp | 17 +++++------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/chapter11_07/src/os/os_task.h b/examples/chapter11_07/src/os/os_task.h index 5c454297e..f0afad80a 100644 --- a/examples/chapter11_07/src/os/os_task.h +++ b/examples/chapter11_07/src/os/os_task.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2020 - 2024. +// Copyright Christopher Kormanyos 2020 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,18 +11,18 @@ #include #include - #define OS_TASK_STATIC_RESOURCES(name, size) \ - StackType_t os_task_##name##_stack_buffer[size]; \ - StaticTask_t os_task_##name##_cb_buffer - - #define OS_TASK_CREATE(name, param, prio) \ - xTaskCreateStatic(name, \ - #name, \ - sizeof(os_task_##name##_stack_buffer) / sizeof(StackType_t), \ - (void*) param, \ - prio, \ - &os_task_##name##_stack_buffer[0U], \ - &os_task_##name##_cb_buffer) + #define OS_TASK_CREATE(name, param, prio, size) \ + { \ + static StackType_t os_task_##name##_stack_buffer[size]; \ + static StaticTask_t os_task_##name##_cb_buffer; \ + xTaskCreateStatic(name, \ + #name, \ + sizeof(os_task_##name##_stack_buffer) / sizeof(StackType_t), \ + (void*) param, \ + prio, \ + &os_task_##name##_stack_buffer[0U], \ + &os_task_##name##_cb_buffer); \ + } #define OS_TASK_START_SCHEDULER() vTaskStartScheduler() diff --git a/examples/chapter11_07/src/sys/start/sys_start.cpp b/examples/chapter11_07/src/sys/start/sys_start.cpp index a08a9d686..2987989c9 100644 --- a/examples/chapter11_07/src/sys/start/sys_start.cpp +++ b/examples/chapter11_07/src/sys/start/sys_start.cpp @@ -9,14 +9,6 @@ #include #include -namespace -{ - // Setup the task static resources including the - // task control block structures and task stacks. - OS_TASK_STATIC_RESOURCES(app_led_task_background, 512U); - OS_TASK_STATIC_RESOURCES(app_led_task_toggle_led0, 32U); -} - #if defined(__AVR__) extern "C" int main(void) __attribute__((used, noinline)); #endif @@ -26,9 +18,12 @@ extern "C" int main(void) // Initialize the microcontroller abstraction layer. mcal::init(); - // Configure and create the OS tasks. - OS_TASK_CREATE(app_led_task_background, nullptr, 1U); - OS_TASK_CREATE(app_led_task_toggle_led0, nullptr, 3U); + // Configure and create the OS tasks. These macros + // also setup the task static resources including the + // task control block structures and task stacks. + + OS_TASK_CREATE(app_led_task_background, nullptr, 1U, 64U) + OS_TASK_CREATE(app_led_task_toggle_led0, nullptr, 3U, 64U) // Start the OS scheduler (and never return). OS_TASK_START_SCHEDULER();