34#ifdef _STK_ARCH_ARM_CORTEX_M
36 #define _STK_ARCH_DEFINED
38#ifdef _STK_ARCH_RISC_V
40 #define _STK_ARCH_DEFINED
42#ifdef _STK_ARCH_X86_WIN32
44 #define _STK_ARCH_DEFINED
47#ifndef STK_PANIC_HANDLER
57 #define STK_PANIC_HANDLER(id) STK_PANIC_HANDLER_DEFAULT(id)
109 return reinterpret_cast<Word>(ptr);
126 return reinterpret_cast<T *
>(value);
141#if STK_TLS && !STK_INLINE_TLS
176template <
class _TyTls>
190template <
class _TyTls>
352#ifdef _STK_ARCH_X86_WIN32
353 volatile long m_lock;
395 #if STK_STRICT_COMPLIANCY
400 volatile const uint32_t *
const p_base =
reinterpret_cast<volatile const uint32_t *
>(addr);
409 __stk_full_memfence();
412 __stk_full_memfence();
414 while (hi != (*phi));
416 const uint64_t result = (
static_cast<uint64_t
>(hi) << 32U) |
static_cast<uint64_t
>(lo);
418 return static_cast<T
>(result);
457 #if STK_STRICT_COMPLIANCY
462 volatile uint32_t *
const p_base =
reinterpret_cast<volatile uint32_t *
>(addr);
469 (*phi) =
static_cast<uint32_t
>(
static_cast<uint64_t
>(value) >> 32U);
470 __stk_full_memfence();
472 (*plo) =
static_cast<uint32_t
>(value);
505 const Cycles ticksu = (cycles * 1000000ULL) /
static_cast<Cycles>(freq);
507 ticks =
static_cast<Ticks>(ticksu);
533#ifndef _STK_CUSTOM_MEMCPY
538 if ((dest !=
nullptr) && (src !=
nullptr) && (size != 0U))
545 if (((dest_addr & 0x03U) == 0U) &&
546 ((src_addr & 0x03U) == 0U) &&
547 ((size & 0x03U) == 0U))
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);
558 uint8_t *
const p_d =
static_cast<uint8_t *
>(dest);
559 const uint8_t *
const p_s =
static_cast<const uint8_t *
>(src);
Platform port for ARM Cortex-M.
Platform port for RISC-V.
Platform port for Windows Win32 (STK emulator).
void STK_PANIC_HANDLER_DEFAULT(stk::EKernelPanicId id)
Default panic handler: disable interrupts, record the id, and spin in a tight loop — a defined,...
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.
#define STK_PANIC_HANDLER(id)
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#define STK_STATIC_ASSERT_N(NAME, X)
Compile-time assertion with a user-defined name suffix.
#define STK_ENDIAN_IDX_LO
Array index of the low 32-bit word when a 64-bit value is viewed as uint32_t[2].
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ENDIAN_IDX_HI
Array index of the high 32-bit word when a 64-bit value is viewed as uint32_t[2].
#define __stk_constexpr_cpp17
constexpr definition for C++17 and above.
static void __stk_debug_break()
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Namespace of STK package.
uintptr_t Word
Native processor word type.
static constexpr ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
static __stk_forceinline void SetTls(Word tp)
Set thread-local storage (TLS).
int64_t Ticks
Ticks value.
static __stk_forceinline Word GetTls()
Get thread-local storage (TLS).
static __stk_forceinline void STK_KERNEL_PANIC(stk::EKernelPanicId id)
Called when the kernel detects an unrecoverable internal fault.
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
uint64_t Cycles
Cycles value.
Word TId
Task (thread) id.
EKernelPanicId
Identifies the source of a kernel panic.
Hardware Abstraction Layer (HAL) for architecture-specific operations.
static __stk_forceinline void WriteVolatile64(volatile T *addr, T value)
Atomically write a 64-bit volatile value.
static constexpr T * WordToPtr(Word value) noexcept
Cast a CPU register-width integer back to a pointer.
static constexpr Word PtrToWord(T *const ptr) noexcept
Cast a pointer to a CPU register-width integer.
static __stk_forceinline T ReadVolatile64(volatile const T *addr)
Atomically read a 64-bit volatile value.
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
static void Enter()
Enter a critical section.
static void Exit()
Exit a critical section.
STK_NONCOPYABLE_CLASS(CriticalSection)
STK_NONCOPYABLE_CLASS(ScopedLock)
ScopedLock()
Enter the critical section.
~ScopedLock()
Exit the critical section.
bool TryLock()
Attempt to acquire SpinLock in a single non-blocking attempt.
SpinLock()
Construct a SpinLock (unlocked by default).
EState
Internal lock state values.
@ UNLOCKED
Lock is free and available for acquisition.
@ LOCKED
Lock is held by a thread or core.
STK_NONCOPYABLE_CLASS(SpinLock)
bool IsLocked() const
Sample current lock state.
volatile bool m_lock __stk_aligned(8)
Lock state (see EState). 8-byte aligned to occupy its own cache line word and avoid false sharing on ...
void Lock()
Acquire SpinLock, blocking until it is available.
void Unlock()
Release SpinLock, allowing another thread or core to acquire it.
High-resolution clock for high-precision measurements.
static uint32_t GetFrequency()
Get clock frequency.
static __stk_forceinline Ticks GetTimeUs()
Get elapsed time in microseconds.
static Cycles GetCycles()
Get number of clock cycles elapsed.
Interface for a user task.