tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
task.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_FREERTOS_TASK_HPP
4#define TETL_FREERTOS_TASK_HPP
5
6#include <etl/version.hpp>
7
8#include <etl/cstddef.hpp>
9#include <etl/utility.hpp>
10
11#if defined(TETL_FREERTOS_USE_STUBS)
13#endif
14
17struct never {
18 [[nodiscard]] auto operator()() const -> bool { return false; }
19};
20
22struct forever {
23 [[nodiscard]] auto operator()() const -> bool { return true; }
24};
25
27template <etl::size_t Count>
28struct times {
30
31 [[nodiscard]] auto operator()() -> bool { return (run_count-- != 0); }
32};
33
35using once = times<1>;
36
39
41template <typename TaskType>
42inline auto rtos_task(void* task) -> void
43{
44 static_cast<TaskType*>(task)->run();
45}
46
48template <typename TaskType>
49inline auto create_task(
50 TaskType& task,
51 char const* const name,
53 UBaseType_t prio = 0,
54 TaskHandle_t* const handle = nullptr
55) -> void
56{
57 xTaskCreate(rtos_task<TaskType>, name, stack, static_cast<void*>(&task), prio, handle);
58}
59
62inline auto delete_task(TaskHandle_t task) -> void { vTaskDelete(task); }
63
66inline auto start_scheduler() -> void { vTaskStartScheduler(); }
67
68namespace this_task {
80auto yield() -> void;
81
98auto sleep_for(etl::uint32_t ticks) -> void;
99
117auto sleep_until(etl::uint32_t& prev, etl::uint32_t increment) -> void;
118
119inline auto yield() -> void { taskYIELD(); }
120
121inline auto sleep_for(etl::uint32_t ticks) -> void { vTaskDelay(ticks); }
122
123inline auto sleep_until(etl::uint32_t& prev, etl::uint32_t increment) -> void { vTaskDelayUntil(&prev, increment); }
124} // namespace this_task
125
126} // namespace etl::experimental::freertos
127
128#endif // TETL_FREERTOS_TASK_HPP
constexpr auto prev(BidirIt it, typename iterator_traits< BidirIt >::difference_type n=1) -> BidirIt
Return the nth predecessor of iterator it.
Definition prev.hpp:14
auto sleep_for(etl::uint32_t ticks) -> void
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on th...
Definition task.hpp:121
auto sleep_until(etl::uint32_t &prev, etl::uint32_t increment) -> void
Delay a task until a specified time. This function can be used by periodic tasks to ensure a constant...
Definition task.hpp:123
auto yield() -> void
Request a context switch to another task.
Definition task.hpp:119
Definition queue.hpp:15
auto delete_task(TaskHandle_t task) -> void
Delete a rtos task. If handle is nullptr, the current task will be deleted.
Definition task.hpp:62
auto rtos_task(void *task) -> void
Wrapper for an rtos task struct. Calls the run() member.
Definition task.hpp:42
auto create_task(TaskType &task, char const *const name, uint16_t stack, UBaseType_t prio=0, TaskHandle_t *const handle=nullptr) -> void
Create a rtos task. TaskType needs a void run() public method.
Definition task.hpp:49
times< 1 > once
Runs the task loop once.
Definition task.hpp:35
times< 2 > twice
Runs the task loop twice.
Definition task.hpp:38
auto start_scheduler() -> void
Start the RTOS, this function will never return and will schedule the tasks.
Definition task.hpp:66
TETL_BUILTIN_UINT16 uint16_t
Unsigned integer type with width of exactly 16 bits.
Definition uint_t.hpp:14
TETL_BUILTIN_UINT32 uint32_t
Unsigned integer type with width of exactly 32 bits.
Definition uint_t.hpp:17
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
Runs the task loop forever.
Definition task.hpp:22
auto operator()() const -> bool
Definition task.hpp:23
Runs the task loop 0 times.
Definition task.hpp:17
auto operator()() const -> bool
Definition task.hpp:18
Runs the task loop Count times.
Definition task.hpp:28
etl::size_t run_count
Definition task.hpp:29
auto operator()() -> bool
Definition task.hpp:31
The stack class is a container adapter that gives the programmer the functionality of a stack - speci...
Definition stack.hpp:31
tskTaskControlBlock * TaskHandle_t
Definition stubs.hpp:35
unsigned long UBaseType_t
Definition stubs.hpp:14
auto vTaskStartScheduler() -> void
Definition stubs.hpp:53
auto xTaskCreate(TaskFunction_t pvTaskCode, char const *const pcName, configSTACK_DEPTH_TYPE usStackDepth, void *const pvParameters, UBaseType_t uxPriority, TaskHandle_t *const pxCreatedTask) -> BaseType_t
Definition stubs.hpp:38
auto vTaskDelete(TaskHandle_t xTask) -> void
Definition stubs.hpp:51
#define taskYIELD()
Definition stubs.hpp:30
auto vTaskDelayUntil(TickType_t *const pxPreviousWakeTime, TickType_t const xTimeIncrement) -> void
Definition stubs.hpp:57
auto vTaskDelay(TickType_t const xTicksToDelay) -> void
Definition stubs.hpp:55