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

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.
enum  
 A tag for type-safe casts done by CastListEntryToParent. More...
typedef DListEntry< IKernelTask, TClosedLoop > DLEntryType
 Convenience alias for this entry type. Used to avoid repeating the full template spelling.
typedef DListHead< IKernelTask, TClosedLoop > 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 () override
 Get bound user task.
Stack GetUserStack () const override
 Get stack descriptor for this task slot.
bool IsBusy () const
 Check whether this slot is bound to a user task.
bool IsSleeping () const override
 Check whether this task is currently sleeping (waiting for a tick or a wake event).
TId GetTid () const
 Get task identifier.
void Wake () override
 Wake this task on the next scheduling tick.
void SetCurrentWeight (Weight weight) override
 Update the run-time scheduling weight (weighted strategies only).
Weight GetWeight () const override
 Get static scheduling weight from the user task.
Weight GetCurrentWeight () const override
 Get current (run-time) scheduling weight.
Timeout GetHrtPeriodicity () const override
 Get HRT scheduling periodicity.
Timeout GetHrtDeadline () const override
 Get absolute HRT deadline (ticks elapsed since task was activated).
Timeout GetHrtRelativeDeadline () const override
 Get remaining HRT deadline (ticks left before the deadline expires).
Timeout GetSleepTicks (Timeout sleep_ticks)
DLHeadTypeGetHead ()
 Get the list head this entry currently belongs to.
DLEntryTypeGetNext ()
 Get the next entry in the list.
DLEntryTypeGetPrev ()
 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 ()=default
 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 ()
 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.
StackGetUserStackPtr ()
 Get pointer to user Stack.

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 [STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 0U, 1U >::Value]
 SRT metadata. Zero-size (no memory) in KERNEL_HRT mode.
HrtInfo m_hrt [STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 1U, 0U >::Value]
 HRT metadata. Zero-size (no memory) in non-HRT mode.
Weight m_rt_weight [STK_ALLOCATE_COUNT< TStrategy::WEIGHT_API, 1U, 1U, 0U >::Value]
 Run-time weight for weighted-round-robin scheduling. Zero-size for unweighted strategies.
WaitObject m_wait_obj [STK_ALLOCATE_COUNT< TMode, KERNEL_SYNC, 1U, 0U >::Value]
 Embedded wait object for synchronization. Zero-size (no memory) if KERNEL_SYNC is not set.

Private Types

