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
stk::Task< _StackSize, _AccessMode > Class Template Referenceabstract

Partial implementation of the user task. More...

#include <stk_helper.h>

Inheritance diagram for stk::Task< _StackSize, _AccessMode >:
Collaboration diagram for stk::Task< _StackSize, _AccessMode >:

Public Types

enum  { STACK_SIZE = _StackSize }

Public Member Functions

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.
EAccessMode GetAccessMode () const override
 Get hardware access mode of the user task.
virtual void Run ()=0
 Entry point of the user task.
virtual void OnDeadlineMissed (uint32_t duration)
 Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time mode (see stk::KERNEL_HRT).
virtual void OnExit ()
 Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
virtual Weight GetWeight () const
 Get static base weight of the task.
TId GetId () const
 Get task Id set by application.
virtual const char * GetTraceName () const
 Get task trace name set by application.
virtual size_t GetStackSpace () const
 Get available stack space.

Protected Member Functions

 Task (const Task &)=delete
Taskoperator= (const Task &)=delete
 Task ()
 Initializes task instance and zero-initializes its internal stack memory.
 ~Task ()=default
 Destructor.

Private Attributes

StackMemoryDef< _StackSize >::Type m_stack
 Stack memory region, 16-byte aligned.

Detailed Description

template<size_t _StackSize, EAccessMode _AccessMode>
class stk::Task< _StackSize, _AccessMode >

Partial implementation of the user task.

Provides stack storage and default implementations of all optional ITask methods. Inherit from this class and implement GetFunc() and GetFuncUserData() to make a schedulable task. Use ACCESS_USER for unprivileged tasks and ACCESS_PRIVILEGED for tasks requiring full hardware access.

Usage example:

template <stk::EAccessMode _AccessMode>
class MyTask : public stk::Task<256, _AccessMode>
{
private:
void Run()
{
while (true)
{
// do some work here ...
}
}
};
MyTask<ACCESS_PRIVILEGED> my_task;
virtual void Run()=0
Entry point of the user task.
Partial implementation of the user task.
Definition stk_helper.h:50

Definition at line 49 of file stk_helper.h.

Member Enumeration Documentation

◆ anonymous enum

template<size_t _StackSize, EAccessMode _AccessMode>
anonymous enum
Enumerator
STACK_SIZE 

Definition at line 52 of file stk_helper.h.

Constructor & Destructor Documentation

◆ Task() [1/2]

template<size_t _StackSize, EAccessMode _AccessMode>
stk::Task< _StackSize, _AccessMode >::Task ( const Task< _StackSize, _AccessMode > & )
protecteddelete

Referenced by operator=().

Here is the caller graph for this function:

◆ Task() [2/2]

template<size_t _StackSize, EAccessMode _AccessMode>
stk::Task< _StackSize, _AccessMode >::Task ( )
inlineprotected

Initializes task instance and zero-initializes its internal stack memory.

The constructor is protected to ensure that the Task class can only be instantiated through a derived subclass. It handles the allocation (if applicable) and zero-initialization of the m_stack member based on the _StackSize template parameter.

Definition at line 69 of file stk_helper.h.

69 : m_stack()
70 {}
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, 16-byte aligned.
Definition stk_helper.h:78

References m_stack.

◆ ~Task()

template<size_t _StackSize, EAccessMode _AccessMode>
stk::Task< _StackSize, _AccessMode >::~Task ( )
protecteddefault

Destructor.

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

Member Function Documentation

◆ GetAccessMode()

template<size_t _StackSize, EAccessMode _AccessMode>
EAccessMode stk::Task< _StackSize, _AccessMode >::GetAccessMode ( ) const
inlineoverridevirtual

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 57 of file stk_helper.h.

57{ return _AccessMode; }

◆ 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:495

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()

template<size_t _StackSize, EAccessMode _AccessMode>
const Word * stk::Task< _StackSize, _AccessMode >::GetStack ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 54 of file stk_helper.h.

54{ return const_cast<Word *>(m_stack); }

References m_stack.

◆ GetStackSize()

template<size_t _StackSize, EAccessMode _AccessMode>
size_t stk::Task< _StackSize, _AccessMode >::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 55 of file stk_helper.h.

55{ return _StackSize; }

◆ GetStackSizeBytes()

template<size_t _StackSize, EAccessMode _AccessMode>
size_t stk::Task< _StackSize, _AccessMode >::GetStackSizeBytes ( ) const
inlineoverridevirtual

Get size of the memory in bytes.

Implements stk::IStackMemory.

Definition at line 56 of file stk_helper.h.

56{ return _StackSize * sizeof(Word); }

◆ 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 318 of file stk_common.h.

319 {
320 ArrayView<const Word> stack(GetStack(), GetStackSize());
321
322 // count leading Words equal to STK_STACK_MEMORY_FILLER (watermark)
323 size_t space = 0U;
324 for ( ; (space < stack.GetSize()) && (stack[space] == STK_STACK_MEMORY_FILLER); ++space)
325 {}
326
327 return space;
328 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:458
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()

virtual const char * stk::ITask::GetTraceName ( ) const
inlinevirtualinherited

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 in FrtosTask, stk::time::TimerHost::TimerWorkerTask, StkThread, and TaskWrapper.

Definition at line 648 of file stk_common.h.

648{ return nullptr; }

◆ GetWeight()

virtual Weight stk::ITask::GetWeight ( ) const
inlinevirtualinherited

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 in FrtosTask, stk::TaskW< _Weight, _StackSize, _AccessMode >, stk::time::TimerHost::TimerWorkerTask, StkThread, and TaskWrapper.

Definition at line 635 of file stk_common.h.

635{ return DEFAULT_WEIGHT; }
static constexpr Weight DEFAULT_WEIGHT
Weight value: default weight of value (1) (see SwitchStrategySmoothWeightedRoundRobin).
Definition stk_common.h:199

References stk::DEFAULT_WEIGHT.

Referenced by stk::ISyncObject::FindWeightHigherThan().

Here is the caller graph for this function:

◆ OnDeadlineMissed()

virtual void stk::ITask::OnDeadlineMissed ( uint32_t duration)
inlinevirtualinherited

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 in FrtosTask, stk::time::TimerHost::TimerWorkerTask, StkThread, and TaskWrapper.

Definition at line 618 of file stk_common.h.

618{ STK_UNUSED(duration); }
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:610

References STK_UNUSED.

◆ OnExit()

virtual void stk::ITask::OnExit ( )
inlinevirtualinherited

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 in FrtosTask, stk::time::TimerHost::TimerWorkerTask, StkThread, and TaskWrapper.

Definition at line 628 of file stk_common.h.

628{}

Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RemoveTask().

Here is the caller graph for this function:

◆ operator=()

template<size_t _StackSize, EAccessMode _AccessMode>
Task & stk::Task< _StackSize, _AccessMode >::operator= ( const Task< _StackSize, _AccessMode > & )
protecteddelete

References Task().

Here is the call graph for this function:

◆ Run()

virtual void stk::ITask::Run ( )
pure virtualinherited

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
}
}

Implemented in FrtosTask, stk::time::TimerHost::TimerWorkerTask, StkThread, and TaskWrapper.

Member Data Documentation

◆ m_stack

template<size_t _StackSize, EAccessMode _AccessMode>
StackMemoryDef<_StackSize>::Type stk::Task< _StackSize, _AccessMode >::m_stack
private

Stack memory region, 16-byte aligned.

Definition at line 78 of file stk_helper.h.

Referenced by GetStack(), and Task().


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