23#define STK_WRAPPER_API_VERSION 20030000UL
24#define STK_WRAPPER_KERNEL_VERSION 20030000UL
25#define STK_WRAPPER_KERNEL_ID "STK RTOS2 Wrapper v1.1"
33#ifndef CMSIS_STK_MAX_THREADS
34#define CMSIS_STK_MAX_THREADS (16U)
38#ifndef CMSIS_STK_DEFAULT_STACK_WORDS
39#define CMSIS_STK_DEFAULT_STACK_WORDS (256U)
43#define CMSIS_STK_MIN_STACK_WORDS (STK_STACK_SIZE_MIN)
54 size_t total_len = 0U;
56 while (str[total_len] !=
'\0')
67extern "C" void free(
void *ptr);
91 result = ((
static_cast<int32_t
>(p) * 31) / 56);
99 int32_t r = (p * 56) / 31;
128 else if (ticks == 0U)
298 return reinterpret_cast<osThreadId_t>(
static_cast<void *
>(
299 reinterpret_cast<StkThread *
>(
static_cast<uintptr_t
>(tid))));
326#ifndef STK_CMSIS_USE_FAST_MUTEX
327#define STK_CMSIS_USE_FAST_MUTEX 1
411 explicit StkSemaphore(uint16_t initial, uint16_t max_count,
const char *n =
nullptr)
434 m_ef.SetTraceName(n);
498 const char *name, uint8_t *ext_storage)
499 :
m_mpool(static_cast<size_t>(cap),
500 static_cast<size_t>(raw_block_size),
502 cap *
stk::memory::BlockMemoryPool::AlignBlockSize(raw_block_size),
508 explicit StkMemPool(uint32_t cap, uint32_t raw_block_size,
const char *name)
509 :
m_mpool(static_cast<size_t>(cap),
510 static_cast<size_t>(raw_block_size),
547 explicit StkMessageQueue(uint32_t cap, uint32_t msz,
const char *name,uint8_t *ext_buf)
548 :
m_mq(ext_buf, static_cast<size_t>(cap), static_cast<size_t>(msz)),
551 m_mq.SetTraceName(name);
556 :
m_mq(
AllocBuffer(cap, msz), static_cast<size_t>(cap), static_cast<size_t>(msz)),
559 m_mq.SetTraceName(name);
566 delete[]
m_mq.GetBuffer();
572 uint8_t *
const ret =
new (std::nothrow) uint8_t[
static_cast<size_t>(cap) * msz];
592template <
typename T,
typename... Args>
597 if ((mem !=
nullptr) && (size >=
sizeof(T)))
599 obj =
new (mem) T(args...);
600 obj->m_cb_owned =
false;
604 obj =
new (std::nothrow) T(args...);
640 while (list !=
nullptr)
669 uint32_t cmsis_result;
673 cmsis_result = result;
729 if (version !=
nullptr)
735 if ((id_buf !=
nullptr) && (id_size > 0U))
738 size_t copy_len = id_size - 1U;
740 if (copy_len > id_len)
746 id_buf[copy_len] =
'\0';
943 result = (1000000U /
static_cast<uint32_t
>(res_us));
978 bool is_valid = (!is_irq && (func !=
nullptr) && (kernel_state !=
osKernelInactive));
982 if (is_valid && (attr !=
nullptr))
1001 if (is_valid && (attr !=
nullptr))
1015 stack_words = req_words;
1034 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1035 const uint32_t cb_size = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1042 th->
m_name = (attr !=
nullptr) ? attr->
name :
nullptr;
1046 if (stack_mem !=
nullptr)
1087 if (thread_id ==
nullptr)
1093 result =
static_cast<StkThread *
>(thread_id)->m_name;
1144 if (thread_id ==
nullptr)
1161 if (thread_id ==
nullptr)
1182 else if (thread_id ==
nullptr)
1246 else if (thread_id ==
nullptr)
1272 else if (thread_id ==
nullptr)
1309 else if (thread_id ==
nullptr)
1362 else if (thread_id ==
nullptr)
1374 bool destroy =
false;
1465 if ((thread_id !=
nullptr) && is_active)
1501 uint32_t count = 0U;
1515 count =
static_cast<uint32_t
>(
g_StkKernel.GetSwitchStrategy()->GetSize());
1523 uint32_t result_count = 0U;
1527 if ((kstate !=
osKernelInactive) && (thread_array !=
nullptr) && (array_items != 0U))
1537 reinterpret_cast<void *
>(thread_array));
1543 result_count =
static_cast<uint32_t
>(count);
1546 return result_count;
1557 if ((thread_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1575 if (self ==
nullptr)
1593 if (self ==
nullptr)
1599 result =
static_cast<StkThread *
>(self)->m_thread_flags.Get();
1616 if (self ==
nullptr)
1697 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1698 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1699 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1714 if (timer_id ==
nullptr)
1720 result =
static_cast<StkTimer *
>(timer_id)->m_name;
1734 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1745 const bool ok =
g_TimerHost->Restart(*tmr, ticks, period_ticks);
1760 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1785 if (timer_id ==
nullptr)
1805 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1847 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1848 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1849 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1862 if (ef_id ==
nullptr)
1868 result =
static_cast<StkEventFlags *
>(ef_id)->m_ef.GetTraceName();
1878 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1894 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1910 if (ef_id ==
nullptr)
1927 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1948 else if (ef_id ==
nullptr)
1981 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1982 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1983 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2015 if (mutex_id ==
nullptr)
2021 result =
static_cast<const StkMutexBase *
>(mutex_id)->GetTraceName();
2035 else if (mutex_id ==
nullptr)
2055 else if (mutex_id ==
nullptr)
2082 if (mutex_id ==
nullptr)
2102 else if (mutex_id ==
nullptr)
2124 if (
IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
2134 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2135 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2136 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2149 if (semaphore_id ==
nullptr)
2155 result =
static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.GetTraceName();
2165 if (semaphore_id ==
nullptr)
2188 if (semaphore_id ==
nullptr)
2194 static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.Signal();
2205 if (semaphore_id ==
nullptr)
2211 result =
static_cast<uint32_t
>(
2226 else if (semaphore_id ==
nullptr)
2251 if (
IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2257 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2258 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2259 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2260 void *
const mp_mem = ((attr !=
nullptr) ? attr->
mp_mem :
nullptr);
2261 const uint32_t mp_sz = ((attr !=
nullptr) ? attr->
mp_size : 0U);
2265 const uint32_t storage_required = (block_count * aligned_blk);
2269 if ((mp_mem !=
nullptr) && (mp_sz >= storage_required))
2273 block_count, block_size, name,
static_cast<uint8_t *
>(mp_mem));
2279 block_count, block_size, name);
2299 if (mp_id ==
nullptr)
2305 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetTraceName();
2315 if (mp_id ==
nullptr)
2336 if ((mp_id ==
nullptr) || (block ==
nullptr))
2340 else if (!
static_cast<StkMemPool *
>(mp_id)->m_mpool.Free(block))
2356 if (mp_id ==
nullptr)
2362 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetCapacity();
2372 if (mp_id ==
nullptr)
2388 if (mp_id ==
nullptr)
2394 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetUsedCount();
2404 if (mp_id ==
nullptr)
2410 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetFreeCount();
2424 else if (mp_id ==
nullptr)
2447 if (
IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
2454 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2455 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2456 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2457 void *
const ext_buf = ((attr !=
nullptr) ? attr->
mq_mem :
nullptr);
2458 const uint32_t ext_buf_size = ((attr !=
nullptr) ? attr->
mq_size : 0U);
2460 const uint32_t buf_required = (msg_count * msg_size);
2464 if ((ext_buf !=
nullptr) && (ext_buf_size >= buf_required))
2468 msg_count, msg_size, name,
static_cast<uint8_t *
>(ext_buf));
2474 msg_count, msg_size, name);
2497 if (mq_id ==
nullptr)
2510 uint8_t , uint32_t timeout)
2514 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2527 static_cast<StkMessageQueue *
>(mq_id)->m_mq.PutEx(msg_ptr, stk_timeout), stk_timeout);
2534 uint8_t *msg_prio, uint32_t timeout)
2538 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2551 static_cast<StkMessageQueue *
>(mq_id)->m_mq.GetEx(msg_ptr, stk_timeout), stk_timeout);
2553 if ((result ==
osOK) && (msg_prio !=
nullptr))
2566 if (mq_id ==
nullptr)
2582 if (mq_id ==
nullptr)
2598 if (mq_id ==
nullptr)
2614 if (mq_id ==
nullptr)
2634 else if (mq_id ==
nullptr)
2655 else if (mq_id ==
nullptr)
Collection of memory-related primitives (stk::memory namespace).
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
static void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
Implementation of STK_MEMCPY.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Collection of synchronization primitives (stk::sync namespace).
Collection of time-related primitives (stk::time namespace).
static constexpr size_t StkGetWordCountForType()
void * malloc(size_t size)
CMSIS RTOS2 interface for SuperTinyKernel RTOS.
static size_t CmsisStrlen(const char str[])
stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS,(16U), stk::SwitchStrategyFP32, stk::PlatformDefault > StkKernel
static uint32_t g_StkKernelLocked
static StkKernel g_StkKernel
static StkThread * g_ZombieThreads
static __stk_forceinline bool IsIrqContext()
static __stk_forceinline uint32_t StkFlagsResultToCmsis(uint32_t result)
static stk::time::TimerHost * g_TimerHost
static constexpr size_t StkGetWordCountForType()
#define CMSIS_STK_MIN_STACK_WORDS
#define CMSIS_STK_MAX_THREADS
static stk::Word g_TimerHostBuf[StkGetWordCountForType< stk::time::TimerHost >()]
static __stk_forceinline stk::Timeout CmsisTimeoutToStk(uint32_t ticks)
static void StkReapZombieThreads()
static __stk_forceinline osStatus_t StkWaitResultToCmsis(stk::EWaitResult wr, stk::Timeout timeout)
void * malloc(size_t size)
static void ObjDestroy(T *obj)
#define CMSIS_STK_DEFAULT_STACK_WORDS
#define STK_WRAPPER_KERNEL_VERSION
#define STK_WRAPPER_KERNEL_ID
#define STK_CMSIS_USE_FAST_MUTEX
static __stk_forceinline osPriority_t StkPrioToCmsis(int32_t p)
static __stk_forceinline osStatus_t StkWaitFailToCmsis(stk::Timeout timeout)
static __stk_forceinline uint32_t CmsisFlagsOptionsToStk(uint32_t options)
static __stk_forceinline int32_t CmsisPrioToStk(osPriority_t p)
static T * PlacementNewOrHeap(void *mem, size_t size, const Args &... args)
#define STK_WRAPPER_API_VERSION
#define osFlagsError
Error indicator.
uint32_t osMemoryPoolGetSpace(osMemoryPoolId_t mp_id)
osKernelState_t
Kernel state.
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
osPriority_t osThreadGetPriority(osThreadId_t thread_id)
const char * osMutexGetName(osMutexId_t mutex_id)
void * osMessageQueueId_t
#define osThreadJoinable
Thread created in joinable mode.
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
#define osFlagsErrorTimeout
osErrorTimeout (-2).
osStatus_t osThreadTerminate(osThreadId_t thread_id)
uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
#define osFlagsErrorUnknown
osError (-1).
osStatus_t osDelayUntil(uint32_t ticks)
osStatus_t osThreadResume(osThreadId_t thread_id)
osStatus_t osThreadJoin(osThreadId_t thread_id)
osKernelState_t osKernelGetState(void)
osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
uint32_t osThreadGetCount(void)
osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr)
uint64_t osKernelGetSysTimerCount64(void)
uint32_t osKernelGetSysTimerFreq(void)
uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
uint32_t osThreadEnumerate(osThreadId_t *thread_array, uint32_t array_items)
const char * osEventFlagsGetName(osEventFlagsId_t ef_id)
uint32_t osThreadFlagsClear(uint32_t flags)
#define osMutexRecursive
Recursive mutex.
uint32_t osTimerIsRunning(osTimerId_t timer_id)
uint32_t osMessageQueueGetCount(osMessageQueueId_t mq_id)
osStatus_t
Status code values returned by CMSIS-RTOS functions.
osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
void osThreadExit(void)
Terminate execution of current running thread.
void(* osTimerFunc_t)(void *argument)
Timer callback function.
const char * osTimerGetName(osTimerId_t timer_id)
uint32_t osKernelGetTickFreq(void)
osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
uint32_t osKernelGetTickCount(void)
uint32_t osThreadFlagsGet(void)
osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
#define osFlagsWaitAll
Wait for all flags.
uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
osStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id)
void osKernelResume(uint32_t sleep_ticks)
osThreadId_t osThreadGetId(void)
void * osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout)
void(* osThreadFunc_t)(void *argument)
Entry point of a thread.
uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
int32_t osKernelLock(void)
const char * osSemaphoreGetName(osSemaphoreId_t semaphore_id)
uint32_t osMemoryPoolGetCount(osMemoryPoolId_t mp_id)
uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t mq_id)
osStatus_t osKernelStart(void)
uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
#define osFlagsErrorParameter
osErrorParameter (-4).
osStatus_t osThreadSuspend(osThreadId_t thread_id)
osStatus_t osThreadDetach(osThreadId_t thread_id)
#define osFlagsNoClear
Do not clear flags which have been specified to wait for.
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
uint32_t osMemoryPoolGetBlockSize(osMemoryPoolId_t mp_id)
const char * osMemoryPoolGetName(osMemoryPoolId_t mp_id)
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
osMutexId_t osMutexNew(const osMutexAttr_t *attr)
uint32_t osThreadGetStackSize(osThreadId_t thread_id)
osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id)
osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block)
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
osStatus_t osTimerStop(osTimerId_t timer_id)
osStatus_t osMutexDelete(osMutexId_t mutex_id)
uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
uint32_t osMessageQueueGetCapacity(osMessageQueueId_t mq_id)
const char * osThreadGetName(osThreadId_t thread_id)
osStatus_t osMessageQueueReset(osMessageQueueId_t mq_id)
osThreadState_t osThreadGetState(osThreadId_t thread_id)
osStatus_t osTimerDelete(osTimerId_t timer_id)
osStatus_t osThreadYield(void)
osThreadState_t
Thread state.
osPriority_t
Priority values.
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
uint32_t osMemoryPoolGetCapacity(osMemoryPoolId_t mp_id)
osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
uint32_t osMessageQueueGetSpace(osMessageQueueId_t mq_id)
uint32_t osKernelGetSysTimerCount(void)
uint32_t osKernelSuspend(void)
const char * osMessageQueueGetName(osMessageQueueId_t mq_id)
int32_t osKernelRestoreLock(int32_t lock)
osStatus_t osKernelInitialize(void)
#define osFlagsErrorISR
osErrorISR (-6).
osStatus_t osMutexRelease(osMutexId_t mutex_id)
#define osMutexRobust
Robust mutex.
int32_t osKernelUnlock(void)
osStatus_t osDelay(uint32_t ticks)
@ osKernelSuspended
Suspended.
@ osKernelRunning
Running.
@ osKernelInactive
Inactive.
@ osErrorISR
Not allowed in ISR context: the function cannot be called from interrupt service routines.
@ osErrorResource
Resource not available.
@ osErrorTimeout
Operation not completed within the timeout period.
@ osOK
Operation completed successfully.
@ osError
Unspecified RTOS error: run-time error but no other error message fits.
@ osErrorParameter
Parameter error.
@ osTimerPeriodic
Repeating timer.
@ osThreadBlocked
Blocked.
@ osThreadRunning
Running.
@ osPriorityISR
Reserved for ISR deferred thread.
@ osPriorityNormal
Priority: normal.
@ osPriorityIdle
Reserved for Idle thread.
@ osPriorityNone
No priority (not initialized).
@ osPriorityError
System cannot determine priority or illegal priority.
Namespace of STK package.
uintptr_t Word
Native processor word type.
static void Yield()
Notify scheduler to switch to the next runnable task.
SwitchStrategyFixedPriority< 32 > SwitchStrategyFP32
Shorthand alias for SwitchStrategyFixedPriority<32>: 32 priority levels (0..31), using a single 32-bi...
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
EAccessMode
Hardware access modes by the task.
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
EWaitResult
Wait result (see IKernelService::Wait).
@ WAIT_RESULT_FAIL
IKernelService::Wait returned with error without waiting.
@ WAIT_RESULT_CANCELED
The wait was cancelled by another task via IKernel::CancelTaskWait(), independent of signal/timeout.
@ WAIT_RESULT_TIMEOUT
The wake was caused by a timeout expiry.
@ WAIT_RESULT_SIGNAL
The wake was caused by a signal.
int64_t Ticks
Ticks value.
int32_t Timeout
Timeout time (ticks).
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
static constexpr T Max(T a, T b) noexcept
Compile-time maximum of two values.
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
PlatformArmCortexM PlatformDefault
Default platform implementation.
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
static TId GetTid()
Get task/thread Id of the calling task.
static constexpr T Min(T a, T b) noexcept
Compile-time minimum of two values.
static Cycles GetSysTimerCount()
Get system timer count value.
Word TId
Task (thread) id.
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
@ KERNEL_SYNC
Synchronization support (see Event).
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
static void Free(void *ptr) __stk_weak
Free the memory chunk.
static void * Allocate(size_t size) __stk_weak
Allocate the memory chunk.
Fixed-size block allocator with O(1) alloc/free and proper task-blocking semantics.
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
static constexpr size_t AlignBlockSize(size_t raw_size)
Round a raw block size up to the nearest multiple of BLOCK_ALIGN.
size_t GetBlockSize() const
Get the aligned block size used internally by the allocator.
Concrete implementation of IKernel.
static Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.
Lightweight, non-owning view over a contiguous sequence of elements.
virtual size_t GetStackSpace() const
Get available stack space.
Interface for a user task.
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
@ KSTATE_READY
Ready to start, IKernel::Start() must be called.
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual void Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.
virtual Timeout Suspend()=0
Suspend scheduling.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Condition Variable primitive for signaling between tasks based on specific predicates.
EWaitResult WaitEx(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal, preserving the full wait outcome.
32-bit event flags group for multi-flag synchronization between tasks.
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout_ticks=WAIT_INFINITE)
Wait for one or more flags to be set.
static const uint32_t ERROR_CANCELED
Return sentinel: the wait was cancelled via IKernel::CancelTaskWait() before the flag condition was m...
static const uint32_t ERROR_ISR
Return sentinel: called from an ISR with a blocking timeout.
static const uint32_t ERROR_FAIL
Return sentinel: the kernel rejected the wait (IKernelService::Wait() returned WAIT_RESULT_FAIL,...
static const uint32_t ERROR_TIMEOUT
Return sentinel: wait timed out before the flags condition was met.
static bool IsError(uint32_t result)
Checks if a return value from Set(), Clear(), or Wait() is an error.
static const uint32_t OPT_NO_CLEAR
Do not clear matched flags after a successful wait.
static const uint32_t ERROR_PARAMETER
Return sentinel: invalid flags argument (bit 31 set).
static const uint32_t OPT_WAIT_ALL
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
uint32_t Clear(uint32_t flags)
Clear one or more flags.
static const uint32_t OPT_WAIT_ANY
Wait for ANY of the specified flags to be set (OR semantics, default).
uint32_t Set(uint32_t flags)
Set one or more flags.
Non-recursive (binary) mutex primitive with ownership tracking.
Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.
size_t GetCapacity() const
Get the maximum number of messages the queue can hold.
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
size_t GetMsgSize() const
Get the size of each message in bytes.
size_t GetSpace() const
Get the number of free slots currently available.
size_t GetCount() const
Get the current number of messages in the queue.
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
Counting semaphore primitive for resource management and signaling.
uint16_t GetCount() const
Get current counter value.
static const uint16_t COUNT_MAX
Max count value supported.
EWaitResult WaitEx(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter), preserving the full wait outcome.
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...
Abstract base class for a timer managed by TimerHost.
bool IsActive() const
Check whether the timer is currently active.
uint32_t api
API version (major.minor.rev: mmnnnrrrr dec).
uint32_t kernel
Kernel version (major.minor.rev: mmnnnrrrr dec).
Attributes structure for thread.
void * cb_mem
memory for control block
uint32_t attr_bits
attribute bits
uint32_t cb_size
size of provided memory for control block
void * stack_mem
memory for stack
osPriority_t priority
initial thread priority (default: osPriorityNormal)
uint32_t stack_size
size of stack
const char * name
name of the thread
Attributes structure for timer.
void * cb_mem
memory for control block
const char * name
name of the timer
uint32_t cb_size
size of provided memory for control block
Attributes structure for event flags.
uint32_t cb_size
size of provided memory for control block
const char * name
name of the event flags
void * cb_mem
memory for control block
Attributes structure for mutex.
uint32_t cb_size
size of provided memory for control block
uint32_t attr_bits
attribute bits
const char * name
name of the mutex
void * cb_mem
memory for control block
Attributes structure for semaphore.
const char * name
name of the semaphore
uint32_t cb_size
size of provided memory for control block
void * cb_mem
memory for control block
Attributes structure for memory pool.
uint32_t mp_size
size of provided memory for data storage
const char * name
name of the memory pool
void * cb_mem
memory for control block
uint32_t cb_size
size of provided memory for control block
void * mp_mem
memory for data storage
Attributes structure for message queue.
const char * name
name of the message queue
void * cb_mem
memory for control block
uint32_t mq_size
size of provided memory for data storage
uint32_t cb_size
size of provided memory for control block
void * mq_mem
memory for data storage
const stk::Word * GetStack() const override
Get pointer to the stack memory.
int32_t GetWeight() const override
Get static base weight of the task.
void OnExit() override
Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
STK_NONCOPYABLE_CLASS(StkThread)
const char * GetTraceName() const override
Get task trace name set by application.
volatile JoinState m_join_state
static osThreadId_t ConvertTIdToThreadId(const stk::TId tid)
size_t GetStackSize() const override
Get number of elements of the stack memory array.
stk::sync::EventFlags m_thread_flags
void Run() override
Entry point of the user task.
stk::sync::ConditionVariable m_join_cv
volatile int32_t m_stk_priority
stk::EAccessMode GetAccessMode() const override
Get pointer to the stack memory.
void OnDeadlineMissed(uint32_t) override
Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time ...
virtual stk::TId GetOwner() const =0
virtual osStatus_t Acquire(stk::Timeout timeout)=0
virtual const char * GetTraceName() const =0
StkMutex(const char *n=nullptr)
stk::TId GetOwner() const override
osStatus_t Acquire(stk::Timeout timeout) override
const char * GetTraceName() const override
osStatus_t Acquire(stk::Timeout timeout) override
const char * GetTraceName() const override
stk::TId GetOwner() const override
stk::sync::FastMutex m_mutex
StkFastMutex(const char *n=nullptr)
stk::sync::Semaphore m_semaphore
StkSemaphore(uint16_t initial, uint16_t max_count, const char *n=nullptr)
stk::sync::EventFlags m_ef
StkEventFlags(const char *n=nullptr)
STK_NONCOPYABLE_CLASS(StkTimer)
static void EnsureTimerHostCreated()
void OnExpired(stk::time::TimerHost *) override
Callback invoked by the handler task when this timer expires.
virtual ~StkTimer()=default
StkTimer(osTimerFunc_t const func, osTimerType_t tt, void *arg, const char *name)
StkMemPool(uint32_t cap, uint32_t raw_block_size, const char *name)
STK_NONCOPYABLE_CLASS(StkMemPool)
stk::memory::BlockMemoryPool m_mpool
StkMemPool(uint32_t cap, uint32_t raw_block_size, const char *name, uint8_t *ext_storage)
StkMessageQueue(uint32_t cap, uint32_t msz, const char *name, uint8_t *ext_buf)
StkMessageQueue(uint32_t cap, uint32_t msz, const char *name)
static uint8_t * AllocBuffer(uint32_t cap, uint32_t msz)
STK_NONCOPYABLE_CLASS(StkMessageQueue)
stk::sync::MessageQueue m_mq