22#include "stk_config.h"
35#ifndef STK_TICKLESS_IDLE
36 #define STK_TICKLESS_IDLE 0
47#ifndef STK_TICKLESS_USE_ARM_DWT
48 #define STK_TICKLESS_USE_ARM_DWT 1
61#ifndef STK_TICKLESS_TICKS_MAX
62 #define STK_TICKLESS_TICKS_MAX 1000
64#if STK_TICKLESS_TICKS_MAX > 100000
65 #error "STK_TICKLESS_TICKS_MAX is too large: cpu_ticks_requested may overflow uint32_t."
77 #define STK_NEED_TASK_ID 1
87#if !defined(STK_SYNC_DEBUG_NAMES) && STK_SEGGER_SYSVIEW
88 #define STK_SYNC_DEBUG_NAMES 1
89#elif !defined(STK_SYNC_DEBUG_NAMES)
90 #define STK_SYNC_DEBUG_NAMES 0
100 #define __stk_forceinline __attribute__((always_inline)) inline
101#elif defined(__ICCARM__) || defined(_MSC_VER)
102 #define __stk_forceinline __forceinline
104 #define __stk_forceinline
114 #define __stk_aligned(x) __attribute__((aligned(x)))
115#elif defined(__ICCARM__)
116 #define __stk_aligned(x) __attribute__((aligned(x)))
118 #define __stk_aligned(x)
129 #define __stk_attr_naked __attribute__((naked))
130#elif defined(__ICCARM__)
131 #define __stk_attr_naked __attribute__((naked))
133 #define __stk_attr_naked
142 #define __stk_attr_noreturn __attribute__((__noreturn__))
143#elif defined(__ICCARM__)
144 #define __stk_attr_noreturn __attribute__((noreturn))
146 #define __stk_attr_noreturn
155 #define __stk_attr_unused __attribute__((unused))
156#elif defined(__ICCARM__)
157 #define __stk_attr_unused __attribute__((unused))
159 #define __stk_attr_unused
168 #define __stk_attr_used __attribute__((used))
169#elif defined(__ICCARM__)
170 #define __stk_attr_used __attribute__((used))
172 #define __stk_attr_used
181 #define __stk_attr_noinline __attribute__((noinline))
182#elif defined(__ICCARM__)
183 #define __stk_attr_noinline __attribute__((noinline))
185 #define __stk_attr_noinline
194 #define __stk_attr_deprecated __attribute__((deprecated))
195#elif defined(__ICCARM__)
196 #define __stk_attr_deprecated __attribute__((deprecated))
197#elif defined(_MSC_VER)
198 #define __stk_attr_deprecated __declspec(deprecated)
200 #define __stk_attr_deprecated
209#if defined(__GNUC__) || defined(__clang__)
210 #define __stk_full_memfence() __sync_synchronize()
211#elif defined(_MSC_VER)
212 #define __stk_full_memfence() __stk_dmb()
214 #error "__stk_full_memfence() is not implemented for this compiler. Add a definition to stk_defs.h."
226#if defined(__GNUC__) || defined(__clang__)
227 #define __stk_compiler_barrier() __asm volatile("" ::: "memory")
228#elif defined(_MSC_VER)
229 #define __stk_compiler_barrier() _ReadWriteBarrier()
231 #error "__stk_compiler_barrier() is not implemented for this compiler. Add a definition to stk_defs.h."
247#ifndef __stk_relax_cpu
248#if defined(__GNUC__) || defined(__clang__)
249 #if defined(__i386__) || defined(__x86_64__)
250 #define __stk_relax_cpu() __builtin_ia32_pause()
251 #elif defined(__riscv)
252 #ifdef __riscv_zihintpause
253 #define __stk_relax_cpu() __builtin_riscv_pause()
255 #define __stk_relax_cpu() __stk_full_memfence()
258 #define __stk_relax_cpu() __stk_full_memfence()
260#elif defined(_MSC_VER)
262 #if defined(_M_IX86) || defined(_M_X64)
264 #define __stk_relax_cpu() _mm_pause()
265 #elif defined(_M_ARM) || defined(_M_ARM64)
267 #define __stk_relax_cpu() __yield()
269 #define __stk_relax_cpu() __stk_full_memfence()
272 #error "__stk_relax_cpu() is not implemented for this compiler. Add a definition to stk_defs.h."
290#if defined(DEBUG) || defined(_DEBUG)
291 #if defined(_STK_ARCH_ARM_CORTEX_M)
292 #define __stk_debug_break() __asm volatile("bkpt 0")
293 #elif defined(_STK_ARCH_RISC_V)
294 #define __stk_debug_break() __asm volatile("ebreak")
295 #elif defined(_STK_ARCH_X86_WIN32)
297 #define __stk_debug_break() __debugbreak()
299 #define __stk_debug_break() __asm volatile("int $3")
303 #define __stk_debug_break()
322#ifdef _STK_ASSERT_REDIRECT
324 #define STK_ASSERT(e) ((e) ? (void)0 : STK_ASSERT_HANDLER(#e, __FILE__, __LINE__))
326 #if defined(DEBUG) || defined(_DEBUG)
328 #define STK_ASSERT(e) assert(e)
330 #define STK_ASSERT(e)
342#define STK_STATIC_ASSERT_DESC_N(NAME, X, DESC) static_assert((X), DESC)
350#define STK_STATIC_ASSERT_DESC(X, DESC) STK_STATIC_ASSERT_DESC_N(_, X, DESC)
359#define STK_STATIC_ASSERT_N(NAME, X) STK_STATIC_ASSERT_DESC_N(N, (X), #X)
367#define STK_STATIC_ASSERT(X) STK_STATIC_ASSERT_DESC_N(_, (X), #X)
376#ifndef STK_STACK_MEMORY_FILLER
377 #define STK_STACK_MEMORY_FILLER ((Word)(sizeof(Word) <= 4 ? 0xdeadbeef : 0xdeadbeefdeadbeef))
383#ifndef STK_STACK_MEMORY_ALIGN
385 #define STK_STACK_MEMORY_ALIGN 16
386 #elif defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
387 #define STK_STACK_MEMORY_ALIGN 8
389 #define STK_STACK_MEMORY_ALIGN 4
403#ifndef STK_CRITICAL_SECTION_NESTINGS_MAX
404 #define STK_CRITICAL_SECTION_NESTINGS_MAX 16
413#ifndef STK_ARCH_CPU_COUNT
414 #define STK_ARCH_CPU_COUNT 1
432#ifndef STK_STACK_SIZE_MIN
434 #if defined(__riscv_32e) && (__riscv_32e == 1)
436 #if !defined(__riscv_flen) || (__riscv_flen == 0)
437 #define STK_STACK_SIZE_MIN 32
440 #define STK_STACK_SIZE_MIN (32 + (__riscv_flen * 2))
445 #if !defined(__riscv_flen) || (__riscv_flen == 0)
446 #define STK_STACK_SIZE_MIN 256
449 #define STK_STACK_SIZE_MIN (512 + (__riscv_flen * 2))
454 #define STK_STACK_SIZE_MIN 32
466#ifndef STK_SLEEP_TRAP_STACK_SIZE
467 #define STK_SLEEP_TRAP_STACK_SIZE (STK_STACK_SIZE_MIN)
483 #define STK_ALLOCATE_COUNT(MODE, FLAG, ONTRUE, ONFALSE) ((ONTRUE) > (ONFALSE) ? (ONTRUE) : (ONFALSE))
485 #define STK_ALLOCATE_COUNT(MODE, FLAG, ONTRUE, ONFALSE) ((((MODE) & (FLAG)) != 0U) ? (ONTRUE) : (ONFALSE))
498#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
499 #define STK_ENDIAN_IDX_HI (0)
500 #define STK_ENDIAN_IDX_LO (1)
502 #define STK_ENDIAN_IDX_HI (1)
503 #define STK_ENDIAN_IDX_LO (0)
517#define STK_NONCOPYABLE_CLASS(TYPE)\
518 TYPE(const TYPE &) = delete;\
519 TYPE &operator=(const TYPE &) = delete;
530constexpr T
Min(T a, T b)
noexcept {
return (a < b) ? a : b; }
536constexpr T
Max(T a, T b)
noexcept {
return (a < b) ? b : a; }
void STK_ASSERT_HANDLER(const char *message, const char *file, int32_t line)
Namespace of STK package.
constexpr T Max(T a, T b) noexcept
Compile-time maximum of two values.
constexpr T Min(T a, T b) noexcept
Compile-time minimum of two values.
Internal utility namespace containing data structure helpers (linked lists, etc.) used by the kernel ...