17 #include <intrinsics.h>
18 #if (__IAR_SYSTEMS_ICC__ < 8)
19 #error "Only IAR EWARM 8.0 and higher is supported by STK."
29#include "stk_config.h"
42#ifndef STK_TICKLESS_IDLE
43 #define STK_TICKLESS_IDLE (0)
50#ifndef STK_STRICT_COMPLIANCY
51 #define STK_STRICT_COMPLIANCY (0)
62#ifndef STK_TICKLESS_USE_ARM_DWT
63 #define STK_TICKLESS_USE_ARM_DWT (1)
76#ifndef STK_TICKLESS_TICKS_MAX
77 #define STK_TICKLESS_TICKS_MAX (1000)
79#if STK_TICKLESS_TICKS_MAX > 100000
80 #error "STK_TICKLESS_TICKS_MAX is too large: cpu_ticks_requested may overflow uint32_t."
126#ifndef STK_TLS_PREFER_REGISTER
127 #define STK_TLS_PREFER_REGISTER (0)
138#if STK_SEGGER_SYSVIEW
139 #define STK_STACK_NEEDS_TASK_ID (1)
149#if !defined(STK_SYNC_DEBUG_NAMES) && STK_SEGGER_SYSVIEW
150 #define STK_SYNC_DEBUG_NAMES (1)
151#elif !defined(STK_SYNC_DEBUG_NAMES)
152 #define STK_SYNC_DEBUG_NAMES (0)
158#if !STK_STRICT_COMPLIANCY
159 #define STK_VIRT_DTOR
161 #define STK_VIRT_DTOR virtual
170#if defined(__GNUC__) || defined(__ICCARM__)
171 #define __stk_forceinline __attribute__((always_inline)) inline
172#elif defined(_MSC_VER)
173 #define __stk_forceinline __forceinline
175 #define __stk_forceinline inline
184#if defined(__GNUC__) || defined(__ICCARM__)
185 #define __stk_aligned(x) __attribute__((aligned(x)))
187 #define __stk_aligned(x)
195#if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__) || defined(__CC_ARM) || defined(__ARMCC_VERSION)
196 #define __stk_weak __attribute__((weak))
208#if defined(__GNUC__) || defined(__ICCARM__)
209 #define __stk_attr_naked __attribute__((naked))
211 #define __stk_attr_naked
219#if defined(__GNUC__) || defined(__ICCARM__)
220 #define __stk_attr_noreturn __attribute__((__noreturn__))
222 #define __stk_attr_noreturn
230#if defined(__GNUC__) || defined(__ICCARM__)
231 #define __stk_attr_unused __attribute__((unused))
233 #define __stk_attr_unused
241#if defined(__GNUC__) || defined(__ICCARM__)
242 #define __stk_attr_used __attribute__((used))
244 #define __stk_attr_used
252#if defined(__GNUC__) || defined(__ICCARM__)
253 #define __stk_attr_noinline __attribute__((noinline))
255 #define __stk_attr_noinline
263#if defined(__GNUC__) || defined(__ICCARM__)
264 #define __stk_attr_deprecated __attribute__((deprecated))
265#elif defined(_MSC_VER)
266 #define __stk_attr_deprecated __declspec(deprecated)
268 #define __stk_attr_deprecated
276#if defined(__GNUC__) || defined(__clang__)
278#elif defined(__ICCARM__)
280#elif defined(_MSC_VER)
283 #error "__stk_full_memfence() is not implemented for this compiler. Add a definition to stk_defs.h."
294#if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
295 static __stk_forceinline void __stk_compiler_barrier() { __asm
volatile(
"" :::
"memory"); }
296#elif defined(_MSC_VER)
299 #error "__stk_compiler_barrier() is not implemented for this compiler. Add a definition to stk_defs.h."
314#ifndef __stk_relax_cpu
315#if defined(__GNUC__) || defined(__clang__)
316 #if defined(__i386__) || defined(__x86_64__)
318 #elif defined(__riscv)
319 #ifdef __riscv_zihintpause
324 #elif defined(__ARM_ARCH) || defined(_STK_ARCH_ARM_CORTEX_M)
329#elif defined(__ICCARM__)
331#elif defined(_MSC_VER)
333 #if defined(_M_IX86) || defined(_M_X64)
335 #elif defined(_M_ARM) || defined(_M_ARM64)
341 #error "__stk_relax_cpu() is not implemented for this compiler. Add a definition to stk_defs.h."
359#if defined(DEBUG) || defined(_DEBUG)
360 #if defined(_STK_ARCH_ARM_CORTEX_M)
362 #elif defined(_STK_ARCH_RISC_V)
364 #elif defined(_STK_ARCH_X86_WIN32)
379#if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))
380 #define __stk_constexpr_cpp17 constexpr
382 #define __stk_constexpr_cpp17
401#ifdef _STK_ASSERT_REDIRECT
402 extern void STK_ASSERT_HANDLER(
const char *,
const char *, int32_t);
403 #define STK_ASSERT(e) ((e) ? (void)0 : STK_ASSERT_HANDLER(#e, __FILE__, __LINE__))
405 #if defined(DEBUG) || defined(_DEBUG)
407 #define STK_ASSERT(e) assert(e)
409 #define STK_ASSERT(e)
421#define STK_STATIC_ASSERT_DESC_N(NAME, X, DESC) static_assert((X), DESC)
429#define STK_STATIC_ASSERT_DESC(X, DESC) STK_STATIC_ASSERT_DESC_N(_, X, DESC)
438#define STK_STATIC_ASSERT_N(NAME, X) STK_STATIC_ASSERT_DESC_N(N, (X), #X)
446#define STK_STATIC_ASSERT(X) STK_STATIC_ASSERT_DESC_N(_, (X), #X)
455#ifndef STK_STACK_MEMORY_FILLER
456 #define STK_STACK_MEMORY_FILLER (static_cast<stk::Word>((sizeof(stk::Word) <= 4U) ? 0xDEADBEEFU : 0xDEADBEEFDEADBEEFULL))
462#ifndef STK_STACK_MEMORY_ALIGN
464 #define STK_STACK_MEMORY_ALIGN (16U)
465 #elif defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
466 #define STK_STACK_MEMORY_ALIGN (8U)
468 #define STK_STACK_MEMORY_ALIGN (4U)
482#ifndef STK_CRITICAL_SECTION_NESTINGS_MAX
483 #define STK_CRITICAL_SECTION_NESTINGS_MAX (16U)
492#ifndef STK_ARCH_CPU_COUNT
493 #define STK_ARCH_CPU_COUNT (1U)
511#ifndef STK_STACK_SIZE_MIN
513 #if defined(__riscv_32e) && (__riscv_32e == 1)
515 #if !defined(__riscv_flen) || (__riscv_flen == 0)
516 #define STK_STACK_SIZE_MIN (32U)
519 #define STK_STACK_SIZE_MIN (32U + (__riscv_flen * 2))
524 #if !defined(__riscv_flen) || (__riscv_flen == 0)
525 #define STK_STACK_SIZE_MIN (256U)
528 #define STK_STACK_SIZE_MIN (512U + (__riscv_flen * 2))
533 #define STK_STACK_SIZE_MIN (32U)
545#ifndef STK_SLEEP_TRAP_STACK_SIZE
546 #define STK_SLEEP_TRAP_STACK_SIZE (STK_STACK_SIZE_MIN)
560template <
size_t MODE,
size_t FLAG,
size_t ONTRUE,
size_t ONFALSE>
563#if defined(_MSC_VER) || defined(__ICCARM__)
565 static constexpr size_t Value = ((ONTRUE > ONFALSE) ? ONTRUE : ONFALSE);
568 static constexpr size_t Value = (((MODE & FLAG) != 0U) ? ONTRUE : ONFALSE);
582#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
583 #define STK_ENDIAN_IDX_HI (0U)
584 #define STK_ENDIAN_IDX_LO (1U)
586 #define STK_ENDIAN_IDX_HI (1U)
587 #define STK_ENDIAN_IDX_LO (0U)
601#define STK_NONCOPYABLE_CLASS(TYPE)\
602 TYPE(const TYPE &) = delete;\
603 TYPE &operator=(const TYPE &) = delete;
608#define STK_UNUSED(X) static_cast<void>((X))
619static constexpr T
Min(T a, T b) {
return ((a < b) ? a : b); }
625static constexpr T
Max(T a, T b) {
return ((a > b) ? a : b); }
static void __stk_dmb()
Hardware memory barrier: ensures visibility across cores and bus masters.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
static void __stk_debug_break()
Namespace of STK package.
static constexpr T Max(T a, T b)
Compile-time maximum of two values.
static constexpr T Min(T a, T b)
Compile-time minimum of two values.
Internal utility namespace containing data structure helpers (linked lists, etc.) used by the kernel ...
Selects a static array element count at compile time based on a mode flag.
static constexpr size_t Value