SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
TaskWrapper Class Referencefinal
Inheritance diagram for TaskWrapper:
Collaboration diagram for TaskWrapper:

Public Member Functions

 TaskWrapper ()
 ~TaskWrapper ()=default
 Destructor.
EAccessMode GetAccessMode () const override
 Get hardware access mode of the user task.
void OnDeadlineMissed (uint32_t duration) override
 Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time mode (see stk::KERNEL_HRT).
int32_t GetWeight () const override
 Get static base weight of the task.
const char * GetTraceName () const override
 Get task trace name set by application.
const WordGetStack () const override
 Get pointer to the stack memory.
size_t GetStackSize () const override
 Get number of elements of the stack memory array.
size_t GetStackSizeBytes () const override
 Get size of the memory in bytes.
void Initialize (stk_task_entry_t const func, void *user_data, stk_word_t *stack, size_t stack_size, EAccessMode mode)
void SetWeight (Weight weight)
void SetName (const char *tname)
TId GetId () const
 Get task Id set by application.
virtual size_t GetStackSpace () const
 Get available stack space.

Private Member Functions

 TaskWrapper (const TaskWrapper &)=delete
TaskWrapperoperator= (const TaskWrapper &)=delete
void Run () override
 Entry point of the user task.
void OnExit () override
 Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).

Private Attributes

stk_task_entry_t m_func
void * m_user_data
stk_word_tm_stack
size_t m_stack_size
EAccessMode m_mode
Weight m_weight
const char * m_tname

Detailed Description

Definition at line 74 of file stk_c.cpp.

Constructor & Destructor Documentation

◆ TaskWrapper() [1/2]

TaskWrapper::TaskWrapper ( )
inlineexplicit

Definition at line 77 of file stk_c.cpp.

77 : m_func(nullptr), m_user_data(nullptr), m_stack(nullptr),
79 {}
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
Definition stk_common.h:33
constexpr Weight DEFAULT_WEIGHT
Weight value: default weight of value (1) (see SwitchStrategySmoothWeightedRoundRobin).
Definition stk_common.h:199
stk_word_t * m_stack
Definition stk_c.cpp:119
const char * m_tname
Definition stk_c.cpp:123
stk_task_entry_t m_func
Definition stk_c.cpp:117
EAccessMode m_mode
Definition stk_c.cpp:121
Weight m_weight
Definition stk_c.cpp:122
size_t m_stack_size
Definition stk_c.cpp:120
void * m_user_data
Definition stk_c.cpp:118

References stk::ACCESS_USER, stk::DEFAULT_WEIGHT, m_func, m_mode, m_stack, m_stack_size, m_tname, m_user_data, and m_weight.

Referenced by operator=().

Here is the caller graph for this function:

◆ ~TaskWrapper()

TaskWrapper::~TaskWrapper ( )
default

Destructor.

Note
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

References STK_VIRT_DTOR.

◆ TaskWrapper() [2/2]

TaskWrapper::TaskWrapper ( const TaskWrapper & )
privatedelete

Member Function Documentation

◆ GetAccessMode()

EAccessMode TaskWrapper::GetAccessMode ( ) const
inlineoverridevirtual

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 87 of file stk_c.cpp.

87{ return m_mode; }

References m_mode.

◆ GetId()

TId stk::ITask::GetId ( ) const
inlineinherited

Get task Id set by application.

Implementation of ITask::GetId, see ITask. Placed here as it depends on GetTidFromUserTask.

Returns
Application-defined task identifier. Return 0 if unused.
Note
Used for debugging and tracing only. The kernel does not interpret this value.

Definition at line 234 of file stk_helper.h.

235{
236 return GetTidFromUserTask(this);
237}
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:520

References stk::GetTidFromUserTask().

Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Bind(), and stk_task_get_id().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetStack()

const Word * TaskWrapper::GetStack ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 93 of file stk_c.cpp.

