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 Namespace Reference

Namespace of STK package. More...

Namespaces

namespace  hw
 Hardware Abstraction Layer (HAL) for architecture-specific operations.
namespace  util
 Internal utility namespace containing data structure helpers (linked lists, etc.) used by the kernel implementation. Not part of the public user API.
namespace  sync
 Synchronization primitives for task coordination and resource protection.
namespace  time
 Time-related primitives.
namespace  test
 Namespace of the test inventory.

Classes

class  PlatformArmCortexM
 Concrete implementation of IPlatform driver for the Arm Cortex-M0, M3, M4, M7 processors. More...
class  PlatformRiscV
 Concrete implementation of IPlatform driver for the Risc-V processors. More...
class  PlatformContext
 Base platform context for all platform implementations. More...
class  PlatformX86Win32
 Concrete implementation of IPlatform driver for the x86 Win32 platform. More...
class  Kernel
 Concrete implementation of IKernel. More...
class  StackMemoryDef
 Stack memory type definition. More...
class  Stack
 Stack descriptor. More...
class  IStackMemory
 Interface for a stack memory region. More...
class  IWaitObject
 Wait object. More...
class  ITraceable
 Traceable object. More...
class  ISyncObject
 Synchronization object. More...
class  IMutex
 Interface for mutex synchronization primitive. More...
class  ITask
 Interface for a user task. More...
class  IKernelTask
 Scheduling-strategy-facing interface for a kernel task slot. More...
class  IPlatform
 Interface for a platform driver. More...
class  ITaskSwitchStrategy
 Interface for a task switching strategy implementation. More...
class  IKernel
 Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time modes. More...
class  IKernelService
 Interface for the kernel services exposed to the user processes during run-time when Kernel started scheduling the processes. More...
class  Task
 Partial implementation of the user task. More...
class  TaskW
 Partial implementation of the user task with a compile-time scheduling weight. Use when the kernel is configured with SwitchStrategySmoothWeightedRoundRobin. More...
class  StackMemoryWrapper
 Adapts an externally-owned stack memory array to the IStackMemory interface. More...
class  SwitchStrategyEDF
 Earliest Deadline First (EDF) scheduling strategy: always selects the runnable task with the least time remaining before its deadline expires. More...
class  SwitchStrategyFixedPriority
 Fixed-priority preemptive scheduling strategy with round-robin arbitration within each priority level. More...
class  SwitchStrategyMonotonic
 Monotonic scheduling strategy: Rate-Monotonic (RM) or Deadline-Monotonic (DM), selected at compile time by the _Type template parameter. More...
class  SchedulabilityCheck
 Utility class providing static methods for Worst-Case Response Time (WCRT) schedulability analysis of a monotonic HRT task set. More...
class  SwitchStrategyRoundRobin
 Round-Robin task-switching strategy: each runnable task receives one time slice (one tick interval) in turn before the kernel moves to the next task. More...
class  SwitchStrategySmoothWeightedRoundRobin
 Smooth Weighted Round-Robin (SWRR) task-switching strategy: distributes CPU time proportionally to per-task weights while avoiding execution bursts by spreading selections evenly over time. More...

Typedefs

typedef PlatformArmCortexM PlatformDefault
 Default platform implementation.
typedef uintptr_t Word
 Native processor word type.
typedef Word TId
typedef int32_t Timeout
 Timeout time (ticks).
typedef int64_t Ticks
 Ticks value.
typedef uint64_t Cycles
 Cycles value.
typedef SwitchStrategyFixedPriority< 32 > SwitchStrategyFP32
 Shorthand alias for SwitchStrategyFixedPriority<32>: 32 priority levels (0..31), using a single 32-bit m_ready_bitmap for O(1) highest-priority lookup.
typedef SwitchStrategyMonotonic< MSS_TYPE_RATESwitchStrategyRM
 Shorthand alias for SwitchStrategyMonotonic<MSS_TYPE_RATE>: Rate-Monotonic scheduling (shorter scheduling period -> higher priority).
typedef SwitchStrategyMonotonic< MSS_TYPE_DEADLINESwitchStrategyDM
 Shorthand alias for SwitchStrategyMonotonic<MSS_TYPE_DEADLINE>: Deadline-Monotonic scheduling (shorter execution deadline -> higher priority).
typedef SwitchStrategyRoundRobin SwitchStrategyRR
 Shorthand alias for SwitchStrategyRoundRobin.
typedef SwitchStrategySmoothWeightedRoundRobin SwitchStrategySWRR
 Shorthand alias for SwitchStrategySmoothWeightedRoundRobin.

Enumerations

enum  EAccessMode : int32_t {
  ACCESS_USER = 0 ,
  ACCESS_PRIVILEGED
}
 Hardware access mode by the user task. More...
enum  EKernelMode : uint8_t {
  KERNEL_STATIC = (1 << 0) ,
  KERNEL_DYNAMIC = (1 << 1) ,
  KERNEL_HRT = (1 << 2) ,
  KERNEL_SYNC = (1 << 3) ,
  KERNEL_TICKLESS = (1 << 4)
}
 Kernel operating mode. More...
