|
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Concrete implementation of IKernelService exposed to running tasks. More...
#include <stk.h>
Public Member Functions | |
| TId | GetTid () const override |
| Get thread Id of the currently running task. | |
| Ticks | GetTicks () const override |
| Get number of ticks elapsed since kernel start. | |
| uint32_t | GetTickResolution () const override |
| Get number of microseconds in one tick. | |
| Cycles | GetSysTimerCount () const override |
| Get system timer count value. | |
| uint32_t | GetSysTimerFrequency () const override |
| Get system timer frequency. | |
| void | Delay (Timeout ticks) override |
| Delay calling process. | |
| bool | Sleep (Timeout ticks) override |
| Put calling process into a sleep state. | |
| bool | SleepUntil (Ticks timestamp) override |
| Put calling process into a sleep state until the specified timestamp. | |
| void | SleepCancel (TId task_id) override |
| Cancel sleep of the task. | |
| void | SwitchToNext () override |
| Notify scheduler to switch to the next task (yield). | |
| void | ExitTask () override |
| Terminate the calling task: schedule its removal and switch it out. Does not return. | |
| EWaitResult | Wait (ISyncObject *sobj, IMutex *mutex, Timeout ticks) override |
| Put calling process into a waiting state until synchronization object is signaled or timeout occurs. | |
| void | Wake (ISyncObject *sobj, bool all) override |
| Wake one or all tasks currently waiting on a synchronization object. | |
| Timeout | Suspend () override |
| Suspend scheduling. | |
| void | Resume (Timeout elapsed_ticks) override |
| Resume scheduling after a prior Suspend() call. | |
| void | InheritWeight (TId tid, Weight weight) override |
| Inherit weight for the task. | |
| void | RestoreWeight (TId tid, ISyncObject *sobj) override |
| Restore weight of the task to the original value. | |
| Weight | SetWeight (TId tid, Weight weight) override |
| Change the base weight of the task at run-time (replaces ITask::GetWeight() value). | |
| Timeout | SetTimeSlice (TId tid, Timeout ticks) override |
| Change the time-slice quantum of the task at run-time and reload its slice. | |
| ELockResult | LockScheduler () override |
| Disable task switching (CMSIS-RTOS2 osKernelLock equivalent). | |
| ELockResult | UnlockScheduler () override |
| Enable task switching (CMSIS-RTOS2 osKernelUnlock equivalent). | |
| ELockResult | RestoreSchedulerLock (bool locked) override |
| Set the lock state (CMSIS-RTOS2 osKernelRestoreLock equivalent). | |
Static Public Member Functions | |
| static IKernelService * | GetInstance () |
| Get CPU-local instance of the kernel service. | |
Static Protected Member Functions | |
| static IWaitObject::ListHeadType & | GetMutableWaitList (ISyncObject *sobj) |
| Access helper to the mutable IWaitObject::GetWaitList(). | |
Private Member Functions | |
| KernelService () | |
| Construct an uninitialized service instance (m_kernel = null, m_ticks = 0). | |
| ~KernelService ()=default | |
| Destructor. | |
| void | Initialize (Kernel *kernel) |
| Bind this service to its kernel. | |
| void | IncrementTicks (Ticks advance) |
| Increment counter by value. | |
| Word | GetCallerSP () const |
| Get caller's Stack Pointer (SP). | |
Private Attributes | |
| Kernel * | m_kernel |
| Pointer to the Kernel. | |
| volatile Ticks | m_ticks |
| Global tick counter. Written via hw::WriteVolatile64() by IncrementTick() (ISR context); read via hw::ReadVolatile64() by GetTicks() (task context) for a lock-free consistent 64-bit read on 32-bit CPUs. | |
Friends | |
| class | Kernel |
Concrete implementation of IKernelService exposed to running tasks.
Holds the global tick counter (m_ticks, advanced by IncrementTicks() from the tick ISR) and a pointer to the owning Kernel. Tasks access this object via IKernelService::GetInstance().
|
inlineexplicitprivate |
Construct an uninitialized service instance (m_kernel = null, m_ticks = 0).
Definition at line 1340 of file stk.h.
|
privatedefault |
|
inlineoverridevirtual |
Delay calling process.
| [in] | ticks | Delay time (ticks). |
Implements stk::IKernelService.
Definition at line 1047 of file stk.h.
References GetTicks(), stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Terminate the calling task: schedule its removal and switch it out. Does not return.
Implements stk::IKernelService.
Definition at line 1147 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::BusyWaitWhileSleeping(), GetCallerSP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsDynamicMode(), stk::hw::IsInsideISR(), stk::KERNEL_PANIC_BAD_MODE, m_kernel, STK_ASSERT, and stk::STK_KERNEL_PANIC().
|
inlineprivate |
Get caller's Stack Pointer (SP).
Definition at line 1369 of file stk.h.
References __stk_forceinline, and m_kernel.
Referenced by ExitTask(), Sleep(), SleepUntil(), SwitchToNext(), and Wait().
|
staticinherited |
Get CPU-local instance of the kernel service.
Referenced by stk::Delay(), stk::ExitTask(), EXTI0_IRQHandler(), stk::GetSysTimerCount(), stk::GetSysTimerFrequency(), stk::GetTickResolution(), stk::GetTicks(), stk::GetTid(), stk::GetTimeNowMs(), stk::pthread::IsMutexOwner(), stk::LockScheduler(), LowPowerOverrider::OnSleep(), osKernelResume(), osKernelSuspend(), stk::RestoreSchedulerLock(), stk::IKernelService::ScopedSchedulerLock::ScopedSchedulerLock(), stk::SetTimeSlice(), stk::SetWeight(), stk::Sleep(), stk::SleepCancel(), stk::SleepUntil(), stk::sync::FastMutex::TimedLockEx(), stk::sync::Mutex::TimedLockEx(), stk::sync::FastMutex::Unlock(), stk::sync::Mutex::Unlock(), stk::UnlockScheduler(), vTaskPrioritySet(), stk::sync::ConditionVariable::WaitEx(), stk::sync::Event::WaitEx(), stk::sync::SemaphoreT< T >::WaitEx(), stk::SyncObjectBase::WakeAll(), stk::SyncObjectBase::WakeOne(), stk::Yield(), and stk::IKernelService::ScopedSchedulerLock::~ScopedSchedulerLock().
|
inlinestaticprotectedinherited |
Access helper to the mutable IWaitObject::GetWaitList().
Definition at line 2091 of file stk_common.h.
References __stk_forceinline, and stk::ISyncObject::GetMutableWaitList().
Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService::Wake().
|
inlineoverridevirtual |
Get system timer count value.
Implements stk::IKernelService.
Definition at line 1043 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get system timer frequency.
Implements stk::IKernelService.
Definition at line 1045 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get number of microseconds in one tick.
Implements stk::IKernelService.
Definition at line 1041 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get number of ticks elapsed since kernel start.
Implements stk::IKernelService.
Definition at line 1039 of file stk.h.
References m_ticks, and stk::hw::ReadVolatile64().
Referenced by Delay().
|
inlineoverridevirtual |
|
inlineprivate |
Increment counter by value.
| [in] | advance | Number of ticks to add to the counter. |
Definition at line 1359 of file stk.h.
References m_ticks, and stk::hw::WriteVolatile64().
|
inlineoverridevirtual |
Inherit weight for the task.
| [in] | tid | Task id. |
| [in] | weight | New weight, shall be higher than task's current weight (see ITask::GetWeight). |
Implements stk::IKernelService.
Definition at line 1241 of file stk.h.
References __stk_constexpr_cpp17, and m_kernel.
|
inlineprivate |
|
inlineoverridevirtual |
Disable task switching (CMSIS-RTOS2 osKernelLock equivalent).
Implements stk::IKernelService.
Definition at line 1310 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Set the lock state (CMSIS-RTOS2 osKernelRestoreLock equivalent).
| [in] | locked | true to lock, false to unlock. |
Implements stk::IKernelService.
Definition at line 1323 of file stk.h.
References stk::LOCK_WAS_LOCKED, stk::LOCK_WAS_UNLOCKED, and m_kernel.
|
inlineoverridevirtual |
Restore weight of the task to the original value.
| [in] | tid | Task id. |
| [in] | sobj | Optional, if provided than weight will be restored to the highest weight of the task in the wait list, otherwise to the original value. |
Implements stk::IKernelService.
Definition at line 1249 of file stk.h.
References __stk_constexpr_cpp17, and m_kernel.
|
inlineoverridevirtual |
Resume scheduling after a prior Suspend() call.
| [in] | elapsed_ticks | Number of ticks that elapsed during the suspended period. The kernel uses this value to advance internal time counters and wake tasks whose sleep deadlines have expired. |
stk::KERNEL_TICKLESS; asserts otherwise. Implements stk::IKernelService.
Definition at line 1229 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Change the time-slice quantum of the task at run-time and reload its slice.
| [in] | tid | Task id. |
| [in] | ticks | New quantum (ticks), NO_TIME_SLICE disables time-slicing for the task. |
Implements stk::IKernelService.
Definition at line 1282 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTimesliceMode(), m_kernel, stk::NO_TIME_SLICE, STK_ASSERT, and STK_UNUSED.
|
inlineoverridevirtual |
Change the base weight of the task at run-time (replaces ITask::GetWeight() value).
| [in] | tid | Task id. |
| [in] | weight | New base weight. Must not be NO_WEIGHT; must satisfy the constraints of the active strategy (see e.g. SwitchStrategyPreemptionThreshold::MakeWeight). |
Implements stk::IKernelService.
Definition at line 1257 of file stk.h.
References __stk_constexpr_cpp17, m_kernel, stk::NO_WEIGHT, STK_ASSERT, and STK_UNUSED.
|
inlineoverridevirtual |
Put calling process into a sleep state.
| [in] | ticks | Sleep time (ticks). |
Implements stk::IKernelService.
Definition at line 1066 of file stk.h.
References __stk_constexpr_cpp17, GetCallerSP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Cancel sleep of the task.
| [in] | task_id | Id of the task. |
Ends a sleep started by Sleep()/SleepUntil() early. If the task is instead blocked on a synchronization object (KERNEL_SYNC mode), the wait is cancelled the same way as IKernel::CancelTaskWait() does: the task is removed from the object's wait list and its Wait() returns WAIT_RESULT_CANCELED (not WAIT_RESULT_TIMEOUT or WAIT_RESULT_SIGNAL, no resource is acquired or consumed).
Implements stk::IKernelService.
Definition at line 1124 of file stk.h.
References __stk_constexpr_cpp17, stk::GetUserTaskFromTid(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), and m_kernel.
|
inlineoverridevirtual |
Put calling process into a sleep state until the specified timestamp.
| [in] | timestamp | Absolute timestamp (ticks). |
Implements stk::IKernelService.
Definition at line 1095 of file stk.h.
References __stk_constexpr_cpp17, GetCallerSP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Suspend scheduling.
stk::KERNEL_TICKLESS; asserts otherwise. Implements stk::IKernelService.
Definition at line 1216 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Notify scheduler to switch to the next task (yield).
Implements stk::IKernelService.
Definition at line 1132 of file stk.h.
References GetCallerSP(), stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Enable task switching (CMSIS-RTOS2 osKernelUnlock equivalent).
Implements stk::IKernelService.
Definition at line 1316 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Put calling process into a waiting state until synchronization object is signaled or timeout occurs.
| [in] | sobj | Synchronization object to wait on. |
| [in] | mutex | Mutex protecting the state of the synchronization object. |
| [in] | timeout | Maximum wait time (ticks). Use WAIT_INFINITE to block indefinitely, use NO_WAIT to poll without blocking. |
EWaitResult). WAIT_RESULT_FAIL without waiting. Implements stk::IKernelService.
Definition at line 1173 of file stk.h.
References __stk_constexpr_cpp17, GetCallerSP(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_kernel, STK_ASSERT, and stk::WAIT_RESULT_FAIL.
|
inlineoverridevirtual |
Wake one or all tasks currently waiting on a synchronization object.
| [in] | sobj | Synchronization object whose waiting queue will be notified. |
| [in] | all | If true, unblocks all waiting tasks (broadcast mode); if false, unblocks only the next waiting task (signal mode). |
Implements stk::IKernelService.
Definition at line 1197 of file stk.h.
References __stk_constexpr_cpp17, stk::IKernelService::GetMutableWaitList(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), STK_ASSERT, stk::ISyncObject::WakeAll(), and stk::ISyncObject::WakeOne().
|
friend |
|
private |
Pointer to the Kernel.
Definition at line 1374 of file stk.h.
Referenced by Delay(), ExitTask(), GetCallerSP(), GetSysTimerCount(), GetSysTimerFrequency(), GetTickResolution(), GetTid(), InheritWeight(), Initialize(), KernelService(), LockScheduler(), RestoreSchedulerLock(), RestoreWeight(), Resume(), SetTimeSlice(), SetWeight(), Sleep(), SleepCancel(), SleepUntil(), Suspend(), SwitchToNext(), UnlockScheduler(), and Wait().
|
private |
Global tick counter. Written via hw::WriteVolatile64() by IncrementTick() (ISR context); read via hw::ReadVolatile64() by GetTicks() (task context) for a lock-free consistent 64-bit read on 32-bit CPUs.
Definition at line 1375 of file stk.h.
Referenced by GetTicks(), IncrementTicks(), and KernelService().