48template <
size_t _StackSize, EAccessMode _AccessMode>
120template <
int32_t _Weight,
size_t _StackSize, EAccessMode _AccessMode>
182template <
size_t _StackSize>
240 return (ticks * resolution) / 1000;
251 return ms * 1000 / resolution;
296 if (resolution == 1000)
299 return (service->
GetTicks() * resolution) / 1000;
Hardware Abstraction Layer (HAL) declarations for the stk::hw namespace.
Contains interface definitions of the library.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#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_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Namespace of STK package.
uintptr_t Word
Native processor word type.
static int64_t GetTimeNowMs()
Get current time in milliseconds since kernel start.
uint32_t GetSysTimerFrequency()
Get system timer frequency.
static void SleepMs(Timeout ms)
Put calling process into a sleep state.
void Sleep(Timeout ticks)
Put calling process into a sleep state.
int64_t GetMsFromTicks(int64_t ticks, int32_t resolution)
Convert ticks to milliseconds.
Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Cycles GetSysTimerCount()
Get system timer count value.
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).
void Yield()
Notify scheduler to switch to the next runnable task.
Ticks GetTicksFromMs(int64_t ms, int32_t resolution)
Convert milliseconds to ticks.
void SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
@ STACK_SIZE_MIN
Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task,...
TId GetTid()
Get task/thread Id of the calling task.
void Delay(Timeout ticks)
Delay calling process by busy-waiting until the deadline expires.
int32_t GetTickResolution()
Get number of microseconds in one tick.
uint64_t Cycles
Cycles value.
EAccessMode
Hardware access mode by the user task.
__stk_forceinline Word PtrToWord(T *ptr) noexcept
Cast a pointer to a CPU register-width integer.
Word Type[_StackSize]
Stack memory type.
Interface for a stack memory region.
Interface for a user task.
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.
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 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 void SleepUntil(Ticks timestamp)=0
Put calling process into a sleep state until the specified timestamp.
virtual uint32_t GetSysTimerFrequency() const =0
Get system timer frequency.
virtual void Delay(Timeout ticks)=0
Delay calling process.
virtual void OnExit()
Default no-op handler. Override to implement join semantics (signal a waiting joiner).
virtual const char * GetTraceName() const
Override in subclass to supply a name for SEGGER SystemView tracing. Returns NULL by default.
Task()
Initializes task instance and zero-initializes its internal stack memory.
size_t GetStackSizeBytes() const
Get size of the memory in bytes.
Task(const Task &)=delete
virtual TId GetId() const
Get object's own address as its Id. Unique per task instance, requires no manual assignment.
EAccessMode GetAccessMode() const
Get hardware access mode of the user task.
virtual void OnDeadlineMissed(uint32_t duration)
Default no-op handler. Override in subclass to log or handle missed deadlines.
size_t GetStackSize() const
Get number of elements of the stack memory array.
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, 16-byte aligned.
virtual int32_t GetWeight() const
Default weight of 1. Override in subclass if custom scheduling weight is needed.
Word * GetStack() const
Get pointer to the stack memory.
virtual const char * GetTraceName() const
Override in subclass to supply a name for SEGGER SystemView tracing. Returns NULL by default.
size_t GetStackSize() const
Get number of elements of the stack memory array.
TaskW(const TaskW &)=delete
virtual int32_t GetWeight() const
Returns the compile-time weight _Weight.
virtual void OnExit()
Default no-op handler. Override to implement join semantics (signal a waiting joiner).
virtual void OnDeadlineMissed(uint32_t duration)
Hard Real-Time mode is unsupported for weighted tasks. Triggers an assertion if called.
Word * GetStack() const
Get pointer to the stack memory.
virtual TId GetId() const
Get object's own address as its Id. Unique per task instance, requires no manual assignment.
TaskW()
Initializes task instance and zero-initializes its internal stack memory.
size_t GetStackSizeBytes() const
Get size of the memory in bytes.
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, 16-byte aligned.
EAccessMode GetAccessMode() const
Get hardware access mode of the user task.
size_t GetStackSize() const
Get number of elements in the wrapped stack array.
StackMemoryDef< _StackSize >::Type MemoryType
StackMemoryWrapper(MemoryType *stack)
Construct a wrapper around an existing stack memory array.
size_t GetStackSizeBytes() const
Get size of the wrapped stack array in bytes.
Word * GetStack() const
Get pointer to the first element of the wrapped stack array.
~StackMemoryWrapper()
Destructor.