enum  EKernelPanicId : uint32_t {
  KERNEL_PANIC_NONE = 0 ,
  KERNEL_PANIC_SPINLOCK_DEADLOCK = 1 ,
  KERNEL_PANIC_STACK_CORRUPT = 2 ,
  KERNEL_PANIC_ASSERT = 3 ,
  KERNEL_PANIC_HRT_HARD_FAULT = 4 ,
  KERNEL_PANIC_CPU_EXCEPTION = 5 ,
  KERNEL_PANIC_CS_NESTING_OVERFLOW = 6 ,
  KERNEL_PANIC_UNKNOWN_SVC = 7 ,
  KERNEL_PANIC_BAD_STATE = 8 ,
  KERNEL_PANIC_BAD_MODE = 9
}
 Identifies the source of a kernel panic. More...
enum  EStackType {
  STACK_USER_TASK = 0 ,
  STACK_SLEEP_TRAP ,
  STACK_EXIT_TRAP
}
 Stack type. More...
enum  EConsts {
  PERIODICITY_MAX = 99000 ,
  PERIODICITY_DEFAULT = 1000 ,
  STACK_SIZE_MIN = 32
}
 Constants. More...
enum  ESystemTaskId {
  SYS_TASK_ID_SLEEP = 0xFFFFFFFF ,
  SYS_TASK_ID_EXIT = 0xFFFFFFFE
}
 System task id. More...
enum  ETraceEventId {
  TRACE_EVENT_UNKNOWN = 0 ,
  TRACE_EVENT_SWITCH = 1000 + 1 ,
  TRACE_EVENT_SLEEP = 1000 + 2
}
 Trace event id for tracing tasks suspension and resume with debugging tools (SEGGER SysView and etc.). More...
enum  EMonotonicSwitchStrategyType {
  MSS_TYPE_RATE ,
  MSS_TYPE_DEADLINE
}
 Policy selector for SwitchStrategyMonotonic: determines the timing attribute used to assign fixed priorities to tasks at AddTask() time. More...

Functions

Word GetTls ()
 Get thread-local storage (TLS).
void SetTls (Word tp)
 Set thread-local storage (TLS).
static __stk_forceinline Cycles ConvertTimeUsToClockCycles (Cycles clock_freq, Ticks time_us)
 Convert time (microseconds) to core clock cycles.
template<typename T>
constexpr T Min (T a, T b) noexcept
 Compile-time minimum of two values.
template<typename T>
constexpr T Max (T a, T b) noexcept
 Compile-time maximum of two values.
TId GetTid ()
 Get task/thread Id of the calling task.
int64_t GetMsFromTicks (int64_t ticks, int32_t resolution)
 Convert ticks to milliseconds.
Ticks GetTicksFromMs (int64_t ms, int32_t resolution)
 Convert milliseconds to ticks.
Ticks GetTicks ()
 Get number of ticks elapsed since kernel start.
int32_t GetTickResolution ()
 Get number of microseconds in one tick.
Ticks GetTicksFromMs (int64_t ms)
 Convert milliseconds to ticks using the current kernel tick resolution.
static int64_t GetTimeNowMs ()
 Get current time in milliseconds since kernel start.
void Sleep (uint32_t ticks)
 Put calling process into a sleep state.
static void SleepMs (uint32_t ms)
 Put calling process into a sleep state.
void SleepUntil (Ticks timestamp)
 Put calling process into a sleep state until the specified timestamp.
void Yield ()
 Notify scheduler to switch to the next runnable task.
void Delay (uint32_t ticks)
 Delay calling process by busy-waiting until the deadline expires.
static void DelayMs (uint32_t ms)
 Delay calling process by busy-waiting until the deadline expires.

Variables

const TId TID_ISR = static_cast<TId>(~0)
 Reserved task/thread id representing an ISR context.
const TId TID_NONE = static_cast<TId>(0)
 Reserved task/thread id representing zero/none thread id.
const Timeout WAIT_INFINITE = INT32_MAX
 Timeout value: block indefinitely until the synchronization object is signaled.
const Timeout NO_WAIT = 0
 Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking poll).

Detailed Description

Namespace of STK package.

Typedef Documentation

◆ Cycles

typedef uint64_t stk::Cycles

Cycles value.

Definition at line 155 of file stk_common.h.

◆ PlatformDefault

Default platform implementation.

Definition at line 52 of file stk_arch_arm-cortex-m.h.

◆ SwitchStrategyDM

Shorthand alias for SwitchStrategyMonotonic<MSS_TYPE_DEADLINE>: Deadline-Monotonic scheduling (shorter execution deadline -> higher priority).

See also
SwitchStrategyMonotonic, SchedulabilityCheck

Definition at line 505 of file stk_strategy_monotonic.h.

◆ SwitchStrategyFP32

Shorthand alias for SwitchStrategyFixedPriority<32>: 32 priority levels (0..31), using a single 32-bit m_ready_bitmap for O(1) highest-priority lookup.

See also
SwitchStrategyFixedPriority

Definition at line 355 of file stk_strategy_fpriority.h.

◆ SwitchStrategyRM

Shorthand alias for SwitchStrategyMonotonic<MSS_TYPE_RATE>: Rate-Monotonic scheduling (shorter scheduling period -> higher priority).

See also
SwitchStrategyMonotonic, SchedulabilityCheck

Definition at line 498 of file stk_strategy_monotonic.h.

