SuperTinyKernel™ RTOS 1.05.3
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 > Class Template Reference

Concrete implementation of IKernel. More...

#include <stk.h>

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

Classes

class  KernelTask
 Internal per-slot kernel descriptor that wraps a user ITask instance. More...
class  KernelService
 Concrete implementation of IKernelService exposed to running tasks. More...
class  SleepTrapStack
 Storage bundle for the sleep trap: a Stack descriptor paired with its backing memory. More...
class  ExitTrapStack
 Storage bundle for the exit trap: a Stack descriptor paired with its backing memory. More...

Public Types

enum  EConsts { TASKS_MAX = TSize }
 Constants. More...
enum  EState : uint8_t {
  STATE_INACTIVE = 0 ,
  STATE_READY ,
  STATE_RUNNING
}
 Kernel state. More...

Public Member Functions

 Kernel ()
 Construct the kernel with all storage zero-initialised and the request flag set to ~0 (indicating uninitialized state; cleared to REQUEST_NONE by Initialize()).
 ~Kernel ()
 Destructor.
void Initialize (uint32_t resolution_us=PERIODICITY_DEFAULT)
 Prepare kernel for use: reset state, configure the platform, and register the service singleton.
void AddTask (ITask *user_task)
 Register task for a soft real-time (SRT) scheduling.
void AddTask (ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)
 Register a task for hard real-time (HRT) scheduling.
void RemoveTask (ITask *user_task)
 Remove a previously added task from the kernel before Start().
void Start ()
 Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or indefinitely (KERNEL_STATIC mode).
bool IsStarted () const
 Check whether scheduler is currently running.
IPlatformGetPlatform ()
 Get platform driver instance owned by this kernel.
ITaskSwitchStrategyGetSwitchStrategy ()
 Get task-switching strategy instance owned by this kernel.
EState GetState () const
 Get kernel state.

Protected Types

enum  ERequest : uint8_t {
  REQUEST_NONE = 0 ,
  REQUEST_ADD_TASK = (1 << 0)
}
 Bitmask flags for pending inter-task requests that must be processed by the kernel on the next tick (in UpdateTaskRequest()). More...
enum  EFsmState : int8_t {
  FSM_STATE_NONE = -1 ,
  FSM_STATE_SWITCHING ,
  FSM_STATE_SLEEPING ,
  FSM_STATE_WAKING ,
  FSM_STATE_EXITING ,
  FSM_STATE_MAX
}
 Finite-state machine (FSM) state. Encodes what the kernel is currently doing between two consecutive tick events. More...
enum  EFsmEvent : int8_t {
  FSM_EVENT_SWITCH = 0 ,
  FSM_EVENT_SLEEP ,
  FSM_EVENT_WAKE ,
  FSM_EVENT_EXIT ,
  FSM_EVENT_MAX
}
 Finite-state machine (FSM) event. Computed by FetchNextEvent() each tick based on strategy output and current kernel state. More...
typedef StackMemoryWrapper<(32)> SleepTrapStackMemory
 Stack memory wrapper type for the sleep trap.
typedef StackMemoryWrapper< STACK_SIZE_MINExitTrapStackMemory
 Stack memory wrapper type for the exit trap.
typedef KernelTask TaskStorageType[TASKS_MAX]
 KernelTask array type used as a storage for the KernelTask instances.
typedef ISyncObject::ListHeadType SyncObjectList
 Intrusive list of active ISyncObject instances registered with this kernel. Each sync object in this list receives a Tick() call every kernel tick for timeout tracking. Allocated only when KERNEL_SYNC is set (zero-size otherwise).

Protected Member Functions

void InitTraps ()
 Initialize stack of the traps.
KernelTaskAllocateNewTask (ITask *user_task)
 Allocate new instance of KernelTask.
void AddKernelTask (KernelTask *task)
 Add kernel task to the scheduling strategy.
void AllocateAndAddNewTask (ITask *user_task)
 Allocate new instance of KernelTask and add it into the scheduling process.
void HrtAllocateAndAddNewTask (ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)
 Allocate new instance of KernelTask and add it into the HRT scheduling process.
void RequestAddTask (ITask *user_task)
 Request to add new task.
KernelTaskFindTaskByUserTask (const ITask *user_task)
 Find kernel task by the bound ITask instance.
KernelTaskFindTaskByStack (const Stack *stack)
 Find kernel task by the bound Stack instance.
KernelTaskFindTaskBySP (Word SP)
 Find kernel task for a Stack Pointer (SP).
void RemoveTask (KernelTask *task)
 Remove kernel task.
void OnStart (Stack *&active)
 Called by platform driver immediately after a scheduler start (first tick).
void OnStop ()
 Called by the platform driver after a scheduler stop (all tasks have exited).
bool OnTick (Stack *&idle, Stack *&active)
 Process one scheduler tick. Called from the platform timer/tick ISR.
void OnTaskSwitch (Word caller_SP)
 Called by Thread process (via IKernelService::SwitchToNext) to switch to a next task.
void OnTaskSleep (Word caller_SP, Timeout ticks)
 Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from scheduling (sleeping).
void OnTaskSleepUntil (Word caller_SP, Ticks timestamp)
 Called by Thread process (via IKernelService::SleepUntil) for exclusion of the calling process from scheduling (sleeping).
void OnTaskExit (Stack *stack)
 Called from the Thread process when task finished (its Run function exited by return).
IWaitObjectOnTaskWait (Word caller_SP, ISyncObject *sync_obj, IMutex *mutex, Timeout timeout)
 Called from the Thread process when task needs to wait.
TId OnGetTid (Word caller_SP)
 Called from the Thread process when for getting task/thread id of the process.
Timeout UpdateTasks (const Timeout elapsed_ticks)
 Update tasks (sleep, requests).
Timeout UpdateTaskState (const Timeout elapsed_ticks)
 Update task state: process removals, advance sleep timers, and track HRT durations.
void UpdateSyncObjects (const Timeout elapsed_ticks)
 Update synchronization objects.
void UpdateTaskRequest ()
 Update pending task requests.
EFsmEvent FetchNextEvent (KernelTask *&next)
 Fetch next event for the FSM.
EFsmState GetNewFsmState (KernelTask *&next)
 Get new FSM state.
bool UpdateFsmState (Stack *&idle, Stack *&active)
 Update FSM state.
