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::IKernelService Class Referenceabstract

Interface for the kernel services exposed to the user processes during run-time when Kernel started scheduling the processes. More...

#include <stk_common.h>

Inheritance diagram for stk::IKernelService:

Public Member Functions

virtual TId GetTid () const =0
 Get thread Id of the currently running task.
virtual Ticks GetTicks () const =0
 Get number of ticks elapsed since kernel start.
virtual int32_t GetTickResolution () const =0
 Get number of microseconds in one tick.
virtual void Delay (Timeout ticks)=0
 Delay calling process.
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 SwitchToNext ()=0
 Notify scheduler to switch to the next task (yield).
virtual IWaitObjectWait (ISyncObject *sobj, IMutex *mutex, Timeout timeout)=0
 Put calling process into a waiting state until synchronization object is signaled or timeout occurs.

Static Public Member Functions

static IKernelServiceGetInstance ()
 Get CPU-local instance of the kernel service.

Detailed Description

Interface for the kernel services exposed to the user processes during run-time when Kernel started scheduling the processes.

Note
State design pattern: this interface represents the kernel's active running state. It becomes valid only after IKernel::Start() is called. Before that point the kernel is in an idle/unstarted state and this interface must not be used. Obtain the CPU-local instance via IKernelService::GetInstance().

Definition at line 928 of file stk_common.h.

Member Function Documentation

◆ Delay()

virtual void stk::IKernelService::Delay ( Timeout ticks)
pure virtual

Delay calling process.

Note
Unlike Sleep this function delays code execution by spinning in a loop until deadline expiry.
Use with care in HRT mode to avoid missed deadline (see stk::KERNEL_HRT, ITask::OnDeadlineMissed).
Parameters
[in]ticksDelay time (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.
See also
Delay

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::Delay().

Here is the caller graph for this function:

◆ GetInstance()

◆ GetTickResolution()

virtual int32_t stk::IKernelService::GetTickResolution ( ) const
pure virtual

Get number of microseconds in one tick.

Note
Tick is a periodicity of the system timer expressed in microseconds.
ISR-safe.
Returns
Microseconds in one tick.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::GetTickResolution(), and stk::GetTimeNowMs().

Here is the caller graph for this function:

◆ GetTicks()

virtual Ticks stk::IKernelService::GetTicks ( ) const
pure virtual

Get number of ticks elapsed since kernel start.

Returns
Ticks.
Note
ISR-safe.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::GetTicks(), and stk::GetTimeNowMs().

Here is the caller graph for this function:

◆ GetTid()

virtual TId stk::IKernelService::GetTid ( ) const
pure virtual

Get thread Id of the currently running task.

Returns
Thread Id.
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::GetTid(), and stk::sync::Mutex::TimedLock().

Here is the caller graph for this function:

◆ Sleep()

virtual void stk::IKernelService::Sleep ( Timeout ticks)
pure virtual

Put calling process into a sleep state.

Note
Unlike Delay this function does not waste CPU cycles and allows kernel to put CPU into a low-power state.
Unsupported in HRT mode (see stk::KERNEL_HRT); in HRT mode tasks sleep automatically according to their periodicity and workload.
Parameters
[in]ticksSleep time (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::Sleep().

Here is the caller graph for this function:

◆ SleepUntil()

virtual void stk::IKernelService::SleepUntil ( Ticks timestamp)
pure virtual

Put calling process into a sleep state until the specified timestamp.

Note
Unlike Delay this function does not waste CPU cycles and allows kernel to put CPU into a low-power state.
Unsupported in HRT mode (see stk::KERNEL_HRT); in HRT mode tasks sleep automatically according to their periodicity and workload.
Parameters
[in]timestampAbsolute timestamp (ticks).
Warning
ISR-unsafe. Calling from an ISR context is not permitted and will trigger an assertion.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::SleepUntil().

Here is the caller graph for this function:

◆ SwitchToNext()

virtual void stk::IKernelService::SwitchToNext ( )
pure virtual

Notify scheduler to switch to the next task (yield).

Note
A cooperation mechanism in HRT mode (see stk::KERNEL_HRT).
Warning
ISR-unsafe.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::Yield().

Here is the caller graph for this function:

◆ Wait()

virtual IWaitObject * stk::IKernelService::Wait ( ISyncObject * sobj,
IMutex * mutex,
Timeout timeout )
pure virtual

Put calling process into a waiting state until synchronization object is signaled or timeout occurs.

Note
This function implements core blocking logic using the Monitor pattern to ensure atomicity between state check and suspension.
The kernel automatically unlocks the provided mutex before the task is suspended and re-locks it before this function returns.
Parameters
[in]sobjSynchronization object to wait on.
[in]mutexMutex protecting the state of the synchronization object.
[in]timeoutMaximum wait time (ticks). Use WAIT_INFINITE to block indefinitely, use NO_WAIT to poll without blocking.
Returns
Pointer to the wait object representing this wait operation (always non-NULL). The caller must check IWaitObject::IsTimeout() after this function returns to determine whether the wake was caused by a signal or by timeout expiry. The returned pointer is valid until the calling task re-enters a wait or the wait object is explicitly released by the kernel. The return value is guaranteed non nullptr and points to a valid IWaitObject.
Warning
ISR-unsafe.

Implemented in stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelService, stk::test::KernelServiceMock, and stk::test::stk::KernelServiceMock.

Referenced by stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::TEST(), stk::test::Test_SyncWait(), stk::sync::Mutex::TimedLock(), stk::sync::ConditionVariable::Wait(), stk::sync::Event::Wait(), and stk::sync::Semaphore::Wait().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: