![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Internal per-slot kernel descriptor that wraps a user ITask instance. More...
#include <stk.h>
Classes | |
| class | AddTaskRequest |
| Payload for an in-flight AddTask() request issued by a running task. More... | |
| class | SrtInfo |
| Per-task soft real-time (SRT) metadata. More... | |
| class | HrtInfo |
| Per-task Hard Real-Time (HRT) scheduling metadata. More... | |
| class | WaitObject |
| Concrete implementation of IWaitObject, embedded in each KernelTask slot. More... | |
Public Types | |
| typedef DLHeadType | ListHeadType |
| List head type for IKernelTask elements. | |
| typedef DLEntryType | ListEntryType |
| List entry type of IKernelTask elements. | |
| typedef DListEntry< IKernelTask, _ClosedLoop > | DLEntryType |
| Convenience alias for this entry type. Used to avoid repeating the full template spelling. | |
| typedef DListHead< IKernelTask, _ClosedLoop > | DLHeadType |
| Convenience alias for the corresponding list head type. | |
Public Member Functions | |
| KernelTask () | |
| Construct a free (unbound) task slot. All fields set to zero/null. | |
| ITask * | GetUserTask () |
| Get bound user task. | |
| Stack * | GetUserStack () |
| Get stack descriptor for this task slot. | |
| bool | IsBusy () const |
| Check whether this slot is bound to a user task. | |
| bool | IsSleeping () const |
| Check whether this task is currently sleeping (waiting for a tick or a wake event). | |
| TId | GetTid () const |
| Get task identifier. | |
| void | Wake () |
| Wake this task on the next scheduling tick. | |
| void | SetCurrentWeight (int32_t weight) |
| Update the run-time scheduling weight (weighted strategies only). | |
| int32_t | GetWeight () const |
| Get static scheduling weight from the user task. | |
| int32_t | GetCurrentWeight () const |
| Get current (run-time) scheduling weight. | |
| Timeout | GetHrtPeriodicity () const |
| Get HRT scheduling periodicity. | |
| Timeout | GetHrtDeadline () const |
| Get absolute HRT deadline (ticks elapsed since task was activated). | |
| Timeout | GetHrtRelativeDeadline () const |
| Get remaining HRT deadline (ticks left before the deadline expires). | |
| Timeout | GetSleepTicks (Timeout sleep_ticks) |
| DLHeadType * | GetHead () const |
| Get the list head this entry currently belongs to. | |
| DLEntryType * | GetNext () const |
| Get the next entry in the list. | |
| DLEntryType * | GetPrev () const |
| Get the previous entry in the list. | |
| bool | IsLinked () const |
| Check whether this entry is currently a member of any list. | |
| operator IKernelTask * () | |
| Implicit conversion to a mutable pointer to the host object (T). | |
| operator const IKernelTask * () const | |
| Implicit conversion to a const pointer to the host object (T). | |
Protected Member Functions | |
| ~KernelTask () | |
| Destructor. | |
| void | Bind (TPlatform *platform, ITask *user_task) |
| Bind this slot to a user task: set access mode, task ID, and initialize the stack. | |
| void | Unbind () |
| Reset this slot to the free (unbound) state, clearing all scheduling metadata. | |
| void | ScheduleRemoval () |
| Schedule the removal of the task from the kernel on next tick. | |
| bool | IsPendingRemoval () const |
| Check if task is pending removal. | |
| bool | IsMemoryOfSP (Word SP) const |
| Check if Stack Pointer (SP) belongs to this task. | |
| void | HrtInit (Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc) |
| Initialize task with HRT info. | |
| void | HrtOnSwitchedIn () |
| Called when task is switched into the scheduling process. | |
| void | HrtOnSwitchedOut (IPlatform *) |
| Called when task is switched out from the scheduling process. | |
| void | HrtHardFailDeadline (IPlatform *platform) |
| Hard-fail HRT task when it missed its deadline. | |
| void | HrtOnWorkCompleted () |
| Called when task process called IKernelService::SwitchToNext to inform Kernel that work is completed. | |
| bool | HrtIsDeadlineMissed (Timeout duration) const |
| Check if deadline missed. | |
| void | ScheduleSleep (Timeout ticks) |
| Put the task into a sleeping state for the specified number of ticks. | |
| void | BusyWaitWhileSleeping () const |
| Block further execution of the task's context while in sleeping state. | |
Protected Attributes | |
| ITask * | m_user |
Bound user task, or NULL when slot is free. | |
| Stack | m_stack |
| Stack descriptor (SP register value + access mode + optional tid). | |
| volatile uint32_t | m_state |
| Bitmask of EStateFlags. Written by task thread, read/cleared by kernel tick. | |
| volatile Timeout | m_time_sleep |
| Sleep countdown: negative while sleeping (absolute value = ticks remaining), zero when awake. | |
| SrtInfo | m_srt [((((TMode) &(KERNEL_HRT)) !=0U) ?(0) :(1))] |
| SRT metadata. Zero-size (no memory) in KERNEL_HRT mode. | |
| HrtInfo | m_hrt [((((TMode) &(KERNEL_HRT)) !=0U) ?(1) :(0))] |
| HRT metadata. Zero-size (no memory) in non-HRT mode. | |
| int32_t | m_rt_weight [((((TStrategy::WEIGHT_API) &(1)) !=0U) ?(1) :(0))] |
| Run-time weight for weighted-round-robin scheduling. Zero-size for unweighted strategies. | |
| WaitObject | m_wait_obj [((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))] |
| Embedded wait object for synchronization. Zero-size (no memory) if KERNEL_SYNC is not set. | |
Private Types | |
| enum | EStateFlags { STATE_NONE = 0 , STATE_REMOVE_PENDING = (1 << 0) , STATE_SLEEP_PENDING = (1 << 1) } |
| Bitmask of transient state flags. Set by the task or the kernel and consumed (cleared) during UpdateTaskState() on the next tick. More... | |
Private Member Functions | |
| void | Link (DLHeadType *head, DLEntryType *next, DLEntryType *prev) |
| Wire this entry into a list between prev and next. | |
| void | Unlink () |
| Remove this entry from its current list. | |
Private Attributes | |
| DLHeadType * | m_head |
Owning list head, or NULL when the entry is not linked. | |
| DLEntryType * | m_next |
Next entry in the list, or NULL (open list boundary) / first entry (closed loop). | |
| DLEntryType * | m_prev |
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop). | |
Friends | |
| class | Kernel |
Internal per-slot kernel descriptor that wraps a user ITask instance.
Holds the kernel-side state for one task slot: the Stack descriptor, sleep timer, HRT or SRT scheduling metadata, optional wait object (KERNEL_SYNC), and optional weight (weighted strategies). The task-switching strategy operates on KernelTask pointers rather than ITask pointers directly.
A slot is "free" when m_user == NULL (IsBusy() == false). The Kernel pre-allocates TSize slots in m_task_storage; AddTask() finds a free slot and calls Bind().
|
inherited |
Convenience alias for this entry type. Used to avoid repeating the full template spelling.
Definition at line 70 of file stk_linked_list.h.
|
inherited |
Convenience alias for the corresponding list head type.
Definition at line 75 of file stk_linked_list.h.
|
inherited |
List entry type of IKernelTask elements.
Definition at line 572 of file stk_common.h.
|
inherited |
List head type for IKernelTask elements.
Definition at line 567 of file stk_common.h.
|
private |
Bitmask of transient state flags. Set by the task or the kernel and consumed (cleared) during UpdateTaskState() on the next tick.
| Enumerator | |
|---|---|
| STATE_NONE | No pending state flags. |
| STATE_REMOVE_PENDING | Task returned from its Run function; slot will be freed on the next tick (KERNEL_DYNAMIC only). |
| STATE_SLEEP_PENDING | Task called Sleep/SleepUntil/Yield; strategy's OnTaskSleep() will be invoked on the next tick (sleep-aware strategies only). |
Definition at line 124 of file stk.h.
|
inlineexplicit |
Construct a free (unbound) task slot. All fields set to zero/null.
Definition at line 148 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_hrt, m_rt_weight, m_srt, m_stack, m_state, m_time_sleep, m_user, m_wait_obj, and STATE_NONE.
|
inlineprotected |
|
inlineprotected |
Bind this slot to a user task: set access mode, task ID, and initialize the stack.
| [in] | platform | Platform driver used to initialize the stack frame. |
| [in] | user_task | User task to bind. Asserts that the stack is successfully initialized. |
Definition at line 445 of file stk.h.
References stk::ITask::GetAccessMode(), stk::ITask::GetId(), m_stack, m_user, stk::STACK_USER_TASK, and STK_ASSERT.
|
inlineprotected |
Block further execution of the task's context while in sleeping state.
Definition at line 618 of file stk.h.
References IsSleeping().
|
inlinevirtual |
Get current (run-time) scheduling weight.
Implements stk::IKernelTask.
Definition at line 212 of file stk.h.
References m_rt_weight.
|
inlineinherited |
Get the list head this entry currently belongs to.
NULL if the entry is not linked. Definition at line 80 of file stk_linked_list.h.
|
inlinevirtual |
Get absolute HRT deadline (ticks elapsed since task was activated).
Implements stk::IKernelTask.
Definition at line 230 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_hrt, and STK_ASSERT.
|
inlinevirtual |
Get HRT scheduling periodicity.
Implements stk::IKernelTask.
Definition at line 218 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_hrt, and STK_ASSERT.
|
inlinevirtual |
Get remaining HRT deadline (ticks left before the deadline expires).
Implements stk::IKernelTask.
Definition at line 242 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), IsSleeping(), m_hrt, and STK_ASSERT.
|
inlineinherited |
Get the next entry in the list.
NULL if this is the last entry (open list) or the first entry (closed loop, where next wraps to first). _ClosedLoop == true) this pointer is never NULL when the entry is linked. Definition at line 88 of file stk_linked_list.h.
|
inlineinherited |
Get the previous entry in the list.
NULL if this is the first entry (open list) or the last entry (closed loop, where prev wraps to last). _ClosedLoop == true) this pointer is never NULL when the entry is linked. Definition at line 96 of file stk_linked_list.h.
|
inline |
Definition at line 250 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_time_sleep, m_wait_obj, stk::Max(), and stk::Min().
|
inline |
Get task identifier.
Definition at line 179 of file stk.h.
References m_user, and stk::hw::PtrToWord().
|
inlinevirtual |
|
inlinevirtual |
|
inlinevirtual |
Get static scheduling weight from the user task.
Implements stk::IKernelTask.
Definition at line 205 of file stk.h.
References m_user.
|
inlineprotected |
Hard-fail HRT task when it missed its deadline.
| [in] | platform | Platform driver instance. |
Definition at line 567 of file stk.h.
References HrtIsDeadlineMissed(), m_hrt, m_user, stk::IPlatform::ProcessHardFault(), and STK_ASSERT.
|
inlineprotected |
Initialize task with HRT info.
| [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 523 of file stk.h.
References m_hrt, ScheduleSleep(), and STK_ASSERT.
|
inlineprotected |
Check if deadline missed.
Definition at line 590 of file stk.h.
References m_hrt.
Referenced by HrtHardFailDeadline().
|
inlineprotected |
Called when task is switched into the scheduling process.
| [in] | ticks | Current ticks of the Kernel. |
Definition at line 542 of file stk.h.
|
inlineprotected |
Called when task is switched out from the scheduling process.
| [in] | platform | Platform driver instance. |
| [in] | ticks | Current ticks of the Kernel. |
Definition at line 549 of file stk.h.
References m_hrt, ScheduleSleep(), and STK_ASSERT.
|
inlineprotected |
Called when task process called IKernelService::SwitchToNext to inform Kernel that work is completed.
Definition at line 581 of file stk.h.
References m_hrt.
Referenced by ScheduleRemoval().
|
inline |
|
inlineinherited |
Check whether this entry is currently a member of any list.
true if linked (m_head != NULL); false otherwise. Definition at line 101 of file stk_linked_list.h.
|
inlineprotected |
|
inlineprotected |
Check if task is pending removal.
Definition at line 504 of file stk.h.
References m_state, and STATE_REMOVE_PENDING.
|
inlinevirtual |
Check whether this task is currently sleeping (waiting for a tick or a wake event).
true if m_time_sleep < 0 (negative value encodes remaining sleep ticks). Implements stk::IKernelTask.
Definition at line 174 of file stk.h.
References m_time_sleep.
Referenced by BusyWaitWhileSleeping(), GetHrtRelativeDeadline(), and Wake().
|
inlineprivateinherited |
Wire this entry into a list between prev and next.
| [in] | head | The owning DListHead. Stored as a back-pointer for IsLinked() and ownership checks. |
| [in] | next | The entry that will follow this one, or NULL if this becomes the last entry. |
| [in] | prev | The entry that will precede this one, or NULL if this becomes the first entry. |
Definition at line 137 of file stk_linked_list.h.
|
inlineinherited |
Implicit conversion to a const pointer to the host object (T).
Definition at line 115 of file stk_linked_list.h.
|
inlineinherited |
Implicit conversion to a mutable pointer to the host object (T).
Definition at line 108 of file stk_linked_list.h.
|
inlineprotected |
Schedule the removal of the task from the kernel on next tick.
Definition at line 489 of file stk.h.
References HrtOnWorkCompleted(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_state, ScheduleSleep(), STATE_REMOVE_PENDING, and stk::WAIT_INFINITE.
|
inlineprotected |
Put the task into a sleeping state for the specified number of ticks.
| [in] | ticks | Number of ticks to sleep. Must be > 0. |
-ticks in m_time_sleep (negative values indicate sleeping; UpdateTaskState() increments toward 0 each tick until the task wakes). Definition at line 601 of file stk.h.
References m_state, m_time_sleep, STATE_SLEEP_PENDING, and STK_ASSERT.
Referenced by HrtInit(), HrtOnSwitchedOut(), and ScheduleRemoval().
|
inlinevirtual |
Update the run-time scheduling weight (weighted strategies only).
| [in] | weight | New current weight. Ignored unless TStrategy::WEIGHT_API is true. |
Implements stk::IKernelTask.
Definition at line 196 of file stk.h.
References m_rt_weight.
|
inlineprotected |
Reset this slot to the free (unbound) state, clearing all scheduling metadata.
Definition at line 468 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_hrt, m_srt, m_stack, m_state, m_time_sleep, m_user, m_wait_obj, STATE_NONE, and STK_ASSERT.
|
inlineprivateinherited |
Remove this entry from its current list.
Definition at line 157 of file stk_linked_list.h.
|
inlinevirtual |
Wake this task on the next scheduling tick.
Implements stk::IKernelTask.
Definition at line 185 of file stk.h.
References IsSleeping(), m_time_sleep, and STK_ASSERT.
|
friend |
|
privateinherited |
Owning list head, or NULL when the entry is not linked.
Definition at line 170 of file stk_linked_list.h.
|
protected |
HRT metadata. Zero-size (no memory) in non-HRT mode.
Definition at line 631 of file stk.h.
Referenced by GetHrtDeadline(), GetHrtPeriodicity(), GetHrtRelativeDeadline(), HrtHardFailDeadline(), HrtInit(), HrtIsDeadlineMissed(), HrtOnSwitchedOut(), HrtOnWorkCompleted(), KernelTask(), and Unbind().
|
privateinherited |
Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
Definition at line 171 of file stk_linked_list.h.
|
privateinherited |
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).
Definition at line 172 of file stk_linked_list.h.
|
protected |
Run-time weight for weighted-round-robin scheduling. Zero-size for unweighted strategies.
Definition at line 632 of file stk.h.
Referenced by GetCurrentWeight(), KernelTask(), and SetCurrentWeight().
|
protected |
SRT metadata. Zero-size (no memory) in KERNEL_HRT mode.
Definition at line 630 of file stk.h.
Referenced by KernelTask(), and Unbind().
|
protected |
Stack descriptor (SP register value + access mode + optional tid).
Definition at line 627 of file stk.h.
Referenced by Bind(), GetUserStack(), KernelTask(), and Unbind().
|
protected |
Bitmask of EStateFlags. Written by task thread, read/cleared by kernel tick.
Definition at line 628 of file stk.h.
Referenced by IsPendingRemoval(), KernelTask(), ScheduleRemoval(), ScheduleSleep(), and Unbind().
|
protected |
Sleep countdown: negative while sleeping (absolute value = ticks remaining), zero when awake.
Definition at line 629 of file stk.h.
Referenced by GetSleepTicks(), IsSleeping(), KernelTask(), ScheduleSleep(), Unbind(), and Wake().
|
protected |
Bound user task, or NULL when slot is free.
Definition at line 626 of file stk.h.
Referenced by Bind(), GetTid(), GetUserTask(), GetWeight(), HrtHardFailDeadline(), IsBusy(), IsMemoryOfSP(), KernelTask(), and Unbind().
|
protected |
Embedded wait object for synchronization. Zero-size (no memory) if KERNEL_SYNC is not set.
Definition at line 633 of file stk.h.
Referenced by GetSleepTicks(), KernelTask(), and Unbind().