![]() |
SuperTinyKernel™ RTOS 1.06.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. | |
| void | 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). | |
| IWaitObject * | Wait (ISyncObject *sobj, IMutex *mutex, Timeout ticks) override |
| Put calling process into a waiting state until synchronization object is signaled or timeout occurs. | |
| 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. | |
Static Public Member Functions | |
| static IKernelService * | GetInstance () |
| Get CPU-local instance of the kernel service. | |
Private Member Functions | |
| KernelService () | |
| Construct an uninitialized service instance (m_platform = null, m_ticks = 0). | |
| ~KernelService ()=default | |
| Destructor. | |
| void | Initialize (Kernel *kernel) |
| Initialize instance. | |
| void | IncrementTicks (Ticks advance) |
| Increment counter by value. | |
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, updated atomically by IncrementTick() each SysTick) and a typed pointer to the platform driver. Tasks access this object via IKernelService::GetInstance() which returns the singleton registered at Initialize().
|
inlineexplicitprivate |
Construct an uninitialized service instance (m_platform = null, m_ticks = 0).
Definition at line 890 of file stk.h.
|
privatedefault |
|
inlineoverridevirtual |
Delay calling process.
| [in] | ticks | Delay time (ticks). |
Implements stk::IKernelService.
Definition at line 770 of file stk.h.
References GetTicks(), stk::hw::IsInsideISR(), and STK_ASSERT.
|
staticinherited |
Get CPU-local instance of the kernel service.
Referenced by stk::Delay(), stk::GetSysTimerCount(), stk::GetSysTimerFrequency(), stk::GetTickResolution(), stk::GetTicks(), stk::GetTid(), stk::GetTimeNowMs(), osKernelResume(), osKernelSuspend(), stk::Sleep(), stk::SleepCancel(), stk::SleepUntil(), stk::sync::Mutex::TimedLock(), stk::sync::Mutex::Unlock(), stk::sync::ConditionVariable::Wait(), stk::sync::Event::Wait(), stk::sync::Semaphore::Wait(), and stk::Yield().
|
inlineoverridevirtual |
Get system timer count value.
Implements stk::IKernelService.
Definition at line 766 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get system timer frequency.
Implements stk::IKernelService.
Definition at line 768 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get number of microseconds in one tick.
Implements stk::IKernelService.
Definition at line 764 of file stk.h.
References m_kernel.
|
inlineoverridevirtual |
Get number of ticks elapsed since kernel start.
Implements stk::IKernelService.
Definition at line 762 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 911 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 870 of file stk.h.
References __stk_constexpr_cpp17, and m_kernel.
|
inlineprivate |
|
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 878 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. |
Implements stk::IKernelService.
Definition at line 858 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Put calling process into a sleep state.
| [in] | ticks | Sleep time (ticks). |
Implements stk::IKernelService.
Definition at line 785 of file stk.h.
References __stk_constexpr_cpp17, 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. |
Implements stk::IKernelService.
Definition at line 817 of file stk.h.
References __stk_constexpr_cpp17, 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 801 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
inlineoverridevirtual |
Suspend scheduling.
Implements stk::IKernelService.
Definition at line 845 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 825 of file stk.h.
References stk::hw::IsInsideISR(), m_kernel, and STK_ASSERT.
|
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. |
Implements stk::IKernelService.
Definition at line 832 of file stk.h.
References __stk_constexpr_cpp17, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_kernel, and STK_ASSERT.
|
friend |
|
private |
Pointer to the Kernel.
Definition at line 917 of file stk.h.
Referenced by GetSysTimerCount(), GetSysTimerFrequency(), GetTickResolution(), GetTid(), InheritWeight(), Initialize(), KernelService(), RestoreWeight(), Resume(), Sleep(), SleepCancel(), SleepUntil(), Suspend(), SwitchToNext(), 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 918 of file stk.h.
Referenced by GetTicks(), IncrementTicks(), and KernelService().