ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::FreeRtosTask Class Reference

Ownership-based wrapper for a task/thread execution object. More...

#include <freertos_task.hpp>

Inheritance diagram for c7222::FreeRtosTask:
Inheritance graph
Collaboration diagram for c7222::FreeRtosTask:
Collaboration graph

Public Types

using TaskFunction = std::function< void(void *)>
 Task callable signature.
 

Public Member Functions

 FreeRtosTask ()=default
 Construct an uninitialized task wrapper.
 
 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.
 
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.
 
 ~FreeRtosTask ()
 Delete owned task resource if initialized.
 
bool Delete (std::uint32_t ticks_to_wait=0)
 Delete the task.
 
bool Suspend ()
 Suspend the task.
 
bool Resume ()
 Resume the task from task context.
 
bool ResumeFromISR ()
 Resume the task from ISR context.
 
bool SetPriority (std::uint32_t priority)
 Set task priority.
 
std::uint32_t GetPriority () const
 Get current task priority.
 
bool IsValid () const
 
bool IsRunning () const
 
void * GetHandle () const
 
void RunTaskBody ()
 Internal bridge used by platform task-entry trampolines.
 
- Public Member Functions inherited from c7222::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=default
 
NonCopyableoperator= (NonCopyable &&)=default
 
- Public Member Functions inherited from c7222::NonMovable
 NonMovable (const NonMovable &)=default
 
NonMovableoperator= (const NonMovable &)=default
 
 NonMovable (NonMovable &&)=delete
 
NonMovableoperator= (NonMovable &&)=delete
 

Static Public Member Functions

static void Delay (std::uint32_t ticks)
 Delay current task for a number of ticks.
 
static void Yield ()
 Yield current task.
 
static std::uint32_t GetTickCount ()
 
static void StartScheduler ()
 Start the scheduler.
 
static std::uint32_t MsToTicks (std::uint32_t milliseconds)
 Convert milliseconds to scheduler ticks.
 
static std::uint32_t IdlePriority ()
 

Static Public Attributes

static constexpr std::uint32_t kInfinite = std::numeric_limits<std::uint32_t>::max()
 Sentinel tick value representing an infinite wait.
 

Additional Inherited Members

- Protected Member Functions inherited from c7222::NonCopyableNonMovable
 NonCopyableNonMovable ()=default
 
 ~NonCopyableNonMovable ()=default
 
- Protected Member Functions inherited from c7222::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 
- Protected Member Functions inherited from c7222::NonMovable
 NonMovable ()=default
 
 ~NonMovable ()=default
 

Detailed Description

Ownership-based wrapper for a task/thread execution object.

The wrapper owns a task handle and stores a C++ callable task body. Platform implementations bridge the native task entry point to RunTaskBody(). RAII here refers to task-handle cleanup on destruction.

Typical usage:

void Worker(void* arg) {
(void)arg;
for(;;) {
}
}
c7222::FreeRtosTask task("worker", 1024, c7222::FreeRtosTask::IdlePriority() + 1, Worker, nullptr);
Ownership-based wrapper for a task/thread execution object.
Definition freertos_task.hpp:36
static void Delay(std::uint32_t ticks)
Delay current task for a number of ticks.
static std::uint32_t MsToTicks(std::uint32_t milliseconds)
Convert milliseconds to scheduler ticks.
static std::uint32_t IdlePriority()

Member Typedef Documentation

◆ TaskFunction

using c7222::FreeRtosTask::TaskFunction = std::function<void(void*)>

Task callable signature.

Constructor & Destructor Documentation

◆ FreeRtosTask() [1/2]

c7222::FreeRtosTask::FreeRtosTask ( )
default

Construct an uninitialized task wrapper.

◆ FreeRtosTask() [2/2]

c7222::FreeRtosTask::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.

Parameters
nameTask name.
stack_depth_wordsStack depth in words.
priorityInitial task priority.
task_functionCallable run as the task body.
task_argArgument passed to task_function.

◆ ~FreeRtosTask()

c7222::FreeRtosTask::~FreeRtosTask ( )

Delete owned task resource if initialized.

Member Function Documentation

◆ Delay()

static void c7222::FreeRtosTask::Delay ( std::uint32_t  ticks)
static

Delay current task for a number of ticks.

Here is the caller graph for this function:

◆ Delete()

bool c7222::FreeRtosTask::Delete ( std::uint32_t  ticks_to_wait = 0)

Delete the task.

Parameters
ticks_to_waitOptional platform-specific wait.
Returns
true if a task was deleted.

◆ GetHandle()

void * c7222::FreeRtosTask::GetHandle ( ) const
Returns
Opaque platform task handle.

◆ GetPriority()

std::uint32_t c7222::FreeRtosTask::GetPriority ( ) const

Get current task priority.

◆ GetTickCount()

static std::uint32_t c7222::FreeRtosTask::GetTickCount ( )
static
Returns
Current scheduler tick count.
Here is the caller graph for this function:

◆ IdlePriority()

static std::uint32_t c7222::FreeRtosTask::IdlePriority ( )
static
Returns
Idle task priority.
Here is the caller graph for this function:

◆ Initialize()

bool c7222::FreeRtosTask::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.

Returns
true on successful creation/start.
Here is the caller graph for this function:

◆ IsRunning()

bool c7222::FreeRtosTask::IsRunning ( ) const
Returns
true if the task is currently considered running/alive.

◆ IsValid()

bool c7222::FreeRtosTask::IsValid ( ) const
Returns
true if wrapper owns a valid task handle.

◆ MsToTicks()

static std::uint32_t c7222::FreeRtosTask::MsToTicks ( std::uint32_t  milliseconds)
static

Convert milliseconds to scheduler ticks.

Here is the caller graph for this function:

◆ Resume()

bool c7222::FreeRtosTask::Resume ( )

Resume the task from task context.

◆ ResumeFromISR()

bool c7222::FreeRtosTask::ResumeFromISR ( )

Resume the task from ISR context.

◆ RunTaskBody()

void c7222::FreeRtosTask::RunTaskBody ( )

Internal bridge used by platform task-entry trampolines.

Public by design to avoid friend declarations for C-linkage bridge code.

◆ SetPriority()

bool c7222::FreeRtosTask::SetPriority ( std::uint32_t  priority)

Set task priority.

◆ StartScheduler()

static void c7222::FreeRtosTask::StartScheduler ( )
static

Start the scheduler.

Here is the caller graph for this function:

◆ Suspend()

bool c7222::FreeRtosTask::Suspend ( )

Suspend the task.

◆ Yield()

static void c7222::FreeRtosTask::Yield ( )
static

Yield current task.

Member Data Documentation

◆ kInfinite

constexpr std::uint32_t c7222::FreeRtosTask::kInfinite = std::numeric_limits<std::uint32_t>::max()
staticconstexpr

Sentinel tick value representing an infinite wait.


The documentation for this class was generated from the following file: