15#ifdef _STK_CORTEX_M_TRUSTZONE_NON_SECURE
16 #include "arch/arm/cortex-m/stk_arch_arm-tz.h"
45#if STK_MPU_STACK_GUARD
91template <
size_t _StackSize, EAccessMode _AccessMode>
93#ifdef _STK_CORTEX_M_TRUSTZONE_NON_SECURE
94 :
public tz::nsec::NsTask
144template <Weight _Weight,
size_t _StackSize, EAccessMode _AccessMode>
146#ifdef _STK_CORTEX_M_TRUSTZONE_NON_SECURE
147 :
public tz::nsec::NsTask
190template <
size_t _StackSize>
246#ifdef _STK_CORTEX_M_TRUSTZONE_NON_SECURE
247 :
public tz::nsec::NsSyncObject
327#if (STK_ARCH_CPU_COUNT > 1)
333 while (itr !=
nullptr)
337 if (!itr->
Tick(elapsed_ticks))
354 while (itr !=
nullptr)
365 return ((max_weight > comp) ? max_weight :
NO_WEIGHT);
397 return static_cast<Time>((tick_count *
static_cast<Time>(resolution)) / 1000LL);
408 Ticks tick_count = 0LL;
410 if (resolution != 0U)
412 tick_count =
static_cast<Ticks>((ms * 1000LL) /
static_cast<Time>(resolution));
436 const Time time_ms =
static_cast<Time>(ms);
441 return static_cast<Timeout>(final_ticks);
465 return ((resolution == 1000U) ? tick_count :
466 ((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_aligned(x)
Specifies minimum alignment in bytes for the decorated variable or struct member (data instance prefi...
#define STK_NONCOPYABLE_CLASS(TYPE)
Deletes (= delete) the copy constructor and copy assignment operator of a class.
#define STK_STACK_MEMORY_ALIGN
Stack memory alignment.
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
#define STK_VIRT_DTOR
Expands to nothing if STK_STRICT_COMPLIANCY=0 (non-virtual destructors, smaller objects),...
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 Timeout SetTimeSlice(TId tid, Timeout ticks)
Change the time-slice quantum of a task at run-time and reload its slice.
static void SleepCancel(TId task_id)
Cancel sleep of the task.
EAccessMode
Hardware access modes by the task.
static Time GetTimeNowMs()
Get current time in milliseconds since kernel start.
ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
static bool SleepMs(Timeout ms)
Put calling process into a sleep state.
@ STACK_SIZE_MIN
Minimum stack size in elements of Word. Used as a lower bound for all stack allocations (user task,...
TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
static void ExitTask()
Terminate the calling task: schedule its removal and switch it out. Does not return.
int64_t Ticks
Ticks value.
static bool Sleep(Timeout tick_count)
Put calling process into a sleep state.
static void DelayMs(Timeout ms)
Delay calling process by busy-waiting until the deadline expires.
int32_t Timeout
Timeout time (ticks).
static ELockResult UnlockScheduler()
Enable task switching (equivalent of CMSIS-RTOS2 osKernelUnlock).
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
static ELockResult LockScheduler()
Disable task switching (equivalent of CMSIS-RTOS2 osKernelLock). Ticks, timeouts and ISRs keep runnin...
ELockResult
Result of IKernel::SetSchedulerLock(), IKernelService::LockScheduler(), UnlockScheduler() and Restore...
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.
static constexpr Weight NO_WEIGHT
Weight value: weight is not set.
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
static Weight SetWeight(TId tid, Weight weight)
Change the base scheduling weight of a task at run-time.
static 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.
IKernelService::ScopedSchedulerLock ScopedSchedulerLock
RAII scheduler lock: disables task switching for the lifetime of the object.
static ELockResult RestoreSchedulerLock(bool locked)
Set the scheduler lock state (equivalent of CMSIS-RTOS2 osKernelRestoreLock).
static Timeout GetTicksFromMsClampedToTimeout(Timeout ms)
Convert milliseconds to ticks and clamp the result to a Timeout type.
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 instance that enters the critical section on construction and exits it on destruction.
Interface for a stack memory region.
DLHeadType ListHeadType
List head type for IWaitObject elements.
virtual TId GetTid() const =0
Get thread Id of the task that owns this wait object.
virtual void Wake(bool timeout)=0
Wake task.
virtual bool Tick(Timeout elapsed_ticks)=0
Update wait object's waiting time.
Synchronization object interface.
virtual bool Tick(Timeout elapsed_ticks)
Called by kernel on every system tick to handle timeout logic of waiting tasks.
DLHeadType ListHeadType
List head type for ISyncObject elements.
static void AddWaitObject(IWaitObject::ListHeadType &wlist, IWaitObject *wobj)
Called by kernel when a new task starts waiting on this event.
virtual IWaitObject::ListHeadType & GetMutableWaitList()=0
Get list of tasks blocked on this object.
static void RemoveWaitObject(IWaitObject::ListHeadType &wlist, IWaitObject *wobj)
Called by kernel when a waiting task is being removed (timeout expired, wait aborted,...
virtual const IWaitObject::ListHeadType & GetWaitList() const =0
Get list of tasks blocked on this object.
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.
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 Timeout SetTimeSlice(TId tid, Timeout ticks)=0
Change the time-slice quantum of the task at run-time and reload its slice.
virtual void Wake(ISyncObject *sobj, bool all)=0
Wake one or all tasks currently waiting on a synchronization object.
virtual ELockResult UnlockScheduler()=0
Enable task switching (equivalent of CMSIS-RTOS2 osKernelUnlock).
virtual void SleepCancel(TId task_id)=0
Cancel sleep of the task.
virtual bool Sleep(Timeout ticks)=0
Put calling process into a sleep state.
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 Weight SetWeight(TId tid, Weight weight)=0
Change the base weight of the task at run-time (replaces ITask::GetWeight() value).
virtual void ExitTask()=0
Terminate the calling task: schedule its removal and switch it out. Does not return.
virtual ELockResult LockScheduler()=0
Disable task switching (equivalent of CMSIS-RTOS2 osKernelLock). Ticks, timeouts and ISRs keep runnin...
virtual ELockResult RestoreSchedulerLock(bool locked)=0
Set the lock state (equivalent of CMSIS-RTOS2 osKernelRestoreLock).
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.
Disable task switching (equivalent of CMSIS-RTOS2 osKernelLock). Ticks, timeouts and ISRs keep runnin...
Stack memory type definition.
Word Type[SIZE]
Stack memory type.
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.
const Word * GetStack() const override
Get pointer to the stack memory.
StackMemoryDef< _StackSize >::Type m_stack
Stack memory region, STK_STACK_MEMORY_ALIGN-byte aligned.
EAccessMode GetAccessMode() const override
Get pointer to the stack memory.
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 pointer to the stack memory.
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, STK_STACK_MEMORY_ALIGN-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.
~SyncObjectBase()
Destructor.
void WakeAll() override
Wake all tasks currently in the wait list.
SyncObjectBase()
Constructor.
void RemoveWaitObject(IWaitObject *wobj) override
Called by kernel when a waiting task is being removed (timeout expired, wait aborted,...
IWaitObject::ListHeadType & GetMutableWaitList() override
Get list of tasks blocked on this object.
IWaitObject::ListHeadType m_wait_list
Tasks blocked on this object.
void WakeOne() override
Wake the first task in the wait list (FIFO order).
const IWaitObject::ListHeadType & GetWaitList() const override
Get list of tasks blocked on this object.
friend class IKernelService
void AddWaitObject(IWaitObject *wobj) override
Called by kernel when a new task starts waiting on this event.
bool IsEmpty() const
Check whether the list contains no entries.
void Unlink(DLEntryType *entry)
Remove entry from this list.
DLEntryType * GetFirst()
Get the first (front) entry without removing it.
DLEntryType * GetNext()
Get the next entry in the list.
static __stk_forceinline TTargetType * ListEntryToParent(TSourceType *const lentry)
Casts an intrusive list entry to the concrete type that derives from it.