48template <
size_t _StackSize, EAccessMode _AccessMode>
95template <Weight _Weight,
size_t _StackSize, EAccessMode _AccessMode>
135template <
size_t _StackSize>
192#if (STK_ARCH_CPU_COUNT > 1)
198 while (itr !=
nullptr)
202 if (!itr->
Tick(elapsed_ticks))
219 while (itr !=
nullptr)
230 return ((max_weight > comp) ? max_weight :
NO_WEIGHT);
266 return static_cast<Time>((tick_count *
static_cast<Time>(resolution)) / 1000LL);
277 Ticks tick_count = 0LL;
279 if (resolution != 0U)
281 tick_count =
static_cast<Ticks>((ms * 1000LL) /
static_cast<Time>(resolution));
306 const Time time_ms =
static_cast<Time>(ms);
312 return static_cast<Timeout>(final_ticks);
336 return ((resolution == 1000U) ? tick_count :
337 ((tick_count *
static_cast<Ticks>(resolution)) / 1000LL));
Hardware Abstraction Layer (HAL) declarations for the stk::hw namespace.
Contains interface definitions of the library.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_NONCOPYABLE_CLASS(TYPE)
Disables copy construction and assignment for a class.
#define STK_TICKLESS_TICKS_MAX
Maximum number of kernel ticks the hardware timer may be suppressed in one tickless idle interval whe...
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Namespace of STK package.
uintptr_t Word
Native processor word type.
static Time GetMsFromTicks(Ticks tick_count, uint32_t resolution)
Convert ticks to milliseconds.
static void Yield()
Notify scheduler to switch to the next runnable task.
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
static void SleepCancel(TId task_id)
Cancel sleep of the task.
static void SleepMs(Timeout ms)
Put calling process into a sleep state.
EAccessMode
Hardware access mode by the user task.
static constexpr ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
static Time GetTimeNowMs()
Get current time in milliseconds since kernel start.
int64_t Ticks
Ticks value.
static void DelayMs(Timeout ms)
Delay calling process by busy-waiting until the deadline expires.
int32_t Timeout
Timeout time (ticks).
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
static Ticks GetTicksFromMs(Time ms, uint32_t resolution)
Convert milliseconds to ticks.
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
static void Delay(Timeout tick_count)
Delay calling process by busy-waiting until the deadline expires.
constexpr Weight NO_WEIGHT
Weight value: weight is not set.
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
@ STACK_SIZE_MIN
Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task,...
Timeout GetInitialSleepTicks()
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
static TId GetTid()
Get task/thread Id of the calling task.
Timeout GetInitialSleepTicks< false >()
static Timeout GetTicksFromMsClampedToTimeout(Timeout ms)
Convert milliseconds to ticks and clamp the result to a Timeout type.
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Timeout GetInitialSleepTicks< true >()
static Cycles GetSysTimerCount()
Get system timer count value.
uint64_t Cycles
Cycles value.
Word TId
Task (thread) id.
int32_t Weight
Weight value (aka priority).
RAII guard that enters the critical section on construction and exits it on destruction.
Word Type[TStackSize]
Stack memory type.
Interface for a stack memory region.
virtual TId GetTid() const =0
Get thread Id of this task.
virtual void Wake(bool timeout)=0
Wake task.
virtual bool Tick(Timeout elapsed_ticks)=0
Update wait object's waiting time.
IWaitObject::ListHeadType m_wait_list
tasks blocked on this object
virtual bool Tick(Timeout elapsed_ticks)
Called by kernel on every system tick to handle timeout logic of waiting tasks.
Weight FindWeightHigherThan(Weight comp) const
Find higher weight within linked wait objects.
Interface for a user task.
virtual Weight GetWeight() const
Get static base weight of the task.
TId GetId() const
Get task Id set by application.
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
virtual TId GetTid() const =0
Get thread Id of the currently running task.
virtual void SleepCancel(TId task_id)=0
Cancel sleep of the task.
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual uint32_t GetTickResolution() const =0
Get number of microseconds in one tick.
virtual bool SleepUntil(Ticks timestamp)=0
Put calling process into a sleep state until the specified timestamp.
virtual Ticks GetTicks() const =0
Get number of ticks elapsed since kernel start.
virtual void SwitchToNext()=0
Notify scheduler to switch to the next task (yield).
virtual void Sleep(Timeout ticks)=0
Put calling process into a sleep state.
virtual Cycles GetSysTimerCount() const =0
Get system timer count value.
virtual uint32_t GetSysTimerFrequency() const =0
Get system timer frequency.
virtual void Delay(Timeout ticks)=0
Delay calling process.
Task()
Initializes task instance and zero-initializes its internal stack memory.
Task(const Task &)=delete
~Task()=default
Destructor.
size_t GetStackSize() const override
Get number of elements of the stack memory array.
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.
const Word * GetStack() const override
Get pointer to the stack memory.
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, 16-byte aligned.
EAccessMode GetAccessMode() const override
Get hardware access mode of the user task.
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.
Weight GetWeight() const override
Get static base weight of the task.
TaskW(const TaskW &)=delete
const Word * GetStack() const override
Get pointer to the stack memory.
~TaskW()=default
Destructor.
EAccessMode GetAccessMode() const override
Get hardware access mode of the user task.
size_t GetStackSize() const override
Get number of elements of the stack memory array.
TaskW()
Initializes task instance and zero-initializes its internal stack memory.
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, 16-byte aligned.
size_t GetStackSize() const override
Get number of elements in the wrapped stack array.
~StackMemoryWrapper()=default
Destructor.
const Word * GetStack() const override
Get pointer to the first element of the wrapped stack array.
StackMemoryDef< _StackSize >::Type MemoryType
StackMemoryWrapper(MemoryType *stack)
Construct a wrapper around an existing stack memory array.
size_t GetStackSizeBytes() const override
Get size of the wrapped stack array in bytes.
DLEntryType * GetNext()
Get the next entry in the list.
static __stk_forceinline TTargetType * ListEntryToParent(TSourceType *const lentry)
Safely casts an intrusive list entry to its concrete parent container object type.