|
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time modes. More...
#include <stk_common.h>
Public Types | |
| enum | EKernelState : uint8_t { KSTATE_INACTIVE = 0 , KSTATE_READY , KSTATE_RUNNING , KSTATE_SUSPENDED , KSTATE_LOCKED } |
| Kernel state. More... | |
Public Member Functions | |
| virtual void | Initialize (uint32_t resolution_us=PERIODICITY_DEFAULT)=0 |
| Initialize kernel. | |
| virtual EAddResult | AddTask (ITask *user_task)=0 |
| Add user task. | |
| virtual EAddResult | 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 when it is not started. | |
| virtual void | ScheduleTaskRemoval (ITask *user_task)=0 |
| Schedule task removal from scheduling (exit). | |
| virtual ESuspendResult | SuspendTask (ITask *user_task)=0 |
| Suspend task. | |
| void | SuspendTask (ITask *user_task, bool &suspended) |
| Suspend task (legacy form). | |
| virtual EResumeResult | ResumeTask (ITask *user_task)=0 |
| Resume task suspended by SuspendTask(), or lift its deferred suspension. | |
| virtual void | CancelTaskWait (ITask *user_task)=0 |
| Cancel a task's in-progress wait or sleep, waking it early. | |
| virtual bool | GetTaskState (ITask *user_task, TaskStateInfo &info) const =0 |
| Get a snapshot of the kernel-side state of a 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 ELockResult | SetSchedulerLock (bool lock)=0 |
| Lock or unlock task switching. Ticks, timeouts and ISRs keep running. | |
| virtual void | Start ()=0 |
| Start kernel scheduling. | |
| virtual EKernelState | GetState () const =0 |
| Get a snapshot of the kernel state. | |
| virtual IPlatform * | GetPlatform ()=0 |
| Get platform driver instance. | |
| virtual ITaskSwitchStrategy * | GetSwitchStrategy ()=0 |
| Get switch strategy instance. | |
Protected Member Functions | |
| ~IKernel ()=default | |
| Destructor. | |
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time modes.
Definition at line 1536 of file stk_common.h.
| enum stk::IKernel::EKernelState : uint8_t |
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(). |
| KSTATE_LOCKED | Running, but task switching is disabled with IKernelService::LockScheduler(). Ticks, timeouts and ISRs keep running. |
Definition at line 1542 of file stk_common.h.
|
protecteddefault |
Destructor.
|
pure virtual |
Add user task.
KERNEL_HRT must not be set in the kernel mode flags). KERNEL_DYNAMIC only): the task is bound and added immediately, inside a critical section, then scheduled by the next tick. The call does not block, does not yield and is not deferred to the tick handler, so it is also valid while the caller holds a critical section. KERNEL_DYNAMIC mode. Restrictions for an ISR caller:KERNEL_TICKLESS, a task added from an ISR while all other tasks are sleeping is first scheduled when the already armed timer expires (up to the current idle period), not on the next tick; a call from a task is not affected;| [in] | user_task | Pointer to the user task to add. |
KERNEL_DYNAMIC: any failure is only returned, never asserted. The caller is responsible for checking the result (assert, retry or recover), a task which is not added is silently dropped otherwise (e.g. ADD_FAIL_POOL_FULL, ADD_FAIL_DUPLICATE);Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
Referenced by stk::time::TimerHost::Initialize().
|
pure virtual |
Add user task.
| [in] | user_task | Pointer to the user task to add. |
| [in] | periodicity_tc | Periodicity time at which task is scheduled (ticks). |
| [in] | deadline_tc | Deadline time within which a task must complete its work (ticks). |
| [in] | start_delay_tc | Initial start delay for the task (ticks). 0 means activate immediately. |
KERNEL_HRT mode. KERNEL_DYNAMIC mode: the HRT schedule (periodicity, deadlines, start delays) is built from the complete task set and is not recomputed at runtime. KERNEL_DYNAMIC: any failure is only returned, never asserted. The caller is responsible for checking the result;KERNEL_STATIC: any failure asserts (application design failure), in a release build the failure is only returned and the task is not added. Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Cancel a task's in-progress wait or sleep, waking it early.
| [in] | user_task | Pointer to the user task whose wait should be cancelled. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Enumerate kernel tasks.
| [in] | tasks | Reference to the ArrayView of IKernelTask pointers. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
Enumerate user tasks.
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
Referenced by EnumerateTasksT().
|
inline |
Enumerate tasks, invoking a callback for each active task.
| TMaxCount | Maximum 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). |
| TCallback | Callable type, deduced automatically. Must satisfy: bool(ITask*) |
| [in] | callback | Callable invoked for each active task. Return true to continue, false to stop early. |
TMaxCount). Example:
Definition at line 1744 of file stk_common.h.
References EnumerateTasks(), and STK_STATIC_ASSERT.
|
pure virtual |
Get platform driver instance.
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Get a snapshot of the kernel state.
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Get switch strategy instance.
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Get a snapshot of the kernel-side state of a task.
| [in] | user_task | Pointer to the user task to query. Must not be nullptr. |
| [out] | info | Receives the snapshot (see TaskStateInfo). Written only if the function returns true, left unchanged otherwise. |
true if the query succeeded and info is valid (TaskStateInfo::state is TASK_STATE_REMOVED if the task is not bound to a kernel slot), false if user_task is nullptr or the kernel is built without KERNEL_TELEMETRY. Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Initialize kernel.
| [in] | resolution_us | Resolution of the system tick (SysTick) timer in microseconds. Defaults to PERIODICITY_DEFAULT (1000 µs = 1 ms). |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
References stk::PERIODICITY_DEFAULT.
|
pure virtual |
Remove a previously added task from the kernel when it is not started.
| [in] | user_task | User task to remove. Must not be nullptr. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Resume task suspended by SuspendTask(), or lift its deferred suspension.
| [in] | user_task | Pointer to the user task to resume. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Schedule task removal from scheduling (exit).
| [in] | user_task | User task to remove. Must not be nullptr. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Lock or unlock task switching. Ticks, timeouts and ISRs keep running.
| [in] | lock | true to lock, false to unlock. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Start kernel scheduling.
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
|
pure virtual |
Suspend task.
| [in] | user_task | Pointer to the user task to suspend. |
Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >.
Referenced by SuspendTask().
|
inline |
Suspend task (legacy form).
| [in] | user_task | Pointer to the user task to suspend. |
| [out] | suspended | Set to true if the task is suspended immediately (SUSPEND_DONE). |
Definition at line 1661 of file stk_common.h.
References stk::SUSPEND_DONE, and SuspendTask().