◆ SwitchStrategyRR

◆ SwitchStrategySWRR

◆ Ticks

typedef int64_t stk::Ticks

Ticks value.

Definition at line 150 of file stk_common.h.

◆ TId

typedef Word stk::TId

Definition at line 117 of file stk_common.h.

◆ Timeout

typedef int32_t stk::Timeout

Timeout time (ticks).

Definition at line 133 of file stk_common.h.

◆ Word

typedef uintptr_t stk::Word

Native processor word type.

Represents natural data width of the CPU (matching uintptr_t). Used for stack allocation, register storage, pointer value storage, and memory alignment to ensure atomic access, optimal performance, and hardware compatibility.

Definition at line 112 of file stk_common.h.

Enumeration Type Documentation

◆ EAccessMode

enum stk::EAccessMode : int32_t

Hardware access mode by the user task.

Warning
Type is explicitly 32-bit to be compatible with platform implementations.
Enumerator
ACCESS_USER 

Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).

ACCESS_PRIVILEGED 

Privileged access mode (access to hardware is fully unrestricted).

Definition at line 30 of file stk_common.h.

31{
32 ACCESS_USER = 0,
34};
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
Definition stk_common.h:32
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:33

◆ EConsts

Constants.

Enumerator
PERIODICITY_MAX 

Maximum periodicity (microseconds), 99 milliseconds (note: this value is the highest working on a real hardware and QEMU).

PERIODICITY_DEFAULT 

Default periodicity (microseconds), 1 millisecond.

STACK_SIZE_MIN 

Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task, sleep trap, exit trap). See: StackMemoryDef, StackMemoryWrapper.

Definition at line 79 of file stk_common.h.