bool StateSwitch (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
 Switches contexts.
bool StateWake (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
 Wakes up after sleeping.
bool StateSleep (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
 Enters into a sleeping mode.
bool StateExit (KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
 Exits from scheduling.
bool IsInitialized () const
 Check whether Initialize() has been called and completed successfully.
void ScheduleAddTask ()
 Signal the kernel to process a pending AddTask request on the next tick.

Static Protected Member Functions

static bool IsValidFsmState (EFsmState state)
 Check if FSM state is valid.
static bool IsStaticMode ()
static bool IsDynamicMode ()
static bool IsHrtMode ()
static bool IsSyncMode ()
static bool IsTicklessMode ()

Protected Attributes

KernelService m_service
 Kernel service singleton exposed to running tasks via IKernelService::GetInstance().
TPlatform m_platform
 Platform driver (SysTick, PendSV, context switch implementation).
TStrategy m_strategy
 Task-switching strategy (determines which task runs next).
KernelTaskm_task_now
 Currently executing task, or nullptr before Start() or after all tasks exit.
TaskStorageType m_task_storage
 Static pool of TSize KernelTask slots (free slots have m_user == nullptr).
SleepTrapStack m_sleep_trap [1]
 Sleep trap (always present): executed when all tasks are sleeping.
ExitTrapStack m_exit_trap [((((TMode) &(KERNEL_DYNAMIC)) !=0U) ?(1) :(0))]
 Exit trap: zero-size in KERNEL_STATIC mode; one entry in KERNEL_DYNAMIC mode.
EFsmState m_fsm_state
 Current FSM state. Drives context-switch decision on every tick.
volatile uint8_t m_request
 Bitmask of pending ERequest flags from running tasks. Written by tasks, read/cleared by UpdateTaskRequest() in tick context.
volatile EState m_state
 Current kernel state.
SyncObjectList m_sync_list [((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))]
 List of active sync objects. Zero-size (no memory) if KERNEL_SYNC is not set.
const EFsmState m_fsm [FSM_STATE_MAX][FSM_EVENT_MAX]

Detailed Description

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

Concrete implementation of IKernel.

All configuration is expressed as template parameters. No virtual dispatch, no heap allocation - the entire kernel, tasks, and traps live in statically reserved storage.

Template Parameters
TModeBitmask of EKernelMode flags that configures kernel features:
  • KERNEL_STATIC — fixed task list, no add/remove after Start().
  • KERNEL_DYNAMIC — tasks may be added or removed at runtime.
  • KERNEL_HRT — Hard Real-Time mode (must combine with STATIC or DYNAMIC).
  • KERNEL_SYNC — enables synchronization primitives (Mutex, Event, etc.).
  • KERNEL_TICKLESS — enables tickless low-power operation. Requires STK_TICKLESS_IDLE=1 in stk_config.h. Incompatible with KERNEL_HRT (tickless suppresses the timer, which destroys the precise periodicity HRT depends on — enforced by the compile-time assertion TICKLESS_HRT_CONFLICT). KERNEL_STATIC and KERNEL_DYNAMIC are mutually exclusive.
TSizeMaximum number of concurrent tasks. Must be > 0.
TStrategyTask-switching strategy type (e.g. SwitchStrategyRoundRobin). Must inherit ITaskSwitchStrategy.
TPlatformPlatform driver type (e.g. PlatformArmCortexM, or PlatformDefault). Must inherit IPlatform.
Note
At least 1 task is required: TSize must be > 0 (enforced by compile-time assertion).
KERNEL_HRT is incompatible with weighted scheduling strategies (WEIGHT_API == true), also enforced by a compile-time assertion.
KERNEL_TICKLESS is incompatible with KERNEL_HRT, also enforced by a compile-time assertion (TICKLESS_HRT_CONFLICT).

Usage example:

PlatformDefault> kernel;
static MyTask1<256, ACCESS_PRIVILEGED> task1;
static MyTask2<512, ACCESS_USER> task2;
static MyTask3<512, ACCESS_USER> task3;
kernel.Initialize();
kernel.AddTask(&task1);
kernel.AddTask(&task2);
kernel.AddTask(&task3);
kernel.Start();
PlatformArmCortexM PlatformDefault
Default platform implementation.
@ KERNEL_STATIC
All tasks are static and can not exit.
Definition stk_common.h:41
Concrete implementation of IKernel.
Definition stk.h:83
Round-Robin task-switching strategy: each runnable task receives one time slice (one tick interval) i...

Definition at line 82 of file stk.h.

Member Typedef Documentation

◆ ExitTrapStackMemory

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
typedef StackMemoryWrapper<STACK_SIZE_MIN> stk::Kernel< TMode, TSize, TStrategy, TPlatform >::ExitTrapStackMemory
protected

Stack memory wrapper type for the exit trap.

See also
ExitTrapStack, STACK_SIZE_MIN

Definition at line 95 of file stk.h.

◆ SleepTrapStackMemory

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
typedef StackMemoryWrapper< ( 32 )> stk::Kernel< TMode, TSize, TStrategy, TPlatform >::SleepTrapStackMemory
protected

Stack memory wrapper type for the sleep trap.

See also
SleepTrapStack, STK_SLEEP_TRAP_STACK_SIZE

Definition at line 89 of file stk.h.

◆ SyncObjectList

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
typedef ISyncObject::ListHeadType stk::Kernel< TMode, TSize, TStrategy, TPlatform >::SyncObjectList
protected

Intrusive list of active ISyncObject instances registered with this kernel. Each sync object in this list receives a Tick() call every kernel tick for timeout tracking. Allocated only when KERNEL_SYNC is set (zero-size otherwise).

Definition at line 1988 of file stk.h.

◆ TaskStorageType

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
typedef KernelTask stk::Kernel< TMode, TSize, TStrategy, TPlatform >::TaskStorageType[TASKS_MAX]
protected

KernelTask array type used as a storage for the KernelTask instances.

Definition at line 1950 of file stk.h.

Member Enumeration Documentation

◆ EConsts

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

Constants.

Enumerator
TASKS_MAX 

Maximum number of concurrently registered tasks. Fixed at compile time. Exceeding this limit in AddTask() triggers a compile-time assert (TASKS_MAX > 0) and a runtime STK_ASSERT.

Definition at line 762 of file stk.h.

763 {
765 };
@ TASKS_MAX
Maximum number of concurrently registered tasks. Fixed at compile time. Exceeding this limit in AddTa...
Definition stk.h:764

◆ EFsmEvent

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
enum stk::Kernel::EFsmEvent : int8_t
protected

Finite-state machine (FSM) event. Computed by FetchNextEvent() each tick based on strategy output and current kernel state.

Enumerator
FSM_EVENT_SWITCH 

Strategy returned a runnable task, perform a context switch.

FSM_EVENT_SLEEP 

No runnable tasks, enter sleep trap.

FSM_EVENT_WAKE 

A task became runnable while the kernel was sleeping, wake from sleep trap.

FSM_EVENT_EXIT 

No tasks remain (KERNEL_DYNAMIC), exit scheduling and return from Start().

FSM_EVENT_MAX 

Sentinel: number of valid events (used to size the FSM table).

Definition at line 984 of file stk.h.

985 {
986 FSM_EVENT_SWITCH = 0,
991 };
@ FSM_EVENT_EXIT
No tasks remain (KERNEL_DYNAMIC), exit scheduling and return from Start().
Definition stk.h:989
@ FSM_EVENT_WAKE
A task became runnable while the kernel was sleeping, wake from sleep trap.
Definition stk.h:988
@ FSM_EVENT_SLEEP
No runnable tasks, enter sleep trap.
Definition stk.h:987
@ FSM_EVENT_SWITCH
Strategy returned a runnable task, perform a context switch.
Definition stk.h:986
@ FSM_EVENT_MAX
Sentinel: number of valid events (used to size the FSM table).
Definition stk.h:990

◆ EFsmState

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
enum stk::Kernel::EFsmState : int8_t
protected

Finite-state machine (FSM) state. Encodes what the kernel is currently doing between two consecutive tick events.

Enumerator
FSM_STATE_NONE 

Sentinel / uninitialized value. Set by the constructor, replaced by FSM_STATE_SWITCHING on the first tick.

FSM_STATE_SWITCHING 

Normal operation: switching between runnable tasks each tick.

FSM_STATE_SLEEPING 

All tasks are sleeping, the sleep trap is executing (CPU in low-power state).

FSM_STATE_WAKING 

At least one task woke up, transitioning from sleep trap back to a user task.

FSM_STATE_EXITING 

All tasks exited (KERNEL_DYNAMIC only), executing the exit trap to return from Start().

FSM_STATE_MAX 

Sentinel: number of valid states (used to size the FSM table), denotes uninitialized state.

Definition at line 970 of file stk.h.

971 {
972 FSM_STATE_NONE = -1,
978 };
@ FSM_STATE_EXITING
All tasks exited (KERNEL_DYNAMIC only), executing the exit trap to return from Start().
Definition stk.h:976
@ FSM_STATE_SLEEPING
All tasks are sleeping, the sleep trap is executing (CPU in low-power state).
Definition stk.h:974
@ FSM_STATE_SWITCHING
Normal operation: switching between runnable tasks each tick.
Definition stk.h:973
@ FSM_STATE_NONE
Sentinel / uninitialized value. Set by the constructor, replaced by FSM_STATE_SWITCHING on the first ...
Definition stk.h:972
@ FSM_STATE_MAX
Sentinel: number of valid states (used to size the FSM table), denotes uninitialized state.
Definition stk.h:977
@ FSM_STATE_WAKING
At least one task woke up, transitioning from sleep trap back to a user task.
Definition stk.h:975

◆ ERequest

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
enum stk::Kernel::ERequest : uint8_t
protected

Bitmask flags for pending inter-task requests that must be processed by the kernel on the next tick (in UpdateTaskRequest()).

Enumerator
REQUEST_NONE 

No pending requests.

REQUEST_ADD_TASK 

An AddTask() request is pending from a running task (KERNEL_DYNAMIC only).

Definition at line 101 of file stk.h.

102 {
103 REQUEST_NONE = 0,
104 REQUEST_ADD_TASK = (1 << 0)
105 };
@ REQUEST_NONE
No pending requests.
Definition stk.h:103
@ REQUEST_ADD_TASK
An AddTask() request is pending from a running task (KERNEL_DYNAMIC only).
Definition stk.h:104

◆ EState

enum stk::IKernel::EState : uint8_t
inherited

Kernel state.

Enumerator
STATE_INACTIVE 

not ready, IKernel::Initialize() must be called

STATE_READY 

ready to start, IKernel::Start() must be called

STATE_RUNNING 

initialized and running, IKernel::Start() was called successfully

Definition at line 859 of file stk_common.h.

860 {
861 STATE_INACTIVE = 0,
864 };
@ STATE_INACTIVE
not ready, IKernel::Initialize() must be called
Definition stk_common.h:861
@ STATE_READY
ready to start, IKernel::Start() must be called
Definition stk_common.h:862
@ STATE_RUNNING
initialized and running, IKernel::Start() was called successfully
Definition stk_common.h:863

Constructor & Destructor Documentation

◆ Kernel()

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

Construct the kernel with all storage zero-initialised and the request flag set to ~0 (indicating uninitialized state; cleared to REQUEST_NONE by Initialize()).

Note
In debug builds also verifies that TPlatform derives from IPlatform and TStrategy from ITaskSwitchStrategy.
If TMode includes KERNEL_TICKLESS, a compile-time assertion fires unless STK_TICKLESS_IDLE is defined to 1 in stk_config.h.

Definition at line 774 of file stk.h.

776 {
777 #ifdef _DEBUG
778 // TPlatform must inherit IPlatform
780 (void)platform;
781
782 // TStrategy must inherit ITaskSwitchStrategy
784 (void)strategy;
785 #endif
786
787 #if !STK_TICKLESS_IDLE
789 "STK_TICKLESS_IDLE must be defined to 1 for KERNEL_TICKLESS");
790 #endif
791 }
#define STK_STATIC_ASSERT_DESC(X, DESC)
Compile-time assertion with a custom error description. Produces a compilation error if X is false.
Definition stk_defs.h:350
volatile uint8_t m_request
Bitmask of pending ERequest flags from running tasks. Written by tasks, read/cleared by UpdateTaskReq...
Definition stk.h:1998
TStrategy m_strategy
Task-switching strategy (determines which task runs next).
Definition stk.h:1992
volatile EState m_state
Current kernel state.
Definition stk.h:1999
SleepTrapStack m_sleep_trap[1]
Sleep trap (always present): executed when all tasks are sleeping.
Definition stk.h:1995
ExitTrapStack m_exit_trap[((((TMode) &(KERNEL_DYNAMIC)) !=0U) ?(1) :(0))]
Exit trap: zero-size in KERNEL_STATIC mode; one entry in KERNEL_DYNAMIC mode.
Definition stk.h:1996
TaskStorageType m_task_storage
Static pool of TSize KernelTask slots (free slots have m_user == nullptr).
Definition stk.h:1994
KernelTask * m_task_now
Currently executing task, or nullptr before Start() or after all tasks exit.
Definition stk.h:1993
TPlatform m_platform
Platform driver (SysTick, PendSV, context switch implementation).
Definition stk.h:1991
EFsmState m_fsm_state
Current FSM state. Drives context-switch decision on every tick.
Definition stk.h:1997

References FSM_STATE_NONE, stk::KERNEL_TICKLESS, m_exit_trap, m_fsm_state, m_platform, m_request, m_sleep_trap, m_state, m_strategy, m_task_now, m_task_storage, REQUEST_NONE, stk::IKernel::STATE_INACTIVE, and STK_STATIC_ASSERT_DESC.

◆ ~Kernel()

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

Destructor.

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

Definition at line 796 of file stk.h.

797 {}

Member Function Documentation

◆ AddKernelTask()

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

Add kernel task to the scheduling strategy.

Parameters
[in]taskPointer to the kernel task.

Definition at line 1073 of file stk.h.

1074 {
1075 #if STK_SEGGER_SYSVIEW
1076 // start tracing new task
1077 SEGGER_SYSVIEW_OnTaskCreate(task->GetUserStack()->tid);
1078 if (IsStarted())
1080 #endif
1081
1082 m_strategy.AddTask(task);
1083 }
bool IsStarted() const
Check whether scheduler is currently running.
Definition stk.h:946

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), IsStarted(), and m_strategy.

Referenced by AllocateAndAddNewTask(), and HrtAllocateAndAddNewTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTask() [1/2]

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::AddTask ( ITask * user_task)
inlinevirtual

Register task for a soft real-time (SRT) scheduling.

Parameters
[in]user_taskUser task to add. Must not already be registered. Must not be nullptr.
Note
Before Start(): allocates a free KernelTask slot and adds it to the strategy immediately.
After Start() (KERNEL_DYNAMIC only): serialises the request via RequestAddTask() — the calling task yields and the kernel processes the request on the next tick.
Warning
Asserts if called in KERNEL_HRT mode (use the HRT overload instead), if called after Start() without KERNEL_DYNAMIC, or if TASKS_MAX is exceeded.

Implements stk::IKernel.

Definition at line 832 of file stk.h.

833 {
834 if (!IsHrtMode())
835 {
836 STK_ASSERT(user_task != nullptr);
838
839 // when started the operation must be serialized by switching out from processing until
840 // kernel processes this request
841 if (IsStarted())
842 {
843 if (IsDynamicMode())
844 {
846 }
847 else
848 {
849 STK_ASSERT(false);
850 }
851 }
852 else
853 {
855 }
856 }
857 else
858 {
859 STK_ASSERT(false);
860 }
861 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
void RequestAddTask(ITask *user_task)
Request to add new task.
Definition stk.h:1119
static bool IsHrtMode()
Definition stk.h:1924
static bool IsDynamicMode()
Definition stk.h:1923
void AllocateAndAddNewTask(ITask *user_task)
Allocate new instance of KernelTask and add it into the scheduling process.
Definition stk.h:1089
bool IsInitialized() const
Check whether Initialize() has been called and completed successfully.
Definition stk.h:1888

References __stk_attr_noinline, AllocateAndAddNewTask(), IsDynamicMode(), IsHrtMode(), IsInitialized(), IsStarted(), RequestAddTask(), and STK_ASSERT.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TestAlgorithm(), stk::test::TestHrtTaskExitDuringSleepState(), stk::test::TestPriorityNext(), stk::test::TestTaskExit(), and stk::test::TestTaskSleep().

Here is the call graph for this function:

◆ AddTask() [2/2]

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::AddTask ( ITask * user_task,
Timeout periodicity_tc,
Timeout deadline_tc,
Timeout start_delay_tc )
inlinevirtual

Register a task for hard real-time (HRT) scheduling.

Parameters
[in]user_taskUser task to add. Must not already be registered. Must not be nullptr.
[in]periodicity_tcActivation period in ticks. Must be > 0 and < INT32_MAX.
[in]deadline_tcMaximum allowed active duration in ticks. Must be > 0 and < INT32_MAX.
[in]start_delay_tcInitial sleep delay in ticks before the first activation. 0 means activate immediately.
Note
Must be called before Start(). Dynamic (post-Start) HRT task addition is not supported.
Warning
Asserts if called outside KERNEL_HRT mode (use the SRT overload instead) or after Start().

Implements stk::IKernel.

Definition at line 871 of file stk.h.

872 {
873 if (IsHrtMode())
874 {
875 STK_ASSERT(user_task != nullptr);
878
880 }
881 else
882 {
883 STK_ASSERT(false);
884 }
885 }
void HrtAllocateAndAddNewTask(ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)
Allocate new instance of KernelTask and add it into the HRT scheduling process.
Definition stk.h:1105

References __stk_attr_noinline, HrtAllocateAndAddNewTask(), IsHrtMode(), IsInitialized(), IsStarted(), and STK_ASSERT.

Here is the call graph for this function:

◆ AllocateAndAddNewTask()

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

Allocate new instance of KernelTask and add it into the scheduling process.

Parameters
[in]user_taskUser task for which kernel task object is allocated.
Returns
Kernel task.

Definition at line 1089 of file stk.h.

1090 {
1092 STK_ASSERT(task != nullptr);
1093
1095 }
KernelTask * AllocateNewTask(ITask *user_task)
Allocate new instance of KernelTask.
Definition stk.h:1037
void AddKernelTask(KernelTask *task)
Add kernel task to the scheduling strategy.
Definition stk.h:1073
Internal per-slot kernel descriptor that wraps a user ITask instance.
Definition stk.h:119

References AddKernelTask(), AllocateNewTask(), and STK_ASSERT.

Referenced by AddTask(), and UpdateTaskRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateNewTask()

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

Allocate new instance of KernelTask.

Parameters
[in]user_taskUser task for which kernel task object is allocated.
Returns
Kernel task.

Definition at line 1037 of file stk.h.

1038 {
1039 // look for a free kernel task
1040 KernelTask *new_task = nullptr;
1041 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1042 {
1044 if (task->IsBusy())
1045 {
1046 // avoid task collision
1047 STK_ASSERT(task->m_user != user_task);
1048
1049 // avoid stack collision
1050 STK_ASSERT(task->m_user->GetStack() != user_task->GetStack());
1051 }
1052 else
1053 if (new_task == nullptr)
1054 {
1055 new_task = task;
1056 #if defined(NDEBUG) && !defined(_STK_ASSERT_REDIRECT)
1057 break; // break if assertions are inactive and do not try to validate collision with existing tasks
1058 #endif
1059 }
1060 }
1061
1062 // if nullptr - exceeded max supported kernel task count, application design failure
1063 STK_ASSERT(new_task != nullptr);
1064
1065 new_task->Bind(&m_platform, user_task);
1066
1067 return new_task;
1068 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Bind(), stk::IStackMemory::GetStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy(), m_platform, m_task_storage, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_user, STK_ASSERT, and TASKS_MAX.

Referenced by AllocateAndAddNewTask(), and HrtAllocateAndAddNewTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FetchNextEvent()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
EFsmEvent stk::Kernel< TMode, TSize, TStrategy, TPlatform >::FetchNextEvent ( KernelTask *& next)
inlineprotected

Fetch next event for the FSM.

Parameters
[out]nextNext kernel task to which Kernel can switch.
Returns
FSM event.

Definition at line 1656 of file stk.h.

1657 {
1659 KernelTask *itr = nullptr;
1660
1661 // check if no tasks left in KERNEL_DYNAMIC mode and exit, if KERNEL_DYNAMIC is not
1662 // set then 'is_empty' will always be false
1663 bool is_empty = IsDynamicMode() && (m_strategy.GetSize() == 0U);
1664
1665 if (!is_empty)
1666 {
1667 // MISRA 5-2-3 deviation: GetNext/GetFirst returns IKernelTask*, all objects in
1668 // the strategy pool are KernelTask instances - downcast is guaranteed safe.
1669 itr = static_cast<KernelTask *>(m_strategy.GetNext());
1670
1671 // sleep-aware strategy returns nullptr if no active tasks available, start sleeping
1672 if (itr == nullptr)
1673 {
1675 }
1676 else
1677 {
1678 // strategy must provide active-only task
1679 STK_ASSERT(!itr->IsSleeping());
1680
1681 // if was sleeping, process wake event first
1683 }
1684 }
1685
1686 next = itr;
1687 return type;
1688 }
EFsmEvent
Finite-state machine (FSM) event. Computed by FetchNextEvent() each tick based on strategy output and...
Definition stk.h:985

References FSM_EVENT_EXIT, FSM_EVENT_SLEEP, FSM_EVENT_SWITCH, FSM_EVENT_WAKE, FSM_STATE_SLEEPING, IsDynamicMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), m_fsm_state, m_strategy, and STK_ASSERT.

Referenced by GetNewFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindTaskBySP()

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

Find kernel task for a Stack Pointer (SP).

Parameters
[in]SPStack pointer.
Returns
Kernel task.

Definition at line 1175 of file stk.h.

1176 {
1177 STK_ASSERT(m_task_now != nullptr);
1178
1179 if (m_task_now->IsMemoryOfSP(SP))
1180 return m_task_now;
1181
1182 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1183 {
1185
1186 // skip finished tasks (applicable only for KERNEL_DYNAMIC mode)
1187 if (IsDynamicMode() && !task->IsBusy())
1188 continue;
1189
1190 if (task->IsMemoryOfSP(SP))
1191 return task;
1192 }
1193
1194 return nullptr;
1195 }

References __stk_attr_noinline, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy(), IsDynamicMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsMemoryOfSP(), m_task_now, m_task_storage, STK_ASSERT, and TASKS_MAX.

Referenced by OnGetTid(), OnTaskSleep(), OnTaskSleepUntil(), OnTaskWait(), and RequestAddTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindTaskByStack()

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

Find kernel task by the bound Stack instance.

Parameters
[in]stackStack.
Returns
Kernel task.

Definition at line 1159 of file stk.h.

1160 {
1161 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1162 {
1164 if (task->GetUserStack() == stack)
1165 return task;
1166 }
1167
1168 return nullptr;
1169 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), m_task_storage, and TASKS_MAX.

Referenced by OnTaskExit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindTaskByUserTask()

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

Find kernel task by the bound ITask instance.

Parameters
[in]user_taskUser task.
Returns
Kernel task.

Definition at line 1143 of file stk.h.

1144 {
1145 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1146 {
1148 if (task->GetUserTask() == user_task)
1149 return task;
1150 }
1151
1152 return nullptr;
1153 }

References __stk_attr_noinline, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserTask(), m_task_storage, and TASKS_MAX.

Referenced by RemoveTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNewFsmState()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
EFsmState stk::Kernel< TMode, TSize, TStrategy, TPlatform >::GetNewFsmState ( KernelTask *& next)
inlineprotected

Get new FSM state.

Parameters
[out]nextNext kernel task to which Kernel can switch.
Returns
FSM state.

Definition at line 1697 of file stk.h.

1698 {
1701 }
static bool IsValidFsmState(EFsmState state)
Check if FSM state is valid.
Definition stk.h:995
const EFsmState m_fsm[FSM_STATE_MAX][FSM_EVENT_MAX]
Definition stk.h:2002
EFsmEvent FetchNextEvent(KernelTask *&next)
Fetch next event for the FSM.
Definition stk.h:1656

References FetchNextEvent(), IsValidFsmState(), m_fsm, m_fsm_state, and STK_ASSERT.

Referenced by stk::test::KernelMock< TMode, TSize, TStrategy, TPlatform >::GetNewFsmState(), OnStart(), and UpdateFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPlatform()

◆ GetState()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
EState stk::Kernel< TMode, TSize, TStrategy, TPlatform >::GetState ( ) const
inlinevirtual

Get kernel state.

Implements stk::IKernel.

Definition at line 963 of file stk.h.

963{ return m_state; }

References m_state.

Referenced by stk::test::TEST(), stk::test::TEST(), and stk::test::TEST().

Here is the caller graph for this function:

◆ GetSwitchStrategy()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
ITaskSwitchStrategy * stk::Kernel< TMode, TSize, TStrategy, TPlatform >::GetSwitchStrategy ( )
inlinevirtual

◆ HrtAllocateAndAddNewTask()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::HrtAllocateAndAddNewTask ( ITask * user_task,
Timeout periodicity_tc,
Timeout deadline_tc,
Timeout start_delay_tc )
inlineprotected

Allocate new instance of KernelTask and add it into the HRT scheduling process.

Note
Related to stk::KERNEL_HRT mode only.
Parameters
[in]user_taskUser task for which kernel task object is allocated.
[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).
Returns
Kernel task.

Definition at line 1105 of file stk.h.

1106 {
1108 STK_ASSERT(task != nullptr);
1109
1111
1113 }

References AddKernelTask(), AllocateNewTask(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtInit(), and STK_ASSERT.

Referenced by AddTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::Initialize ( uint32_t resolution_us = PERIODICITY_DEFAULT)
inlinevirtual

Prepare kernel for use: reset state, configure the platform, and register the service singleton.

Parameters
[in]resolution_usSystem tick resolution in microseconds per tick (default: PERIODICITY_DEFAULT). Valid range: 1 .. PERIODICITY_MAX. Asserts if 0 or out of range.
Note
Must be called before AddTask() or Start(). Calling twice without an intervening Stop() asserts (IsInitialized() is false until this call completes).

Implements stk::IKernel.

Definition at line 805 of file stk.h.

806 {
810
811 // reinitialize key state variables
812 m_task_now = nullptr;
815
816 m_service.Initialize(&m_platform);
817
818 m_platform.Initialize(this, &m_service, resolution_us, (IsDynamicMode() ? &m_exit_trap[0].stack : nullptr));
819
820 // now ready to Start()
822 }
KernelService m_service
Kernel service singleton exposed to running tasks via IKernelService::GetInstance().
Definition stk.h:1990

References __stk_attr_noinline, FSM_STATE_NONE, IsDynamicMode(), IsInitialized(), m_exit_trap, m_fsm_state, m_platform, m_request, m_service, m_state, m_task_now, stk::PERIODICITY_DEFAULT, stk::PERIODICITY_MAX, REQUEST_NONE, stk::IKernel::STATE_READY, and STK_ASSERT.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TestAlgorithm(), stk::test::TestHrtTaskExitDuringSleepState(), stk::test::TestPriorityNext(), stk::test::TestTaskExit(), and stk::test::TestTaskSleep().

Here is the call graph for this function:

◆ InitTraps()

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

Initialize stack of the traps.

Definition at line 1003 of file stk.h.

1004 {
1005 // init stack for a Sleep trap
1006 {
1008
1010 sleep.stack.mode = ACCESS_PRIVILEGED;
1011 #if STK_NEED_TASK_ID
1012 sleep.stack.tid = SYS_TASK_ID_SLEEP;
1013 #endif
1014
1015 m_platform.InitStack(STACK_SLEEP_TRAP, &sleep.stack, &wrapper, nullptr);
1016 }
1017
1018 // init stack for an Exit trap
1019 if (IsDynamicMode())
1020 {
1022
1024 exit.stack.mode = ACCESS_PRIVILEGED;
1025 #if STK_NEED_TASK_ID
1026 exit.stack.tid = SYS_TASK_ID_EXIT;
1027 #endif
1028
1029 m_platform.InitStack(STACK_EXIT_TRAP, &exit.stack, &wrapper, nullptr);
1030 }
1031 }
StackMemoryWrapper< STACK_SIZE_MIN > ExitTrapStackMemory
Stack memory wrapper type for the exit trap.
Definition stk.h:95
StackMemoryWrapper<(32)> SleepTrapStackMemory
Stack memory wrapper type for the sleep trap.
Definition stk.h:89
Storage bundle for the sleep trap: a Stack descriptor paired with its backing memory.
Definition stk.h:1960
Storage bundle for the exit trap: a Stack descriptor paired with its backing memory.
Definition stk.h:1976

References __stk_attr_noinline, stk::ACCESS_PRIVILEGED, IsDynamicMode(), m_exit_trap, m_platform, m_sleep_trap, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::ExitTrapStack::memory, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::SleepTrapStack::memory, stk::Stack::mode, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::ExitTrapStack::stack, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::SleepTrapStack::stack, stk::STACK_EXIT_TRAP, stk::STACK_SLEEP_TRAP, stk::SYS_TASK_ID_EXIT, and stk::SYS_TASK_ID_SLEEP.

Referenced by Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDynamicMode()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsDynamicMode ( )
inlinestaticprotected

Definition at line 1923 of file stk.h.

1923{ return ((TMode & KERNEL_DYNAMIC) != 0U); }

References __stk_forceinline, and stk::KERNEL_DYNAMIC.

Referenced by AddTask(), FetchNextEvent(), FindTaskBySP(), Initialize(), InitTraps(), OnStop(), OnTaskExit(), RemoveTask(), RequestAddTask(), StateExit(), UpdateTaskRequest(), and UpdateTaskState().

Here is the caller graph for this function:

◆ IsHrtMode()

◆ IsInitialized()

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

Check whether Initialize() has been called and completed successfully.

Returns
true if Initialize() was called, false otherwise.

Definition at line 1888 of file stk.h.

1888{ return (m_state != STATE_INACTIVE); }

References m_state, and stk::IKernel::STATE_INACTIVE.

Referenced by AddTask(), AddTask(), Initialize(), and Start().

Here is the caller graph for this function:

◆ IsStarted()

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

Check whether scheduler is currently running.

Returns
true if Start() has been called and the first task switch has occurred (m_task_now != nullptr), false before Start() or after all tasks exit.

Definition at line 946 of file stk.h.

947 {
948 return (m_task_now != nullptr);
949 }

References m_task_now.

Referenced by AddKernelTask(), AddTask(), AddTask(), and RemoveTask().

Here is the caller graph for this function:

◆ IsStaticMode()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsStaticMode ( )
inlinestaticprotected

Definition at line 1922 of file stk.h.

1922{ return ((TMode & KERNEL_STATIC) != 0U); }

References __stk_forceinline, and stk::KERNEL_STATIC.

◆ IsSyncMode()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode ( )
inlinestaticprotected

◆ IsTicklessMode()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode ( )
inlinestaticprotected

Definition at line 1926 of file stk.h.

1926{ return ((TMode & KERNEL_TICKLESS) != 0U); }

References __stk_forceinline, and stk::KERNEL_TICKLESS.

Referenced by UpdateTaskState().

Here is the caller graph for this function:

◆ IsValidFsmState()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsValidFsmState ( EFsmState state)
inlinestaticprotected

Check if FSM state is valid.

Definition at line 995 of file stk.h.

996 {
997 return (state > FSM_STATE_NONE) &&
999 }

References __stk_forceinline, FSM_STATE_MAX, and FSM_STATE_NONE.

Referenced by GetNewFsmState().

Here is the caller graph for this function:

◆ OnGetTid()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
TId stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnGetTid ( Word caller_SP)
inlineprotectedvirtual

Called from the Thread process when for getting task/thread id of the process.

Parameters
[in]caller_SPValue of Stack Pointer (SP) register (for locating the calling process inside the kernel).
Returns
Task/thread id of the process.

Implements stk::IPlatform::IEventHandler.

Definition at line 1460 of file stk.h.

1461 {
1463 STK_ASSERT(task != nullptr);
1464
1465 return task->GetTid();
1466 }
KernelTask * FindTaskBySP(Word SP)
Find kernel task for a Stack Pointer (SP).
Definition stk.h:1175

References FindTaskBySP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetTid(), and STK_ASSERT.

Here is the call graph for this function:

◆ OnStart()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnStart ( Stack *& active)
inlineprotectedvirtual

Called by platform driver immediately after a scheduler start (first tick).

Parameters
[out]activeSet to the stack of the first task to run, or to the sleep-trap stack if all tasks are initially sleeping.
Note
Delivers initial OnTaskSleep notifications to sleep-aware strategies for any tasks that were added in a sleeping state before Start() was called.
Selects the first runnable task via GetNewFsmState() and transitions the kernel to STATE_RUNNING.
If STK_SEGGER_SYSVIEW is enabled, emits a task-start trace event for the first task.
Warning
At least one task must have been added via AddTask(); asserts if the strategy pool is empty.

Implements stk::IPlatform::IEventHandler.

Definition at line 1223 of file stk.h.

1224 {
1225 STK_ASSERT(m_strategy.GetSize() != 0);
1226
1227 // iterate tasks and generate OnTaskSleep for a strategy for all initially sleeping tasks
1229 {
1230 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1231 {
1233
1234 if (task->IsSleeping())
1235 {
1237 {
1239
1240 // notify strategy that task is sleeping
1241 m_strategy.OnTaskSleep(task);
1242 }
1243 }
1244 }
1245 }
1246
1247 // get initial state and first task
1248 {
1250
1251 KernelTask *next = nullptr;
1253
1254 // expecting only SLEEPING or SWITCHING states
1256
1258 {
1259 m_task_now = next;
1260
1261 active = next->GetUserStack();
1262
1263 if (IsHrtMode())
1264 next->HrtOnSwitchedIn();
1265 }
1266 else
1268 {
1269 // MISRA 5-2-3 deviation: GetNext/GetFirst returns IKernelTask*, all objects in
1270 // the strategy pool are KernelTask instances - downcast is guaranteed safe.
1271 m_task_now = static_cast<KernelTask *>(m_strategy.GetFirst());
1272
1273 active = &m_sleep_trap[0].stack;
1274 }
1275 }
1276
1277 // is in running state
1279
1280 #if STK_SEGGER_SYSVIEW
1282 #endif
1283 }
EFsmState GetNewFsmState(KernelTask *&next)
Get new FSM state.
Definition stk.h:1697
@ STATE_SLEEP_PENDING
Task called Sleep/SleepUntil/Yield; strategy's OnTaskSleep() will be invoked on the next tick (sleep-...
Definition stk.h:130

References __stk_attr_noinline, FSM_STATE_SLEEPING, FSM_STATE_SWITCHING, GetNewFsmState(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedIn(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), m_fsm_state, m_sleep_trap, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_state, m_state, m_strategy, m_task_now, m_task_storage, stk::IKernel::STATE_RUNNING, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::STATE_SLEEP_PENDING, STK_ASSERT, and TASKS_MAX.

Here is the call graph for this function:

◆ OnStop()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnStop ( )
inlineprotectedvirtual

Called by the platform driver after a scheduler stop (all tasks have exited).

Note
KERNEL_DYNAMIC mode only: resets FSM to FSM_STATE_NONE and transitions kernel back to STATE_READY so Start() may be called again.
Has no effect in KERNEL_STATIC mode (static kernels never stop).

Implements stk::IPlatform::IEventHandler.

Definition at line 1290 of file stk.h.

1291 {
1292 if (IsDynamicMode())
1293 {
1295
1296 // is in stopped state, i.e. is ready to Start() again
1298 }
1299 }

References __stk_attr_noinline, FSM_STATE_NONE, IsDynamicMode(), m_fsm_state, m_state, and stk::IKernel::STATE_READY.

Here is the call graph for this function:

◆ OnTaskExit()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTaskExit ( Stack * stack)
inlineprotectedvirtual

Called from the Thread process when task finished (its Run function exited by return).

Parameters
[out]stackStack of the exited task.

Implements stk::IPlatform::IEventHandler.

Definition at line 1401 of file stk.h.

1402 {
1403 if (IsDynamicMode())
1404 {
1406 STK_ASSERT(task != nullptr);
1407
1408 task->ScheduleRemoval();
1409 }
1410 else
1411 {
1412 // kernel operating mode must be KERNEL_DYNAMIC for tasks to be able to exit
1414 }
1415 }
#define STK_KERNEL_PANIC(id)
Called when the kernel detects an unrecoverable internal fault.
Definition stk_arch.h:63
KernelTask * FindTaskByStack(const Stack *stack)
Find kernel task by the bound Stack instance.
Definition stk.h:1159

References FindTaskByStack(), IsDynamicMode(), stk::KERNEL_PANIC_BAD_MODE, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleRemoval(), STK_ASSERT, and STK_KERNEL_PANIC.

Here is the call graph for this function:

◆ OnTaskSleep()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTaskSleep ( Word caller_SP,
Timeout ticks )
inlineprotectedvirtual

Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from scheduling (sleeping).

Parameters
[in]caller_SPValue of Stack Pointer (SP) register (for locating the calling process inside the kernel).
[in]ticksTime to sleep (ticks).

Implements stk::IPlatform::IEventHandler.

Definition at line 1352 of file stk.h.

1353 {
1355 STK_ASSERT(task != nullptr);
1356
1357 // make change to HRT state and sleep time atomic
1358 {
1360
1361 if (IsHrtMode())
1362 task->HrtOnWorkCompleted();
1363
1364 task->ScheduleSleep(ticks);
1365 }
1366
1367 // note: we do not spin long here, kernel will switch this task out from scheduling on the next tick
1368 while (task->IsSleeping())
1369 {
1371 }
1372 }
#define __stk_relax_cpu
Emits a CPU pipeline-relaxation hint for use inside hot busy-wait (spin) loops (in-code statement).
Definition stktest.h:33

References __stk_relax_cpu, FindTaskBySP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnWorkCompleted(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleSleep(), and STK_ASSERT.

Referenced by OnTaskSwitch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnTaskSleepUntil()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTaskSleepUntil ( Word caller_SP,
Ticks timestamp )
inlineprotectedvirtual

Called by Thread process (via IKernelService::SleepUntil) for exclusion of the calling process from scheduling (sleeping).

Parameters
[in]caller_SPValue of Stack Pointer (SP) register (for locating the calling process inside the kernel).
[in]timestampAbsolute timestamp (ticks).

Implements stk::IPlatform::IEventHandler.

Definition at line 1374 of file stk.h.

1375 {
1377
1379 STK_ASSERT(task != nullptr);
1380
1381 // make change to HRT state and sleep time atomic
1382 {
1384
1385 Ticks ticks = timestamp - m_service.m_ticks;
1386
1387 // if provided timestamp expired, just ignore any sleep for this task
1388 if (ticks <= 0)
1389 return;
1390
1391 task->ScheduleSleep(ticks);
1392 }
1393
1394 // note: we do not spin long here, kernel will switch this task out from scheduling on the next tick
1395 while (task->IsSleeping())
1396 {
1398 }
1399 }

References __stk_relax_cpu, FindTaskBySP(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), m_service, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleSleep(), and STK_ASSERT.

Here is the call graph for this function:

◆ OnTaskSwitch()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTaskSwitch ( Word caller_SP)
inlineprotectedvirtual

Called by Thread process (via IKernelService::SwitchToNext) to switch to a next task.

Parameters
[in]caller_SPValue of Stack Pointer (SP) register (for locating the calling process inside the kernel).

Implements stk::IPlatform::IEventHandler.

Definition at line 1344 of file stk.h.

1345 {
1346 // yield with 2 ticks: 1 will be incremented on the next OnTick call by UpdateTasks
1347 // and remaining 1 will cause a context switch by UpdateFsmState when strategy detects
1348 // it as a sleeping test
1350 }
void OnTaskSleep(Word caller_SP, Timeout ticks)
Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from schedu...
Definition stk.h:1352

References OnTaskSleep().

Here is the call graph for this function:

◆ OnTaskWait()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
IWaitObject * stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTaskWait ( Word caller_SP,
ISyncObject * sync_obj,
IMutex * mutex,
Timeout timeout )
inlineprotectedvirtual

Called from the Thread process when task needs to wait.

Parameters
[in]caller_SPValue of Stack Pointer (SP) register (for locating the calling process inside the kernel).
[in]sync_objISyncObject instance (passed by Wait).
[in]mutexIMutex instance (passed by Wait).
[in]timeoutTime to sleep (ticks).

Implements stk::IPlatform::IEventHandler.

Definition at line 1417 of file stk.h.

1418 {
1419 if (IsSyncMode())
1420 {
1421 STK_ASSERT(timeout != 0); // API contract: caller must not be in ISR
1422 STK_ASSERT(sync_obj != nullptr); // API contract: ISyncObject instance must be provided
1423 STK_ASSERT(mutex != nullptr); // API contract: IMutex instance must be provided
1424 STK_ASSERT((sync_obj->GetHead() == nullptr) || (sync_obj->GetHead() == &m_sync_list[0]));
1425
1427 STK_ASSERT(task != nullptr);
1428
1429 // configure waiting
1430 task->m_wait_obj->SetupWait(sync_obj, timeout);
1431
1432 // register ISyncObject if not yet
1433 if (sync_obj->GetHead() == nullptr)
1434 m_sync_list->LinkBack(sync_obj);
1435
1436 // start sleeping infinitely, we rely on a Wake call via WaitObject
1437 task->ScheduleSleep(WAIT_INFINITE);
1438
1439 // unlock mutex locked externally, so that we could wait in a busy-waiting loop
1440 mutex->Unlock();
1441
1442 // note: we do not spin long here, kernel will switch this task out from scheduling on the next tick
1443 while (task->IsSleeping())
1444 {
1446 }
1447
1448 // re-lock mutex when returning to the task's execution space
1449 mutex->Lock();
1450
1451 return task->m_wait_obj;
1452 }
1453 else
1454 {
1455 STK_ASSERT(false);
1456 return nullptr;
1457 }
1458 }
static bool IsSyncMode()
Definition stk.h:1925
SyncObjectList m_sync_list[((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))]
List of active sync objects. Zero-size (no memory) if KERNEL_SYNC is not set.
Definition stk.h:2000

References __stk_relax_cpu, FindTaskBySP(), stk::util::DListEntry< T, _ClosedLoop >::GetHead(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), IsSyncMode(), stk::IMutex::Lock(), m_sync_list, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_wait_obj, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::ScheduleSleep(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::SetupWait(), STK_ASSERT, stk::IMutex::Unlock(), and stk::WAIT_INFINITE.

Here is the call graph for this function:

◆ OnTick()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::OnTick ( Stack *& idle,
Stack *& active )
inlineprotectedvirtual

Process one scheduler tick. Called from the platform timer/tick ISR.

Parameters
[out]idleStack descriptor to context-switch out (nullptr if no switch needed).
[out]activeStack descriptor to context-switch in (nullptr if no switch needed).
[in,out]ticks(KERNEL_TICKLESS builds only) On entry: actual number of ticks elapsed since the last call, as measured by the platform driver. On return: the number of ticks the hardware timer may suppress before the next required wakeup, computed as the minimum remaining sleep across all active tasks, clamped to [1, STK_TICKLESS_TICKS_MAX]. The platform driver programs this value into the timer to avoid unnecessary wakeups. This parameter is absent in non-tickless builds.
Returns
true if a context switch is required (idle and active are valid); false if the current task continues running.
Note
In non-tickless mode the internal tick counter always advances by exactly 1 per call.
In tickless mode (KERNEL_TICKLESS) the counter advances by the ticks value supplied by the platform driver, which may be greater than 1 after a suppressed interval.

Implements stk::IPlatform::IEventHandler.

Definition at line 1317 of file stk.h.

1322 {
1323 #if !STK_TICKLESS_IDLE
1324 // in non-tickless mode kernel is advancing strictly by 1 tick on every OnTick call
1325 enum { ticks = 1 };
1326 #endif
1327
1328 // advance internal timestamp
1329 m_service.IncrementTicks(ticks);
1330
1331 // consume elapsed and update to ticks to sleep
1332 #if STK_TICKLESS_IDLE
1333 ticks = (
1334 #else
1335 // notify compiler that we ignore a return value of UpdateTasks
1336 static_cast<void>(
1337 #endif
1339
1340 // decide on a context switch
1341 return UpdateFsmState(idle, active);
1342 }
bool UpdateFsmState(Stack *&idle, Stack *&active)
Update FSM state.
Definition stk.h:1708
Timeout UpdateTasks(const Timeout elapsed_ticks)
Update tasks (sleep, requests).
Definition stk.h:1470

References m_service, STK_TICKLESS_IDLE, UpdateFsmState(), and UpdateTasks().

Here is the call graph for this function:

◆ RemoveTask() [1/2]

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::RemoveTask ( ITask * user_task)
inlinevirtual

Remove a previously added task from the kernel before Start().

Parameters
[in]user_taskUser task to remove. Must not be nullptr.
Note
Only valid before Start() (i.e. while the kernel is not running). To remove tasks after Start() the task should return from its Run function (in KERNEL_DYNAMIC mode the slot is freed automatically on the next tick).
Warning
KERNEL_DYNAMIC mode only. Asserts if called in KERNEL_STATIC or KERNEL_HRT mode, or if called after Start().

Implements stk::IKernel.

Definition at line 895 of file stk.h.

896 {
897 if (IsDynamicMode())
898 {
899 STK_ASSERT(user_task != nullptr);
901
903 if (task != nullptr)
905 }
906 else
907 {
908 // kernel operating mode must be KERNEL_DYNAMIC for tasks to be able to be removed
909 STK_ASSERT(false);
910 }
911 }
KernelTask * FindTaskByUserTask(const ITask *user_task)
Find kernel task by the bound ITask instance.
Definition stk.h:1143
void RemoveTask(ITask *user_task)
Remove a previously added task from the kernel before Start().
Definition stk.h:895

References __stk_attr_noinline, FindTaskByUserTask(), IsDynamicMode(), IsStarted(), RemoveTask(), and STK_ASSERT.

Referenced by RemoveTask(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TestAlgorithm(), stk::test::TestPriorityNext(), and UpdateTaskState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveTask() [2/2]

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

Remove kernel task.

Note
Removal of the kernel task means releasing it from the user task details.
Parameters
[in]taskKernel task.

Definition at line 1201 of file stk.h.

1202 {
1203 STK_ASSERT(task != nullptr);
1204
1205 #if STK_SEGGER_SYSVIEW
1206 SEGGER_SYSVIEW_OnTaskTerminate(task->GetUserStack()->tid);
1207 #endif
1208
1209 m_strategy.RemoveTask(task);
1210 task->Unbind();
1211 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), m_strategy, STK_ASSERT, and stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::Unbind().

Here is the call graph for this function:

◆ RequestAddTask()

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

Request to add new task.

Note
Must be called by the task process only!
Parameters
[in]user_taskUser task to add.

Definition at line 1119 of file stk.h.

1120 {
1122
1123 KernelTask *caller = FindTaskBySP(m_platform.GetCallerSP());
1124 STK_ASSERT(caller != nullptr);
1125
1126 typename KernelTask::AddTaskRequest req = { .user_task = user_task };
1127 caller->m_srt[0].add_task_req = &req;
1128
1129 // notify kernel
1131
1132 // switch out and wait for completion (due to context switch request could be processed here)
1133 if (caller->m_srt[0].add_task_req != nullptr)
1134 m_service.SwitchToNext();
1135
1136 STK_ASSERT(caller->m_srt[0].add_task_req == nullptr);
1137 }
void ScheduleAddTask()
Signal the kernel to process a pending AddTask request on the next tick.
Definition stk.h:1894
Payload for an in-flight AddTask() request issued by a running task.
Definition stk.h:142

References __stk_attr_noinline, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::SrtInfo::add_task_req, FindTaskBySP(), IsDynamicMode(), m_platform, m_service, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_srt, ScheduleAddTask(), and STK_ASSERT.

Referenced by AddTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScheduleAddTask()

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

Signal the kernel to process a pending AddTask request on the next tick.

Note
Sets the REQUEST_ADD_TASK bit in m_request and emits a full memory fence so the ISR-side tick handler observes the flag without delay.

Definition at line 1894 of file stk.h.

References m_request, and REQUEST_ADD_TASK.

Referenced by RequestAddTask().

Here is the caller graph for this function:

◆ Start()

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

Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or indefinitely (KERNEL_STATIC mode).

Note
Re-initialises trap stacks on every call so Start() can be called again after a previous scheduling session ended.
If STK_SEGGER_SYSVIEW is enabled, starts tracing and registers all pre-added tasks.
Warning
At least one task must have been added via AddTask() before calling Start(). Asserts if called before Initialize().

Implements stk::IKernel.

Definition at line 921 of file stk.h.

922 {
924
925 // stacks of the traps must be re-initilized on every subsequent Start
926 InitTraps();
927
928 // start tracing
929 #if STK_SEGGER_SYSVIEW
931 for (int32_t i = 0; i < TASKS_MAX; ++i)
932 {
934 if (task->IsBusy())
936 }
937 #endif
938
939 m_platform.Start();
940 }
void InitTraps()
Initialize stack of the traps.
Definition stk.h:1003

References __stk_attr_noinline, InitTraps(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy(), IsInitialized(), m_platform, m_task_storage, STK_ASSERT, and TASKS_MAX.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TestHrtTaskExitDuringSleepState(), stk::test::TestTaskExit(), and stk::test::TestTaskSleep().

Here is the call graph for this function:

◆ StateExit()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::StateExit ( KernelTask * now,
KernelTask * next,
Stack *& idle,
Stack *& active )
inlineprotected

Exits from scheduling.

Note
FSM state: stk::FSM_STATE_EXITING.
Exits only if stk::KERNEL_DYNAMIC mode is specified, otherwise ignored.
Parameters
[in]nowCurrently active kernel task (ignored).
[in]nextNext kernel task (ignored).
[out]idleStack of the task which must enter Idle state.
[out]activeStack of the task which must enter Active state (to which context will switch).

Definition at line 1859 of file stk.h.

1860 {
1861 (void)now;
1862 (void)next;
1863
1864 if (IsDynamicMode())
1865 {
1866 // dynamic tasks are not supported if main processes's stack memory is not provided in Start()
1867 STK_ASSERT(m_exit_trap[0].stack.SP != 0);
1868
1869 idle = nullptr;
1870 active = &m_exit_trap[0].stack;
1871
1872 m_task_now = nullptr;
1873
1874 m_platform.Stop();
1875 }
1876 else
1877 {
1878 (void)idle;
1879 (void)active;
1880 }
1881
1882 return false;
1883 }

References IsDynamicMode(), m_exit_trap, m_platform, m_task_now, and STK_ASSERT.

Referenced by UpdateFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StateSleep()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::StateSleep ( KernelTask * now,
KernelTask * next,
Stack *& idle,
Stack *& active )
inlineprotected

Enters into a sleeping mode.

Note
FSM state: stk::FSM_STATE_SLEEPING.
Parameters
[in]nowCurrently active kernel task.
[in]nextNext kernel task (ignored).
[out]idleStack of the task which must enter Idle state.
[out]activeStack of the task which must enter Active state (to which context will switch).

Definition at line 1826 of file stk.h.

1827 {
1828 (void)next;
1829
1830 STK_ASSERT(now != nullptr);
1831 STK_ASSERT(m_sleep_trap[0].stack.SP != 0);
1832
1833 idle = now->GetUserStack();
1834 active = &m_sleep_trap[0].stack;
1835
1836 m_task_now = static_cast<KernelTask *>(m_strategy.GetFirst());
1837
1838 #if STK_SEGGER_SYSVIEW
1840 #endif
1841
1842 if (IsHrtMode())
1843 {
1844 if (!now->IsPendingRemoval())
1845 now->HrtOnSwitchedOut(&m_platform);
1846 }
1847
1848 return true; // switch context
1849 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedOut(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsPendingRemoval(), m_platform, m_sleep_trap, m_strategy, m_task_now, STK_ASSERT, and stk::TRACE_EVENT_SLEEP.

Referenced by UpdateFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StateSwitch()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::StateSwitch ( KernelTask * now,
KernelTask * next,
Stack *& idle,
Stack *& active )
inlineprotected

Switches contexts.

Note
FSM state: stk::FSM_STATE_SWITCHING.
Parameters
[in]nowCurrently active kernel task.
[in]nextNext kernel task.
[out]idleStack of the task which must enter Idle state.
[out]activeStack of the task which must enter Active state (to which context will switch).

Definition at line 1748 of file stk.h.

1749 {
1750 STK_ASSERT(now != nullptr);
1751 STK_ASSERT(next != nullptr);
1752
1753 // do not switch context because task did not change
1754 if (next == now)
1755 return false;
1756
1757 idle = now->GetUserStack();
1758 active = next->GetUserStack();
1759
1760 // if stack memory is exceeded these assertions will be hit
1761 if (now->IsBusy())
1762 {
1763 // current task could exit, thus we check it with IsBusy to avoid referencing nullptr returned by GetUserTask()
1764 STK_ASSERT(now->GetUserTask()->GetStack()[0] == STK_STACK_MEMORY_FILLER);
1765 }
1766 STK_ASSERT(next->GetUserTask()->GetStack()[0] == STK_STACK_MEMORY_FILLER);
1767
1768 m_task_now = next;
1769
1770 if ((IsHrtMode()))
1771 {
1772 if (now->m_hrt[0].done)
1773 {
1774 now->HrtOnSwitchedOut(&m_platform);
1775 next->HrtOnSwitchedIn();
1776 }
1777 }
1778
1779 #if STK_SEGGER_SYSVIEW
1781 SEGGER_SYSVIEW_OnTaskStartReady(next->GetUserStack()->tid);
1782 #endif
1783
1784 return true; // switch context
1785 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtInfo::done, stk::IStackMemory::GetStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserTask(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedIn(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedOut(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_hrt, m_platform, m_task_now, STK_ASSERT, STK_STACK_MEMORY_FILLER, and stk::TRACE_EVENT_SWITCH.

Referenced by UpdateFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StateWake()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::StateWake ( KernelTask * now,
KernelTask * next,
Stack *& idle,
Stack *& active )
inlineprotected

Wakes up after sleeping.

Note
FSM state: stk::FSM_STATE_WAKING.
Parameters
[in]nowCurrently active kernel task (ignored).
[in]nextNext kernel task.
[out]idleStack of the task which must enter Idle state.
[out]activeStack of the task which must enter Active state (to which context will switch).

Definition at line 1794 of file stk.h.

1795 {
1796 (void)now;
1797
1798 STK_ASSERT(next != nullptr);
1799
1800 idle = &m_sleep_trap[0].stack;
1801 active = next->GetUserStack();
1802
1803 // if stack memory is exceeded these assertions will be hit
1805 STK_ASSERT(next->GetUserTask()->GetStack()[0] == STK_STACK_MEMORY_FILLER);
1806
1807 m_task_now = next;
1808
1809 #if STK_SEGGER_SYSVIEW
1810 SEGGER_SYSVIEW_OnTaskStartReady(next->GetUserStack()->tid);
1811 #endif
1812
1813 if ((IsHrtMode()))
1814 next->HrtOnSwitchedIn();
1815
1816 return true; // switch context
1817 }

References stk::IStackMemory::GetStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserStack(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::GetUserTask(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedIn(), IsHrtMode(), m_sleep_trap, m_task_now, STK_ASSERT, and STK_STACK_MEMORY_FILLER.

Referenced by UpdateFsmState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateFsmState()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
bool stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateFsmState ( Stack *& idle,
Stack *& active )
inlineprotected

Update FSM state.

Parameters
[out]idleStack of the task which must enter Idle state.
[out]activeStack of the task which must enter Active state (to which context will switch).
Returns
FSM state.

Definition at line 1708 of file stk.h.

1709 {
1710 KernelTask *now = m_task_now, *next = nullptr;
1711 bool switch_context = false;
1712
1714
1715 switch (new_state)
1716 {
1719 break;
1720 case FSM_STATE_SLEEPING:
1722 break;
1723 case FSM_STATE_WAKING:
1725 break;
1726 case FSM_STATE_EXITING:
1728 break;
1729 case FSM_STATE_NONE:
1730 return switch_context; // valid intermittent non-persisting state: no-transition
1731 case FSM_STATE_MAX:
1732 default: // invalid state value
1734 break;
1735 }
1736
1738 return switch_context;
1739 }
EFsmState
Finite-state machine (FSM) state. Encodes what the kernel is currently doing between two consecutive ...
Definition stk.h:971
bool StateWake(KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
Wakes up after sleeping.
Definition stk.h:1794
bool StateExit(KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
Exits from scheduling.
Definition stk.h:1859
bool StateSwitch(KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
Switches contexts.
Definition stk.h:1748
bool StateSleep(KernelTask *now, KernelTask *next, Stack *&idle, Stack *&active)
Enters into a sleeping mode.
Definition stk.h:1826

References FSM_STATE_EXITING, FSM_STATE_MAX, FSM_STATE_NONE, FSM_STATE_SLEEPING, FSM_STATE_SWITCHING, FSM_STATE_WAKING, GetNewFsmState(), stk::KERNEL_PANIC_BAD_STATE, m_fsm_state, m_task_now, StateExit(), StateSleep(), StateSwitch(), StateWake(), and STK_KERNEL_PANIC.

Referenced by stk::test::KernelMock< TMode, TSize, TStrategy, TPlatform >::ForceUpdateInvalidFsmState(), and OnTick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateSyncObjects()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
void stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateSyncObjects ( const Timeout elapsed_ticks)
inlineprotected

Update synchronization objects.

Definition at line 1600 of file stk.h.

1601 {
1603
1605
1606 while (itr != nullptr)
1607 {
1608 ISyncObject::ListEntryType *next = itr->GetNext();
1609
1610 // MISRA 5-2-3 deviation: GetNext/GetFirst returns ISyncObject*, all objects in
1611 // m_sync_list are ISyncObject instances - downcast is guaranteed safe.
1612 if (!static_cast<ISyncObject *>(itr)->Tick(elapsed_ticks))
1613 m_sync_list->Unlink(itr);
1614
1615 itr = next;
1616 }
1617 }

References stk::util::DListEntry< T, _ClosedLoop >::GetNext(), IsSyncMode(), m_sync_list, and STK_ASSERT.

Referenced by UpdateTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTaskRequest()

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

Update pending task requests.

Definition at line 1621 of file stk.h.

1622 {
1623 if (m_request == REQUEST_NONE)
1624 return;
1625
1626 // process AddTask requests coming from tasks (KERNEL_DYNAMIC mode only, KERNEL_HRT is
1627 // excluded as we assume that HRT tasks must be known to the kernel before a Start())
1628 if (IsDynamicMode() && !IsHrtMode())
1629 {
1630 // process serialized AddTask request made from another active task, requesting process
1631 // is currently waiting due to SwitchToNext()
1632 if ((m_request & REQUEST_ADD_TASK) != 0U)
1633 {
1635
1636 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1637 {
1639
1640 if (task->m_srt[0].add_task_req != nullptr)
1641 {
1642 AllocateAndAddNewTask(task->m_srt[0].add_task_req->user_task);
1643
1644 task->m_srt[0].add_task_req = nullptr;
1646 }
1647 }
1648 }
1649 }
1650 }

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::SrtInfo::add_task_req, AllocateAndAddNewTask(), IsDynamicMode(), IsHrtMode(), m_request, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_srt, m_task_storage, REQUEST_ADD_TASK, REQUEST_NONE, TASKS_MAX, and stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::AddTaskRequest::user_task.

Referenced by UpdateTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTasks()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateTasks ( const Timeout elapsed_ticks)
inlineprotected

Update tasks (sleep, requests).

Definition at line 1470 of file stk.h.

1471 {
1472 // sync objects are updated before UpdateTaskRequest which may add a new object (newly added object must become 1 tick older)
1473 if (IsSyncMode())
1475
1477
1479 }
void UpdateTaskRequest()
Update pending task requests.
Definition stk.h:1621
Timeout UpdateTaskState(const Timeout elapsed_ticks)
Update task state: process removals, advance sleep timers, and track HRT durations.
Definition stk.h:1490
void UpdateSyncObjects(const Timeout elapsed_ticks)
Update synchronization objects.
Definition stk.h:1600

References IsSyncMode(), UpdateSyncObjects(), UpdateTaskRequest(), and UpdateTaskState().

Referenced by OnTick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTaskState()

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
Timeout stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateTaskState ( const Timeout elapsed_ticks)
inlineprotected

Update task state: process removals, advance sleep timers, and track HRT durations.

Parameters
[in]elapsed_ticksNumber of ticks elapsed since the previous call. Always 1 in non-tickless mode, may be >1 in tickless mode.
Returns
In non-tickless mode: always 1. In tickless mode (KERNEL_TICKLESS): the minimum remaining sleep ticks across all active tasks, clamped to [1, STK_TICKLESS_TICKS_MAX]. The platform driver uses this value to program the next timer wakeup interval, suppressing timer/tick ISR for that many ticks when the system would otherwise be idle.

Definition at line 1490 of file stk.h.

1491 {
1493
1494 for (uint32_t i = 0; i < TASKS_MAX; ++i)
1495 {
1497
1498 if (task->IsSleeping())
1499 {
1500 if (IsDynamicMode())
1501 {
1502 // task is pending removal, wait until it is switched out
1503 if (task->IsPendingRemoval())
1504 {
1505 if ((task != m_task_now) ||
1506 ((m_strategy.GetSize() == 1) && (m_fsm_state == FSM_STATE_SLEEPING)))
1507 {
1509 continue;
1510 }
1511 }
1512 }
1513
1514 // deliver sleep event to strategy
1515 // note: only currently scheduled task can be pending to sleep
1517 {
1519 {
1521
1522 // notify strategy that task is sleeping
1523 m_strategy.OnTaskSleep(task);
1524 }
1525 }
1526
1527 // advance sleep time by a tick
1528 task->m_time_sleep += elapsed_ticks;
1529
1530 // deliver sleep event to strategy
1532 {
1533 // notify strategy that task woke up
1534 if (task->m_time_sleep >= 0)
1535 m_strategy.OnTaskWake(task);
1536 }
1537 }
1538 else
1539 if (IsHrtMode())
1540 {
1541 // in HRT mode we trace how long task spent in active state (doing some work)
1542 if (task->IsBusy())
1543 {
1544 task->m_hrt[0].duration += elapsed_ticks;
1545
1546 // check if deadline is missed (HRT failure)
1547 if (task->HrtIsDeadlineMissed(task->m_hrt[0].duration))
1548 {
1549 bool can_recover = false;
1550
1551 // report deadline overrun to a strategy which supports overrun recovery
1553 can_recover = m_strategy.OnTaskDeadlineMissed(task);
1554
1555 // report failure if it could not be recovered by a scheduling strategy
1556 if (!can_recover)
1557 task->HrtHardFailDeadline(&m_platform);
1558 }
1559 }
1560 }
1561
1562 // get the number ticks the driver has to keep CPU in Idle
1563 if (IsTicklessMode() && (sleep_ticks > 1) && task->IsBusy())
1564 {
1565 // note: task sleep time is negative
1566 Timeout task_sleep = stk::Max<Timeout>(0, -task->m_time_sleep);
1567
1568 if (IsSyncMode())
1569 {
1570 // likely task is sleeping during sync operation (see Wait)
1571 if (task->m_wait_obj->IsWaiting())
1572 {
1573 // note: sync wait time is positive
1574 task_sleep = task->m_wait_obj->m_time_wait;
1575
1576 // we shall account for only valid time (when task is waiting during sync operation)
1577 if (task_sleep > 0)
1579 }
1580 else
1581 {
1583 }
1584 }
1585 else
1586 {
1588 }
1589
1590 // clamp to [1, STK_TICKLESS_TICKS_MAX] range
1592 }
1593 }
1594
1595 return sleep_ticks;
1596 }
constexpr T Max(T a, T b) noexcept
Compile-time maximum of two values.
Definition stk_defs.h:536
constexpr T Min(T a, T b) noexcept
Compile-time minimum of two values.
Definition stk_defs.h:530
static bool IsTicklessMode()
Definition stk.h:1926

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtInfo::duration, FSM_STATE_SLEEPING, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtHardFailDeadline(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtIsDeadlineMissed(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsBusy(), IsDynamicMode(), IsHrtMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsPendingRemoval(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::IsSleeping(), IsSyncMode(), IsTicklessMode(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::IsWaiting(), m_fsm_state, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_hrt, m_platform, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_state, m_strategy, m_task_now, m_task_storage, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_time_sleep, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::WaitObject::m_time_wait, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::m_wait_obj, stk::Max(), stk::Min(), RemoveTask(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::STATE_SLEEP_PENDING, STK_TICKLESS_TICKS_MAX, and TASKS_MAX.

Referenced by UpdateTasks().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_exit_trap

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
ExitTrapStack stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_exit_trap[((((TMode) &(KERNEL_DYNAMIC)) !=0U) ?(1) :(0))]
protected

Exit trap: zero-size in KERNEL_STATIC mode; one entry in KERNEL_DYNAMIC mode.

Definition at line 1996 of file stk.h.

Referenced by Initialize(), InitTraps(), Kernel(), and StateExit().

◆ m_fsm

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
const EFsmState stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_fsm[FSM_STATE_MAX][FSM_EVENT_MAX]
protected
Initial value:

Compile-time FSM transition table. Indexed as m_fsm[current_state][event] -> next_state. FSM_STATE_NONE as a next-state means "no transition": the FSM stays in the current state. Updated by UpdateFsmState() each tick via GetNewFsmState() -> FetchNextEvent().

Definition at line 2002 of file stk.h.

2002 {
2003 // FSM_EVENT_SWITCH FSM_EVENT_SLEEP FSM_EVENT_WAKE FSM_EVENT_EXIT
2008 };

Referenced by GetNewFsmState().

◆ m_fsm_state

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
EFsmState stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_fsm_state
protected

Current FSM state. Drives context-switch decision on every tick.

Definition at line 1997 of file stk.h.

Referenced by FetchNextEvent(), GetNewFsmState(), Initialize(), Kernel(), OnStart(), OnStop(), UpdateFsmState(), and UpdateTaskState().

◆ m_platform

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

Platform driver (SysTick, PendSV, context switch implementation).

Definition at line 1991 of file stk.h.

Referenced by AllocateNewTask(), GetPlatform(), Initialize(), InitTraps(), Kernel(), RequestAddTask(), Start(), StateExit(), StateSleep(), StateSwitch(), and UpdateTaskState().

◆ m_request

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
volatile uint8_t stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_request
protected

Bitmask of pending ERequest flags from running tasks. Written by tasks, read/cleared by UpdateTaskRequest() in tick context.

Definition at line 1998 of file stk.h.

Referenced by Initialize(), Kernel(), ScheduleAddTask(), and UpdateTaskRequest().

◆ m_service

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
KernelService stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_service
protected

Kernel service singleton exposed to running tasks via IKernelService::GetInstance().

Definition at line 1990 of file stk.h.

Referenced by Initialize(), OnTaskSleepUntil(), OnTick(), and RequestAddTask().

◆ m_sleep_trap

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
SleepTrapStack stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_sleep_trap[1]
protected

Sleep trap (always present): executed when all tasks are sleeping.

Definition at line 1995 of file stk.h.

Referenced by InitTraps(), Kernel(), OnStart(), StateSleep(), and StateWake().

◆ m_state

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
volatile EState stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_state
protected

Current kernel state.

Definition at line 1999 of file stk.h.

Referenced by GetState(), Initialize(), IsInitialized(), Kernel(), OnStart(), and OnStop().

◆ m_strategy

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

Task-switching strategy (determines which task runs next).

Definition at line 1992 of file stk.h.

Referenced by AddKernelTask(), FetchNextEvent(), GetSwitchStrategy(), Kernel(), OnStart(), RemoveTask(), StateSleep(), and UpdateTaskState().

◆ m_sync_list

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
SyncObjectList stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_sync_list[((((TMode) &(KERNEL_SYNC)) !=0U) ?(1) :(0))]
protected

List of active sync objects. Zero-size (no memory) if KERNEL_SYNC is not set.

Definition at line 2000 of file stk.h.

Referenced by OnTaskWait(), and UpdateSyncObjects().

◆ m_task_now

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

◆ m_task_storage

template<uint8_t TMode, uint32_t TSize, class TStrategy, class TPlatform>
TaskStorageType stk::Kernel< TMode, TSize, TStrategy, TPlatform >::m_task_storage
protected

Static pool of TSize KernelTask slots (free slots have m_user == nullptr).

Definition at line 1994 of file stk.h.

Referenced by AllocateNewTask(), FindTaskBySP(), FindTaskByStack(), FindTaskByUserTask(), Kernel(), OnStart(), Start(), UpdateTaskRequest(), and UpdateTaskState().


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