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::test::KernelServiceMock Class Reference

IKernelService mock. More...

#include <stktest.h>

Inheritance diagram for stk::test::KernelServiceMock:
Collaboration diagram for stk::test::KernelServiceMock:

Public Member Functions

 KernelServiceMock ()
virtual ~KernelServiceMock ()
size_t GetTid () const
 Get thread Id of the currently running task.
int64_t 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).
IWaitObjectWait (ISyncObject *sobj, IMutex *mutex, Timeout timeout)
 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 IKernelServiceGetInstance ()
 Get CPU-local instance of the kernel service.

Public Attributes

bool m_inc_ticks
bool m_switch_to_next
int64_t m_ticks
int32_t m_resolution
size_t m_tid
uint64_t m_systimer_count
uint32_t m_systimer_freq

Detailed Description

IKernelService mock.

Definition at line 286 of file stktest.h.

Constructor & Destructor Documentation

◆ KernelServiceMock()

stk::test::KernelServiceMock::KernelServiceMock ( )
inline

◆ ~KernelServiceMock()

virtual stk::test::KernelServiceMock::~KernelServiceMock ( )
inlinevirtual

Definition at line 299 of file stktest.h.

300 {}

Member Function Documentation

◆ Delay()

void stk::test::KernelServiceMock::Delay ( Timeout ticks)
inlinevirtual

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

Implements stk::IKernelService.

Definition at line 330 of file stktest.h.

331 {
332 (void)ticks;
333 }

◆ GetInstance()

◆ GetSysTimerCount()

Cycles stk::test::KernelServiceMock::GetSysTimerCount ( ) const
inlinevirtual

Get system timer count value.

Note
ISR-safe.
Returns
64-bit count value.

Implements stk::IKernelService.

Definition at line 320 of file stktest.h.

321 {
322 return m_systimer_count;
323 }

References m_systimer_count.

◆ GetSysTimerFrequency()

uint32_t stk::test::KernelServiceMock::GetSysTimerFrequency ( ) const
inlinevirtual

Get system timer frequency.

Note
ISR-safe.
Returns
Frequency (Hz).

Implements stk::IKernelService.

Definition at line 325 of file stktest.h.

326 {
327 return m_systimer_freq;
328 }

References m_systimer_freq.

◆ GetTickResolution()

uint32_t stk::test::KernelServiceMock::GetTickResolution ( ) const
inlinevirtual

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.

Implements stk::IKernelService.

Definition at line 315 of file stktest.h.

316 {
317 return m_resolution;
318 }

References m_resolution.

Referenced by stk::test::TEST().

Here is the caller graph for this function:

◆ GetTicks()

int64_t stk::test::KernelServiceMock::GetTicks ( ) const
inlinevirtual

Get number of ticks elapsed since kernel start.

Returns
Ticks.
Note
ISR-safe.

Implements stk::IKernelService.

Definition at line 307 of file stktest.h.

308 {
309 if (m_inc_ticks)
310 const_cast<int64_t &>(m_ticks) = m_ticks + 1;
311
312 return m_ticks;
313 }

References m_inc_ticks, and m_ticks.

◆ GetTid()

size_t stk::test::KernelServiceMock::GetTid ( ) const
inlinevirtual

Get thread Id of the currently running task.

Returns
Thread Id.
Warning
ISR-safe.
See also
TID_ISR_N, TID_NONE, IsIsrTid

Implements stk::IKernelService.

Definition at line 302 of file stktest.h.

303 {
304 return m_tid;
305 }

References m_tid.

◆ Resume()

void stk::test::KernelServiceMock::Resume ( Timeout elapsed_ticks)
inlinevirtual

Resume scheduling after a prior Suspend() call.

Parameters
[in]elapsed_ticksNumber 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.
Note
ISR-safe.
See also
IKernel::EState::STATE_SUSPENDED

Implements stk::IKernelService.

Definition at line 363 of file stktest.h.

364 {
365 (void)elapsed_ticks;
366 }

◆ Sleep()

void stk::test::KernelServiceMock::Sleep ( Timeout ticks)
inlinevirtual

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.

Implements stk::IKernelService.

Definition at line 335 of file stktest.h.

336 {
337 (void)ticks;
338 }

◆ SleepUntil()

void stk::test::KernelServiceMock::SleepUntil ( Ticks timestamp)
inlinevirtual

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.

Implements stk::IKernelService.

Definition at line 340 of file stktest.h.

341 {
342 (void)timestamp;
343 }

◆ Suspend()

Timeout stk::test::KernelServiceMock::Suspend ( )
inlinevirtual

Suspend scheduling.

Returns
Number of ticks available for the suspension period, as determined by the nearest pending wake-up. The caller may program a hardware timer with this value to avoid unnecessary wakeups (tickless idle).
Note
ISR-safe. Pair with Resume().
See also
IKernel::EState::STATE_SUSPENDED

Implements stk::IKernelService.

Definition at line 358 of file stktest.h.

359 {
360 return 1;
361 }

◆ SwitchToNext()

void stk::test::KernelServiceMock::SwitchToNext ( )
inlinevirtual

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

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

Implements stk::IKernelService.

Definition at line 345 of file stktest.h.

346 {
347 m_switch_to_next = true;
348 }

References m_switch_to_next.

◆ Wait()

IWaitObject * stk::test::KernelServiceMock::Wait ( ISyncObject * sobj,
IMutex * mutex,
Timeout timeout )
inlinevirtual

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.

Implements stk::IKernelService.

Definition at line 350 of file stktest.h.

351 {
352 (void)sobj;
353 (void)mutex;
354 (void)timeout;
355 return nullptr;
356 }

Member Data Documentation

◆ m_inc_ticks

bool stk::test::KernelServiceMock::m_inc_ticks

Definition at line 368 of file stktest.h.

Referenced by GetTicks(), and KernelServiceMock().

◆ m_resolution

int32_t stk::test::KernelServiceMock::m_resolution

Definition at line 371 of file stktest.h.

Referenced by GetTickResolution(), KernelServiceMock(), and stk::test::TEST().

◆ m_switch_to_next

bool stk::test::KernelServiceMock::m_switch_to_next

Definition at line 369 of file stktest.h.

Referenced by KernelServiceMock(), and SwitchToNext().

◆ m_systimer_count

uint64_t stk::test::KernelServiceMock::m_systimer_count

Definition at line 373 of file stktest.h.

Referenced by GetSysTimerCount(), and KernelServiceMock().

◆ m_systimer_freq

uint32_t stk::test::KernelServiceMock::m_systimer_freq

Definition at line 374 of file stktest.h.

Referenced by GetSysTimerFrequency(), and KernelServiceMock().

◆ m_ticks

int64_t stk::test::KernelServiceMock::m_ticks

Definition at line 370 of file stktest.h.

Referenced by GetTicks(), KernelServiceMock(), and stk::test::TEST().

◆ m_tid

size_t stk::test::KernelServiceMock::m_tid

Definition at line 372 of file stktest.h.

Referenced by GetTid(), and KernelServiceMock().


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