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

Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time modes. More...

#include <stk_common.h>

Inheritance diagram for stk::IKernel:

Public Types

enum  EKernelState : uint8_t {
  KSTATE_INACTIVE = 0 ,
  KSTATE_READY ,
  KSTATE_RUNNING ,
  KSTATE_SUSPENDED
}
 Kernel state. More...

Public Member Functions

virtual void Initialize (uint32_t resolution_us=PERIODICITY_DEFAULT)=0
 Initialize kernel.
virtual void AddTask (ITask *user_task)=0
 Add user task.
virtual void AddTask (ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)=0
 Add user task.
virtual void RemoveTask (ITask *user_task)=0
 Remove a previously added task from the kernel before Start().
virtual void ScheduleTaskRemoval (ITask *user_task)=0
 Schedule task removal from scheduling (exit).
virtual void SuspendTask (ITask *user_task, bool &suspended)=0
 Suspend task.
virtual void ResumeTask (ITask *user_task)=0
 Resume task.
virtual size_t EnumerateKernelTasks (ArrayView< IKernelTask * > tasks)=0
 Enumerate kernel tasks.
virtual size_t EnumerateTasks (ArrayView< ITask * > user_tasks)=0
 Enumerate user tasks.
template<size_t TMaxCount, typename TCallback>
size_t EnumerateTasksT (TCallback &&callback)
 Enumerate tasks, invoking a callback for each active task.
virtual void Start ()=0
 Start kernel scheduling.
virtual EKernelState GetState () const =0
 Get a snapshot of the kernel state.
virtual IPlatformGetPlatform ()=0
 Get platform driver instance.
virtual ITaskSwitchStrategyGetSwitchStrategy ()=0
 Get switch strategy instance.

Protected Member Functions

 ~IKernel ()=default
 Destructor.

Detailed Description

Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time modes.

Note
Mediator design pattern.

Definition at line 1125 of file stk_common.h.

Member Enumeration Documentation

◆ EKernelState

Kernel state.

Enumerator
KSTATE_INACTIVE 

Not ready, IKernel::Initialize() must be called.

KSTATE_READY 

Ready to start, IKernel::Start() must be called.

KSTATE_RUNNING 

Initialized and running, IKernel::Start() was called successfully.

KSTATE_SUSPENDED 

Scheduling is suspended with IKernelService::Suspend().

Definition at line 1131 of file stk_common.h.

1132 {
1133 KSTATE_INACTIVE = 0,
1134 KSTATE_READY,
1137 };
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
@ KSTATE_READY
Ready to start, IKernel::Start() must be called.

Constructor & Destructor Documentation

◆ ~IKernel()

stk::IKernel::~IKernel ( )
protecteddefault

Destructor.

Member Function Documentation

◆ AddTask() [1/2]

virtual void stk::IKernel::AddTask ( ITask * user_task)
pure virtual

Add user task.

Note
This function is for Soft Real-Time modes only (i.e. KERNEL_HRT must not be set in the kernel mode flags).
Parameters
[in]user_taskPointer to the user task to add.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

Referenced by stk::time::TimerHost::Initialize(), stk_kernel_add_task(), and stk_kernel_add_task_hrt().

Here is the caller graph for this function:

◆ AddTask() [2/2]

virtual void stk::IKernel::AddTask ( ITask * user_task,
Timeout periodicity_tc,
Timeout deadline_tc,
Timeout start_delay_tc )
pure virtual

Add user task.

Note
This function is for Hard Real-time mode only, e.g. stk::KERNEL_HRT is used as parameter.
Parameters
[in]user_taskPointer to the user task to add.
[in]periodicity_tcPeriodicity time at which task is scheduled (ticks).
[in]deadline_tcDeadline time within which a task must complete its work (ticks).
[in]start_delay_tcInitial start delay for the task (ticks).

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

◆ EnumerateKernelTasks()

virtual size_t stk::IKernel::EnumerateKernelTasks ( ArrayView< IKernelTask * > tasks)
pure virtual

◆ EnumerateTasks()

virtual size_t stk::IKernel::EnumerateTasks ( ArrayView< ITask * > user_tasks)
pure virtual

◆ EnumerateTasksT()

template<size_t TMaxCount, typename TCallback>
size_t stk::IKernel::EnumerateTasksT ( TCallback && callback)
inline

Enumerate tasks, invoking a callback for each active task.

