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)
233 return reinterpret_cast<osThreadId_t>(
static_cast<void *
>(
234 reinterpret_cast<StkThread *
>(
static_cast<uintptr_t
>(tid))));
274 explicit StkSemaphore(uint16_t initial, uint16_t max_count,
const char *n =
nullptr)
297 m_ef.SetTraceName(n);
361 const char *name, uint8_t *ext_storage)
362 :
m_mpool(static_cast<size_t>(cap),
363 static_cast<size_t>(raw_block_size),
365 cap *
stk::memory::BlockMemoryPool::AlignBlockSize(raw_block_size),
371 explicit StkMemPool(uint32_t cap, uint32_t raw_block_size,
const char *name)
372 :
m_mpool(static_cast<size_t>(cap),
373 static_cast<size_t>(raw_block_size),
410 explicit StkMessageQueue(uint32_t cap, uint32_t msz,
const char *name,uint8_t *ext_buf)
411 :
m_mq(ext_buf, static_cast<size_t>(cap), static_cast<size_t>(msz)),
414 m_mq.SetTraceName(name);
419 :
m_mq(
AllocBuffer(cap, msz), static_cast<size_t>(cap), static_cast<size_t>(msz)),
422 m_mq.SetTraceName(name);
429 delete[]
m_mq.GetBuffer();
435 uint8_t *
const ret =
new (std::nothrow) uint8_t[
static_cast<size_t>(cap) * msz];
455template <
typename T,
typename... Args>
460 if ((mem !=
nullptr) && (size >=
sizeof(T)))
462 obj =
new (mem) T(args...);
463 obj->m_cb_owned =
false;
467 obj =
new (std::nothrow) T(args...);
512 uint32_t cmsis_result;
516 cmsis_result = result;
566 if (version !=
nullptr)
572 if ((id_buf !=
nullptr) && (id_size > 0U))
575 size_t copy_len = id_size - 1U;
577 if (copy_len > id_len)
583 id_buf[copy_len] =
'\0';
780 result = (1000000U /
static_cast<uint32_t
>(res_us));
815 bool is_valid = (!is_irq && (func !=
nullptr) && (kernel_state !=
osKernelInactive));
819 if (is_valid && (attr !=
nullptr))
835 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
836 const uint32_t cb_size = ((attr !=
nullptr) ? attr->
cb_size : 0U);
843 th->
m_name = (attr !=
nullptr) ? attr->
name :
nullptr;
894 if (thread_id ==
nullptr)
900 result =
static_cast<StkThread *
>(thread_id)->m_name;
951 if (thread_id ==
nullptr)
968 if (thread_id ==
nullptr)
989 else if (thread_id ==
nullptr)
1053 else if (thread_id ==
nullptr)
1079 else if (thread_id ==
nullptr)
1116 else if (thread_id ==
nullptr)
1169 else if (thread_id ==
nullptr)
1242 if ((thread_id !=
nullptr) && !is_active)
1270 uint32_t count = 0U;
1277 count =
static_cast<uint32_t
>(
g_StkKernel.GetSwitchStrategy()->GetSize());
1285 uint32_t result_count = 0U;
1289 if ((kstate !=
osKernelInactive) && (thread_array !=
nullptr) && (array_items != 0U))
1293 reinterpret_cast<void *
>(thread_array));
1299 result_count =
static_cast<uint32_t
>(count);
1302 return result_count;
1313 if ((thread_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1331 if (self ==
nullptr)
1349 if (self ==
nullptr)
1355 result =
static_cast<StkThread *
>(self)->m_thread_flags.Get();
1372 if (self ==
nullptr)
1453 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1454 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1455 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1470 if (timer_id ==
nullptr)
1476 result =
static_cast<StkTimer *
>(timer_id)->m_name;
1490 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1501 const bool ok =
g_TimerHost->Restart(*tmr, ticks, period_ticks);
1516 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1541 if (timer_id ==
nullptr)
1561 else if ((timer_id ==
nullptr) || (
g_TimerHost ==
nullptr))
1603 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1604 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1605 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1618 if (ef_id ==
nullptr)
1624 result =
static_cast<StkEventFlags *
>(ef_id)->m_ef.GetTraceName();
1634 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1650 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1666 if (ef_id ==
nullptr)
1683 if ((ef_id ==
nullptr) || ((flags &
osFlagsError) != 0U))
1704 else if (ef_id ==
nullptr)
1735 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1736 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1737 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1760 if (mutex_id ==
nullptr)
1766 result =
static_cast<StkMutex *
>(mutex_id)->m_mutex.GetTraceName();
1780 else if (mutex_id ==
nullptr)
1811 else if (mutex_id ==
nullptr)
1817 static_cast<StkMutex *
>(mutex_id)->m_mutex.Unlock();
1828 if (mutex_id ==
nullptr)
1835 static_cast<StkMutex *
>(mutex_id)->m_mutex.GetOwner());
1849 else if (mutex_id ==
nullptr)
1872 if (
IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
1882 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
1883 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
1884 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
1897 if (semaphore_id ==
nullptr)
1903 result =
static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.GetTraceName();
1913 if (semaphore_id ==
nullptr)
1944 if (semaphore_id ==
nullptr)
1950 static_cast<StkSemaphore *
>(semaphore_id)->m_semaphore.Signal();
1961 if (semaphore_id ==
nullptr)
1967 result =
static_cast<uint32_t
>(
1982 else if (semaphore_id ==
nullptr)
2007 if (
IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2013 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2014 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2015 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2016 void *
const mp_mem = ((attr !=
nullptr) ? attr->
mp_mem :
nullptr);
2017 const uint32_t mp_sz = ((attr !=
nullptr) ? attr->
mp_size : 0U);
2021 const uint32_t storage_required = (block_count * aligned_blk);
2025 if ((mp_mem !=
nullptr) && (mp_sz >= storage_required))
2029 block_count, block_size, name,
static_cast<uint8_t *
>(mp_mem));
2035 block_count, block_size, name);
2055 if (mp_id ==
nullptr)
2061 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetTraceName();
2071 if (mp_id ==
nullptr)
2092 if ((mp_id ==
nullptr) || (block ==
nullptr))
2096 else if (!
static_cast<StkMemPool *
>(mp_id)->m_mpool.Free(block))
2112 if (mp_id ==
nullptr)
2118 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetCapacity();
2128 if (mp_id ==
nullptr)
2144 if (mp_id ==
nullptr)
2150 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetUsedCount();
2160 if (mp_id ==
nullptr)
2166 result =
static_cast<StkMemPool *
>(mp_id)->m_mpool.GetFreeCount();
2180 else if (mp_id ==
nullptr)
2203 if (
IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
2210 const char *
const name = ((attr !=
nullptr) ? attr->
name :
nullptr);
2211 void *
const cb_mem = ((attr !=
nullptr) ? attr->
cb_mem :
nullptr);
2212 const uint32_t cb_sz = ((attr !=
nullptr) ? attr->
cb_size : 0U);
2213 void *
const ext_buf = ((attr !=
nullptr) ? attr->
mq_mem :
nullptr);
2214 const uint32_t ext_buf_size = ((attr !=
nullptr) ? attr->
mq_size : 0U);
2216 const uint32_t buf_required = (msg_count * msg_size);
2220 if ((ext_buf !=
nullptr) && (ext_buf_size >= buf_required))
2224 msg_count, msg_size, name,
static_cast<uint8_t *
>(ext_buf));
2230 msg_count, msg_size, name);
2253 if (mq_id ==
nullptr)
2266 uint8_t , uint32_t timeout)
2270 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2282 if (!
static_cast<StkMessageQueue *
>(mq_id)->m_mq.Put(msg_ptr, stk_timeout))
2296 uint8_t *msg_prio, uint32_t timeout)
2300 if ((mq_id ==
nullptr) || (msg_ptr ==
nullptr))
2312 if (!
static_cast<StkMessageQueue *
>(mq_id)->m_mq.Get(msg_ptr, stk_timeout))
2318 if (msg_prio !=
nullptr)
2333 if (mq_id ==
nullptr)
2349 if (mq_id ==
nullptr)
2365 if (mq_id ==
nullptr)
2381 if (mq_id ==
nullptr)
2401 else if (mq_id ==
nullptr)
2422 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 modes by the 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).
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