enum  EStateFlags : uint32_t {
  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 120 of file stk.h.

Member Typedef Documentation

◆ DLEntryType

typedef DListEntry<IKernelTask, TClosedLoop> stk::util::DListEntry< IKernelTask, TClosedLoop >::DLEntryType
inherited

Convenience alias for this entry type. Used to avoid repeating the full template spelling.

Definition at line 75 of file stk_linked_list.h.

◆ DLHeadType

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

Convenience alias for the corresponding list head type.

Definition at line 80 of file stk_linked_list.h.

◆ ListEntryType

List entry type of IKernelTask elements.

Definition at line 758 of file stk_common.h.

◆ ListHeadType

List head type for IKernelTask elements.

Definition at line 753 of file stk_common.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited

A tag for type-safe casts done by CastListEntryToParent.

See also
CastListEntryToParent.

Definition at line 70 of file stk_linked_list.h.

70{ DLEntryTag = 1 };
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...

◆ EStateFlags

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

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

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 152 of file stk.h.

153 m_srt(), m_hrt(), m_rt_weight()
154 {
155 // bind to wait object
157 {
158 m_wait_obj->m_task = this;
159 }
160 }
#define __stk_constexpr_cpp17
constexpr definition for C++17 and above.
Definition stk_defs.h:382
Concrete implementation of IKernel.
Definition stk.h:85
static constexpr bool IsSyncMode()
Definition stk.h:2374
SrtInfo m_srt[STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 0U, 1U >::Value]
SRT metadata. Zero-size (no memory) in KERNEL_HRT mode.
Definition stk.h:766
Stack m_stack
Stack descriptor (SP register value + access mode + optional tid).
Definition stk.h:763
Weight m_rt_weight[STK_ALLOCATE_COUNT< TStrategy::WEIGHT_API, 1U, 1U, 0U >::Value]
Run-time weight for weighted-round-robin scheduling. Zero-size for unweighted strategies.
Definition stk.h:768
volatile uint32_t m_state
Bitmask of EStateFlags. Written by task thread, read/cleared by kernel tick.
Definition stk.h:764
ITask * m_user
Bound user task, or NULL when slot is free.
Definition stk.h:762
HrtInfo m_hrt[STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 1U, 0U >::Value]
HRT metadata. Zero-size (no memory) in non-HRT mode.
Definition stk.h:767
volatile Timeout m_time_sleep
Sleep countdown: negative while sleeping (absolute value = ticks remaining), zero when awake.
Definition stk.h:765
WaitObject m_wait_obj[STK_ALLOCATE_COUNT< TMode, KERNEL_SYNC, 1U, 0U >::Value]
Embedded wait object for synchronization. Zero-size (no memory) if KERNEL_SYNC is not set.
Definition stk.h:769

References __stk_constexpr_cpp17, 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, stk::NO_WAIT, 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 ( )
protecteddefault

Destructor.

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

References STK_VIRT_DTOR.

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 537 of file stk.h.

538 {
539 // set access mode for this stack
540 m_stack.access_mode = user_task->GetAccessMode();
541
542 // set task id for tracking purpose
543 #if STK_NEED_TASK_ID
544 m_stack.tid = user_task->GetId();
545 #endif
546
547 // init stack of the user task
549
550 // bind user task
552
553 // initialize current weight to NO_WEIGHT for priority inheritance mechanism
555 {
557 }
558 }
void SetCurrentWeight(Weight weight) override
Update the run-time scheduling weight (weighted strategies only).
Definition stk.h:202

References __stk_constexpr_cpp17, stk::ITask::GetAccessMode(), stk::ITask::GetId(), m_stack, m_user, stk::NO_WEIGHT, SetCurrentWeight(), and stk::STACK_USER_TASK.

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 749 of file stk.h.

750 {
751 while (IsSleeping())
752 {
754 }
755 }
bool IsSleeping() const override
Check whether this task is currently sleeping (waiting for a tick or a wake event).
Definition stk.h:180

References IsSleeping().

Here is the call graph for this function:

◆ GetCurrentWeight()

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

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 252 of file stk.h.

253 {
255
257 {
259 }
260 else
261 {
263 }
264
265 return cur_weight;
266 }

References __stk_constexpr_cpp17, stk::DEFAULT_WEIGHT, and m_rt_weight.

◆ GetHead()

DLHeadType * stk::util::DListEntry< IKernelTask, TClosedLoop >::GetHead ( )
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 85 of file stk_linked_list.h.

85{ return m_head; }

◆ GetHrtDeadline()

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

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 295 of file stk.h.

296 {
298
300
302 {
303 deadline = m_hrt[0].deadline;
304 }
305 else
306 {
307 deadline = 0;
308 }
309
310 return deadline;
311 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
static constexpr bool IsHrtMode()
Definition stk.h:2373

References __stk_constexpr_cpp17, 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
inlineoverridevirtual

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 272 of file stk.h.

273 {
275
276 Timeout to;
277
279 {
280 to = m_hrt[0].periodicity;
281 }
282 else
283 {
284 to = 0;
285 }
286
287 return to;
288 }

References __stk_constexpr_cpp17, 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
inlineoverridevirtual

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 318 of file stk.h.

319 {
322
324
326 {
327 relative_deadline = (m_hrt[0].deadline - m_hrt[0].duration);
328 }
329 else
330 {
332 }
333
334 return relative_deadline;
335 }

References __stk_constexpr_cpp17, 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, TClosedLoop >::GetNext ( )
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 (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 98 of file stk_linked_list.h.

98{ return m_next; }

◆ GetPrev()

DLEntryType * stk::util::DListEntry< IKernelTask, TClosedLoop >::GetPrev ( )
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 (TClosedLoop == true) this pointer is never NULL when the entry is linked.

Definition at line 114 of file stk_linked_list.h.

114{ 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 337 of file stk.h.

338 {
339 // note: task sleep time is negative
341
343 {
344 // likely task is sleeping during sync operation (see Wait)
345 if (m_wait_obj->IsWaiting())
346 {
347 // note: sync wait time is positive
348 task_sleep = m_wait_obj->m_time_wait;
349
350 // we shall account for only valid time (when task is waiting during sync operation)
351 if (task_sleep > NO_WAIT)
352 {
354 }
355 }
356 else
357 {
359 }
360 }
361 else
362 {
364 }
365
366 // clamp to [1, STK_TICKLESS_TICKS_MAX] range
367 return Max<Timeout>(1, sleep_ticks);
368 }
static constexpr T Max(T a, T b)
Compile-time maximum of two values.
Definition stk_defs.h:645
static constexpr T Min(T a, T b)
Compile-time minimum of two values.
Definition stk_defs.h:639

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

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 185 of file stk.h.

185{ return GetTidFromUserTask(m_user); }
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:526

References stk::GetTidFromUserTask(), and m_user.

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 ( ) const
inlineoverridevirtual

Get stack descriptor for this task slot.

Returns
Stack info (SP register value and access mode flags).

Implements stk::IKernelTask.

Definition at line 170 of file stk.h.

170{ return m_stack;}

References m_stack.

◆ GetUserStackPtr()

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

Get pointer to user Stack.

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

Definition at line 760 of file stk.h.

760{ 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 ( )
inlineoverridevirtual

Get bound user task.

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

Implements stk::IKernelTask.

Definition at line 165 of file stk.h.

165{ return m_user; }

References m_user.

◆ GetWeight()

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

Get static scheduling weight from the user task.

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

Implements stk::IKernelTask.

Definition at line 213 of file stk.h.

214 {
216
218 {
219 if (m_rt_weight[0] != NO_WEIGHT)
220 {
222 }
223 else
224 {
226 {
227 static_weight = m_user->GetWeight();
228 }
229 else
230 {
232 }
233 }
234 }
236 {
237 static_weight = m_user->GetWeight();
238 }
239 else
240 {
242 }
243
244 return static_weight;
245 }

References __stk_constexpr_cpp17, stk::DEFAULT_WEIGHT, m_rt_weight, m_user, and stk::NO_WEIGHT.

◆ 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 693 of file stk.h.

694 {
695 const Timeout duration = m_hrt[0].duration;
696
697 STK_ASSERT(duration >= 0);
699
700 m_user->OnDeadlineMissed(duration);
701 platform->ProcessHardFault();
702 }
bool HrtIsDeadlineMissed(Timeout duration) const
Check if deadline missed.
Definition stk.h:716

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 648 of file stk.h.

649 {
655
656 m_hrt[0].periodicity = periodicity_tc;
657 m_hrt[0].deadline = deadline_tc;
658
659 if (start_delay_tc > 0)
660 {
662 }
663 }
void ScheduleSleep(Timeout ticks)
Put the task into a sleeping state for the specified number of ticks.
Definition stk.h:730

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 716 of file stk.h.

717 {
718 return (duration > m_hrt[0].deadline);
719 }

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.

Definition at line 668 of file stk.h.

668{}

◆ HrtOnSwitchedOut()

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

Called when task is switched out from the scheduling process.

Note
Related to stk::KERNEL_HRT mode only.

Definition at line 673 of file stk.h.

674 {
675 const Timeout duration = m_hrt[0].duration;
676
677 STK_ASSERT(duration >= 0);
678
679 const Timeout sleep = m_hrt[0].periodicity - duration;
680 if (sleep > 0)
681 {
683 }
684
685 m_hrt[0].duration = 0;
686 m_hrt[0].done = false;
687 }

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 707 of file stk.h.

708 {
709 m_hrt[0].done = true;
711 }

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 175 of file stk.h.

175{ return (m_user != nullptr); }

References m_user.

◆ IsLinked()

bool stk::util::DListEntry< IKernelTask, TClosedLoop >::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 127 of file stk_linked_list.h.

127{ 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 610 of file stk.h.

611 {
612 bool is_match = false;
613
614 const Word start = hw::PtrToWord(m_user->GetStack());
615 const Word end = start + (m_user->GetStackSize() * sizeof(Word));
616
617 if ((SP >= start) && (SP <= end))
618 {
619 is_match = true;
620 }
621 #if STK_TZ_SECURE // lookup Secure memory region too when on a Secure side
622 else
623 {
624 IStackMemory *const secure_mem = m_user->GetSecureStackMemory();
625
626 if (secure_mem != nullptr)
627 {
628 const Word s_start = hw::PtrToWord(secure_mem->GetStack());
629 const Word s_end = s_start + (secure_mem->GetStackSize() * sizeof(Word));
630
631 if ((SP >= s_start) && (SP <= s_end))
632 {
633 is_match = true;
634 }
635 }
636 }
637 #endif
638
639 return is_match;
640 }
static constexpr Word PtrToWord(T *const ptr) noexcept
Cast a pointer to a CPU register-width integer.
Definition stk_arch.h:106

References stk::IStackMemory::GetStack(), stk::IStackMemory::GetStackSize(), 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 605 of file stk.h.

605{ 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
inlineoverridevirtual

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 180 of file stk.h.

180{ return (m_time_sleep < 0); }

References m_time_sleep.

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

Here is the caller graph for this function:

◆ Link()

void stk::util::DListEntry< IKernelTask, TClosedLoop >::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 162 of file stk_linked_list.h.

163 {
164 m_head = head;
165 m_next = next;
166 m_prev = prev;
167
168 if (m_prev != nullptr)
169 {
170 m_prev->m_next = this;
171 }
172
173 if (m_next != nullptr)
174 {
175 m_next->m_prev = this;
176 }
177 }
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, TClosedLoop >::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, TClosedLoop>. Eliminates the need for explicit static_cast at call sites.
MISRA deviation: [STK-DEV-004] Rule 5-2-x.

Definition at line 141 of file stk_linked_list.h.

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

◆ operator IKernelTask *()

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

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

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

Definition at line 134 of file stk_linked_list.h.

134{ 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 588 of file stk.h.

589 {
590 // make this task sleeping to switch it out from scheduling process
592
593 // mark it as done HRT task
595 {
597 }
598
599 // mark it as pending for removal
601 }
void HrtOnWorkCompleted()
Called when task process called IKernelService::SwitchToNext to inform Kernel that work is completed.
Definition stk.h:707

References __stk_constexpr_cpp17, 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 730 of file stk.h.

731 {
732 STK_ASSERT(ticks > 0);
733
734 // set state first as kernel checks it when task IsSleeping
736 {
737 if (!IsSleeping())
738 {
740 }
741 }
742
745 }

References __stk_constexpr_cpp17, IsSleeping(), m_state, m_time_sleep, STATE_SLEEP_PENDING, and STK_ASSERT.

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

Here is the call graph for this function:
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 ( Weight weight)
inlineoverridevirtual

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 202 of file stk.h.

203 {
205 {
206 m_rt_weight[0] = weight;
207 }
208 }

References __stk_constexpr_cpp17, and m_rt_weight.

Referenced by Bind().

Here is the caller graph for this function:

◆ 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 563 of file stk.h.

564 {
566 {
567 // should be freed from waiting on task exit
568 STK_ASSERT(!m_wait_obj->IsWaiting());
569 }
570
571 m_user = nullptr;
572 m_stack = {};
574 m_time_sleep = 0;
575
577 {
578 m_hrt[0].Clear();
579 }
580 else
581 {
582 m_srt->Clear();
583 }
584 }

References __stk_constexpr_cpp17, 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, TClosedLoop >::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 186 of file stk_linked_list.h.

187 {
188 if (m_prev != nullptr)
189 {
191 }
192
193 if (m_next != nullptr)
194 {
196 }
197
198 m_head = nullptr;
199 m_next = nullptr;
200 m_prev = nullptr;
201 }

◆ Wake()

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

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 191 of file stk.h.

192 {
194
195 // wakeup on a next cycle
196 m_time_sleep = -1;
197 }

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 122 of file stk.h.

References Kernel.

Referenced by Kernel.

Member Data Documentation

◆ m_head

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

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

Definition at line 203 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[STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 1U, 0U >::Value]
protected

HRT metadata. Zero-size (no memory) in non-HRT mode.

Definition at line 767 of file stk.h.

Referenced by GetHrtDeadline(), GetHrtPeriodicity(), GetHrtRelativeDeadline(), HrtHardFailDeadline(), HrtInit(), HrtIsDeadlineMissed(), HrtOnSwitchedOut(), HrtOnWorkCompleted(), KernelTask(), and Unbind().

◆ m_next

DLEntryType* stk::util::DListEntry< IKernelTask, TClosedLoop >::m_next
privateinherited

Next entry in the list, or NULL (open list boundary) / first entry (closed loop).

Definition at line 204 of file stk_linked_list.h.

◆ m_prev

DLEntryType* stk::util::DListEntry< IKernelTask, TClosedLoop >::m_prev
privateinherited

Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).

Definition at line 205 of file stk_linked_list.h.

◆ m_rt_weight

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Weight stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_rt_weight[STK_ALLOCATE_COUNT< TStrategy::WEIGHT_API, 1U, 1U, 0U >::Value]
protected

Run-time weight for weighted-round-robin scheduling. Zero-size for unweighted strategies.

Definition at line 768 of file stk.h.

Referenced by GetCurrentWeight(), GetWeight(), 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[STK_ALLOCATE_COUNT< TMode, KERNEL_HRT, 0U, 1U >::Value]
protected

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

Definition at line 766 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 763 of file stk.h.

Referenced by Bind(), GetUserStack(), GetUserStackPtr(), 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 764 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 765 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 762 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[STK_ALLOCATE_COUNT< TMode, KERNEL_SYNC, 1U, 0U >::Value]
protected

Embedded wait object for synchronization. Zero-size (no memory) if KERNEL_SYNC is not set.

Definition at line 769 of file stk.h.

Referenced by GetSleepTicks(), KernelTask(), and Unbind().


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