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::ITask Class Referenceabstract

Interface for a user task. More...

#include <stk_common.h>

Inheritance diagram for stk::ITask:
Collaboration diagram for stk::ITask:

Public Member Functions

virtual void Run ()=0
 Entry point of the user task.
virtual IStackMemoryGetSecureStackMemory ()
 Get pointer to the stack memory.
virtual const MpuRegionListGetMpuRegions () const
 Get up to (STK_MPU_TASK_REGIONS - 1) application-defined MPU regions for this task.
virtual EAccessMode GetAccessMode () const =0
 Get hardware access mode 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.
virtual const char * GetTraceName () const
 Get task trace name set by application.
virtual const WordGetStack () const =0
 Get pointer to the stack memory.
virtual size_t GetStackSize () const =0
 Get number of elements of the stack memory array.
virtual size_t GetStackSpace () const
 Get available stack space.

Detailed Description

Interface for a user task.

Note
Inherit this interface by your thread/task class to make it schedulable by the Kernel.

Usage example:

class MyTask : public stk::Task<256, ACCESS_USER>
{
void Run() override
{
while (true)
{
// task logic here
}
}
};
MyTask task1, task2;
kernel.AddTask(&task1);
kernel.AddTask(&task2);
virtual void Run()=0
Entry point of the user task.
Partial implementation of the user task.
Definition stk_helper.h:98

Definition at line 733 of file stk_common.h.

Member Function Documentation

◆ GetAccessMode()

virtual EAccessMode stk::ITask::GetAccessMode ( ) const
pure virtual

◆ GetMpuRegions()

virtual const MpuRegionList * stk::ITask::GetMpuRegions ( ) const
inlinevirtual

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 or 4, 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 { ... }
};
ArrayView< const struct MpuRegionConfig > MpuRegionList
Definition stk_common.h:344
virtual const MpuRegionList * GetMpuRegions() const
Get up to (STK_MPU_TASK_REGIONS - 1) application-defined MPU regions for this task.
Definition stk_common.h:801
See also
TaskMpu::Configure, IPlatform::InitStack, MpuRegionList

Definition at line 801 of file stk_common.h.

802 {
803 return nullptr;
804 }

◆ GetSecureStackMemory()

virtual IStackMemory * stk::ITask::GetSecureStackMemory ( )
inlinevirtual

Get pointer to the stack memory.

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

Definition at line 756 of file stk_common.h.

756{ return nullptr; }

◆ GetStack()

◆ GetStackSize()

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

419 {
420 const ArrayView<const Word> stack(GetStack(), GetStackSize());
421 const size_t total_size = stack.GetSize();
422 size_t space = 0U;
423
424 for (size_t i = 0U; i < total_size; ++i)
425 {
426 if (stack[i] == STK_STACK_MEMORY_FILLER)
427 {
428 space = i + 1U;
429 }
430 else
431 {
432 break; // terminate loop as soon as watermark ends
433 }
434 }
435
436 return space;
437 }
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:502
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
inlinevirtual

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

841{ return nullptr; }

◆ GetWeight()

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

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

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

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

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

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

References STK_UNUSED.

◆ OnExit()

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

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

827{}

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:

◆ Run()

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

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.


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