SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask Class Reference

Internal per-slot kernel descriptor that wraps a user ITask instance. More...

#include <stk.h>

Inheritance diagram for stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask:
Collaboration diagram for stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask:

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.
ITaskGetUserTask ()
 Get bound user task.
StackGetUserStack ()
 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)
DLHeadTypeGetHead () const
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext () const
 Get the next entry in the list.
DLEntryTypeGetPrev () 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

ITaskm_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

DLHeadTypem_head
 Owning list head, or NULL when the entry is not linked.
DLEntryTypem_next
 Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryTypem_prev
 Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Friends

class Kernel

Detailed Description

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
class stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask

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().

Definition at line 116 of file stk.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<IKernelTask, _ClosedLoop> stk::util::DListEntry< IKernelTask, _ClosedLoop >::DLEntryType
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.

◆ DLHeadType

typedef DListHead<IKernelTask, _ClosedLoop> stk::util::DListEntry< IKernelTask, _ClosedLoop >::DLHeadType
inherited

Convenience alias for the corresponding list head type.

Definition at line 75 of file stk_linked_list.h.

◆ ListEntryType

List entry type of IKernelTask elements.

Definition at line 572 of file stk_common.h.

◆ ListHeadType

List head type for IKernelTask elements.

Definition at line 567 of file stk_common.h.

Member Enumeration Documentation

◆ EStateFlags

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
enum stk::Kernel::KernelTask::EStateFlags
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.

125 {
126 STATE_NONE = 0,
127 STATE_REMOVE_PENDING = (1 << 0),
128 STATE_SLEEP_PENDING = (1 << 1)
129 };
@ STATE_REMOVE_PENDING
Task returned from its Run function; slot will be freed on the next tick (KERNEL_DYNAMIC only).
Definition stk.h:127
@ STATE_SLEEP_PENDING
Task called Sleep/SleepUntil/Yield; strategy's OnTaskSleep() will be invoked on the next tick (sleep-...
Definition stk.h:128
@ STATE_NONE
No pending state flags.
Definition stk.h:126

Constructor & Destructor Documentation

◆ KernelTask()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::KernelTask ( )
inlineexplicit

Construct a free (unbound) task slot. All fields set to zero/null.

Note
In KERNEL_SYNC mode the embedded WaitObject back-pointer is wired to this KernelTask at construction so the wait object can wake its owning task.

Definition at line 148 of file stk.h.

148 : m_user(nullptr), m_stack(), m_state(STATE_NONE), m_time_sleep(0),
149 m_srt(), m_hrt(), m_rt_weight()
150 {
151 // bind to wait object
152 if (IsSyncMode())
153 m_wait_obj->m_task = this;
154 }
static bool IsSyncMode()
Definition stk.h:2034
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.
Definition stk.h:632
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.
Definition stk.h:633
Stack m_stack
Stack descriptor (SP register value + access mode + optional tid).
Definition stk.h:627
volatile uint32_t m_state
Bitmask of EStateFlags. Written by task thread, read/cleared by kernel tick.
Definition stk.h:628
ITask * m_user
Bound user task, or NULL when slot is free.
Definition stk.h:626
HrtInfo m_hrt[((((TMode) &(KERNEL_HRT)) !=0U) ?(1) :(0))]
HRT metadata. Zero-size (no memory) in non-HRT mode.
Definition stk.h:631
SrtInfo m_srt[((((TMode) &(KERNEL_HRT)) !=0U) ?(0) :(1))]
SRT metadata. Zero-size (no memory) in KERNEL_HRT mode.
Definition stk.h:630
volatile Timeout m_time_sleep
Sleep countdown: negative while sleeping (absolute value = ticks remaining), zero when awake.
Definition stk.h:629

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.

Here is the call graph for this function:

◆ ~KernelTask()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::~KernelTask ( )
inlineprotected

Destructor.

Note
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

Definition at line 285 of file stk.h.

286 {}

Member Function Documentation

◆ Bind()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Bind ( TPlatform * platform,
ITask * user_task )
inlineprotected

