235 virtual void Wake(
bool timeout) = 0;
257#if STK_SYNC_DEBUG_NAMES
268 #if STK_SYNC_DEBUG_NAMES
280 #if STK_SYNC_DEBUG_NAMES
288#if STK_SYNC_DEBUG_NAMES
289 const char *m_trace_name;
Compiler and platform low-level definitions for STK.
#define STK_TICKLESS_IDLE
Enables tickless (dynamic-tick) low-power operation during idle periods.
#define __stk_aligned(x)
Specifies minimum alignment in bytes for the decorated variable or struct member (data instance prefi...
#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_STACK_SIZE_MIN
Minimum stack size in elements of Word, shared by all stack allocation lower-bound checks.
#define STK_STACK_MEMORY_ALIGN
Stack memory alignment.
Intrusive doubly-linked list implementation used internally by the kernel.
Namespace of STK package.
uintptr_t Word
Native processor word type.
ETraceEventId
Trace event id for tracing tasks suspension and resume with debugging tools (SEGGER SysView and etc....
const TId TID_ISR
Reserved task/thread id representing an ISR context.
const Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
int64_t Ticks
Ticks value.
int32_t Timeout
Timeout time (ticks).
@ STACK_SLEEP_TRAP
Stack of the Sleep trap.
@ STACK_USER_TASK
Stack of the user task.
@ STACK_EXIT_TRAP
Stack of the Exit trap.
const Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
@ 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,...
@ PERIODICITY_MAX
Maximum periodicity (microseconds), 99 milliseconds (note: this value is the highest working on a rea...
ESystemTaskId
System task id.
@ SYS_TASK_ID_EXIT
Exit trap.
@ SYS_TASK_ID_SLEEP
Sleep trap.
uint64_t Cycles
Cycles value.
const TId TID_NONE
Reserved task/thread id representing zero/none thread id.
EAccessMode
Hardware access mode by the user task.
@ 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).
EKernelMode
Kernel operating mode.
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
@ KERNEL_SYNC
Synchronization support (see Event).
@ KERNEL_HRT
Hard Real-Time (HRT) behavior (tasks are scheduled periodically and have an execution deadline,...
@ KERNEL_STATIC
All tasks are static and can not exit.
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
EKernelPanicId
Identifies the source of a kernel panic.
@ KERNEL_PANIC_UNKNOWN_SVC
Unknown service command received by SVC handler.
@ KERNEL_PANIC_BAD_MODE
Kernel is in bad/unsupported mode for the current operation.
@ KERNEL_PANIC_HRT_HARD_FAULT
Kernel running in KERNEL_HRT mode reported deadline failure of the task.
@ KERNEL_PANIC_CS_NESTING_OVERFLOW
Critical section nesting limit exceeded: violation of STK_CRITICAL_SECTION_NESTINGS_MAX.
@ KERNEL_PANIC_NONE
Panic is absent (no fault).
@ KERNEL_PANIC_CPU_EXCEPTION
CPU reported an exception and halted execution.
@ KERNEL_PANIC_STACK_CORRUPT
Stack integrity check failed.
@ KERNEL_PANIC_SPINLOCK_DEADLOCK
Spin-lock timeout expired: lock owner never released.
@ KERNEL_PANIC_BAD_STATE
Kernel entered unexpected (bad) state.
@ KERNEL_PANIC_ASSERT
Internal assertion failed (maps from STK_ASSERT).
Stack memory type definition.
Word Type[_StackSize]
Stack memory type.
Word SP
Stack Pointer (SP) register (note: must be the first entry in this struct).
EAccessMode mode
access mode
Interface for a stack memory region.
virtual size_t GetStackSizeBytes() const =0
Get size of the memory in bytes.
virtual size_t GetStackSize() const =0
Get number of elements of the stack memory array.
virtual Word * GetStack() const =0
Get pointer to the stack memory.
DLEntryType ListEntryType
List entry type of IWaitObject elements.
DLHeadType ListHeadType
List head type for IWaitObject elements.
virtual TId GetTid() const =0
Get thread Id of this task.
virtual bool IsTimeout() const =0
Check if task woke up due to a timeout.
virtual void Wake(bool timeout)=0
Wake task.
virtual bool Tick(Timeout elapsed_ticks)=0
Update wait object's waiting time.
const char * GetTraceName() const
Get name.
void SetTraceName(const char *name)
Set name.
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.
DLEntryType ListEntryType
List entry type of ISyncObject elements.
void WakeOne()
Wake the first task in the wait list (FIFO order).
ISyncObject()
Constructor.
virtual void AddWaitObject(IWaitObject *wobj)
Called by kernel when a new task starts waiting on this event.
DLHeadType ListHeadType
List head type for ISyncObject elements.
~ISyncObject()
Destructor.
void WakeAll()
Wake all tasks currently in the wait list.
virtual void RemoveWaitObject(IWaitObject *wobj)
Called by kernel when a waiting task is being removed (timeout expired, wait aborted,...
Interface for mutex synchronization primitive.
virtual void Unlock()=0
Unlock the mutex.
virtual void Lock()=0
Lock the mutex.
ScopedLock(IMutex &mutex)
Interface for a user task.
virtual EAccessMode GetAccessMode() const =0
Get hardware access mode of the user task.
virtual void Run()=0
Entry point of the user task.
virtual TId GetId() const =0
Get task Id set by application.
virtual void OnDeadlineMissed(uint32_t duration)=0
Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time ...
virtual const char * GetTraceName() const =0
Get task trace name set by application.
virtual int32_t GetWeight() const =0
Get static base weight of the task.
Scheduling-strategy-facing interface for a kernel task slot.
virtual void Wake()=0
Wake a sleeping task on the next scheduling tick.
DLEntryType ListEntryType
List entry type of IKernelTask elements.
virtual Stack * GetUserStack()=0
Get pointer to the user task's stack.
virtual int32_t GetCurrentWeight() const =0
Get the current dynamic weight value of this task.
virtual Timeout GetHrtRelativeDeadline() const =0
Get HRT task's relative deadline.
virtual Timeout GetHrtDeadline() const =0
Get HRT task deadline (max allowed task execution time).
DLHeadType ListHeadType
List head type for IKernelTask elements.
virtual bool IsSleeping() const =0
Check whether the task is currently sleeping.
virtual Timeout GetHrtPeriodicity() const =0
Get HRT task execution periodicity.
virtual void SetCurrentWeight(int32_t weight)=0
Set the current dynamic weight value used by the scheduling strategy.
virtual int32_t GetWeight() const =0
Get static base weight assigned to the task.
virtual ITask * GetUserTask()=0
Get user task.
Interface for a platform driver.
virtual void ProcessTick()=0
Process one tick.
virtual Word GetCallerSP() const =0
Get caller's Stack Pointer (SP).
virtual TId GetTid() const =0
Get thread Id.
virtual bool InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task)=0
Initialize stack memory of the user task.
virtual void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap)=0
Initialize scheduler's context.
virtual void Start()=0
Start scheduling.
virtual void Stop()=0
Stop scheduling.
virtual void SwitchToNext()=0
Switch to a next task.
virtual void Sleep(Timeout ticks)=0
Put calling process into a sleep state.
virtual void SleepUntil(Ticks timestamp)=0
Put calling process into a sleep state until the specified timestamp.
virtual void SetEventOverrider(IEventOverrider *overrider)=0
Set platform event overrider.
virtual uint32_t GetTickResolution() const =0
Get resolution of the system tick timer in microseconds. Resolution means a number of microseconds be...
virtual void ProcessHardFault()=0
Cause a hard fault of the system.
Interface for a back-end event handler.
virtual void OnTaskExit(Stack *stack)=0
Called from the Thread process when task finished (its Run function exited by return).
virtual bool OnTick(Stack *&idle, Stack *&active)=0
Called by ISR handler to notify about the next system tick.
virtual void OnStart(Stack *&active)=0
Called by ISR handler to notify that scheduling is about to start.
virtual TId OnGetTid(Word caller_SP)=0
Called from the Thread process when for getting task/thread id of the process.
virtual void OnTaskSleepUntil(Word caller_SP, Ticks timestamp)=0
Called by Thread process (via IKernelService::SleepUntil) for exclusion of the calling process from s...
virtual IWaitObject * OnTaskWait(Word caller_SP, ISyncObject *sync_obj, IMutex *mutex, Timeout timeout)=0
Called from the Thread process when task needs to wait.
virtual void OnStop()=0
Called by driver to notify that scheduling is stopped.
virtual void OnTaskSleep(Word caller_SP, Timeout ticks)=0
Called by Thread process (via IKernelService::Sleep) for exclusion of the calling process from schedu...
virtual void OnTaskSwitch(Word caller_SP)=0
Called by Thread process (via IKernelService::SwitchToNext) to switch to a next task.
Interface for a platform event overrider.
virtual bool OnHardFault()=0
Called by Kernel when hard fault happens.
virtual bool OnSleep()=0
Called by Kernel when its entering a sleep mode.
Interface for a task switching strategy implementation.
virtual void RemoveTask(IKernelTask *task)=0
Remove task.
virtual void OnTaskSleep(IKernelTask *task)=0
Notification that a task has entered sleep/blocked state.
virtual void OnTaskWake(IKernelTask *task)=0
Notification that a task is becoming runnable again.
virtual size_t GetSize() const =0
Get number of tasks currently managed by this strategy.
virtual IKernelTask * GetNext()=0
Advance the internal iterator and return the next runnable task.
virtual IKernelTask * GetFirst() const =0
Get first task.
virtual void AddTask(IKernelTask *task)=0
Add task.
virtual bool OnTaskDeadlineMissed(IKernelTask *task)=0
Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover with...
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time ...
@ 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
virtual IPlatform * GetPlatform()=0
Get platform driver instance.
virtual EState GetState() const =0
Get a snapshot of the kernel state.
virtual void RemoveTask(ITask *user_task)=0
Remove user task.
virtual void AddTask(ITask *user_task)=0
Add user task.
virtual void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT)=0
Initialize kernel.
virtual ITaskSwitchStrategy * GetSwitchStrategy()=0
Get switch strategy instance.
virtual void Start()=0
Start kernel scheduling.
virtual void AddTask(ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc)=0
Add 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 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 void SleepUntil(Ticks timestamp)=0
Put calling process into a sleep state until the specified timestamp.
virtual IWaitObject * Wait(ISyncObject *sobj, IMutex *mutex, Timeout timeout)=0
Put calling process into a waiting state until synchronization object is signaled or timeout occurs.
virtual int32_t GetTickResolution() const =0
Get number of microseconds in one tick.
virtual void Delay(Timeout ticks)=0
Delay calling process.
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...
DLHeadType * GetHead() const
Get the list head this entry currently belongs to.
DListHead< IWaitObject, _ClosedLoop > DLHeadType
DListEntry< IWaitObject, _ClosedLoop > DLEntryType