Template Parameters
TMaxCountMaximum number of tasks to enumerate. Should match or exceed the kernel's task capacity. Determines the size of the internal stack-allocated buffer (TMaxCount * sizeof(ITask*) bytes on the stack).
TCallbackCallable type, deduced automatically. Must satisfy: bool(ITask*)
Parameters
[in]callbackCallable invoked for each active task. Return true to continue, false to stop early.
Returns
Number of tasks visited (up to TMaxCount).
Warning
ISR-safe.

Example:

kernel.EnumerateTasks<_STK_KERNEL_TASKS_COUNT>([](ITask *t) {
Log(t->GetTraceName());
return true; // continue
});
Interface for a user task.
Definition stk_common.h:599

Definition at line 1235 of file stk_common.h.

1236 {
1237 STK_STATIC_ASSERT(TMaxCount > 0U);
1238
1239 ITask *tasks[TMaxCount] = {};
1240 size_t count = EnumerateTasks(ArrayView<ITask *>(tasks, TMaxCount));
1241 size_t i = 0U;
1242 bool fetch_next = true;
1243
1244 while ((i < count) && fetch_next)
1245 {
1246 fetch_next = callback(tasks[i]);
1247 ++i;
1248 }
1249
1250 return i;
1251 }
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:446
virtual size_t EnumerateTasks(ArrayView< ITask * > user_tasks)=0
Enumerate user tasks.

References EnumerateTasks(), and STK_STATIC_ASSERT.

Here is the call graph for this function:

◆ GetPlatform()

◆ GetState()

◆ GetSwitchStrategy()

◆ Initialize()

virtual void stk::IKernel::Initialize ( uint32_t resolution_us = PERIODICITY_DEFAULT)
pure virtual

Initialize kernel.

Parameters
[in]resolution_usResolution of the system tick (SysTick) timer in microseconds. Defaults to PERIODICITY_DEFAULT (1000 µs = 1 ms).
Note
Must be called before AddTask() and Start().
If running on an STM32 device with HAL driver or on QEMU, do not change the default resolution (PERIODICITY_DEFAULT). STM32's HAL expects 1 millisecond resolution and QEMU does not have enough resolution on Windows to operate correctly at sub-millisecond resolution.
Kernel must be in STATE_INACTIVE state.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

References stk::PERIODICITY_DEFAULT.

Referenced by stk_kernel_init().

Here is the caller graph for this function:

◆ RemoveTask()

virtual void stk::IKernel::RemoveTask ( ITask * user_task)
pure virtual

Remove a previously added task from the kernel before Start().

Parameters
[in]user_taskUser task to remove. Must not be nullptr.
Note
Only valid before Start() (i.e. while the kernel is not running). To remove tasks after Start() the task should return from its Run function (in KERNEL_DYNAMIC mode the slot is freed automatically on the next tick).
Warning
Must only be called when kernel is not running, otherwise call ScheduleTaskRemoval.
KERNEL_DYNAMIC mode only. Asserts if called in KERNEL_STATIC or KERNEL_HRT mode, or if called after Start().
See also
ScheduleTaskRemoval

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

Referenced by stk_kernel_remove_task().

Here is the caller graph for this function:

◆ ResumeTask()

virtual void stk::IKernel::ResumeTask ( ITask * user_task)
pure virtual

◆ ScheduleTaskRemoval()

virtual void stk::IKernel::ScheduleTaskRemoval ( ITask * user_task)
pure virtual

Schedule task removal from scheduling (exit).

Parameters
[in]user_taskUser task to remove. Must not be nullptr.
Warning
KERNEL_DYNAMIC mode only. Asserts if called in KERNEL_STATIC or KERNEL_HRT mode, or if called after Start(). Use RemoveTask to remove task if kernel is not running.
See also
RemoveTask

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

Referenced by stk_kernel_schedule_task_removal().

Here is the caller graph for this function:

◆ Start()

virtual void stk::IKernel::Start ( )
pure virtual

◆ SuspendTask()

virtual void stk::IKernel::SuspendTask ( ITask * user_task,
bool & suspended )
pure virtual

Suspend task.

Parameters
[in]user_taskPointer to the user task to suspend.
[out]suspendedSet to true if task is suspended.
Note
hw::CriticalSection must not be active otherwise a deadlock will happen if task is suspending self.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >, stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >, and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault >.

Referenced by stk_kernel_suspend_task().

Here is the caller graph for this function:

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