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_common.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_COMMON_H_
11#define STK_COMMON_H_
12
13#include "stk_defs.h"
14#include "stk_linked_list.h"
15
19
20namespace stk {
21
22// Forward declarations:
23class IKernelService;
24class IKernelTask;
25
30enum EAccessMode : int32_t
31{
34};
35
39enum EKernelMode : uint8_t
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};
47
64
75
85
90{
91 SYS_TASK_ID_SLEEP = 0xFFFFFFFF,
92 SYS_TASK_ID_EXIT = 0xFFFFFFFE
93};
94
105
113typedef uintptr_t Word;
114
118typedef Word TId;
119
123typedef int32_t Timeout;
124
128typedef int64_t Ticks;
129
133typedef uint64_t Cycles;
134
160static constexpr TId TID_ISR_N = static_cast<TId>(0xFFFFF000U);
161
165static constexpr TId TID_NONE = static_cast<TId>(0U);
166
171static constexpr Timeout WAIT_INFINITE = INT32_MAX;
172
177static constexpr Timeout NO_WAIT = 0;
178
190static inline bool IsIsrTid(TId tid)
191{
192 return ((tid & TID_ISR_N) == TID_ISR_N);
193}
194
205template <size_t _StackSize> struct StackMemoryDef
206{
207 enum { SIZE = _StackSize };
208
213};
214
218struct Stack
219{
222#if STK_NEED_TASK_ID
223 TId tid;
224#endif
225};
226
231{
232public:
235 virtual Word *GetStack() const = 0;
236
239 virtual size_t GetStackSize() const = 0;
240
243 virtual size_t GetStackSizeBytes() const = 0;
244
252 virtual size_t GetStackSpace()
253 {
254 const Word *stack = GetStack();
255 const size_t stack_size = GetStackSize();
256
257 // count leading Words equal to STK_STACK_MEMORY_FILLER (watermark)
258 size_t space = 0U;
259 for ( ; (space < stack_size) && (stack[space] == STK_STACK_MEMORY_FILLER); ++space)
260 {}
261
262 return space;
263 }
264};
265
269class IWaitObject : public util::DListEntry<IWaitObject, false>
270{
271public:
276
281
285 virtual TId GetTid() const = 0;
286
293 virtual void Wake(bool timeout) = 0;
294
298 virtual bool IsTimeout() const = 0;
299
305 virtual bool Tick(Timeout elapsed_ticks) = 0;
306};
307
313{
314public:
315#if STK_SYNC_DEBUG_NAMES
316 ITraceable() : m_trace_name(nullptr)
317 {}
318#endif
319
324 void SetTraceName(const char *name)
325 {
326 #if STK_SYNC_DEBUG_NAMES
327 m_trace_name = name;
328 #else
329 STK_UNUSED(name);
330 #endif
331 }
332
336 const char *GetTraceName() const
337 {
338 #if STK_SYNC_DEBUG_NAMES
339 return m_trace_name;
340 #else
341 return nullptr;
342 #endif
343 }
344
345protected:
346#if STK_SYNC_DEBUG_NAMES
347 const char *m_trace_name;
348#endif
349};
350
354class ISyncObject : public util::DListEntry<ISyncObject, false>
355{
356public:
361 {}
362
367
372
376 virtual void AddWaitObject(IWaitObject *wobj)
377 {
378 STK_ASSERT(wobj->GetHead() == nullptr);
379 m_wait_list.LinkBack(wobj);
380 }
381
385 virtual void RemoveWaitObject(IWaitObject *wobj)
386 {
387 STK_ASSERT(wobj->GetHead() == &m_wait_list);
388 m_wait_list.Unlink(wobj);
389 }
390
402 virtual bool Tick(Timeout elapsed_ticks);
403
404protected:
409 {}
410
415 void WakeOne()
416 {
417 if (!m_wait_list.IsEmpty())
418 static_cast<IWaitObject *>(m_wait_list.GetFirst())->Wake(false);
419 }
420
425 void WakeAll()
426 {
427 while (!m_wait_list.IsEmpty())
428 static_cast<IWaitObject *>(m_wait_list.GetFirst())->Wake(false);
429 }
430
432};
433
439{
440public:
447 {
448 public:
449 explicit ScopedLock(IMutex &mutex) : m_mutex(mutex) { m_mutex.Lock(); }
450 ~ScopedLock() { m_mutex.Unlock(); }
451
452 private:
454
456 };
457
460 virtual void Lock() = 0;
461
464 virtual void Unlock() = 0;
465};
466
490class ITask : public IStackMemory
491{
492public:
507 virtual void Run() = 0;
508
511 virtual EAccessMode GetAccessMode() const = 0;
512
520 virtual void OnDeadlineMissed(uint32_t duration) = 0;
521
530 virtual void OnExit() = 0;
531
536 virtual int32_t GetWeight() const = 0;
537
542 virtual TId GetId() const = 0;
543
549 virtual const char *GetTraceName() const = 0;
550};
551
561class IKernelTask : public util::DListEntry<IKernelTask, true>
562{
563public:
568
573
576 virtual ITask *GetUserTask() = 0;
577
580 virtual Stack *GetUserStack() = 0;
581
587 virtual int32_t GetWeight() const = 0;
588
594 virtual void SetCurrentWeight(int32_t weight) = 0;
595
601 virtual int32_t GetCurrentWeight() const = 0;
602
606 virtual Timeout GetHrtPeriodicity() const = 0;
607
611 virtual Timeout GetHrtDeadline() const = 0;
612
620 virtual Timeout GetHrtRelativeDeadline() const = 0;
621
625 virtual bool IsSleeping() const = 0;
626
632 virtual void Wake() = 0;
633};
634
648{
649public:
656 {
657 public:
662 virtual void OnStart(Stack *&active) = 0;
663
668 virtual void OnStop() = 0;
669
684 virtual bool OnTick(Stack *&idle, Stack *&active
686 , Timeout &ticks
687 #endif
688 ) = 0;
689
693 virtual void OnTaskSwitch(Word caller_SP) = 0;
694
699 virtual void OnTaskSleep(Word caller_SP, Timeout ticks) = 0;
700
705 virtual void OnTaskSleepUntil(Word caller_SP, Ticks timestamp) = 0;
706
710 virtual void OnTaskExit(Stack *stack) = 0;
711
718 virtual IWaitObject *OnTaskWait(Word caller_SP, ISyncObject *sync_obj, IMutex *mutex, Timeout timeout) = 0;
719
724 virtual TId OnGetTid(Word caller_SP) = 0;
725
729 virtual void OnSuspend(bool suspended) = 0;
730 };
731
737 {
738 public:
742 virtual bool OnSleep() = 0;
743
748 virtual bool OnHardFault() = 0;
749 };
750
758 virtual void Initialize(IEventHandler *event_handler, IKernelService *service, uint32_t resolution_us, Stack *exit_trap) = 0;
759
764 virtual void Start() = 0;
765
768 virtual void Stop() = 0;
769
777 virtual bool InitStack(EStackType stack_type, Stack *stack, IStackMemory *stack_memory, ITask *user_task) = 0;
778
783 virtual uint32_t GetTickResolution() const = 0;
784
789 virtual Cycles GetSysTimerCount() const = 0;
790
795 virtual uint32_t GetSysTimerFrequency() const = 0;
796
799 virtual void SwitchToNext() = 0;
800
805 virtual void Sleep(Timeout ticks) = 0;
806
813 virtual void SleepUntil(Ticks timestamp) = 0;
814
824 virtual void ProcessTick() = 0;
825
829 virtual void ProcessHardFault() = 0;
830
835 virtual void SetEventOverrider(IEventOverrider *overrider) = 0;
836
841 virtual Word GetCallerSP() const = 0;
842
848 virtual TId GetTid() const = 0;
849
856 virtual Timeout Suspend() = 0;
857
863 virtual void Resume(Timeout elapsed_ticks) = 0;
864};
865
889{
890public:
895 virtual void AddTask(IKernelTask *task) = 0;
896
901 virtual void RemoveTask(IKernelTask *task) = 0;
902
906 virtual IKernelTask *GetFirst() const = 0;
907
914 virtual IKernelTask *GetNext() = 0;
915
919 virtual size_t GetSize() const = 0;
920
925 virtual void OnTaskSleep(IKernelTask *task) = 0;
926
931 virtual void OnTaskWake(IKernelTask *task) = 0;
932
953 virtual bool OnTaskDeadlineMissed(IKernelTask *task) = 0;
954};
955
961{
962public:
973
983 virtual void Initialize(uint32_t resolution_us = PERIODICITY_DEFAULT) = 0;
984
989 virtual void AddTask(ITask *user_task) = 0;
990
998 virtual void AddTask(ITask *user_task, Timeout periodicity_tc, Timeout deadline_tc, Timeout start_delay_tc) = 0;
999
1010 virtual void RemoveTask(ITask *user_task) = 0;
1011
1018 virtual void ScheduleTaskRemoval(ITask *user_task) = 0;
1019
1026 virtual void SuspendTask(ITask *user_task, bool &suspended) = 0;
1027
1031 virtual void ResumeTask(ITask *user_task) = 0;
1032
1039 virtual size_t EnumerateTasks(ITask **user_tasks, size_t max_size) = 0;
1040
1061 template <size_t TMaxCount, typename TCallback>
1062 size_t EnumerateTasksT(TCallback &&callback)
1063 {
1064 STK_STATIC_ASSERT(TMaxCount > 0);
1065
1066 ITask *tasks[TMaxCount] = {};
1067 size_t i = 0, count = EnumerateTasks(tasks, TMaxCount);
1068
1069 while (i < count)
1070 {
1071 if (!callback(tasks[i++]))
1072 break;
1073 }
1074
1075 return i;
1076 }
1077
1082 virtual void Start() = 0;
1083
1088 virtual EState GetState() const = 0;
1089
1093 virtual IPlatform *GetPlatform() = 0;
1094
1099};
1100
1110{
1111public:
1114 static IKernelService *GetInstance();
1115
1121 virtual TId GetTid() const = 0;
1122
1127 virtual Ticks GetTicks() const = 0;
1128
1134 virtual uint32_t GetTickResolution() const = 0;
1135
1140 virtual Cycles GetSysTimerCount() const = 0;
1141
1146 virtual uint32_t GetSysTimerFrequency() const = 0;
1147
1155 virtual void Delay(Timeout ticks) = 0;
1156
1163 virtual void Sleep(Timeout ticks) = 0;
1164
1171 virtual void SleepUntil(Ticks timestamp) = 0;
1172
1177 virtual void SwitchToNext() = 0;
1178
1192 virtual IWaitObject *Wait(ISyncObject *sobj, IMutex *mutex, Timeout timeout) = 0;
1193
1201 virtual Timeout Suspend() = 0;
1202
1210 virtual void Resume(Timeout elapsed_ticks) = 0;
1211};
1212
1213} // namespace stk
1214
1215#endif /* STK_COMMON_H_ */
Compiler and platform low-level definitions for STK.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:524
#define STK_TICKLESS_IDLE
Enables tickless (dynamic-tick) low-power operation during idle periods.
Definition stk_defs.h:36
#define __stk_aligned(x)
Specifies minimum alignment in bytes for the decorated variable or struct member (data instance prefi...
Definition stk_defs.h:118
#define STK_NONCOPYABLE_CLASS(TYPE)
Disables copy construction and assignment for a class.
Definition stk_defs.h:517
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
#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
#define STK_STACK_MEMORY_ALIGN
Stack memory alignment.
Definition stk_defs.h:389
#define STK_STACK_MEMORY_FILLER
Sentinel value written to the entire stack region at initialization (stack watermark pattern).
Definition stk_defs.h:377
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:367
Intrusive doubly-linked list implementation used internally by the kernel.
Namespace of STK package.
uintptr_t Word
Native processor word type.
Definition stk_common.h:113
static constexpr TId TID_ISR_N
Bitmask sentinel for ISR-context task identifiers.
Definition stk_common.h:160
ETraceEventId
Trace event identifiers for tracing task suspension and resume with debugging tools (e....
Definition stk_common.h:100
@ TRACE_EVENT_UNKNOWN
Unknown / uninitialized trace event.
Definition stk_common.h:101
@ TRACE_EVENT_SLEEP
Task entered sleep / blocked state.
Definition stk_common.h:103
@ TRACE_EVENT_SWITCH
Task context switch event (task became active).
Definition stk_common.h:102
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:177
static bool IsIsrTid(TId tid)
Test whether a task identifier represents an ISR context.
Definition stk_common.h:190
int64_t Ticks
Ticks value.
Definition stk_common.h:128
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:123
EStackType
Stack type.
Definition stk_common.h:70
@ 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
EConsts
Constants.
Definition stk_common.h:80
@ 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
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:171
static constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Definition stk_common.h:165
ESystemTaskId
System task id.
Definition stk_common.h:90
@ SYS_TASK_ID_EXIT
Exit trap.
Definition stk_common.h:92
@ SYS_TASK_ID_SLEEP
Sleep trap.
Definition stk_common.h:91
uint64_t Cycles
Cycles value.
Definition stk_common.h:133
Word TId
Definition stk_common.h:118
EAccessMode
Hardware access mode by the user task.
Definition stk_common.h:31
@ 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
EKernelMode
Kernel operating mode.
Definition stk_common.h:40
@ 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
Identifies the source of a kernel panic.
Definition stk_common.h:52
@ 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
Stack memory type definition.
Definition stk_common.h:206
Word Type[_StackSize]
Stack memory type.
Definition stk_common.h:212
Stack descriptor.
Definition stk_common.h:219
Word SP
Stack Pointer (SP) register (note: must be the first entry in this struct).
Definition stk_common.h:220
EAccessMode mode
Hardware access mode of the owning task (see EAccessMode).
Definition stk_common.h:221
Interface for a stack memory region.
Definition stk_common.h:231
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.
virtual size_t GetStackSpace()
Get available stack space.
Definition stk_common.h:252
Wait object.
Definition stk_common.h:270
DLEntryType ListEntryType
List entry type of IWaitObject elements.
Definition stk_common.h:280
DLHeadType ListHeadType
List head type for IWaitObject elements.
Definition stk_common.h:275
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.
Traceable object.
Definition stk_common.h:313
const char * GetTraceName() const
Get name.
Definition stk_common.h:336
void SetTraceName(const char *name)
Set name.
Definition stk_common.h:324
Synchronization object.
Definition stk_common.h:355
IWaitObject::ListHeadType m_wait_list
tasks blocked on this object
Definition stk_common.h:431
virtual bool Tick(Timeout elapsed_ticks)
Called by kernel on every system tick to handle timeout logic of waiting tasks.
Definition stk_arch.h:467
DLEntryType ListEntryType
List entry type of ISyncObject elements.
Definition stk_common.h:371
void WakeOne()
Wake the first task in the wait list (FIFO order).
Definition stk_common.h:415
ISyncObject()
Constructor.
Definition stk_common.h:408
virtual void AddWaitObject(IWaitObject *wobj)
Called by kernel when a new task starts waiting on this event.
Definition stk_common.h:376
DLHeadType ListHeadType
List head type for ISyncObject elements.
Definition stk_common.h:366
~ISyncObject()
Destructor.
Definition stk_common.h:360
void WakeAll()
Wake all tasks currently in the wait list.
Definition stk_common.h:425
virtual void RemoveWaitObject(IWaitObject *wobj)
Called by kernel when a waiting task is being removed (timeout expired, wait aborted,...
Definition stk_common.h:385
Interface for mutex synchronization primitive.
Definition stk_common.h:439
virtual void Unlock()=0
Unlock the mutex.
virtual void Lock()=0
Lock the mutex.
ScopedLock(IMutex &mutex)
Definition stk_common.h:449
Interface for a user task.
Definition stk_common.h:491
virtual void OnExit()=0
Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
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.
Definition stk_common.h:562
virtual void Wake()=0
Wake a sleeping task on the next scheduling tick.
DLEntryType ListEntryType
List entry type of IKernelTask elements.
Definition stk_common.h:572
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.
Definition stk_common.h:567
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.
Definition stk_common.h:648
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 Timeout Suspend()=0
Suspend scheduling.
virtual Cycles GetSysTimerCount() const =0
Get system timer count value.
virtual void Start()=0
Start scheduling.
virtual void Stop()=0
Stop scheduling.
virtual uint32_t GetSysTimerFrequency() const =0
Get system timer frequency.
virtual void Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.
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.
Definition stk_common.h:656
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 OnSuspend(bool suspended)=0
Called from the Thread process to suspend scheduling.
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.
Definition stk_common.h:737
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.
Definition stk_common.h:889
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 ...
Definition stk_common.h:961
virtual void ResumeTask(ITask *user_task)=0
Resume task.
virtual void SuspendTask(ITask *user_task, bool &suspended)=0
Suspend task.
EState
Kernel state.
Definition stk_common.h:967
@ STATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
Definition stk_common.h:968
@ STATE_READY
Ready to start, IKernel::Start() must be called.
Definition stk_common.h:969
@ STATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
Definition stk_common.h:971
@ STATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
Definition stk_common.h:970
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 a previously added task from the kernel before Start().
virtual void AddTask(ITask *user_task)=0
Add user task.
size_t EnumerateTasksT(TCallback &&callback)
Enumerate tasks, invoking a callback for each active task.
virtual void ScheduleTaskRemoval(ITask *user_task)=0
Schedule task removal from scheduling (exit).
virtual void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT)=0
Initialize kernel.
virtual ITaskSwitchStrategy * GetSwitchStrategy()=0
Get switch strategy instance.
virtual size_t EnumerateTasks(ITask **user_tasks, size_t max_size)=0
Enumerate tasks.
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.
Definition stktest.cpp:69
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 Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.
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 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 Timeout Suspend()=0
Suspend scheduling.
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