SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::TaskW< _Weight, _StackSize, _AccessMode > Class Template Referenceabstract

Partial implementation of the user task with a compile-time scheduling weight. Use when the kernel is configured with SwitchStrategySmoothWeightedRoundRobin. More...

#include <stk_helper.h>

Inheritance diagram for stk::TaskW< _Weight, _StackSize, _AccessMode >:
Collaboration diagram for stk::TaskW< _Weight, _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.
EAccessMode GetAccessMode () const override
 Get pointer to the stack memory.
Weight GetWeight () const override
 Get static base weight of the 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 const char * GetTraceName () const
 Get task trace name set by application.
virtual size_t GetStackSpace () const
 Get available stack space.

Protected Member Functions

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

Private Attributes

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

Detailed Description

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
class stk::TaskW< _Weight, _StackSize, _AccessMode >

Partial implementation of the user task with a compile-time scheduling weight. Use when the kernel is configured with SwitchStrategySmoothWeightedRoundRobin.

Template Parameters
_WeightStatic scheduling weight (positive, non-zero 24-bit integer). Higher values cause this task to receive proportionally more CPU time.
_StackSizeStack size in elements of Word.
_AccessModeHardware access mode (ACCESS_USER or ACCESS_PRIVILEGED).
Note
Hard Real-Time mode (KERNEL_HRT) is not supported for weighted tasks. OnDeadlineMissed() will trigger an assertion if HRT scheduling is attempted.

See Task for full usage example, implementation guidance, and TrustZone Non-Secure inheritance notes.

Definition at line 144 of file stk_helper.h.

Member Enumeration Documentation

◆ anonymous enum

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

Definition at line 152 of file stk_helper.h.

Partial implementation of the user task with a compile-time scheduling weight. Use when the kernel is...
Definition stk_helper.h:150

Constructor & Destructor Documentation

◆ TaskW() [1/2]

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
stk::TaskW< _Weight, _StackSize, _AccessMode >::TaskW ( const TaskW< _Weight, _StackSize, _AccessMode > & )
protecteddelete

Referenced by operator=().

Here is the caller graph for this function:

◆ TaskW() [2/2]

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
stk::TaskW< _Weight, _StackSize, _AccessMode >::TaskW ( )
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 169 of file stk_helper.h.

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

References m_stack.

◆ ~TaskW()

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
stk::TaskW< _Weight, _StackSize, _AccessMode >::~TaskW ( )
protecteddefault

Destructor.

Note
Protected by design. Prevents unsafe polymorphic delete.

References STK_VIRT_DTOR.

Member Function Documentation

◆ GetAccessMode()

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
EAccessMode stk::TaskW< _Weight, _StackSize, _AccessMode >::GetAccessMode ( ) const
inlineoverridevirtual

Get pointer to the stack memory.

Note
Optional. ARM TrustZone only.
Returns
Pointer to the Secure stack memory.

Get up to (STK_MPU_TASK_REGIONS - 1) application-defined MPU regions for this task.

When STK_MPU_STACK_GUARD is enabled, each task owns STK_MPU_TASK_REGIONS (2, 4, 6, 8, 12 or 16, see STK_MPU_TASK_REGIONS) hardware MPU region slots. Slot 0 is always the automatic stack guard, computed by the driver from the task's own stack memory (see IStackMemory::GetStack/GetStackSize). This hook supplies the remaining STK_MPU_TASK_REGIONS-1 slots, letting an application additionally sandbox a task to e.g. a private data buffer, a specific peripheral block, or a shared IPC region - on top of its stack guard.

Returns
Pointer to a constant MpuRegionList containing up to (STK_MPU_TASK_REGIONS - 1) region descriptors, or nullptr if no extra task regions are configured. Array element i is applied at task-relative region index i +1 (i.e. the slots following the stack guard).
Note
Optional. Only consulted when STK_MPU_STACK_GUARD is enabled; a no-op on platforms/builds without MPU stack-guard support.
Read once, when the task is bound via Kernel::AddTask() (through IPlatform::InitStack()), not re-evaluated on every context switch. The underlying MpuRegionList instance referenced by the returned pointer must remain valid (e.g. a static const instance); a stack-local temporary is invalid once this function returns.
Warning
An element count greater than (STK_MPU_TASK_REGIONS - 1) is clamped by the driver (STK_ASSERT fires in debug builds); only the first STK_MPU_TASK_REGIONS-1 entries are ever applied.
class MyTask : public stk::Task<256, stk::ACCESS_USER>
{
static constexpr stk::MpuRegionConfig s_extra_regions[] =
{
{ .addr = MY_BUFFER_ADDR, .size = MY_BUFFER_SIZE,
.access_perm = stk::hw::mpu::ACCESS_FULL,
.mem_type = stk::hw::mpu::TYPE_NORMAL_CACHEABLE,
.exec = stk::hw::mpu::EXEC_NEVER },
};
const stk::MpuRegionList *GetMpuRegions() const override
{
static const stk::MpuRegionList mpu_regions(s_extra_regions, 1U);
return &mpu_regions;
}
void Run() override { ... }
};
virtual void Run()=0
Entry point of the user task.
Partial implementation of the user task.
Definition stk_helper.h:98
See also
TaskMpu::Configure, IPlatform::InitStack, MpuRegionList

Get hardware access mode of the user task.

Implements stk::ITask.

Definition at line 156 of file stk_helper.h.

156{ return _AccessMode; }

◆ GetStack()

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

Get pointer to the stack memory.

Implements stk::IStackMemory.

Definition at line 154 of file stk_helper.h.

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

References m_stack.

◆ GetStackSize()

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
size_t stk::TaskW< _Weight, _StackSize, _AccessMode >::GetStackSize ( ) const
inlineoverridevirtual

Get number of elements of the stack memory array.

Implements stk::IStackMemory.

Definition at line 155 of file stk_helper.h.

155{ return _StackSize; }

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

431 {
432 const ArrayView<const Word> stack(GetStack(), GetStackSize());
433 const size_t total_size = stack.GetSize();
434 size_t space = 0U;
435
436 for (size_t i = 0U; i < total_size; ++i)
437 {
438 if (stack[i] == STK_STACK_MEMORY_FILLER)
439 {
440 space = i + 1U;
441 }
442 else
443 {
444 break; // terminate loop as soon as watermark ends
445 }
446 }
447
448 return space;
449 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:563
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 866 of file stk_common.h.

866{ return nullptr; }

◆ GetWeight()

template<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
Weight stk::TaskW< _Weight, _StackSize, _AccessMode >::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 157 of file stk_helper.h.

157{ return _Weight; }

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

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

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

852{}

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<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
TaskW & stk::TaskW< _Weight, _StackSize, _AccessMode >::operator= ( const TaskW< _Weight, _StackSize, _AccessMode > & )
protecteddelete

References TaskW().

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<Weight _Weight, size_t _StackSize, EAccessMode _AccessMode>
StackMemoryDef<_StackSize>::Type stk::TaskW< _Weight, _StackSize, _AccessMode >::m_stack
private

Stack memory region, 16-byte aligned.

Definition at line 177 of file stk_helper.h.

Referenced by GetStack(), and TaskW().


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