Wrapper class around FreeRTOS's implementation of a task. More...
#include <mn_task.hpp>
Public Types | |
enum class | priority { Idle = MN_THREAD_CONFIG_CORE_PRIORITY_IDLE , Low = MN_THREAD_CONFIG_CORE_PRIORITY_LOW , Normal = MN_THREAD_CONFIG_CORE_PRIORITY_NORM , HalfCritical = MN_THREAD_CONFIG_CORE_PRIORITY_HALFCRT , Urgent = MN_THREAD_CONFIG_CORE_PRIORITY_URGENT , Critical = MN_THREAD_CONFIG_CORE_PRIORITY_CRITICAL } |
Task priority. More... | |
enum class | state { Running = 0 , Ready , Blocked , Suspended , Deleted } |
using | native_handle_type = xTaskHandle |
Public Member Functions | |
basic_task () noexcept | |
basic_task (std::string strName, basic_task::priority uiPriority=basic_task::priority::Normal, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE) noexcept | |
virtual | ~basic_task () |
Our destructor. Delete the task. More... | |
virtual int | start (int uiCore=MN_THREAD_CONFIG_DEFAULT_CORE) |
Create and starts the Task. More... | |
int | kill () |
Destroy and delete the task and call the function 'on_kill'. More... | |
bool | is_running () |
Is the Task running? More... | |
std::string | get_name () |
Get the debug name of this task. More... | |
basic_task::priority | get_priority () |
Get the priority of this task. More... | |
unsigned short | get_stackdepth () |
Get the stack depth of this task. More... | |
xTaskHandle | get_handle () |
Accessor to get the task's backing task handle. There is no setter, on purpose. More... | |
int | get_return_value () |
Get the return value of this task - after run. More... | |
timespan_t | get_time_since_start () const |
Get the time since start of this task. More... | |
int32_t | get_id () |
Get the FreeRTOS task Numberid of this task. More... | |
int32_t | get_on_core () |
Get the core number of this task run. More... | |
void | set_priority (basic_task::priority uiPriority) |
Set the priority of this task. More... | |
void | suspend () |
Suspend this task. More... | |
void | resume () |
Resume a specific task. More... | |
bool | joinable () const noexcept |
int | join (unsigned int xTickTimeout=portMAX_DELAY) |
join the task, Wait in other task to end this task. More... | |
int | join (timespan_t time) |
join the task, Wait in other task to end this task. More... | |
int | wait (unsigned int xTimeOut) |
Wait for start the task. More... | |
int | wait (timespan_t time) |
Wait for start the task. More... | |
virtual void | on_start () |
This virtual function call on creating, use for user code It is optional whether you implement this or not. More... | |
virtual void | on_kill () |
This virtual function call on kill, use for user code It is optional whether you implement this or not. More... | |
virtual int | on_task () |
Implementation of your actual task code. You must override this function. More... | |
virtual void | on_cleanup () |
Called on exit from your on_task() routine. More... | |
state | get_state () |
Get the state of the task. More... | |
operator xTaskHandle () | |
Operator to get the task's backing task handle. More... | |
operator int () | |
Operator to get the ID assigned to the task. More... | |
bool | operator== (const basic_task &r) const |
bool | operator!= (const basic_task &r) const |
bool | operator< (const basic_task &r) const |
bool | operator> (const basic_task &r) const |
Static Public Member Functions | |
static void | suspend (basic_task *t) |
Suspend the given task. More... | |
static void | resume (basic_task *t) |
Resume the given task. More... | |
static void | yield () |
Yield the scheduler. More... | |
static void | sleep (unsigned int secs) |
sleep this task for n seconds More... | |
static void | usleep (unsigned int usec) |
sleep this task for n micro seconds More... | |
static void | nsleep (const timespan_t &req, timespan_t *rem) |
pause execution for a specified time More... | |
static uint32_t | get_tasks () |
Get current number of tasks. More... | |
static bool | is_current (basic_task *task) |
Is the given task the current running task ? More... | |
static basic_task * | get_self () |
Get the current task. More... | |
Static Protected Member Functions | |
static void | runtaskstub (void *parm) |
Adapter function that allows you to write a class specific on_task() function that interfaces with FreeRTOS. More... | |
Protected Attributes | |
LockType_t | m_runningMutex |
Lock Objekt for task safty. More... | |
LockType_t | m_contextMutext |
LockType_t | m_continuemutex |
std::string | m_strName |
The name of this task. More... | |
basic_task::priority | m_uiPriority |
A saved / cached copy of what the task's priority is. More... | |
unsigned short | m_usStackDepth |
Stack depth of this task, in words. More... | |
int | m_retval |
The return value from user task routine. More... | |
bool | m_bRunning |
Flag whether or not the task was started. More... | |
int32_t | m_iID |
The FreeRTOS task Number. More... | |
int32_t | m_iCore |
A saved / cached copy of which core this task is running on. More... | |
native_handle_type | m_pHandle |
Reference to the underlying task handle for this task. More... | |
event_group_t | m_eventGroup |
Detailed Description
Wrapper class around FreeRTOS's implementation of a task.
- Note
- To use this, you need to subclass it. All of your task should be derived from the basic_task class. Then implement the virtual on_task function.
Member Typedef Documentation
◆ native_handle_type
using mn::basic_task::native_handle_type = xTaskHandle |
Member Enumeration Documentation
◆ priority
|
strong |
Task priority.
◆ state
|
strong |
Task states returned by get_state().
Constructor & Destructor Documentation
◆ basic_task() [1/2]
|
inlinenoexcept |
Basic Constructor for this task. The priority is PriorityNormal and use MN_THREAD_CONFIG_MINIMAL_STACK_SIZE for the stack size
◆ basic_task() [2/2]
|
explicitnoexcept |
Constructor for this task.
- Parameters
-
strName Name of the Task. Only useful for debugging. uiPriority FreeRTOS priority of this Task. usStackDepth Number of "words" allocated for the Task stack. default MN_THREAD_CONFIG_MINIMAL_STACK_SIZE
◆ ~basic_task()
|
virtual |
Our destructor. Delete the task.
Member Function Documentation
◆ get_handle()
xTaskHandle mn::basic_task::get_handle | ( | ) |
Accessor to get the task's backing task handle. There is no setter, on purpose.
- Returns
- FreeRTOS task handle.
◆ get_id()
int32_t mn::basic_task::get_id | ( | ) |
Get the FreeRTOS task Numberid of this task.
- Returns
- The FreeRTOS task Number
◆ get_name()
std::string mn::basic_task::get_name | ( | ) |
Get the debug name of this task.
- Returns
- The name of this task
◆ get_on_core()
int32_t mn::basic_task::get_on_core | ( | ) |
Get the core number of this task run.
- Returns
- The core number
◆ get_priority()
basic_task::priority mn::basic_task::get_priority | ( | ) |
Get the priority of this task.
- Returns
- The priority
◆ get_return_value()
int mn::basic_task::get_return_value | ( | ) |
Get the return value of this task - after run.
- Returns
- The return value
◆ get_self()
|
static |
Get the current task.
- Returns
- The current task
◆ get_stackdepth()
unsigned short mn::basic_task::get_stackdepth | ( | ) |
Get the stack depth of this task.
- Returns
- The stack depth
◆ get_state()
basic_task::state mn::basic_task::get_state | ( | ) |
Get the state of the task.
- Returns
- The state of the task at the time the function was called.
◆ get_tasks()
|
static |
Get current number of tasks.
- Returns
- The number of tasks that the real time kernel is currently managing. This includes all ready, blocked and suspended tasks. A task that has been deleted but not yet freed by the idle task will also be included in the count.
◆ get_time_since_start()
timespan_t mn::basic_task::get_time_since_start | ( | ) | const |
Get the time since start of this task.
- Returns
- The time since start of this task
◆ is_current()
|
inlinestatic |
Is the given task the current running task ?
◆ is_running()
bool mn::basic_task::is_running | ( | ) |
Is the Task running?
- Returns
- true If the task running, false If not
◆ join() [1/2]
int mn::basic_task::join | ( | timespan_t | time | ) |
join the task, Wait in other task to end this task.
- Parameters
-
time The maximum amount of time to wait.
- Note
- call never in the this task, then wait this task to end this task.
- Returns
- ERR_TASK_NOTRUNNING Call start first.
- ERR_TASK_CALLFROMSELFTASK Don't do this ... see the notes
- NO_ERROR No error
◆ join() [2/2]
int mn::basic_task::join | ( | unsigned int | xTickTimeout = portMAX_DELAY | ) |
join the task, Wait in other task to end this task.
- Parameters
-
xTickTimeout The maximum amount of ticks to wait.
- Note
- call never in the this task, then wait this task to end this task.
- Returns
- ERR_TASK_NOTRUNNING Call start first.
- ERR_TASK_CALLFROMSELFTASK Don't do this ... see the notes
- NO_ERROR No error
◆ joinable()
|
noexcept |
◆ kill()
int mn::basic_task::kill | ( | ) |
Destroy and delete the task and call the function 'on_kill'.
- Returns
- ERR_TASK_OK The task are destroyed
- ERR_TASK_NOTRUNNING The task was not running
◆ nsleep()
|
inlinestatic |
pause execution for a specified time
- Note
- see Linux nanosleep function
◆ on_cleanup()
|
inlinevirtual |
Called on exit from your on_task() routine.
- Note
- It is optional whether you implement this or not. If you allow your task to exit its on_task method,
◆ on_kill()
|
inlinevirtual |
This virtual function call on kill, use for user code It is optional whether you implement this or not.
◆ on_start()
|
inlinevirtual |
This virtual function call on creating, use for user code It is optional whether you implement this or not.
◆ on_task()
|
inlinevirtual |
Implementation of your actual task code. You must override this function.
- Returns
- Your return your task function, get with get_return_value()
Reimplemented in mn::queue::work_queue_task, mn::basic_thread, mn::ext::basic_message_task, and mn::ext::foreign_task.
◆ operator int()
|
inline |
Operator to get the ID assigned to the task.
- Returns
- The ID assigned to the task being queried.
◆ operator xTaskHandle()
|
inline |
Operator to get the task's backing task handle.
- Returns
- FreeRTOS task handle.
◆ operator!=()
|
inline |
◆ operator<()
|
inline |
◆ operator==()
|
inline |
◆ operator>()
|
inline |
◆ resume() [1/2]
void mn::basic_task::resume | ( | ) |
Resume a specific task.
◆ resume() [2/2]
|
inlinestatic |
Resume the given task.
- Parameters
-
t The given task to resume
◆ runtaskstub()
|
staticprotected |
Adapter function that allows you to write a class specific on_task() function that interfaces with FreeRTOS.
◆ set_priority()
void mn::basic_task::set_priority | ( | basic_task::priority | uiPriority | ) |
Set the priority of this task.
- Parameters
-
uiPriority The task's new priority.
◆ sleep()
|
inlinestatic |
sleep this task for n seconds
- Parameters
-
secs How long seconds to sleep the task.
◆ start()
|
virtual |
Create and starts the Task.
This is the API call that actually starts the Task running. It creates a backing FreeRTOS task. By separating object creation from starting the Task, it solves the pure virtual fuction call failure case. Call after creating the Task the function on_start
- Parameters
-
uiCore If the value is MN_THREAD_CONFIG_CORE_IFNO, the created task is not pinned to any CPU, and the scheduler can run it on any core available. Other values indicate the index number of the CPU which the task should be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will cause the function to fail.
- Returns
- ERR_TASK_OK The task are creating,
- ERR_TASK_CANTINITMUTEX on error creating the using LockObjets, the task is not created.
- ERR_TASK_ALREADYRUNNING the Task is allready running.
- ERR_TASK_CANTSTARTTHREAD can't create the tas.
- ERR_TASK_CANTCREATEEVENTGROUP can't create the event group, the task is not created.
Reimplemented in mn::ext::foreign_task.
◆ suspend() [1/2]
void mn::basic_task::suspend | ( | ) |
◆ suspend() [2/2]
|
inlinestatic |
◆ usleep()
|
inlinestatic |
sleep this task for n micro seconds
- Parameters
-
secs How long micro seconds to sleep the task.
◆ wait() [1/2]
int mn::basic_task::wait | ( | timespan_t | time | ) |
Wait for start the task.
- Parameters
-
xTickTimeout The maximum amount of time to wait.
- Note
- call never in the this task, then wait this task to start this task.
- Returns
- ERR_TASK_NOTRUNNING Call start first.
- ERR_TASK_CALLFROMSELFTASK Don't do this ... see the notes
- NO_ERROR No error
◆ wait() [2/2]
int mn::basic_task::wait | ( | unsigned int | xTimeOut | ) |
Wait for start the task.
- Parameters
-
xTickTimeout The maximum amount of ticks to wait.
- Note
- call never in the this task, then wait this task to start this task.
- Returns
- ERR_TASK_NOTRUNNING Call start first.
- ERR_TASK_CALLFROMSELFTASK Don't do this ... see the notes
- NO_ERROR No error
◆ yield()
|
inlinestatic |
Yield the scheduler.
Member Data Documentation
◆ m_bRunning
|
protected |
Flag whether or not the task was started.
◆ m_contextMutext
|
protected |
◆ m_continuemutex
|
protected |
◆ m_eventGroup
|
protected |
◆ m_iCore
|
protected |
A saved / cached copy of which core this task is running on.
◆ m_iID
|
protected |
The FreeRTOS task Number.
◆ m_pHandle
|
protected |
Reference to the underlying task handle for this task.
- Note
- Can be obtained from get_handle().
◆ m_retval
|
protected |
The return value from user task routine.
◆ m_runningMutex
|
mutableprotected |
Lock Objekt for task safty.
◆ m_strName
|
protected |
The name of this task.
◆ m_uiPriority
|
protected |
A saved / cached copy of what the task's priority is.
◆ m_usStackDepth
|
protected |
Stack depth of this task, in words.
The documentation for this class was generated from the following files: