![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Concrete implementation of IKernel. More...
#include <stk.h>
Classes | |
| class | KernelTask |
| Internal per-slot kernel descriptor that wraps a user ITask instance. More... | |
| class | KernelService |
| Concrete implementation of IKernelService exposed to running tasks. More... | |
| class | SleepTrapStack |
| Storage bundle for the sleep trap: a Stack descriptor paired with its backing memory. More... | |
| class | ExitTrapStack |
| Storage bundle for the exit trap: a Stack descriptor paired with its backing memory. More... | |
Public Types | |
| enum | EState : uint8_t { STATE_INACTIVE = 0 , STATE_READY , STATE_RUNNING , STATE_SUSPENDED } |
| Kernel state. More... | |
Public Member Functions | |
| Kernel () | |
| Construct the kernel with all storage zero-initialized and the request flag set to ~0 (indicating uninitialized state; cleared to REQUEST_NONE by Initialize()). | |
| ~Kernel () | |
| Destructor. | |
| void | Initialize (uint32_t resolution_us=PERIODICITY_DEFAULT) |
| Initialize kernel. | |
| void | AddTask (ITask *user_task) |
| Register task for a soft real-time (SRT) scheduling. | |
| void | AddTask (ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc) |
| Register a task for hard real-time (HRT) scheduling. | |
| void | RemoveTask (ITask *user_task) |
| Remove a previously added task from the kernel before Start(). | |
| void | ScheduleTaskRemoval (ITask *user_task) |
| Schedule task removal from scheduling (exit). | |
| void | SuspendTask (ITask *user_task, bool &suspended) |
| Suspend task. | |
| void | ResumeTask (ITask *user_task) |
| Resume task. | |
| size_t | EnumerateTasks (ITask **user_tasks, const size_t max_size) |
| Enumerate tasks. | |
| void | Start () |
| Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or indefinitely (KERNEL_STATIC mode). | |
| bool | IsStarted () const |
| Check whether scheduler is currently running. | |
| IPlatform * | GetPlatform () |
| Get platform driver instance owned by this kernel. | |
| ITaskSwitchStrategy * | GetSwitchStrategy () |
| Get task-switching strategy instance owned by this kernel. | |
| EState | GetState () const |
| Get kernel state. | |
| template<size_t TMaxCount, typename TCallback> | |
| size_t | EnumerateTasksT (TCallback &&callback) |
| Enumerate tasks, invoking a callback for each active task. | |
Static Public Attributes | |
| static constexpr uint32_t | TASKS_MAX = TSize |
| Maximum number of concurrently registered tasks. Fixed at compile time. Exceeding this limit in AddTask() triggers a compile-time assert (TASKS_MAX > 0) and a runtime STK_ASSERT. | |
Protected Types | |
| enum | ERequest : uint8_t { REQUEST_NONE = 0 , REQUEST_ADD_TASK = (1 << 0) } |
| Bitmask flags for pending inter-task requests that must be processed by the kernel on the next tick (in UpdateTaskRequest()). More... | |
| enum | EFsmState : int8_t { FSM_STATE_NONE = -1 , FSM_STATE_SWITCHING , FSM_STATE_SLEEPING , FSM_STATE_WAKING , FSM_STATE_EXITING , FSM_STATE_MAX } |
| Finite-state machine (FSM) state. Encodes what the kernel is currently doing between two consecutive tick events. More... | |
| enum | EFsmEvent : int8_t { FSM_EVENT_SWITCH = 0 , FSM_EVENT_SLEEP , FSM_EVENT_WAKE , FSM_EVENT_EXIT , FSM_EVENT_MAX } |
| Finite-state machine (FSM) event. Computed by FetchNextEvent() each tick based on strategy output and current kernel state. More... | |
| typedef StackMemoryWrapper<(32U)> | SleepTrapStackMemory |
| Stack memory wrapper type for the sleep trap. | |
| typedef StackMemoryWrapper< STACK_SIZE_MIN > | ExitTrapStackMemory |
| Stack memory wrapper type for the exit trap. | |
| typedef KernelTask | TaskStorageType[TASKS_MAX] |
| KernelTask array type used as a storage for the KernelTask instances. | |
| typedef ISyncObject::ListHeadType | SyncObjectList |
| Intrusive list of active ISyncObject instances registered with this kernel. Each sync object in this list receives a Tick() call every kernel tick for timeout tracking. Allocated only when KERNEL_SYNC is set (zero-size otherwise). | |
Protected Member Functions | |
| void | InitTraps () |
| Initialize stack of the traps. | |
| KernelTask * | AllocateNewTask (ITask *user_task) |
| Allocate new instance of KernelTask. | |
| void | AddKernelTask (KernelTask *task) |
| Add kernel task to the scheduling strategy. | |
| void | AllocateAndAddNewTask (ITask *user_task) |
| Allocate new instance of KernelTask and add it into the scheduling process. | |
| void | HrtAllocateAndAddNewTask (ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc) |
| Allocate new instance of KernelTask and add it into the HRT scheduling process. | |
| void | RequestAddTask (ITask *user_task) |
| Request to add new task. | |
| KernelTask * | FindTaskByUserTask (const ITask *user_task) |
| Find kernel task by the bound ITask instance. | |
| KernelTask * | FindTaskByStack (const Stack *stack) |
| Find kernel task by the bound Stack instance. | |
| KernelTask * | FindTaskBySP (Word SP) |
| Find kernel task for a Stack Pointer (SP). | |
| void | RemoveTask (KernelTask *task) |
| Remove kernel task. | |
| void | OnStart (Stack *&active) |
| Called by platform driver immediately after a scheduler start (first tick). | |
| void | OnStop () |
| Called by the platform driver after a scheduler stop (all tasks have exited). | |
| bool | OnTick (Stack *&idle, Stack *&active) |
| Process one scheduler tick. Called from the platform timer/tick ISR. | |
| void | OnTaskSwitch (Word caller_SP) |
| Called by Thread process (via IKernelService::SwitchToNext) to switch to a next task. | |
| void | OnTaskSleep (Word caller_SP, Timeout ticks) |
| Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from scheduling (sleeping). | |
| void | OnTaskSleepUntil (Word caller_SP, Ticks timestamp) |
| Called by Thread process (via IKernelService::SleepUntil) for exclusion of the calling process from scheduling (sleeping). | |
| void | OnTaskExit (Stack *stack) |
| Called from the Thread process when task finished (its Run function exited by return). | |
| IWaitObject * | OnTaskWait (Word caller_SP, ISyncObject *sync_obj, IMutex *mutex, Timeout timeout) |
| Called from the Thread process when task needs to wait. | |
| TId | OnGetTid (Word caller_SP) |
| Called from the Thread process when for getting task/thread id of the process. | |
| void | OnSuspend (bool suspended) |
| Called from the Thread process to suspend scheduling. | |
| Timeout | UpdateTasks (const Timeout elapsed_ticks) |
| Update tasks (sleep, requests). | |
| Timeout | UpdateTaskState (const Timeout elapsed_ticks) |
| Update task state: process removals, advance sleep timers, and track HRT durations. | |
| void | UpdateSyncObjects (const Timeout elapsed_ticks) |
| Update synchronization objects. | |
| void | UpdateTaskRequest () |
| Update pending task requests. | |
| EFsmEvent | FetchNextEvent (KernelTask *&next) |
| Fetch next event for the FSM. | |
| EFsmState | GetNewFsmState (KernelTask *&next) |
| Get new FSM state. | |
| bool | UpdateFsmState (Stack *&idle, Stack *&active) |
| Update FSM state. | |
| bool | StateSwitch (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active) |
| Switches contexts. | |
| bool | StateWake (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active) |
| Wakes up after sleeping. | |
| bool | StateSleep (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active) |
| Enters into a sleeping mode. | |
| bool | StateExit (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active) |
| Exits from scheduling. | |
| bool | IsInitialized () const |
| Check whether Initialize() has been called and completed successfully. | |
| void | ScheduleAddTask () |
| Signal the kernel to process a pending AddTask request on the next tick. | |
Static Protected Member Functions | |
| static bool | IsValidFsmState (EFsmState state) |
| Check if FSM state is valid. | |
| static bool | IsStaticMode () |
| static bool | IsDynamicMode () |
| static bool | IsHrtMode () |
| static bool | IsSyncMode () |
| static bool | IsTicklessMode () |
Protected Attributes | |
| KernelService | m_service |
| Kernel service singleton exposed to running tasks via IKernelService::GetInstance(). | |
| TPlatform | m_platform |
| Platform driver (SysTick, PendSV, context switch implementation). | |
| TStrategy | m_strategy |
| Task-switching strategy (determines which task runs next). | |
| KernelTask * | m_task_now |
Currently executing task, or nullptr before Start() or after all tasks exit. | |
| TaskStorageType | m_task_storage |
| Static pool of TSize KernelTask slots (free slots have m_user == nullptr). | |
| SleepTrapStack | m_sleep_trap [1] |
| Sleep trap (always present): executed when all tasks are sleeping. | |
| ExitTrapStack | m_exit_trap [((((TMode) &(KERNEL_DYNAMIC)) !=0U) ?(1) :(0))] |
| Exit trap: zero-size in KERNEL_STATIC mode; one entry in KERNEL_DYNAMIC mode. | |
| EFsmState | m_fsm_state |
| Current FSM state. Drives context-switch decision on every tick. | |
| volatile uint8_t | m_request |
| Bitmask of pending ERequest flags from running tasks. Written by tasks, read/cleared by UpdateTaskRequest() in tick context. | |
| volatile EState | m_state |
| Current kernel state. | |
| SyncObjectList | m_sync_list [((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))] |
| List of active sync objects. Zero-size (no memory) if KERNEL_SYNC is not set. | |
| const EFsmState | m_fsm [FSM_STATE_MAX][FSM_EVENT_MAX] |
Static Protected Attributes | |
| static constexpr Timeout | YIELD_TICKS = 2 |
| Ticks to yield. | |
Concrete implementation of IKernel.
All configuration is expressed as template parameters. No virtual dispatch, no heap allocation - the entire kernel, tasks, and traps live in statically reserved storage.
| TMode | Bitmask of EKernelMode flags that configures kernel features:
|
| TSize | Maximum number of concurrent tasks. Must be > 0. |
| TStrategy | Task-switching strategy type (e.g. SwitchStrategyRoundRobin). Must inherit ITaskSwitchStrategy. |
| TPlatform | Platform driver type (e.g. PlatformArmCortexM, or PlatformDefault). Must inherit IPlatform. |
Usage example:
|
protected |
Stack memory wrapper type for the exit trap.
|
protected |
Stack memory wrapper type for the sleep trap.
|
protected |
Intrusive list of active ISyncObject instances registered with this kernel. Each sync object in this list receives a Tick() call every kernel tick for timeout tracking. Allocated only when KERNEL_SYNC is set (zero-size otherwise).
|
protected |
KernelTask array type used as a storage for the KernelTask instances.
|
protected |
Finite-state machine (FSM) event. Computed by FetchNextEvent() each tick based on strategy output and current kernel state.
| Enumerator | |
|---|---|
| FSM_EVENT_SWITCH | Strategy returned a runnable task, perform a context switch. |
| FSM_EVENT_SLEEP | No runnable tasks, enter sleep trap. |
| FSM_EVENT_WAKE | A task became runnable while the kernel was sleeping, wake from sleep trap. |
| FSM_EVENT_EXIT | No tasks remain (KERNEL_DYNAMIC), exit scheduling and return from Start(). |
| FSM_EVENT_MAX | Sentinel: number of valid events (used to size the FSM table). |
Definition at line 1113 of file stk.h.
|
protected |
Finite-state machine (FSM) state. Encodes what the kernel is currently doing between two consecutive tick events.
| Enumerator | |
|---|---|
| FSM_STATE_NONE | Sentinel / uninitialized value. Set by the constructor, replaced by FSM_STATE_SWITCHING on the first tick. |
| FSM_STATE_SWITCHING | Normal operation: switching between runnable tasks each tick. |
| FSM_STATE_SLEEPING | All tasks are sleeping, the sleep trap is executing (CPU in low-power state). |
| FSM_STATE_WAKING | At least one task woke up, transitioning from sleep trap back to a user task. |
| FSM_STATE_EXITING | All tasks exited (KERNEL_DYNAMIC only), executing the exit trap to return from Start(). |
| FSM_STATE_MAX | Sentinel: number of valid states (used to size the FSM table), denotes uninitialized state. |
Definition at line 1099 of file stk.h.
|
protected |
Bitmask flags for pending inter-task requests that must be processed by the kernel on the next tick (in UpdateTaskRequest()).
| Enumerator | |
|---|---|
| REQUEST_NONE | No pending requests. |
| REQUEST_ADD_TASK | An AddTask() request is pending from a running task (KERNEL_DYNAMIC only). |
Definition at line 99 of file stk.h.
|
inherited |
Kernel state.
| Enumerator | |
|---|---|
| STATE_INACTIVE | Not ready, IKernel::Initialize() must be called. |
| STATE_READY | Ready to start, IKernel::Start() must be called. |
| STATE_RUNNING | Initialized and running, IKernel::Start() was called successfully. |
| STATE_SUSPENDED | Scheduling is suspended with IKernelService::Suspend(). |
Definition at line 966 of file stk_common.h.
|
inlineexplicit |
Construct the kernel with all storage zero-initialized and the request flag set to ~0 (indicating uninitialized state; cleared to REQUEST_NONE by Initialize()).
Definition at line 798 of file stk.h.
|
inline |
|
inlineprotected |
Add kernel task to the scheduling strategy.
| [in] | task | Pointer to the kernel task. |
Definition at line 1210 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AllocateAndAddNewTask(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::HrtAllocateAndAddNewTask().
|
inlinevirtual |
Register task for a soft real-time (SRT) scheduling.
| [in] | user_task | User task to add. Must not already be registered. Must not be nullptr. |
Implements stk::IKernel.
Definition at line 859 of file stk.h.
|
inlinevirtual |
Register a task for hard real-time (HRT) scheduling.
| [in] | user_task | User task to add. Must not already be registered. Must not be nullptr. |
| [in] | periodicity_tc | Activation period in ticks. Must be > 0 and < INT32_MAX. |
| [in] | deadline_tc | Maximum allowed active duration in ticks. Must be > 0 and < INT32_MAX. |
| [in] | start_delay_tc | Initial sleep delay in ticks before the first activation. 0 means activate immediately. |
Implements stk::IKernel.
Definition at line 898 of file stk.h.
|
inlineprotected |
Allocate new instance of KernelTask and add it into the scheduling process.
| [in] | user_task | User task for which kernel task object is allocated. |
Definition at line 1226 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskRequest().
|
inlineprotected |
Allocate new instance of KernelTask.
| [in] | user_task | User task for which kernel task object is allocated. |
Definition at line 1174 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AllocateAndAddNewTask(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::HrtAllocateAndAddNewTask().
|
inlinevirtual |
Enumerate tasks.
| [in,out] | user_tasks | Pointer to the array for ITask pointers. |
| [in] | max_size | Max size of the provided array. |
Implements stk::IKernel.
Definition at line 1025 of file stk.h.
|
inlineinherited |
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 1062 of file stk_common.h.
References EnumerateTasks(), and STK_STATIC_ASSERT.
|
inlineprotected |
Fetch next event for the FSM.
| [out] | next | Next kernel task to which Kernel can switch. |
Definition at line 1765 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::GetNewFsmState().
|
inlineprotected |
Find kernel task for a Stack Pointer (SP).
| [in] | SP | Stack pointer. |
Definition at line 1312 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnGetTid(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskSleep(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskSleepUntil(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskWait(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RequestAddTask().
|
inlineprotected |
Find kernel task by the bound Stack instance.
| [in] | stack | Stack. |
Definition at line 1296 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskExit().
|
inlineprotected |
Find kernel task by the bound ITask instance.
| [in] | user_task | User task. |
Definition at line 1280 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RemoveTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::ResumeTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::ScheduleTaskRemoval(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::SuspendTask().
|
inlineprotected |
Get new FSM state.
| [out] | next | Next kernel task to which Kernel can switch. |
Definition at line 1806 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnStart(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateFsmState().
|
inlinevirtual |
Get platform driver instance owned by this kernel.
Implements stk::IKernel.
Definition at line 1083 of file stk.h.
|
inlinevirtual |
|
inlinevirtual |
Get task-switching strategy instance owned by this kernel.
Implements stk::IKernel.
Definition at line 1088 of file stk.h.
|
inlineprotected |
Allocate new instance of KernelTask and add it into the HRT scheduling process.
| [in] | user_task | User task for which kernel task object is allocated. |
| [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). |
Definition at line 1242 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask().
|
inlinevirtual |
Initialize kernel.
| [in] | resolution_us | Resolution of the system tick (SysTick) timer in microseconds. Defaults to PERIODICITY_DEFAULT (1000 µs = 1 ms). |
Implements stk::IKernel.
Definition at line 832 of file stk.h.
|
inlineprotected |
Initialize stack of the traps.
Definition at line 1140 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::Start().
|
inlinestaticprotected |
Definition at line 2032 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::FetchNextEvent(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::FindTaskBySP(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::Initialize(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::InitTraps(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnStop(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskExit(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RemoveTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RequestAddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::ScheduleTaskRemoval(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::StateExit(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskRequest(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskState().
|
inlinestaticprotected |
Definition at line 2033 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtDeadline(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtPeriodicity(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtRelativeDeadline(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnStart(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskSleep(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskSleepUntil(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleRemoval(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::Sleep(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::SleepUntil(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::StateSleep(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::StateSwitch(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::StateWake(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Unbind(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskRequest(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskState().
|
inlineprotected |
Check whether Initialize() has been called and completed successfully.
true if Initialize() was called, false otherwise. Definition at line 1997 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::Initialize(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::Start().
|
inline |
Check whether scheduler is currently running.
true if Start() has been called and the first task switch has occurred (m_task_now != nullptr), false before Start() or after all tasks exit. Definition at line 1075 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddKernelTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RemoveTask(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::ScheduleTaskRemoval().
|
inlinestaticprotected |
|
inlinestaticprotected |
Definition at line 2034 of file stk.h.
Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetSleepTicks(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::KernelTask(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskWait(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Unbind(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateSyncObjects(), stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTasks(), and stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::Wait().
|
inlinestaticprotected |
Definition at line 2035 of file stk.h.
Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::Resume(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::Suspend(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskState().
|
inlinestaticprotected |
Check if FSM state is valid.
Definition at line 1132 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::GetNewFsmState().
|
inlineprotectedvirtual |
Called from the Thread process when for getting task/thread id of the process.
| [in] | caller_SP | Value of Stack Pointer (SP) register (for locating the calling process inside the kernel). |
Implements stk::IPlatform::IEventHandler.
Definition at line 1587 of file stk.h.
|
inlineprotectedvirtual |
Called by platform driver immediately after a scheduler start (first tick).
| [out] | active | Set to the stack of the first task to run, or to the sleep-trap stack if all tasks are initially sleeping. |
Implements stk::IPlatform::IEventHandler.
Definition at line 1363 of file stk.h.
|
inlineprotectedvirtual |
Called by the platform driver after a scheduler stop (all tasks have exited).
Implements stk::IPlatform::IEventHandler.
Definition at line 1430 of file stk.h.
|
inlineprotectedvirtual |
Called from the Thread process to suspend scheduling.
| [in] | suspended | true if scheduling was successfully suspended, false otherwise. |
Implements stk::IPlatform::IEventHandler.
Definition at line 1595 of file stk.h.
|
inlineprotectedvirtual |
Called from the Thread process when task finished (its Run function exited by return).
| [out] | stack | Stack of the exited task. |
Implements stk::IPlatform::IEventHandler.
Definition at line 1530 of file stk.h.
|
inlineprotectedvirtual |
Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from scheduling (sleeping).
| [in] | caller_SP | Value of Stack Pointer (SP) register (for locating the calling process inside the kernel). |
| [in] | ticks | Time to sleep (ticks). |
Implements stk::IPlatform::IEventHandler.
Definition at line 1489 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTaskSwitch().
|
inlineprotectedvirtual |
Called by Thread process (via IKernelService::SleepUntil) for exclusion of the calling process from scheduling (sleeping).
| [in] | caller_SP | Value of Stack Pointer (SP) register (for locating the calling process inside the kernel). |
| [in] | timestamp | Absolute timestamp (ticks). |
Implements stk::IPlatform::IEventHandler.
Definition at line 1509 of file stk.h.
|
inlineprotectedvirtual |
Called by Thread process (via IKernelService::SwitchToNext) to switch to a next task.
| [in] | caller_SP | Value of Stack Pointer (SP) register (for locating the calling process inside the kernel). |
Implements stk::IPlatform::IEventHandler.
Definition at line 1484 of file stk.h.
|
inlineprotectedvirtual |
Called from the Thread process when task needs to wait.
| [in] | caller_SP | Value of Stack Pointer (SP) register (for locating the calling process inside the kernel). |
| [in] | sync_obj | ISyncObject instance (passed by Wait). |
| [in] | mutex | IMutex instance (passed by Wait). |
| [in] | timeout | Time to sleep (ticks). |
Implements stk::IPlatform::IEventHandler.
Definition at line 1547 of file stk.h.
|
inlineprotectedvirtual |
Process one scheduler tick. Called from the platform timer/tick ISR.
| [out] | idle | Stack descriptor to context-switch out (nullptr if no switch needed). |
| [out] | active | Stack descriptor to context-switch in (nullptr if no switch needed). |
| [in,out] | ticks | (KERNEL_TICKLESS builds only) On entry: actual number of ticks elapsed since the last call, as measured by the platform driver. On return: the number of ticks the hardware timer may suppress before the next required wakeup, computed as the minimum remaining sleep across all active tasks, clamped to [1, STK_TICKLESS_TICKS_MAX]. The platform driver programs this value into the timer to avoid unnecessary wakeups. This parameter is absent in non-tickless builds. |
true if a context switch is required (idle and active are valid); false if the current task continues running. Implements stk::IPlatform::IEventHandler.
Definition at line 1457 of file stk.h.
|
inlinevirtual |
Remove a previously added task from the kernel before Start().
| [in] | user_task | User task to remove. Must not be nullptr. |
Implements stk::IKernel.
Definition at line 922 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RemoveTask(), and stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTaskState().
|
inlineprotected |
Remove kernel task.
| [in] | task | Kernel task. |
|
inlineprotected |
Request to add new task.
| [in] | user_task | User task to add. |
Definition at line 1256 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::AddTask().
|
inlinevirtual |
Resume task.
| [in] | user_task | Pointer to the user task to resume. |
Implements stk::IKernel.
|
inlineprotected |
Signal the kernel to process a pending AddTask request on the next tick.
Definition at line 2003 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::RequestAddTask().
|
inlinevirtual |
Schedule task removal from scheduling (exit).
| [in] | user_task | User task to remove. Must not be nullptr. |
Implements stk::IKernel.
Definition at line 945 of file stk.h.
|
inlinevirtual |
Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or indefinitely (KERNEL_STATIC mode).
Implements stk::IKernel.
Definition at line 1050 of file stk.h.
|
inlineprotected |
Exits from scheduling.
| [in] | now | Currently active kernel task (ignored). |
| [in] | next | Next kernel task (ignored). |
| [out] | idle | Stack of the task which must enter Idle state. |
| [out] | active | Stack of the task which must enter Active state (to which context will switch). |
Definition at line 1968 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateFsmState().
|
inlineprotected |
Enters into a sleeping mode.
| [in] | now | Currently active kernel task. |
| [in] | next | Next kernel task (ignored). |
| [out] | idle | Stack of the task which must enter Idle state. |
| [out] | active | Stack of the task which must enter Active state (to which context will switch). |
Definition at line 1935 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateFsmState().
|
inlineprotected |
Switches contexts.
| [in] | now | Currently active kernel task. |
| [in] | next | Next kernel task. |
| [out] | idle | Stack of the task which must enter Idle state. |
| [out] | active | Stack of the task which must enter Active state (to which context will switch). |
Definition at line 1857 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateFsmState().
|
inlineprotected |
Wakes up after sleeping.
| [in] | now | Currently active kernel task (ignored). |
| [in] | next | Next kernel task. |
| [out] | idle | Stack of the task which must enter Idle state. |
| [out] | active | Stack of the task which must enter Active state (to which context will switch). |
Definition at line 1903 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateFsmState().
|
inlinevirtual |
Suspend task.
| [in] | user_task | Pointer to the user task to suspend. |
| [out] | suspended | Set to true if task is suspended. |
Implements stk::IKernel.
Definition at line 971 of file stk.h.
|
inlineprotected |
Update FSM state.
| [out] | idle | Stack of the task which must enter Idle state. |
| [out] | active | Stack of the task which must enter Active state (to which context will switch). |
Definition at line 1817 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTick().
|
inlineprotected |
Update synchronization objects.
Definition at line 1709 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTasks().
|
inlineprotected |
Update pending task requests.
Definition at line 1730 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTasks().
|
inlineprotected |
Update tasks (sleep, requests).
Definition at line 1605 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::OnTick().
|
inlineprotected |
Update task state: process removals, advance sleep timers, and track HRT durations.
| [in] | elapsed_ticks | Number of ticks elapsed since the previous call. Always 1 in non-tickless mode, may be >1 in tickless mode. |
Definition at line 1625 of file stk.h.
Referenced by stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault >::UpdateTasks().
|
protected |
|
protected |
Compile-time FSM transition table. Indexed as m_fsm[current_state][event] -> next_state. FSM_STATE_NONE as a next-state means "no transition": the FSM stays in the current state. Updated by UpdateFsmState() each tick via GetNewFsmState() -> FetchNextEvent().
Definition at line 2111 of file stk.h.
|
protected |
|
protected |
|
protected |
Bitmask of pending ERequest flags from running tasks. Written by tasks, read/cleared by UpdateTaskRequest() in tick context.
|
protected |
Kernel service singleton exposed to running tasks via IKernelService::GetInstance().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Static pool of TSize KernelTask slots (free slots have m_user == nullptr).
|
staticconstexpr |
|
staticconstexprprotected |