93{ return m_stack; }

References m_stack.

◆ GetStackSize()

size_t TaskWrapper::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 94 of file stk_c.cpp.

94{ return m_stack_size; }

References m_stack_size.

◆ GetStackSizeBytes()

size_t TaskWrapper::GetStackSizeBytes ( ) const
inlineoverridevirtual

Get size of the memory in bytes.

Implements stk::IStackMemory.

Definition at line 95 of file stk_c.cpp.

95{ return m_stack_size * sizeof(stk_word_t); }
uintptr_t stk_word_t
CPU register type.
Definition stk_c.h:94

References m_stack_size.

◆ GetStackSpace()

virtual size_t stk::IStackMemory::GetStackSpace ( ) const
inlinevirtualinherited

Get available stack space.

Returns
Number of elements of the stack memory array remaining on the stack (computed via the watermark pattern). Returns 0 if the stack has been fully used or the watermark STK_STACK_MEMORY_FILLER was overwritten.
Warning
Stack type: Bottom to Top (index[0]).

Definition at line 319 of file stk_common.h.

320 {
321 const ArrayView<const Word> stack(GetStack(), GetStackSize());
322 const size_t total_size = stack.GetSize();
323 size_t space = 0U;
324
325 for (size_t i = 0U; i < total_size; ++i)
326 {
327 if (stack[i] == STK_STACK_MEMORY_FILLER)
328 {
329 space = i + 1U;
330 }
331 else
332 {
333 break; // terminate loop as soon as watermark ends
334 }
335 }
336
337 return space;
338 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:456
virtual size_t GetStackSize() const =0
Get number of elements of the stack memory array.
virtual const Word * GetStack() const =0
Get pointer to the stack memory.

References stk::ArrayView< T >::GetSize(), GetStack(), GetStackSize(), and STK_STACK_MEMORY_FILLER.

Referenced by FrtosTask::GetStackHighWaterMark(), and osThreadGetStackSpace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTraceName()

const char * TaskWrapper::GetTraceName ( ) const
inlineoverridevirtual

Get task trace name set by application.

Returns
Null-terminated name string, or NULL if unused.
Note
Used for debugging and tracing only (e.g. SEGGER SystemView). Kernel does not interpret this value.

Reimplemented from stk::ITask.

Definition at line 90 of file stk_c.cpp.

90{ return m_tname; }

References m_tname.

Referenced by stk_task_get_name().

Here is the caller graph for this function:

◆ GetWeight()

int32_t TaskWrapper::GetWeight ( ) const
inlineoverridevirtual

Get static base weight of the task.

Returns
Static weight value of the task (must be non-zero, positive 24-bit number).
See also
SwitchStrategyFixedPriority, SwitchStrategySmoothWeightedRoundRobin, IKernelTask::GetWeight, IKernelService::InheritWeight, IKernelService::RestoreWeight

Reimplemented from stk::ITask.

Definition at line 89 of file stk_c.cpp.

89{ return m_weight; }

References m_weight.

◆ Initialize()

void TaskWrapper::Initialize ( stk_task_entry_t const func,
void * user_data,
stk_word_t * stack,
size_t stack_size,
EAccessMode mode )
inline

Definition at line 97 of file stk_c.cpp.

99 {
100 m_func = func;
101 m_user_data = user_data;
102 m_stack = stack;
103 m_stack_size = stack_size;
104 m_mode = mode;
106 }

References stk::DEFAULT_WEIGHT, m_func, m_mode, m_stack, m_stack_size, m_user_data, and m_weight.

Referenced by AllocateTask().

Here is the caller graph for this function:

◆ OnDeadlineMissed()

void TaskWrapper::OnDeadlineMissed ( uint32_t duration)
inlineoverridevirtual

Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time mode (see stk::KERNEL_HRT).

Parameters
[in]durationElapsed active time in ticks at the point the deadline was detected. Always greater than the task's configured deadline (ticks).
Note
Optional handler. Use it for fault logging.
After this call returns, IPlatform::ProcessHardFault() is invoked and the system enters a safe state. This function should not attempt to recover scheduling.

Reimplemented from stk::ITask.

Definition at line 88 of file stk_c.cpp.

88{ (void)duration; }

◆ OnExit()

void TaskWrapper::OnExit ( )
overrideprivatevirtual

Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).

