SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_arch.h File Reference

Hardware Abstraction Layer (HAL) declarations for the stk::hw namespace. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  stk::hw::CriticalSection
 Nestable, SMP-safe critical section that combines local interrupt masking with a global cross-core spinlock. More...
class  stk::hw::CriticalSection::ScopedLock
 RAII guard that enters the critical section on construction and exits it on destruction. More...
class  stk::hw::SpinLock
 Atomic busy-wait lock used as the global cross-core synchronisation primitive inside CriticalSection. More...
class  stk::hw::HiResClock
 High-resolution clock for high-precision measurements. More...

Namespaces

namespace  stk
 Namespace of STK package.
namespace  stk::hw
 Hardware Abstraction Layer (HAL) for architecture-specific operations.

Macros

#define STK_PANIC_HANDLER(id)

Functions

void STK_PANIC_HANDLER_DEFAULT (stk::EKernelPanicId id)
 Default panic handler: disable interrupts, record the id, and spin in a tight loop — a defined, detectable safe state.
static __stk_forceinline void stk::STK_KERNEL_PANIC (stk::EKernelPanicId id)
 Called when the kernel detects an unrecoverable internal fault.
template<typename T>
static constexpr Word stk::hw::PtrToWord (T *const ptr) noexcept
 Cast a pointer to a CPU register-width integer.
template<typename T>
static constexpr T * stk::hw::WordToPtr (Word value) noexcept
 Cast a CPU register-width integer back to a pointer.
bool stk::hw::IsInsideISR ()
 Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
template<typename T>
static __stk_forceinlinestk::hw::ReadVolatile64 (volatile const T *addr)
 Atomically read a 64-bit volatile value.
template<typename T>
static __stk_forceinline void stk::hw::WriteVolatile64 (volatile T *addr, T value)
 Atomically write a 64-bit volatile value.
static constexpr TId stk::GetTidFromUserTask (const ITask *task) noexcept
 Get task identifier from ITask instance.
static constexpr ITaskstk::GetUserTaskFromTid (TId task_id) noexcept
 Get task instance from its identifier.
static __stk_forceinline void STK_MEMCPY (void *const dest, const void *const src, const size_t size)
 A wrapper for a built-in memcpy, redefine to your own if required.

Detailed Description

Hardware Abstraction Layer (HAL) declarations for the stk::hw namespace.

Selects and includes the correct architecture back-end header based on the active architecture macro (_STK_ARCH_ARM_CORTEX_M, _STK_ARCH_RISC_V, _STK_ARCH_X86_WIN32), then declares the portable stk::hw interface that the rest of the kernel uses:

  • Thread-local storage (TLS) read/write: GetTls, SetTls, GetTlsPtr, SetTlsPtr.
  • ISR context detection: IsInsideISR.
  • Preemption control: CriticalSection (nestable, single-core) and SpinLock (SMP).
  • Lock-free 64-bit volatile I/O: ReadVolatile64, WriteVolatile64.

Definition in file stk_arch.h.

Macro Definition Documentation

◆ STK_PANIC_HANDLER

#define STK_PANIC_HANDLER ( id)
Value:
void STK_PANIC_HANDLER_DEFAULT(stk::EKernelPanicId id)
Default panic handler: disable interrupts, record the id, and spin in a tight loop — a defined,...

Definition at line 57 of file stk_arch.h.

Referenced by stk::STK_KERNEL_PANIC().

Function Documentation

◆ STK_MEMCPY()

__stk_forceinline void STK_MEMCPY ( void *const dest,
const void *const src,
const size_t size )
static

A wrapper for a built-in memcpy, redefine to your own if required.

Note
Can be overridden by defining _STK_CUSTOM_MEMCPY in system configuration.

Definition at line 534 of file stk_arch.h.

535{
536 using namespace stk;
537
538 if ((dest != nullptr) && (src != nullptr) && (size != 0U))
539 {
540 const Word dest_addr = hw::PtrToWord(dest);
541 const Word src_addr = hw::PtrToWord(src);
542
543 // fast path: check if destination, source, and size are all 4-byte aligned
544 // then copy data in 4-byte chunks
545 if (((dest_addr & 0x03U) == 0U) &&
546 ((src_addr & 0x03U) == 0U) &&
547 ((size & 0x03U) == 0U))
548 {
549 uint32_t *const p_d32 = static_cast<uint32_t *>(dest);
550 const uint32_t *const p_s32 = static_cast<const uint32_t *>(src);
551 const size_t words = (size >> 2U);
552
553 STK_UNUSED(std::copy_n(p_s32, words, p_d32));
554 }
555 // slow path
556 else
557 {
558 uint8_t *const p_d = static_cast<uint8_t *>(dest);
559 const uint8_t *const p_s = static_cast<const uint8_t *>(src);
560
561 STK_UNUSED(std::copy_n(p_s, size, p_d));
562 }
563 }
564}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:608
Namespace of STK package.
uintptr_t Word
Native processor word type.
Definition stk_common.h:115
static constexpr Word PtrToWord(T *const ptr) noexcept
Cast a pointer to a CPU register-width integer.
Definition stk_arch.h:106

References __stk_forceinline, stk::hw::PtrToWord(), and STK_UNUSED.

Referenced by stk::sync::Pipe::DrainLocked(), stk::sync::MessageQueue::Get(), osKernelGetInfo(), stk::sync::MessageQueue::Peek(), stk::sync::MessageQueue::PeekFront(), stk::sync::MessageQueue::Put(), stk::sync::MessageQueue::PutFront(), stk::sync::Pipe::Read(), stk::sync::PipeT< Timer *, 32U >::ReadBulk(), stk::sync::Pipe::Write(), stk::sync::Pipe::WriteBulk(), stk::sync::PipeT< Timer *, 32U >::WriteBulk(), xMessageBufferReceive(), xMessageBufferReceiveFromISR(), xMessageBufferSend(), and xMessageBufferSendFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ STK_PANIC_HANDLER_DEFAULT()

void STK_PANIC_HANDLER_DEFAULT ( stk::EKernelPanicId id)
extern

Default panic handler: disable interrupts, record the id, and spin in a tight loop — a defined, detectable safe state.

Note
On a system with a watchdog enabled this will trigger a watchdog reset after the watchdog period, which is the desired behaviour.
Replace with a platform-specific handler (e.g. one that writes a fault log to non-volatile memory and calls NVIC_SystemReset()) by defining STK_PANIC_HANDLER in stk_config.h.