80{
81 PERIODICITY_MAX = 99000,
82 PERIODICITY_DEFAULT = 1000,
84};
#define STK_STACK_SIZE_MIN
Minimum stack size in elements of Word, shared by all stack allocation lower-bound checks.
Definition stk_defs.h:454
@ PERIODICITY_DEFAULT
Default periodicity (microseconds), 1 millisecond.
Definition stk_common.h:82
@ STACK_SIZE_MIN
Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task,...
Definition stk_common.h:83
@ PERIODICITY_MAX
Maximum periodicity (microseconds), 99 milliseconds (note: this value is the highest working on a rea...
Definition stk_common.h:81

◆ EKernelMode

enum stk::EKernelMode : uint8_t

Kernel operating mode.

Enumerator
KERNEL_STATIC 

All tasks are static and can not exit.

KERNEL_DYNAMIC 

Tasks can be added or removed and therefore exit when done.

KERNEL_HRT 

Hard Real-Time (HRT) behavior (tasks are scheduled periodically and have an execution deadline, whole system is failed when task's deadline is failed).

KERNEL_SYNC 

Synchronization support (see Event).

KERNEL_TICKLESS 

Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config.h.

Definition at line 39 of file stk_common.h.

40{
41 KERNEL_STATIC = (1 << 0),
42 KERNEL_DYNAMIC = (1 << 1),
43 KERNEL_HRT = (1 << 2),
44 KERNEL_SYNC = (1 << 3),
45 KERNEL_TICKLESS = (1 << 4),
46};
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
Definition stk_common.h:45
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:44
@ KERNEL_HRT
Hard Real-Time (HRT) behavior (tasks are scheduled periodically and have an execution deadline,...
Definition stk_common.h:43
@ KERNEL_STATIC
All tasks are static and can not exit.
Definition stk_common.h:41
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Definition stk_common.h:42

◆ EKernelPanicId

enum stk::EKernelPanicId : uint32_t

Identifies the source of a kernel panic.

Enumerator
KERNEL_PANIC_NONE 

Panic is absent (no fault).

KERNEL_PANIC_SPINLOCK_DEADLOCK 

Spin-lock timeout expired: lock owner never released.

KERNEL_PANIC_STACK_CORRUPT 

Stack integrity check failed.

KERNEL_PANIC_ASSERT 

Internal assertion failed (maps from STK_ASSERT).

KERNEL_PANIC_HRT_HARD_FAULT 

Kernel running in KERNEL_HRT mode reported deadline failure of the task.

KERNEL_PANIC_CPU_EXCEPTION 

CPU reported an exception and halted execution.

KERNEL_PANIC_CS_NESTING_OVERFLOW 

Critical section nesting limit exceeded: violation of STK_CRITICAL_SECTION_NESTINGS_MAX.

KERNEL_PANIC_UNKNOWN_SVC 

Unknown service command received by SVC handler.

KERNEL_PANIC_BAD_STATE 

Kernel entered unexpected (bad) state.

KERNEL_PANIC_BAD_MODE 

Kernel is in bad/unsupported mode for the current operation.

Definition at line 51 of file stk_common.h.

52{
63};
@ KERNEL_PANIC_UNKNOWN_SVC
Unknown service command received by SVC handler.
Definition stk_common.h:60
@ KERNEL_PANIC_BAD_MODE
Kernel is in bad/unsupported mode for the current operation.
Definition stk_common.h:62
@ KERNEL_PANIC_HRT_HARD_FAULT
Kernel running in KERNEL_HRT mode reported deadline failure of the task.
Definition stk_common.h:57
@ KERNEL_PANIC_CS_NESTING_OVERFLOW
Critical section nesting limit exceeded: violation of STK_CRITICAL_SECTION_NESTINGS_MAX.
Definition stk_common.h:59
@ KERNEL_PANIC_NONE
Panic is absent (no fault).
Definition stk_common.h:53
@ KERNEL_PANIC_CPU_EXCEPTION
CPU reported an exception and halted execution.
Definition stk_common.h:58
@ KERNEL_PANIC_STACK_CORRUPT
Stack integrity check failed.
Definition stk_common.h:55
@ KERNEL_PANIC_SPINLOCK_DEADLOCK
Spin-lock timeout expired: lock owner never released.
Definition stk_common.h:54
@ KERNEL_PANIC_BAD_STATE
Kernel entered unexpected (bad) state.
Definition stk_common.h:61
@ KERNEL_PANIC_ASSERT
Internal assertion failed (maps from STK_ASSERT).
Definition stk_common.h:56

◆ EMonotonicSwitchStrategyType

Policy selector for SwitchStrategyMonotonic: determines the timing attribute used to assign fixed priorities to tasks at AddTask() time.

Enumerator
MSS_TYPE_RATE 

Rate-Monotonic (RM): shorter scheduling period -> higher priority. Priority is derived from GetHrtPeriodicity() and is fixed at task registration.

MSS_TYPE_DEADLINE 

Deadline-Monotonic (DM): shorter execution deadline -> higher priority. Priority is derived from GetHrtDeadline() and is fixed at task registration.

Definition at line 28 of file stk_strategy_monotonic.h.

29{
32};
@ MSS_TYPE_DEADLINE
Deadline-Monotonic (DM): shorter execution deadline -> higher priority. Priority is derived from GetH...
@ MSS_TYPE_RATE
Rate-Monotonic (RM): shorter scheduling period -> higher priority. Priority is derived from GetHrtPer...

◆ EStackType

Stack type.

See also
IPlatform::InitStack
Enumerator
STACK_USER_TASK 

Stack of the user task.

STACK_SLEEP_TRAP 

Stack of the Sleep trap.

STACK_EXIT_TRAP 

Stack of the Exit trap.

Definition at line 69 of file stk_common.h.

70{
71 STACK_USER_TASK = 0,
74};
@ STACK_SLEEP_TRAP
Stack of the Sleep trap.
Definition stk_common.h:72
@ STACK_USER_TASK
Stack of the user task.
Definition stk_common.h:71
@ STACK_EXIT_TRAP
Stack of the Exit trap.
Definition stk_common.h:73

◆ ESystemTaskId

System task id.

Enumerator
SYS_TASK_ID_SLEEP 

Sleep trap.

SYS_TASK_ID_EXIT 

Exit trap.

Definition at line 89 of file stk_common.h.

90{
91 SYS_TASK_ID_SLEEP = 0xFFFFFFFF,
92 SYS_TASK_ID_EXIT = 0xFFFFFFFE
93};
@ SYS_TASK_ID_EXIT
Exit trap.
Definition stk_common.h:92
@ SYS_TASK_ID_SLEEP
Sleep trap.
Definition stk_common.h:91

◆ ETraceEventId

Trace event id for tracing tasks suspension and resume with debugging tools (SEGGER SysView and etc.).

Enumerator
TRACE_EVENT_UNKNOWN 
TRACE_EVENT_SWITCH 
TRACE_EVENT_SLEEP 

Definition at line 98 of file stk_common.h.

99{
101 TRACE_EVENT_SWITCH = 1000 + 1,
102 TRACE_EVENT_SLEEP = 1000 + 2
103};
@ TRACE_EVENT_UNKNOWN
Definition stk_common.h:100
@ TRACE_EVENT_SLEEP
Definition stk_common.h:102
@ TRACE_EVENT_SWITCH
Definition stk_common.h:101

Function Documentation

◆ ConvertTimeUsToClockCycles()

__stk_forceinline Cycles stk::ConvertTimeUsToClockCycles ( Cycles clock_freq,
Ticks time_us )
static

Convert time (microseconds) to core clock cycles.

Parameters
[in]clock_freqClock frequency.
[in]time_usTime (microseconds).
Returns
Clock cycles.

Definition at line 104 of file stk_arch_common.h.

105{
106 return ((clock_freq * static_cast<Cycles>(time_us)) / 1000000ULL);
107}
uint64_t Cycles
Cycles value.
Definition stk_common.h:155

References __stk_forceinline.

◆ Delay()

void stk::Delay ( uint32_t ticks)

Delay calling process by busy-waiting until the deadline expires.

Note
Unlike Sleep this function delays code execution by spinning in a loop until deadline expiry.
Use with care in HRT mode to avoid missed deadline (see stk::KERNEL_HRT, ITask::OnDeadlineMissed).
Parameters
[in]ticksDelay time (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 342 of file stk_helper.h.

343{
345}
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
Definition stktest.cpp:69
virtual void Delay(Timeout ticks)=0
Delay calling process.

References __stk_forceinline, stk::IKernelService::Delay(), and stk::IKernelService::GetInstance().

Referenced by DelayMs(), stk::test::chain::TestTask< _AccessMode >::Run(), stk::test::condvar::NotifyOneOrderTask< _AccessMode >::Run(), stk::test::condvar::NotifyOneWakesTask< _AccessMode >::Run(), stk::test::condvar::PredicateLoopTask< _AccessMode >::Run(), stk::test::event::AutoResetBasicTask< _AccessMode >::Run(), stk::test::event::PulseAutoResetTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAllTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAnyTask< _AccessMode >::Run(), stk::test::hrt::TestTask< _AccessMode >::Run(), stk::test::mutex::BasicLockUnlockTask< _AccessMode >::Run(), stk::test::mutex::InterTaskCoordinationTask< _AccessMode >::Run(), stk::test::mutex::StressTestTask< _AccessMode >::Run(), stk::test::rwmutex::ReaderWriterAlternationTask< _AccessMode >::Run(), stk::test::rwmutex::StressTestTask< _AccessMode >::Run(), stk::test::rwmutex::WriterExclusivityTask< _AccessMode >::Run(), stk::test::rwmutex::WriterStarvationTask< _AccessMode >::Run(), stk::test::semaphore::BasicSignalWaitTask< _AccessMode >::Run(), stk::test::semaphore::BoundedBufferTask< _AccessMode >::Run(), stk::test::semaphore::FIFOOrderTask< _AccessMode >::Run(), stk::test::semaphore::StressTestTask< _AccessMode >::Run(), stk::test::spinlock::MutualExclusionTask< _AccessMode >::Run(), stk::test::spinlock::UnlockTransferTask< _AccessMode >::Run(), stk::test::switch_::TestTask< _AccessMode >::Run(), stk_delay(), stk::test::TEST(), and stk::test::TEST().

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

◆ DelayMs()

void stk::DelayMs ( uint32_t ms)
inlinestatic

Delay calling process by busy-waiting until the deadline expires.

Note
Unlike Sleep this function delays code execution by spinning in a loop until deadline expiry.
Use with care in HRT mode to avoid missed deadline (see stk::KERNEL_HRT, ITask::OnDeadlineMissed).
Parameters
[in]msDelay time (milliseconds).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 353 of file stk_helper.h.

354{
355 Delay(static_cast<Timeout>(GetTicksFromMs(ms)));
356}
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:133
void Delay(uint32_t ticks)
Delay calling process by busy-waiting until the deadline expires.
Definition stk_helper.h:342
Ticks GetTicksFromMs(int64_t ms, int32_t resolution)
Convert milliseconds to ticks.
Definition stk_helper.h:239

References Delay(), and GetTicksFromMs().

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

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

◆ GetMsFromTicks()

int64_t stk::GetMsFromTicks ( int64_t ticks,
int32_t resolution )

Convert ticks to milliseconds.

Parameters
[in]ticksTick count to convert.
[in]resolutionMicroseconds per tick, as returned by IKernelService::GetTickResolution().
Returns
Equivalent time in milliseconds.
Note
ISR-safe (performs only arithmetic, no kernel calls).

Definition at line 228 of file stk_helper.h.

229{
230 return (ticks * resolution) / 1000;
231}

References __stk_forceinline.

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

Here is the caller graph for this function:

◆ GetTickResolution()

int32_t stk::GetTickResolution ( )

Get number of microseconds in one tick.

Note
Tick is a periodicity of the system timer expressed in microseconds.
ISR-safe.
Returns
Microseconds in one tick.

Definition at line 258 of file stk_helper.h.

259{
261}
virtual int32_t GetTickResolution() const =0
Get number of microseconds in one tick.

References __stk_forceinline, stk::IKernelService::GetInstance(), and stk::IKernelService::GetTickResolution().

Referenced by GetTicksFromMs(), stk_tick_resolution(), stk_ticks_from_ms(), and stk::test::TEST().

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

◆ GetTicks()

◆ GetTicksFromMs() [1/2]

Ticks stk::GetTicksFromMs ( int64_t ms)

Convert milliseconds to ticks using the current kernel tick resolution.

Parameters
[in]msTime in milliseconds to convert.
Returns
Equivalent tick count.
Note
Convenience overload that queries GetTickResolution() automatically. Use the two-argument form GetTicksFromMsec(ms, resolution) in ISR context.
Warning
ISR-unsafe (internally calls GetTickResolution() which accesses the kernel service).

Definition at line 270 of file stk_helper.h.

271{
272 return GetTicksFromMs(ms, GetTickResolution());
273}
int32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:258

References __stk_forceinline, GetTickResolution(), and GetTicksFromMs().

Here is the call graph for this function:

◆ GetTicksFromMs() [2/2]

Ticks stk::GetTicksFromMs ( int64_t ms,
int32_t resolution )

Convert milliseconds to ticks.

Parameters
[in]msTime in milliseconds to convert.
[in]resolutionMicroseconds per tick, as returned by IKernelService::GetTickResolution().
Returns
Equivalent tick count.
Note
ISR-safe (performs only arithmetic, no kernel calls).

Definition at line 239 of file stk_helper.h.

240{
241 return ms * 1000 / resolution;
242}

References __stk_forceinline.

Referenced by DelayMs(), GetTicksFromMs(), stk::test::stk::SetTimeNowMsec(), and SleepMs().

Here is the caller graph for this function:

◆ GetTid()

TId stk::GetTid ( )

Get task/thread Id of the calling task.

Returns
Id of the calling task/thread.
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 217 of file stk_helper.h.

218{
220}
virtual TId GetTid() const =0
Get thread Id of the currently running task.

References __stk_forceinline, stk::IKernelService::GetInstance(), and stk::IKernelService::GetTid().

Referenced by stk::sync::SpinLock::Lock(), stk_tid(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::Test_SyncWait(), stk::sync::SpinLock::TryLock(), stk::sync::Mutex::Unlock(), and stk::sync::SpinLock::Unlock().

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

◆ GetTimeNowMs()

int64_t stk::GetTimeNowMs ( )
inlinestatic

Get current time in milliseconds since kernel start.

Returns
Milliseconds elapsed since IKernel::Start() was called.
Note
ISR-safe.
When the tick resolution is exactly 1000 µs (1 ms, the default PERIODICITY_DEFAULT), the tick count is returned directly without multiplication, avoiding a 64-bit multiply.

Definition at line 281 of file stk_helper.h.

282{
284 int32_t resolution = service->GetTickResolution();
285
286 if (resolution == 1000) // fast path: tick == 1 ms, no conversion needed
287 return service->GetTicks();
288 else
289 return (service->GetTicks() * resolution) / 1000;
290}
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
Definition stk_common.h:929

References stk::IKernelService::GetInstance(), stk::IKernelService::GetTickResolution(), and stk::IKernelService::GetTicks().

Referenced by stk::test::timer::TestTimer::OnExpired(), stk::test::chain::TestTask< _AccessMode >::Run(), stk::test::condvar::NoWaitTimeoutTask< _AccessMode >::Run(), stk::test::condvar::TimeoutExpiresTask< _AccessMode >::Run(), stk::test::event::TimeoutWaitTask< _AccessMode >::Run(), stk::test::event::TryWaitTask< _AccessMode >::Run(), stk::test::eventflags::TimeoutTask< _AccessMode >::Run(), stk::test::eventflags::TryWaitTask< _AccessMode >::Run(), stk::test::hrt::TestTask< _AccessMode >::Run(), stk::test::mutex::TimedLockTask< _AccessMode >::Run(), stk::test::mutex::TryLockTask< _AccessMode >::Run(), stk::test::pipe::TimeoutTask< _AccessMode >::Run(), stk::test::rwmutex::ReadUnlockWakesWriterTask< _AccessMode >::Run(), stk::test::rwmutex::TimedReadLockTask< _AccessMode >::Run(), stk::test::rwmutex::TimedWriteLockTask< _AccessMode >::Run(), stk::test::rwmutex::TryReadLockWhileWriterTask< _AccessMode >::Run(), stk::test::rwmutex::WriterStarvationTask< _AccessMode >::Run(), stk::test::semaphore::TimeoutWaitTask< _AccessMode >::Run(), stk::test::semaphore::ZeroTimeoutTask< _AccessMode >::Run(), stk::test::sleep::TestTask< _AccessMode >::Run(), stk::test::spinlock::TryLockContendedTask< _AccessMode >::Run(), stk::test::timer::OneShotTimerTask< _AccessMode >::Run(), stk::test::timer::ResetPeriodicTimerTask< _AccessMode >::Run(), stk::test::timer::RestartTimerTask< _AccessMode >::Run(), stk::test::timer::StartOrResetTask< _AccessMode >::Run(), stk_time_now_ms(), stk::test::TEST(), and stk::test::TEST().

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

◆ GetTls()

uintptr_t stk::hw::GetTls ( )

Get thread-local storage (TLS).

Returns
TLS value.
Note
Using r9 register.
Returns
TLS value.
Note
tp register is an alias for x4

Definition at line 58 of file stk_arch_arm-cortex-m.h.

59{
60 Word tp;
61 __asm volatile("MOV %0, r9" : "=r"(tp) : /* input: none */ : /* clobbers: none */);
62 return tp;
63}
uintptr_t Word
Native processor word type.
Definition stk_common.h:112

References __stk_forceinline.

◆ Max()

template<typename T>
T stk::Max ( T a,
T b )
constexprnoexcept

Compile-time maximum of two values.

Note
Arguments are evaluated exactly once, safe for any expression type.

Definition at line 536 of file stk_defs.h.

536{ return (a < b) ? b : a; }

Referenced by stk::test::TEST(), and stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateTaskState().

Here is the caller graph for this function:

◆ Min()

template<typename T>
T stk::Min ( T a,
T b )
constexprnoexcept

Compile-time minimum of two values.

Note
Arguments are evaluated exactly once, safe for any expression type.

Definition at line 530 of file stk_defs.h.

530{ return (a < b) ? a : b; }

Referenced by stk::test::TEST(), and stk::Kernel< TMode, TSize, TStrategy, TPlatform >::UpdateTaskState().

Here is the caller graph for this function:

◆ SetTls()

void stk::hw::SetTls ( Word tp)

Set thread-local storage (TLS).

Parameters
[in]tpTLS value.
Note
Using r9 register.
Parameters
[in]tpTLS value.
Note
tp register is an alias for x4

Definition at line 69 of file stk_arch_arm-cortex-m.h.

70{
71 __asm volatile("MOV r9, %0" : /* output: none */ : "r"(tp) : /* clobbers: none */);
72}

References __stk_forceinline.

◆ Sleep()

void stk::Sleep ( uint32_t ticks)

Put calling process into a sleep state.

Note
Unlike Delay this function does not waste CPU cycles and allows kernel to put CPU into a low-power state.
Unsupported in HRT mode (see stk::KERNEL_HRT); in HRT mode tasks sleep automatically according to their periodicity and workload.
Parameters
[in]ticksSleep time (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 298 of file stk_helper.h.

299{
301}
virtual void Sleep(Timeout ticks)=0
Put calling process into a sleep state.

References __stk_forceinline, stk::IKernelService::GetInstance(), and stk::IKernelService::Sleep().

Referenced by stk::test::condvar::MutexReacquiredTask< _AccessMode >::Run(), stk::test::condvar::NotifyAllWakesTask< _AccessMode >::Run(), stk::test::condvar::NotifyOneOrderTask< _AccessMode >::Run(), stk::test::condvar::NotifyOneWakesTask< _AccessMode >::Run(), stk::test::condvar::NoWaitTimeoutTask< _AccessMode >::Run(), stk::test::condvar::PredicateLoopTask< _AccessMode >::Run(), stk::test::condvar::StressTestTask< _AccessMode >::Run(), stk::test::condvar::TimeoutExpiresTask< _AccessMode >::Run(), stk::test::event::AutoResetBasicTask< _AccessMode >::Run(), stk::test::event::InitialStateTask< _AccessMode >::Run(), stk::test::event::ManualResetBasicTask< _AccessMode >::Run(), stk::test::event::PulseAutoResetTask< _AccessMode >::Run(), stk::test::event::PulseManualResetTask< _AccessMode >::Run(), stk::test::event::ResetManualTask< _AccessMode >::Run(), stk::test::event::TimeoutWaitTask< _AccessMode >::Run(), stk::test::event::TryWaitTask< _AccessMode >::Run(), stk::test::eventflags::ClearTask< _AccessMode >::Run(), stk::test::eventflags::GetTask< _AccessMode >::Run(), stk::test::eventflags::InitialFlagsTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAllTask< _AccessMode >::Run(), stk::test::eventflags::MultiWaiterAnyTask< _AccessMode >::Run(), stk::test::eventflags::NoClearTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAllTask< _AccessMode >::Run(), stk::test::eventflags::SetWaitAnyTask< _AccessMode >::Run(), stk::test::eventflags::TimeoutTask< _AccessMode >::Run(), stk::test::eventflags::TryWaitTask< _AccessMode >::Run(), stk::test::mutex::BasicLockUnlockTask< _AccessMode >::Run(), stk::test::mutex::FIFOOrderTask< _AccessMode >::Run(), stk::test::mutex::InterTaskCoordinationTask< _AccessMode >::Run(), stk::test::mutex::RecursiveDepthTask< _AccessMode >::Run(), stk::test::mutex::RecursiveLockTask< _AccessMode >::Run(), stk::test::mutex::StressTestTask< _AccessMode >::Run(), stk::test::mutex::TimedLockTask< _AccessMode >::Run(), stk::test::mutex::TryLockTask< _AccessMode >::Run(), stk::test::pipe::BasicWriteReadTask< _AccessMode >::Run(), stk::test::pipe::BulkWriteReadTask< _AccessMode >::Run(), stk::test::pipe::GetSizeIsEmptyTask< _AccessMode >::Run(), stk::test::pipe::MultiProducerConsumerTask< _AccessMode >::Run(), stk::test::pipe::ReadBlocksWhenEmptyTask< _AccessMode >::Run(), stk::test::pipe::StressTestTask< _AccessMode >::Run(), stk::test::pipe::TimeoutTask< _AccessMode >::Run(), stk::test::pipe::WriteBlocksWhenFullTask< _AccessMode >::Run(), stk::test::rwmutex::ConcurrentReadersTask< _AccessMode >::Run(), stk::test::rwmutex::ReaderWriterAlternationTask< _AccessMode >::Run(), stk::test::rwmutex::ReadUnlockWakesWriterTask< _AccessMode >::Run(), stk::test::rwmutex::StressTestTask< _AccessMode >::Run(), stk::test::rwmutex::TimedReadLockTask< _AccessMode >::Run(), stk::test::rwmutex::TimedWriteLockTask< _AccessMode >::Run(), stk::test::rwmutex::TryReadLockWhileWriterTask< _AccessMode >::Run(), stk::test::rwmutex::WriterExclusivityTask< _AccessMode >::Run(), stk::test::rwmutex::WriterPriorityTask< _AccessMode >::Run(), stk::test::rwmutex::WriterStarvationTask< _AccessMode >::Run(), stk::test::semaphore::BasicSignalWaitTask< _AccessMode >::Run(), stk::test::semaphore::BoundedBufferTask< _AccessMode >::Run(), stk::test::semaphore::FIFOOrderTask< _AccessMode >::Run(), stk::test::semaphore::InitialCountTask< _AccessMode >::Run(), stk::test::semaphore::SignalBeforeWaitTask< _AccessMode >::Run(), stk::test::semaphore::StressTestTask< _AccessMode >::Run(), stk::test::semaphore::TimeoutWaitTask< _AccessMode >::Run(), stk::test::semaphore::ZeroTimeoutTask< _AccessMode >::Run(), stk::test::sleep::TestTask< _AccessMode >::Run(), stk::test::spinlock::MutualExclusionTask< _AccessMode >::Run(), stk::test::spinlock::RecursiveLockTask< _AccessMode >::Run(), stk::test::spinlock::RecursiveTryLockTask< _AccessMode >::Run(), stk::test::spinlock::StressTestTask< _AccessMode >::Run(), stk::test::spinlock::TryLockContendedTask< _AccessMode >::Run(), stk::test::spinlock::TryLockFreeTask< _AccessMode >::Run(), stk::test::spinlock::UnlockTransferTask< _AccessMode >::Run(), stk::test::spinlock::YieldUnderContentionTask< _AccessMode >::Run(), stk::test::timer::MultipleTimersTask< _AccessMode >::Run(), stk::test::timer::OneShotTimerTask< _AccessMode >::Run(), stk::test::timer::PeriodicTimerTask< _AccessMode >::Run(), stk::test::timer::ResetPeriodicTimerTask< _AccessMode >::Run(), stk::test::timer::RestartTimerTask< _AccessMode >::Run(), stk::test::timer::SetPeriodTask< _AccessMode >::Run(), stk::test::timer::StartOrResetTask< _AccessMode >::Run(), stk::test::timer::StopTimerTask< _AccessMode >::Run(), stk::test::timer::StressTestTask< _AccessMode >::Run(), SleepMs(), stk_sleep(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), and stk::test::TestTaskSleep().

Here is the call graph for this function:

◆ SleepMs()

void stk::SleepMs ( uint32_t ms)
inlinestatic

Put calling process into a sleep state.

Note
Unlike Delay this function does not waste CPU cycles and allows kernel to put CPU into a low-power state.
Unsupported in HRT mode (see stk::KERNEL_HRT); in HRT mode tasks sleep automatically according to their periodicity and workload.
Converts ms to ticks and calls IKernelService::SleepTicks() which schedules the calling task to sleep and spins until the kernel switches it back in.
Parameters
[in]msSleep time (milliseconds).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 311 of file stk_helper.h.

312{
313 Sleep(static_cast<Timeout>(GetTicksFromMs(ms)));
314}
void Sleep(uint32_t ticks)
Put calling process into a sleep state.
Definition stk_helper.h:298

References GetTicksFromMs(), and Sleep().

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

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

◆ SleepUntil()

void stk::SleepUntil ( Ticks timestamp)

Put calling process into a sleep state until the specified timestamp.

Note
Unlike Delay this function does not waste CPU cycles and allows kernel to put CPU into a low-power state.
Unsupported in HRT mode (see stk::KERNEL_HRT); in HRT mode tasks sleep automatically according to their periodicity and workload.
Parameters
[in]timestampAbsolute timestamp (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 322 of file stk_helper.h.

323{
325}
virtual void SleepUntil(Ticks timestamp)=0
Put calling process into a sleep state until the specified timestamp.

References __stk_forceinline, stk::IKernelService::GetInstance(), and stk::IKernelService::SleepUntil().

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

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

◆ Yield()

void stk::Yield ( )

Notify scheduler to switch to the next runnable task.

Note
A cooperative scheduling mechanism. In HRT mode acts as a cooperation point (see stk::KERNEL_HRT).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Definition at line 331 of file stk_helper.h.

332{
334}
virtual void SwitchToNext()=0
Notify scheduler to switch to the next task (yield).

References __stk_forceinline, stk::IKernelService::GetInstance(), and stk::IKernelService::SwitchToNext().

Referenced by stk::test::EDFDynamicSchedulingContext::Process(), stk::test::hrt::TestTask< _AccessMode >::Run(), stk::test::mutex::BasicLockUnlockTask< _AccessMode >::Run(), stk::test::rwmutex::ReadUnlockWakesWriterTask< _AccessMode >::Run(), stk::test::rwmutex::TimedReadLockTask< _AccessMode >::Run(), stk::test::rwmutex::TimedWriteLockTask< _AccessMode >::Run(), stk::test::rwmutex::TryReadLockWhileWriterTask< _AccessMode >::Run(), stk::test::rwmutex::WriterExclusivityTask< _AccessMode >::Run(), stk::test::rwmutex::WriterPriorityTask< _AccessMode >::Run(), stk::test::spinlock::MutualExclusionTask< _AccessMode >::Run(), stk::test::spinlock::RecursiveTryLockTask< _AccessMode >::Run(), stk::test::spinlock::TryLockContendedTask< _AccessMode >::Run(), stk::test::spinlock::TryLockFreeTask< _AccessMode >::Run(), stk::test::timer::PeriodicTimerTask< _AccessMode >::Run(), stk::test::timer::StartOrResetTask< _AccessMode >::Run(), stk_yield(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), and stk::test::TEST().

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

Variable Documentation

◆ NO_WAIT

◆ TID_ISR

const TId stk::TID_ISR = static_cast<TId>(~0)

Reserved task/thread id representing an ISR context.

Note
Returned by GetTid() when called from an interrupt service routine.

Definition at line 123 of file stk_common.h.

◆ TID_NONE

const TId stk::TID_NONE = static_cast<TId>(0)

◆ WAIT_INFINITE