Skip to content

Commit

Permalink
Merge pull request #601 from ckormanyos/refactor_11_07
Browse files Browse the repository at this point in the history
Refactor task setup chapter11_07
  • Loading branch information
ckormanyos authored Jan 27, 2025
2 parents 7e4d1e8 + afe0ca0 commit 6ef81a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
26 changes: 13 additions & 13 deletions examples/chapter11_07/src/os/os_task.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -11,18 +11,18 @@
#include <FreeRTOS.h>
#include <task.h>

#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()

Expand Down
17 changes: 6 additions & 11 deletions examples/chapter11_07/src/sys/start/sys_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
#include <mcal/mcal.h>
#include <os/os_task.h>

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
Expand All @@ -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();
Expand Down

0 comments on commit 6ef81a3

Please sign in to comment.