ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
freertos_task.hpp
Go to the documentation of this file.
1
5#ifndef ELEC_C7222_UTILS_FREERTOS_TASK_HPP
6#define ELEC_C7222_UTILS_FREERTOS_TASK_HPP
7
8#include <cstdint>
9#include <functional>
10#include <limits>
11
12#include "non_copyable.hpp"
13
14namespace c7222 {
15
37 public:
39 using TaskFunction = std::function<void(void*)>;
41 static constexpr std::uint32_t kInfinite = std::numeric_limits<std::uint32_t>::max();
42
44 FreeRtosTask() = default;
53 FreeRtosTask(const char* name,
54 std::uint32_t stack_depth_words,
55 std::uint32_t priority,
56 TaskFunction task_function,
57 void* task_arg = nullptr);
58
63 bool Initialize(const char* name,
64 std::uint32_t stack_depth_words,
65 std::uint32_t priority,
66 TaskFunction task_function,
67 void* task_arg = nullptr);
68
71
77 bool Delete(std::uint32_t ticks_to_wait = 0);
79 bool Suspend();
81 bool Resume();
84
86 bool SetPriority(std::uint32_t priority);
88 std::uint32_t GetPriority() const;
89
91 bool IsValid() const;
93 bool IsRunning() const;
95 void* GetHandle() const;
96
98 static void Delay(std::uint32_t ticks);
100 static void Yield();
102 static std::uint32_t GetTickCount();
104 static void StartScheduler();
106 static std::uint32_t MsToTicks(std::uint32_t milliseconds);
108 static std::uint32_t IdlePriority();
109
116
117 private:
118 void* handle_{nullptr};
119 TaskFunction task_function_{nullptr};
120 void* task_arg_{nullptr};
121 std::uint32_t priority_{0};
122};
123
124} // namespace c7222
125
126#endif // ELEC_C7222_UTILS_FREERTOS_TASK_HPP
Ownership-based wrapper for a task/thread execution object.
Definition freertos_task.hpp:36
void RunTaskBody()
Internal bridge used by platform task-entry trampolines.
static std::uint32_t GetTickCount()
bool IsRunning() const
bool Delete(std::uint32_t ticks_to_wait=0)
Delete the task.
static void Delay(std::uint32_t ticks)
Delay current task for a number of ticks.
static constexpr std::uint32_t kInfinite
Sentinel tick value representing an infinite wait.
Definition freertos_task.hpp:41
std::uint32_t GetPriority() const
Get current task priority.
static std::uint32_t MsToTicks(std::uint32_t milliseconds)
Convert milliseconds to scheduler ticks.
FreeRtosTask()=default
Construct an uninitialized task wrapper.
static void StartScheduler()
Start the scheduler.
static std::uint32_t IdlePriority()
FreeRtosTask(const char *name, std::uint32_t stack_depth_words, std::uint32_t priority, TaskFunction task_function, void *task_arg=nullptr)
Construct and initialize a task.
static void Yield()
Yield current task.
bool SetPriority(std::uint32_t priority)
Set task priority.
bool Initialize(const char *name, std::uint32_t stack_depth_words, std::uint32_t priority, TaskFunction task_function, void *task_arg=nullptr)
Initialize (or re-initialize) a task.
bool Suspend()
Suspend the task.
bool ResumeFromISR()
Resume the task from ISR context.
bool IsValid() const
~FreeRtosTask()
Delete owned task resource if initialized.
void * GetHandle() const
bool Resume()
Resume the task from task context.
std::function< void(void *)> TaskFunction
Task callable signature.
Definition freertos_task.hpp:39
Disable both copy and move operations.
Definition non_copyable.hpp:75
C7222 course abstractions namespace.
Definition ble.hpp:20
Base classes to control copy/move semantics.