Bind this slot to a user task: set access mode, task ID, and initialize the stack.

Parameters
[in]platformPlatform driver used to initialize the stack frame.
[in]user_taskUser task to bind. Asserts that the stack is successfully initialized.

Definition at line 445 of file stk.h.

446 {
447 // set access mode for this stack
448 m_stack.mode = user_task->GetAccessMode();
449
450 // set task id for tracking purpose
451 #if STK_NEED_TASK_ID
452 m_stack.tid = user_task->GetId();
453 #endif
454
455 // init stack of the user task
457 {
458 STK_ASSERT(false);
459 }
460
461 // bind user task
463 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
Concrete implementation of IKernel.
Definition stk.h:81

References stk::ITask::GetAccessMode(), stk::ITask::GetId(), m_stack, m_user, stk::STACK_USER_TASK, and STK_ASSERT.

Here is the call graph for this function:

◆ BusyWaitWhileSleeping()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::BusyWaitWhileSleeping ( ) const
inlineprotected

Block further execution of the task's context while in sleeping state.

Definition at line 618 of file stk.h.

619 {
620 while (IsSleeping())
621 {
623 }
624 }
bool IsSleeping() const
Check whether this task is currently sleeping (waiting for a tick or a wake event).
Definition stk.h:174

References IsSleeping().

Here is the call graph for this function:

◆ GetCurrentWeight()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
int32_t stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetCurrentWeight ( ) const
inlinevirtual

Get current (run-time) scheduling weight.

Returns
m_rt_weight[0] if WEIGHT_API is true; 1 otherwise.
Note
The run-time weight is decremented each tick by the weighted strategy and reset to GetWeight() when exhausted.

Implements stk::IKernelTask.

Definition at line 212 of file stk.h.

212{ return (TStrategy::WEIGHT_API ? m_rt_weight[0] : 1); }

References m_rt_weight.

◆ GetHead()

DLHeadType * stk::util::DListEntry< IKernelTask, _ClosedLoop >::GetHead ( ) const
inlineinherited

Get the list head this entry currently belongs to.

Returns
Pointer to the owning DListHead, or NULL if the entry is not linked.

Definition at line 80 of file stk_linked_list.h.

80{ return m_head; }
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

◆ GetHrtDeadline()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtDeadline ( ) const
inlinevirtual

Get absolute HRT deadline (ticks elapsed since task was activated).

Returns
Deadline in ticks. The task must complete its work within this many ticks of being switched in, or OnDeadlineMissed() is invoked.
Note
KERNEL_HRT mode only. Asserts if called outside HRT mode.

Implements stk::IKernelTask.

Definition at line 230 of file stk.h.

231 {
233
234 return (IsHrtMode() ? m_hrt[0].deadline : 0);
235 }
static bool IsHrtMode()
Definition stk.h:2033

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_hrt, and STK_ASSERT.

Here is the call graph for this function:

◆ GetHrtPeriodicity()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtPeriodicity ( ) const
inlinevirtual

Get HRT scheduling periodicity.

Returns
Period in ticks between successive activations of this task.
Note
KERNEL_HRT mode only. Asserts if called outside HRT mode.

Implements stk::IKernelTask.

Definition at line 218 of file stk.h.

219 {
221
222 return (IsHrtMode() ? m_hrt[0].periodicity : 0);
223 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_hrt, and STK_ASSERT.

Here is the call graph for this function:

◆ GetHrtRelativeDeadline()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetHrtRelativeDeadline ( ) const
inlinevirtual

Get remaining HRT deadline (ticks left before the deadline expires).

Returns
deadline - duration: ticks remaining before the task must call Yield(). A negative or zero value means the deadline has been missed.
Note
KERNEL_HRT mode only. Asserts if called outside HRT mode or while sleeping.

Implements stk::IKernelTask.

Definition at line 242 of file stk.h.

243 {
246
247 return (IsHrtMode() ? (m_hrt[0].deadline - m_hrt[0].duration) : 0);
248 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), IsSleeping(), m_hrt, and STK_ASSERT.

Here is the call graph for this function:

◆ GetNext()

DLEntryType * stk::util::DListEntry< IKernelTask, _ClosedLoop >::GetNext ( ) const
inlineinherited

Get the next entry in the list.

Returns
Pointer to the next DListEntry, or NULL if this is the last entry (open list) or the first entry (closed loop, where next wraps to first).
Note
In a closed loop (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 88 of file stk_linked_list.h.

88{ return m_next; }

◆ GetPrev()

DLEntryType * stk::util::DListEntry< IKernelTask, _ClosedLoop >::GetPrev ( ) const
inlineinherited

Get the previous entry in the list.

Returns
Pointer to the previous DListEntry, or NULL if this is the first entry (open list) or the last entry (closed loop, where prev wraps to last).
Note
In a closed loop (_ClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 96 of file stk_linked_list.h.

96{ return m_prev; }

◆ GetSleepTicks()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetSleepTicks ( Timeout sleep_ticks)
inline

Definition at line 250 of file stk.h.

251 {
252 // note: task sleep time is negative
254
255 if (IsSyncMode())
256 {
257 // likely task is sleeping during sync operation (see Wait)
258 if (m_wait_obj->IsWaiting())
259 {
260 // note: sync wait time is positive
261 task_sleep = m_wait_obj->m_time_wait;
262
263 // we shall account for only valid time (when task is waiting during sync operation)
264 if (task_sleep > 0)
266 }
267 else
268 {
270 }
271 }
272 else
273 {
275 }
276
277 // clamp to [1, STK_TICKLESS_TICKS_MAX] range
278 return Max<Timeout>(1, sleep_ticks);
279 }
static constexpr T Max(T a, T b)
Compile-time maximum of two values.
Definition stk_defs.h:541
static constexpr T Min(T a, T b)
Compile-time minimum of two values.
Definition stk_defs.h:535

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_time_sleep, m_wait_obj, stk::Max(), and stk::Min().

Here is the call graph for this function:

◆ GetTid()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
TId stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetTid ( ) const
inline

Get task identifier.

Returns
TId derived from the bound ITask pointer address (unique per task instance).

Definition at line 179 of file stk.h.

179{ return hw::PtrToWord(m_user); }
__stk_forceinline Word PtrToWord(T *ptr) noexcept
Cast a pointer to a CPU register-width integer.
Definition stk_arch.h:94

References m_user, and stk::hw::PtrToWord().

Here is the call graph for this function:

◆ GetUserStack()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Stack * stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack ( )
inlinevirtual

Get stack descriptor for this task slot.

Returns
Pointer to the Stack (SP register value and access mode flags).

Implements stk::IKernelTask.

Definition at line 164 of file stk.h.

164{ return &m_stack; }

References m_stack.

◆ GetUserTask()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
ITask * stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserTask ( )
inlinevirtual

Get bound user task.

Returns
Pointer to the ITask, or NULL if the slot is free (IsBusy() == false).

Implements stk::IKernelTask.

Definition at line 159 of file stk.h.

159{ return m_user; }

References m_user.

◆ GetWeight()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
int32_t stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetWeight ( ) const
inlinevirtual

Get static scheduling weight from the user task.

Returns
ITask::GetWeight() if WEIGHT_API is true; 1 otherwise.

Implements stk::IKernelTask.

Definition at line 205 of file stk.h.

205{ return (TStrategy::WEIGHT_API ? m_user->GetWeight() : 1); }

References m_user.

◆ HrtHardFailDeadline()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtHardFailDeadline ( IPlatform * platform)
inlineprotected

Hard-fail HRT task when it missed its deadline.

Note
Related to stk::KERNEL_HRT mode only.
Parameters
[in]platformPlatform driver instance.

Definition at line 567 of file stk.h.

568 {
569 const Timeout duration = m_hrt[0].duration;
570
571 STK_ASSERT(duration >= 0);
573
574 m_user->OnDeadlineMissed(duration);
575 platform->ProcessHardFault();
576 }
bool HrtIsDeadlineMissed(Timeout duration) const
Check if deadline missed.
Definition stk.h:590

References HrtIsDeadlineMissed(), m_hrt, m_user, stk::IPlatform::ProcessHardFault(), and STK_ASSERT.

Here is the call graph for this function:

◆ HrtInit()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtInit ( Timeout periodicity_tc,
Timeout deadline_tc,
Timeout start_delay_tc )
inlineprotected

Initialize task with HRT info.

Note
Related to stk::KERNEL_HRT mode only.
Parameters
[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).

Definition at line 523 of file stk.h.

524 {
530
531 m_hrt[0].periodicity = periodicity_tc;
532 m_hrt[0].deadline = deadline_tc;
533
534 if (start_delay_tc > 0)
536 }
void ScheduleSleep(Timeout ticks)
Put the task into a sleeping state for the specified number of ticks.
Definition stk.h:601

References m_hrt, ScheduleSleep(), and STK_ASSERT.

Here is the call graph for this function:

◆ HrtIsDeadlineMissed()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtIsDeadlineMissed ( Timeout duration) const
inlineprotected

Check if deadline missed.

Note
Related to stk::KERNEL_HRT mode only.

Definition at line 590 of file stk.h.

590{ return (duration > m_hrt[0].deadline); }

References m_hrt.

Referenced by HrtHardFailDeadline().

Here is the caller graph for this function:

◆ HrtOnSwitchedIn()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedIn ( )
inlineprotected

Called when task is switched into the scheduling process.

Note
Related to stk::KERNEL_HRT mode only.
Parameters
[in]ticksCurrent ticks of the Kernel.

Definition at line 542 of file stk.h.

542{}

◆ HrtOnSwitchedOut()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedOut ( IPlatform * )
inlineprotected

Called when task is switched out from the scheduling process.

Note
Related to stk::KERNEL_HRT mode only.
Parameters
[in]platformPlatform driver instance.
[in]ticksCurrent ticks of the Kernel.

Definition at line 549 of file stk.h.

550 {
551 const Timeout duration = m_hrt[0].duration;
552
553 STK_ASSERT(duration >= 0);
554
555 Timeout sleep = m_hrt[0].periodicity - duration;
556 if (sleep > 0)
558
559 m_hrt[0].duration = 0;
560 m_hrt[0].done = false;
561 }

References m_hrt, ScheduleSleep(), and STK_ASSERT.

Here is the call graph for this function:

◆ HrtOnWorkCompleted()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnWorkCompleted ( )
inlineprotected

Called when task process called IKernelService::SwitchToNext to inform Kernel that work is completed.

Note
Related to stk::KERNEL_HRT mode only.

Definition at line 581 of file stk.h.

582 {
583 m_hrt[0].done = true;
585 }

References m_hrt.

Referenced by ScheduleRemoval().

Here is the caller graph for this function:

◆ IsBusy()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy ( ) const
inline

Check whether this slot is bound to a user task.

Returns
true if a user task is assigned (m_user != NULL); false if the slot is free.

Definition at line 169 of file stk.h.

169{ return (m_user != nullptr); }

References m_user.

◆ IsLinked()

bool stk::util::DListEntry< IKernelTask, _ClosedLoop >::IsLinked ( ) const
inlineinherited

Check whether this entry is currently a member of any list.

Returns
true if linked (m_head != NULL); false otherwise.

Definition at line 101 of file stk_linked_list.h.

101{ return (GetHead() != nullptr); }

◆ IsMemoryOfSP()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsMemoryOfSP ( Word SP) const
inlineprotected

Check if Stack Pointer (SP) belongs to this task.

Parameters
[in]SPStack Pointer.

Definition at line 509 of file stk.h.

510 {
511 Word *start = m_user->GetStack();
512 Word *end = start + m_user->GetStackSize();
513
514 return (SP >= hw::PtrToWord(start)) && (SP <= hw::PtrToWord(end));
515 }

References m_user, and stk::hw::PtrToWord().

Here is the call graph for this function:

◆ IsPendingRemoval()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsPendingRemoval ( ) const
inlineprotected

Check if task is pending removal.

Definition at line 504 of file stk.h.

504{ return ((m_state & STATE_REMOVE_PENDING) != 0U); }

References m_state, and STATE_REMOVE_PENDING.

◆ IsSleeping()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping ( ) const
inlinevirtual

Check whether this task is currently sleeping (waiting for a tick or a wake event).

Returns
true if m_time_sleep < 0 (negative value encodes remaining sleep ticks).

Implements stk::IKernelTask.

Definition at line 174 of file stk.h.

174{ return (m_time_sleep < 0); }

References m_time_sleep.

Referenced by BusyWaitWhileSleeping(), GetHrtRelativeDeadline(), and Wake().

Here is the caller graph for this function:

◆ Link()

void stk::util::DListEntry< IKernelTask, _ClosedLoop >::Link ( DLHeadType * head,
DLEntryType * next,
DLEntryType * prev )
inlineprivateinherited

Wire this entry into a list between prev and next.

Parameters
[in]headThe owning DListHead. Stored as a back-pointer for IsLinked() and ownership checks.
[in]nextThe entry that will follow this one, or NULL if this becomes the last entry.
[in]prevThe entry that will precede this one, or NULL if this becomes the first entry.
Note
Called exclusively by DListHead::Link(). Assumes the entry is not currently linked. Updates the neighbours' forward/back pointers to splice this entry in.

Definition at line 137 of file stk_linked_list.h.

138 {
139 m_head = head;
140 m_next = next;
141 m_prev = prev;
142
143 if (m_prev != nullptr)
144 m_prev->m_next = this;
145
146 if (m_next != nullptr)
147 m_next->m_prev = this;
148 }
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).

◆ operator const IKernelTask *()

stk::util::DListEntry< IKernelTask, _ClosedLoop >::operator const IKernelTask * ( ) const
inlineinherited

Implicit conversion to a const pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, _ClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 115 of file stk_linked_list.h.

115{ return static_cast<const T *>(this); }

◆ operator IKernelTask *()

stk::util::DListEntry< IKernelTask, _ClosedLoop >::operator IKernelTask* ( )
inlineinherited

Implicit conversion to a mutable pointer to the host object (T).

Note
Safe because T must derive from DListEntry<T, _ClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 108 of file stk_linked_list.h.

108{ return static_cast<T *>(this); }

◆ ScheduleRemoval()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleRemoval ( )
inlineprotected

Schedule the removal of the task from the kernel on next tick.

Definition at line 489 of file stk.h.

490 {
491 // make this task sleeping to switch it out from scheduling process
493
494 // mark it as done HRT task
495 if (IsHrtMode())
497
498 // mark it as pending for removal
500 }
void HrtOnWorkCompleted()
Called when task process called IKernelService::SwitchToNext to inform Kernel that work is completed.
Definition stk.h:581

References HrtOnWorkCompleted(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), m_state, ScheduleSleep(), STATE_REMOVE_PENDING, and stk::WAIT_INFINITE.

Here is the call graph for this function:

◆ ScheduleSleep()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleSleep ( Timeout ticks)
inlineprotected

Put the task into a sleeping state for the specified number of ticks.

Parameters
[in]ticksNumber of ticks to sleep. Must be > 0.
Note
Stores -ticks in m_time_sleep (negative values indicate sleeping; UpdateTaskState() increments toward 0 each tick until the task wakes).
If the strategy uses SLEEP_EVENT_API and the task is not already sleeping, sets STATE_SLEEP_PENDING so OnTaskSleep() is delivered on the next tick.
A full memory fence is emitted after the assignment so that the ISR-side scheduler sees the updated value without delay.

Definition at line 601 of file stk.h.

602 {
603 STK_ASSERT(ticks > 0);
604
605 // set state first as kernel checks it when task IsSleeping
607 {
608 if (m_time_sleep >= 0)
610 }
611
614 }

References m_state, m_time_sleep, STATE_SLEEP_PENDING, and STK_ASSERT.

Referenced by HrtInit(), HrtOnSwitchedOut(), and ScheduleRemoval().

Here is the caller graph for this function:

◆ SetCurrentWeight()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::SetCurrentWeight ( int32_t weight)
inlinevirtual

Update the run-time scheduling weight (weighted strategies only).

Parameters
[in]weightNew current weight. Ignored unless TStrategy::WEIGHT_API is true.

Implements stk::IKernelTask.

Definition at line 196 of file stk.h.

197 {
199 m_rt_weight[0] = weight;
200 }

References m_rt_weight.

◆ Unbind()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Unbind ( )
inlineprotected

Reset this slot to the free (unbound) state, clearing all scheduling metadata.

Note
Called by RemoveTask(). After Unbind() the slot is available for the next AddTask().

Definition at line 468 of file stk.h.

469 {
470 if (IsSyncMode())
471 {
472 // should be freed from waiting on task exit
473 STK_ASSERT(!m_wait_obj->IsWaiting());
474 }
475
476 m_user = nullptr;
477 m_stack = {};
479 m_time_sleep = 0;
480
481 if (IsHrtMode())
482 m_hrt[0].Clear();
483 else
484 m_srt->Clear();
485 }

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.

Here is the call graph for this function:

◆ Unlink()

void stk::util::DListEntry< IKernelTask, _ClosedLoop >::Unlink ( )
inlineprivateinherited

Remove this entry from its current list.

Note
Called exclusively by DListHead::Unlink(). Patches the neighbours' pointers to bridge over this entry, then clears m_head, m_next, and m_prev to NULL so the entry is in a clean unlinked state.
Does not update DListHead::m_count or m_first / m_last — those are the responsibility of the calling DListHead::Unlink().

Definition at line 157 of file stk_linked_list.h.

158 {
159 if (m_prev != nullptr)
161
162 if (m_next != nullptr)
164
165 m_head = nullptr;
166 m_next = nullptr;
167 m_prev = nullptr;
168 }

◆ Wake()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Wake ( )
inlinevirtual

Wake this task on the next scheduling tick.

Note
Sets m_time_sleep to -1 (one tick remaining) so the task exits sleep state on the next UpdateTaskState() pass. Asserts that the task is currently sleeping.

Implements stk::IKernelTask.

Definition at line 185 of file stk.h.

186 {
188
189 // wakeup on a next cycle
190 m_time_sleep = -1;
191 }

References IsSleeping(), m_time_sleep, and STK_ASSERT.

Here is the call graph for this function:

◆ Kernel

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
friend class Kernel
friend

Definition at line 118 of file stk.h.

References Kernel.

Referenced by Kernel.

Member Data Documentation

◆ m_head

DLHeadType* stk::util::DListEntry< IKernelTask, _ClosedLoop >::m_head
privateinherited

Owning list head, or NULL when the entry is not linked.

Definition at line 170 of file stk_linked_list.h.

◆ m_hrt

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
HrtInfo stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_hrt[((((TMode) &(KERNEL_HRT)) !=0U) ?(1) :(0))]
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().

◆ m_next

DLEntryType* stk::util::DListEntry< IKernelTask, _ClosedLoop >::m_next
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.

◆ m_prev

DLEntryType* stk::util::DListEntry< IKernelTask, _ClosedLoop >::m_prev
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.

◆ m_rt_weight

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
int32_t stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_rt_weight[((((TStrategy::WEIGHT_API) &(1)) !=0U) ?(1) :(0))]
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().

◆ m_srt

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
SrtInfo stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_srt[((((TMode) &(KERNEL_HRT)) !=0U) ?(0) :(1))]
protected

SRT metadata. Zero-size (no memory) in KERNEL_HRT mode.

Definition at line 630 of file stk.h.

Referenced by KernelTask(), and Unbind().

◆ m_stack

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Stack stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_stack
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().

◆ m_state

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
volatile uint32_t stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_state
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().

◆ m_time_sleep

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
volatile Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_time_sleep
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().

◆ m_user

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
ITask* stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_user
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().

◆ m_wait_obj

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
WaitObject stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_wait_obj[((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))]
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().


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