23#define STK_WRAPPER_API_VERSION 20030000UL
24#define STK_WRAPPER_KERNEL_VERSION 20030000UL
25#define STK_WRAPPER_KERNEL_ID "STK RTOS2 Wrapper v1.0"
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)
234 return reinterpret_cast<osThreadId_t>(
static_cast<void *
>(
235 reinterpret_cast<StkThread *
>(
static_cast<uintptr_t
>(tid))));
275 explicit StkSemaphore(uint16_t initial, uint16_t max_count,
const char *n =
nullptr)
298 m_ef.SetTraceName(n);
362 const char *name, uint8_t *ext_storage)
363 :
m_mpool(static_cast<size_t>(cap),
364 static_cast<size_t>(raw_block_size),
366 cap *
stk::memory::BlockMemoryPool::AlignBlockSize(raw_block_size),
372 explicit StkMemPool(uint32_t cap, uint32_t raw_block_size,
const char *name)
373 :
m_mpool(static_cast<size_t>(cap),
374 static_cast<size_t>(raw_block_size),
411 explicit StkMessageQueue(uint32_t cap, uint32_t msz,
const char *name,uint8_t *ext_buf)
412 :
m_mq(ext_buf, static_cast<size_t>(cap), static_cast<size_t>(msz)),
415 m_mq.SetTraceName(name);
420 :
m_mq(
AllocBuffer(cap, msz), static_cast<size_t>(cap), static_cast<size_t>(msz)),
423 m_mq.SetTraceName(name);
430 delete[]
m_mq.GetBuffer();
436 uint8_t *
const ret =
new (std::nothrow) uint8_t[
static_cast<size_t>(cap) * msz];
456template <
typename T,
typename... Args>
461 if ((mem !=
nullptr) && (size >=
sizeof(T)))
463 obj =
new (mem) T(args...);
464 obj->m_cb_owned =
false;
468 obj =
new (std::nothrow) T(args...);
513 uint32_t cmsis_result;
517 cmsis_result = result;
567 if (version !=
nullptr)
573 if ((id_buf !=
nullptr) && (id_size > 0U))
576 size_t copy_len = id_size - 1U;
578 if (copy_len > id_len)
584 id_buf[copy_len] =
'\0';
781 result = (1000000U /
static_cast<uint32_t
>(res_us));
816 bool is_valid = (!is_irq && (func !=
nullptr) && (kernel_state !=
osKernelInactive));
820 if (is_valid && (attr !=
nullptr))
836 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
837 const uint32_t cb_size = ((attr !=
nullptr) ? attr->
cb_size : 0U);
844 th->
m_name = (attr !=
nullptr) ? attr->
name :
nullptr;
895 if (thread_id ==
nullptr)
901 result =
static_cast<StkThread *
>(thread_id)->m_name;
952 if (thread_id ==
nullptr)
969 if (thread_id ==
nullptr)
990 else if (thread_id ==
nullptr)
1054 else if (thread_id ==
nullptr)
1080 else if (thread_id ==
nullptr)
1117 else if (thread_id ==
nullptr)
1170 else if (thread_id ==
nullptr)
1243 if ((thread_id !=
nullptr) && !is_active)
1271 uint32_t count = 0U;
1278 count =
static_cast<uint32_t
>(
g_StkKernel.GetSwitchStrategy()->GetSize());
1286 uint32_t result_count = 0U;
1290 if ((kstate !=
osKernelInactive) && (thread_array !=
nullptr) && (array_items != 0U))
1294 reinterpret_cast<void *
>(thread_array));
1300 result_count =
static_cast<uint32_t
>(count);
1303 return result_count;
1314 if ((thread_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1332 if (self ==
nullptr)
1350 if (self ==
nullptr)
1356 result =
static_cast<StkThread *
>(self)->m_thread_flags.Get();
1373 if (self ==
nullptr)
1454 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1455 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1456 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1471 if (timer_id ==
nullptr)
1477 result =
static_cast<StkTimer *
>(timer_id)->m_name;
1491 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1502 const bool ok =
g_TimerHost->Restart(*tmr, ticks, period_ticks);
1517 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1542 if (timer_id ==
nullptr)
1562 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1604 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1605 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1606 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1619 if (ef_id ==
nullptr)
1625 result =
static_cast<StkEventFlags *
>(ef_id)->m_ef.GetTraceName();
1635 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1651 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1667 if (ef_id ==
nullptr)
1684 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1705 else if (ef_id ==
nullptr)
1736 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1737 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1738 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1761 if (mutex_id ==
nullptr)
1767 result =
static_cast<StkMutex *
>(mutex_id)->m_mutex.GetTraceName();
1781 else if (mutex_id ==
nullptr)
1812 else if (mutex_id ==
nullptr)
1818 static_cast<StkMutex *
>(mutex_id)->m_mutex.Unlock();
1829 if (mutex_id ==
nullptr)
1836 static_cast<StkMutex *
>(mutex_id)->m_mutex.GetOwner());
1850 else if (mutex_id ==
nullptr)
1873 if (
IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
1883 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1884 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1885 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1898 if (semaphore_id ==
nullptr)
1904 result =
static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.GetTraceName();
1914 if (semaphore_id ==
nullptr)
1945 if (semaphore_id ==
nullptr)
1951 static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.Signal();
1962 if (semaphore_id ==
nullptr)
1968 result =
static_cast<uint32_t
>(
1983 else if (semaphore_id ==
nullptr)
2008 if (
IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2014 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2015 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2016 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2017 void *
const mp_mem = ((attr !=
nullptr) ? attr->
mp_mem :
nullptr);
2018 const uint32_t mp_sz = ((attr !=
nullptr) ? attr->
mp_size : 0U);
2022 const uint32_t storage_required = (block_count * aligned_blk);
2026 if ((mp_mem !=
nullptr) && (mp_sz >= storage_required))
2030 block_count, block_size, name,
static_cast<uint8_t *
>(mp_mem));
2036 block_count, block_size, name);
2056 if (mp_id ==
nullptr)
2062 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetTraceName();
2072 if (mp_id ==
nullptr)
2093 if ((mp_id ==
nullptr) || (block ==
nullptr))
2097 else if (!
static_cast<StkMemPool *
>(mp_id)->m_mpool.Free(block))
2113 if (mp_id ==
nullptr)
2119 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetCapacity();
2129 if (mp_id ==
nullptr)
2145 if (mp_id ==
nullptr)
2151 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetUsedCount();
2161 if (mp_id ==
nullptr)
2167 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetFreeCount();
2181 else if (mp_id ==
nullptr)
2204 if (
IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
2211 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2212 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2213 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2214 void *
const ext_buf = ((attr !=
nullptr) ? attr->
mq_mem :
nullptr);
2215 const uint32_t ext_buf_size = ((attr !=
nullptr) ? attr->
mq_size : 0U);
2217 const uint32_t buf_required = (msg_count * msg_size);
2221 if ((ext_buf !=
nullptr) && (ext_buf_size >= buf_required))
2225 msg_count, msg_size, name,
static_cast<uint8_t *
>(ext_buf));
2231 msg_count, msg_size, name);
2254 if (mq_id ==
nullptr)
2267 uint8_t , uint32_t timeout)
2271 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2283 if (!
static_cast<StkMessageQueue *
>(mq_id)->m_mq.Put(msg_ptr, stk_timeout))
2297 uint8_t *msg_prio, uint32_t timeout)
2301 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2313 if (!
static_cast<StkMessageQueue *
>(mq_id)->m_mq.Get(msg_ptr, stk_timeout))
2319 if (msg_prio !=
nullptr)
2334 if (mq_id ==
nullptr)
2350 if (mq_id ==
nullptr)
2366 if (mq_id ==
nullptr)
2382 if (mq_id ==
nullptr)
2402 else if (mq_id ==
nullptr)
2423 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 __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_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 __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)
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
static __stk_forceinline osPriority_t StkPrioToCmsis(int32_t p)
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)
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 mode by the user task.
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
int64_t Ticks
Ticks value.
int32_t Timeout
Timeout time (ticks).
static constexpr T Max(T a, T b)
Compile-time maximum of two values.
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 Ticks GetTicks()
Get number of ticks elapsed since kernel start.
PlatformArmCortexM PlatformDefault
Default platform implementation.
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)
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 void Enter()
Enter a critical section.
static void Exit()
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.
bool Wait(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal.
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_ISR
Return sentinel: called from an ISR with a blocking timeout.
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.
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.
uint8_t * GetBuffer()
Get pointer to the message buffer.
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
bool TimedLock(Timeout timeout_ticks)
Acquire lock.
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.
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter).
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).
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.
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 hardware access mode of the user task.
void OnDeadlineMissed(uint32_t) override
Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time ...
StkMutex(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