Note
The task's stack is no longer in use but the ITask object itself is still valid.
The default no-op implementation is sufficient for detached tasks. Override to implement join semantics (signal a waiting joiner).
Called in kernel/tick context - keep it short. ISR-safe primitives only (e.g. stk::sync::Semaphore::Signal(), stk::sync::EventFlags::Set()).
KERNEL_DYNAMIC only. Never called in KERNEL_STATIC mode.

Reimplemented from stk::ITask.

Definition at line 147 of file stk_c.cpp.

148{
150}
static void FreeTask(const stk_task_t *tsk)
Definition stk_c.cpp:290
static stk_task_t * CastCppTaskInterfaceToC(ITask *const t)
Definition stk_c.cpp:142

References CastCppTaskInterfaceToC(), and FreeTask().

Here is the call graph for this function:

◆ operator=()

TaskWrapper & TaskWrapper::operator= ( const TaskWrapper & )
privatedelete

References TaskWrapper().

Here is the call graph for this function:

◆ Run()

void TaskWrapper::Run ( )
inlineoverrideprivatevirtual

Entry point of the user task.

Note
Called by the Kernel when the task is scheduled for execution. Implement this method with the task's main logic.
Warning
If Kernel is configured as KERNEL_STATIC, the body must contain an infinite loop.
void Run( override)
{
while (true)
{
// task logic here
}
}
void Run() override
Entry point of the user task.
Definition stk_c.cpp:114

Implements stk::ITask.

Definition at line 114 of file stk_c.cpp.

References m_func, and m_user_data.

◆ SetName()

void TaskWrapper::SetName ( const char * tname)
inline

Definition at line 109 of file stk_c.cpp.

109{ m_tname = tname; }

References m_tname.

Referenced by stk_task_set_name().

Here is the caller graph for this function:

◆ SetWeight()

void TaskWrapper::SetWeight ( Weight weight)
inline

Definition at line 108 of file stk_c.cpp.

108{ m_weight = weight; }

References m_weight.

Referenced by stk_task_set_weight().

Here is the caller graph for this function:

Member Data Documentation

◆ m_func

stk_task_entry_t TaskWrapper::m_func
private

Definition at line 117 of file stk_c.cpp.

Referenced by Initialize(), Run(), and TaskWrapper().

◆ m_mode

EAccessMode TaskWrapper::m_mode
private

Definition at line 121 of file stk_c.cpp.

Referenced by GetAccessMode(), Initialize(), and TaskWrapper().

◆ m_stack

stk_word_t* TaskWrapper::m_stack
private

Definition at line 119 of file stk_c.cpp.

Referenced by GetStack(), Initialize(), and TaskWrapper().

◆ m_stack_size

size_t TaskWrapper::m_stack_size
private

Definition at line 120 of file stk_c.cpp.

Referenced by GetStackSize(), GetStackSizeBytes(), Initialize(), and TaskWrapper().

◆ m_tname

const char* TaskWrapper::m_tname
private

Definition at line 123 of file stk_c.cpp.

Referenced by GetTraceName(), SetName(), and TaskWrapper().

◆ m_user_data

void* TaskWrapper::m_user_data
private

Definition at line 118 of file stk_c.cpp.

Referenced by Initialize(), Run(), and TaskWrapper().

◆ m_weight

Weight TaskWrapper::m_weight
private

Definition at line 122 of file stk_c.cpp.

Referenced by GetWeight(), Initialize(), SetWeight(), and TaskWrapper().


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