![]() |
SuperTinyKernel™ RTOS 1.06.0
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 |
| Get thread Id of the currently running task. | |
| Ticks | GetTicks () const |
| Get number of ticks elapsed since kernel start. | |
| uint32_t | GetTickResolution () const |
| Get number of microseconds in one tick. | |
| Cycles | GetSysTimerCount () const |
| Get system timer count value. | |
| uint32_t | GetSysTimerFrequency () const |
| Get system timer frequency. | |
| void | Delay (Timeout ticks) |
| Delay calling process. | |
| void | Sleep (Timeout ticks) |
| Put calling process into a sleep state. | |
| void | SleepUntil (Ticks timestamp) |
| Put calling process into a sleep state until the specified timestamp. | |
| void | SwitchToNext () |
| Notify scheduler to switch to the next task (yield). | |
| IWaitObject * | Wait (ISyncObject *sobj, IMutex *mutex, Timeout ticks) |
| Put calling process into a waiting state until synchronization object is signaled or timeout occurs. | |
| Timeout | Suspend () |
| Suspend scheduling. | |
| void | Resume (Timeout elapsed_ticks) |
| Resume scheduling after a prior Suspend() call. | |
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 () | |
| Destructor. | |
| void | Initialize (IPlatform *platform) |
| Initialize instance. | |
| void | IncrementTicks (Ticks advance) |
| Increment counter by value. | |
Private Attributes | |
| TPlatform * | m_platform |
| Typed platform driver pointer, set at Initialize(). | |
| 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 754 of file stk.h.
References m_platform, and m_ticks.
|
inlineprivate |
|
inlinevirtual |
Delay calling process.
| [in] | ticks | Delay time (ticks). |
Implements stk::IKernelService.
Definition at line 658 of file stk.h.
References __stk_attr_noinline, 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::SleepUntil(), stk::sync::Mutex::TimedLock(), stk::sync::ConditionVariable::Wait(), stk::sync::Event::Wait(), stk::sync::Semaphore::Wait(), and stk::Yield().
|
inlinevirtual |
Get system timer count value.
Implements stk::IKernelService.
Definition at line 654 of file stk.h.
References m_platform.
|
inlinevirtual |
Get system timer frequency.
Implements stk::IKernelService.
Definition at line 656 of file stk.h.
References m_platform.
|
inlinevirtual |
Get number of microseconds in one tick.
Implements stk::IKernelService.
Definition at line 652 of file stk.h.
References m_platform.
|
inlinevirtual |
Get number of ticks elapsed since kernel start.
Implements stk::IKernelService.
Definition at line 650 of file stk.h.
References m_ticks, and stk::hw::ReadVolatile64().
Referenced by Delay().
|
inlinevirtual |
Get thread Id of the currently running task.
Implements stk::IKernelService.
Definition at line 648 of file stk.h.
References m_platform.
|
inlineprivate |
Increment counter by value.
| [in] | advance | Number of ticks to add to the counter. |
Definition at line 776 of file stk.h.
References m_ticks, and stk::hw::WriteVolatile64().
|
inlineprivate |
Initialize instance.
| [in] | platform | IPlatform instance. |
Definition at line 768 of file stk.h.
References m_platform.
|
inlinevirtual |
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 738 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode(), m_platform, and STK_ASSERT.
|
inlinevirtual |
Put calling process into a sleep state.
| [in] | ticks | Sleep time (ticks). |
Implements stk::IKernelService.
Definition at line 673 of file stk.h.
References __stk_attr_noinline, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::hw::IsInsideISR(), m_platform, and STK_ASSERT.
|
inlinevirtual |
Put calling process into a sleep state until the specified timestamp.
| [in] | timestamp | Absolute timestamp (ticks). |
Implements stk::IKernelService.
Definition at line 689 of file stk.h.
References __stk_attr_noinline, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsHrtMode(), stk::hw::IsInsideISR(), m_platform, and STK_ASSERT.
|
inlinevirtual |
Suspend scheduling.
Implements stk::IKernelService.
Definition at line 725 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsTicklessMode(), m_platform, and STK_ASSERT.
|
inlinevirtual |
Notify scheduler to switch to the next task (yield).
Implements stk::IKernelService.
Definition at line 705 of file stk.h.
References stk::hw::IsInsideISR(), m_platform, and STK_ASSERT.
|
inlinevirtual |
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 712 of file stk.h.
References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::IsSyncMode(), m_platform, and STK_ASSERT.
|
friend |
|
private |
Typed platform driver pointer, set at Initialize().
Definition at line 782 of file stk.h.
Referenced by GetSysTimerCount(), GetSysTimerFrequency(), GetTickResolution(), GetTid(), Initialize(), KernelService(), Resume(), Sleep(), 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 783 of file stk.h.
Referenced by GetTicks(), IncrementTicks(), and KernelService().