SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
cmsis_os2_stk.cpp File Reference
#include "cmsis_os2.h"
#include <cstring>
#include <cstdlib>
#include <new>
#include <stdint.h>
#include "stk.h"
#include "sync/stk_sync.h"
#include "time/stk_time.h"
#include "memory/stk_memory.h"
Include dependency graph for cmsis_os2_stk.cpp:

Go to the source code of this file.

Classes

struct  StkThread
struct  StkMutex
struct  StkSemaphore
struct  StkEventFlags
struct  StkTimer
class  StkMemPool
struct  StkMessageQueue

Macros

#define STK_WRAPPER_API_VERSION   20030000UL
#define STK_WRAPPER_KERNEL_VERSION   20030000UL
#define STK_WRAPPER_KERNEL_ID   "STK RTOS2 Wrapper v1.0"
#define CMSIS_STK_MAX_THREADS   16U
#define CMSIS_STK_DEFAULT_STACK_WORDS   256U
#define CMSIS_STK_MIN_STACK_WORDS   STK_STACK_SIZE_MIN

Typedefs

using StkKernel

Functions

template<typename T>
static constexpr size_t StkGetWordCountForType ()
static __stk_forceinline int32_t CmsisPrioToStk (osPriority_t p)
static __stk_forceinline osPriority_t StkPrioToCmsis (int32_t p)
static __stk_forceinline stk::Timeout CmsisTimeoutToStk (uint32_t ticks)
static __stk_forceinline bool IsIrqContext ()
template<typename T, typename... Args>
static T * PlacementNewOrHeap (void *cb_mem, size_t cb_size, Args &&...args)
template<typename T>
static void ObjDestroy (T *obj)
static __stk_forceinline uint32_t CmsisFlagsOptionsToStk (uint32_t options)
static __stk_forceinline uint32_t StkFlagsResultToCmsis (uint32_t result)
osStatus_t osKernelInitialize (void)
osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size)
osKernelState_t osKernelGetState (void)
osStatus_t osKernelStart (void)
int32_t osKernelLock (void)
int32_t osKernelUnlock (void)
int32_t osKernelRestoreLock (int32_t lock)
uint32_t osKernelSuspend (void)
void osKernelResume (uint32_t sleep_ticks)
uint32_t osKernelGetTickCount (void)
uint32_t osKernelGetTickFreq (void)
uint32_t osKernelGetSysTimerCount (void)
uint64_t osKernelGetSysTimerCount64 (void)
uint32_t osKernelGetSysTimerFreq (void)
osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
const char * osThreadGetName (osThreadId_t thread_id)
osThreadId_t osThreadGetId (void)
osThreadState_t osThreadGetState (osThreadId_t thread_id)
uint32_t osThreadGetStackSize (osThreadId_t thread_id)
uint32_t osThreadGetStackSpace (osThreadId_t thread_id)
osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority)
osPriority_t osThreadGetPriority (osThreadId_t thread_id)
osStatus_t osThreadYield (void)
osStatus_t osThreadSuspend (osThreadId_t thread_id)
osStatus_t osThreadResume (osThreadId_t thread_id)
osStatus_t osThreadDetach (osThreadId_t thread_id)
osStatus_t osThreadJoin (osThreadId_t thread_id)
void osThreadExit (void)
 Terminate execution of current running thread.
osStatus_t osThreadTerminate (osThreadId_t thread_id)
uint32_t osThreadGetCount (void)
uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items)
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags)
uint32_t osThreadFlagsClear (uint32_t flags)
uint32_t osThreadFlagsGet (void)
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)
osStatus_t osDelay (uint32_t ticks)
osStatus_t osDelayUntil (uint32_t ticks)
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
const char * osTimerGetName (osTimerId_t timer_id)
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks)
osStatus_t osTimerStop (osTimerId_t timer_id)
uint32_t osTimerIsRunning (osTimerId_t timer_id)
osStatus_t osTimerDelete (osTimerId_t timer_id)
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr)
const char * osEventFlagsGetName (osEventFlagsId_t ef_id)
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags)
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id)
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)
osMutexId_t osMutexNew (const osMutexAttr_t *attr)
const char * osMutexGetName (osMutexId_t mutex_id)
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout)
osStatus_t osMutexRelease (osMutexId_t mutex_id)
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id)
osStatus_t osMutexDelete (osMutexId_t mutex_id)
osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
const char * osSemaphoreGetName (osSemaphoreId_t semaphore_id)
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)
osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id)
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id)
osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id)
osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr)
const char * osMemoryPoolGetName (osMemoryPoolId_t mp_id)
void * osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout)
osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block)
uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id)
osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id)
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
const char * osMessageQueueGetName (osMessageQueueId_t mq_id)
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t, uint32_t timeout)
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id)
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id)
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id)

Variables

static StkKernel g_StkKernel
static uint32_t g_StkKernelLocked = 0
static stk::time::TimerHostg_TimerHost = nullptr
static stk::Word g_TimerHostBuf [StkGetWordCountForType< stk::time::TimerHost >()]

Macro Definition Documentation

◆ CMSIS_STK_DEFAULT_STACK_WORDS

#define CMSIS_STK_DEFAULT_STACK_WORDS   256U

Definition at line 81 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew().

◆ CMSIS_STK_MAX_THREADS

#define CMSIS_STK_MAX_THREADS   16U

Definition at line 76 of file cmsis_os2_stk.cpp.

◆ CMSIS_STK_MIN_STACK_WORDS

#define CMSIS_STK_MIN_STACK_WORDS   STK_STACK_SIZE_MIN

Definition at line 85 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew().

◆ STK_WRAPPER_API_VERSION

#define STK_WRAPPER_API_VERSION   20030000UL

Definition at line 65 of file cmsis_os2_stk.cpp.

Referenced by osKernelGetInfo().

◆ STK_WRAPPER_KERNEL_ID

#define STK_WRAPPER_KERNEL_ID   "STK RTOS2 Wrapper v1.0"

Definition at line 67 of file cmsis_os2_stk.cpp.

Referenced by osKernelGetInfo().

◆ STK_WRAPPER_KERNEL_VERSION

#define STK_WRAPPER_KERNEL_VERSION   20030000UL

Definition at line 66 of file cmsis_os2_stk.cpp.

Referenced by osKernelGetInfo().

Typedef Documentation

◆ StkKernel

using StkKernel
Initial value:
SwitchStrategyFixedPriority< 32 > SwitchStrategyFP32
Shorthand alias for SwitchStrategyFixedPriority<32>: 32 priority levels (0..31), using a single 32-bi...
PlatformArmCortexM PlatformDefault
Default platform implementation.
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:44
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Definition stk_common.h:42
Concrete implementation of IKernel.
Definition stk.h:81

Definition at line 151 of file cmsis_os2_stk.cpp.

Function Documentation

◆ CmsisFlagsOptionsToStk()

__stk_forceinline uint32_t CmsisFlagsOptionsToStk ( uint32_t options)
static

Definition at line 471 of file cmsis_os2_stk.cpp.

472{
473 uint32_t stk_opts = stk::sync::EventFlags::OPT_WAIT_ANY; // default
474
475 if (options & osFlagsWaitAll)
477
478 if (options & osFlagsNoClear)
480
481 return stk_opts;
482}
#define osFlagsWaitAll
Wait for all flags.
Definition cmsis_os2.h:205
#define osFlagsNoClear
Do not clear flags which have been specified to wait for.
Definition cmsis_os2.h:206
static const uint32_t OPT_NO_CLEAR
Do not clear matched flags after a successful wait.
static const uint32_t OPT_WAIT_ALL
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
static const uint32_t OPT_WAIT_ANY
Wait for ANY of the specified flags to be set (OR semantics, default).

References __stk_forceinline, stk::sync::EventFlags::OPT_NO_CLEAR, stk::sync::EventFlags::OPT_WAIT_ALL, stk::sync::EventFlags::OPT_WAIT_ANY, osFlagsNoClear, and osFlagsWaitAll.

Referenced by osEventFlagsWait(), and osThreadFlagsWait().

Here is the caller graph for this function:

◆ CmsisPrioToStk()

__stk_forceinline int32_t CmsisPrioToStk ( osPriority_t p)
static

Definition at line 99 of file cmsis_os2_stk.cpp.

100{
101 if (p <= osPriorityIdle)
102 return 0;
103 if (p >= osPriorityISR)
104 return 31;
105
106 return (static_cast<int32_t>(p) * 31) / 56;
107}
@ osPriorityISR
Reserved for ISR deferred thread.
Definition cmsis_os2.h:183
@ osPriorityIdle
Reserved for Idle thread.
Definition cmsis_os2.h:134

References __stk_forceinline, osPriorityIdle, and osPriorityISR.

Referenced by osThreadNew(), osThreadSetPriority(), and StkThread::StkThread().

Here is the caller graph for this function:

◆ CmsisTimeoutToStk()

__stk_forceinline stk::Timeout CmsisTimeoutToStk ( uint32_t ticks)
static

Definition at line 128 of file cmsis_os2_stk.cpp.

129{
130 if (ticks > stk::WAIT_INFINITE)
131 return stk::WAIT_INFINITE;
132
133 if (ticks == 0U)
134 return stk::NO_WAIT;
135
136 // CMSIS ticks are kernel ticks – pass through directly as STK ticks
137 return static_cast<stk::Timeout>(ticks);
138}
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:177
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:123
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:171

References __stk_forceinline, stk::NO_WAIT, and stk::WAIT_INFINITE.

Referenced by osDelay(), osEventFlagsWait(), osMemoryPoolAlloc(), osMessageQueueGet(), osMessageQueuePut(), osMutexAcquire(), osSemaphoreAcquire(), and osThreadFlagsWait().

Here is the caller graph for this function:

◆ IsIrqContext()

◆ ObjDestroy()

template<typename T>
void ObjDestroy ( T * obj)
static

Definition at line 461 of file cmsis_os2_stk.cpp.

462{
463 if (!obj) return;
464 if (obj->m_cb_owned)
465 delete obj;
466 else
467 obj->~T();
468}

Referenced by osEventFlagsDelete(), osMemoryPoolDelete(), osMemoryPoolNew(), osMessageQueueDelete(), osMessageQueueNew(), osMutexDelete(), osSemaphoreDelete(), osThreadDetach(), osThreadJoin(), osThreadNew(), osThreadTerminate(), and osTimerDelete().

Here is the caller graph for this function:

◆ PlacementNewOrHeap()

template<typename T, typename... Args>
T * PlacementNewOrHeap ( void * cb_mem,
size_t cb_size,
Args &&... args )
static

Definition at line 438 of file cmsis_os2_stk.cpp.

439{
440 T *obj = nullptr;
441
442 if ((cb_mem != nullptr) && (cb_size >= sizeof(T)))
443 {
444 obj = new (cb_mem) T(static_cast<Args &&>(args)...);
445 obj->m_cb_owned = false;
446 return obj;
447 }
448 else
449 {
450 obj = new (std::nothrow) T(static_cast<Args &&>(args)...);
451 // m_cb_owned is already true from the constructor default
452 }
453
454 return obj;
455}

Referenced by osEventFlagsNew(), osMemoryPoolNew(), osMessageQueueNew(), osMutexNew(), osSemaphoreNew(), osThreadNew(), and osTimerNew().

Here is the caller graph for this function:

◆ StkFlagsResultToCmsis()

__stk_forceinline uint32_t StkFlagsResultToCmsis ( uint32_t result)
static

Definition at line 485 of file cmsis_os2_stk.cpp.

486{
488 return result;
489
491 return osFlagsErrorTimeout;
492
495
497 return osFlagsErrorISR;
498
499 return osFlagsErrorUnknown;
500}
#define osFlagsErrorTimeout
osErrorTimeout (-2).
Definition cmsis_os2.h:211
#define osFlagsErrorUnknown
osError (-1).
Definition cmsis_os2.h:210
#define osFlagsErrorParameter
osErrorParameter (-4).
Definition cmsis_os2.h:213
#define osFlagsErrorISR
osErrorISR (-6).
Definition cmsis_os2.h:214
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 ERROR_PARAMETER
Return sentinel: invalid flags argument (bit 31 set).

References __stk_forceinline, stk::sync::EventFlags::ERROR_ISR, stk::sync::EventFlags::ERROR_PARAMETER, stk::sync::EventFlags::ERROR_TIMEOUT, stk::sync::EventFlags::IsError(), osFlagsErrorISR, osFlagsErrorParameter, osFlagsErrorTimeout, and osFlagsErrorUnknown.

Referenced by osEventFlagsClear(), osEventFlagsSet(), osEventFlagsWait(), osThreadFlagsClear(), osThreadFlagsSet(), and osThreadFlagsWait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StkGetWordCountForType()

template<typename T>
constexpr size_t StkGetWordCountForType ( )
staticconstexpr

Definition at line 88 of file cmsis_os2_stk.cpp.

89{
90 return ((sizeof(T) + sizeof(stk::Word) - 1) / sizeof(stk::Word));
91}
uintptr_t Word
Native processor word type.
Definition stk_common.h:113

◆ StkPrioToCmsis()

__stk_forceinline osPriority_t StkPrioToCmsis ( int32_t p)
static

Definition at line 108 of file cmsis_os2_stk.cpp.

109{
110 // Inverse: cmsis_prio = (stk_prio * 56) / 31
111 int32_t r = (p * 56) / 31;
112 if (r < static_cast<int32_t>(osPriorityIdle))
113 r = static_cast<int32_t>(osPriorityIdle);
114
115 if (r > static_cast<int32_t>(osPriorityISR))
116 r = static_cast<int32_t>(osPriorityISR);
117
118 return static_cast<osPriority_t>(r);
119}
osPriority_t
Priority values.
Definition cmsis_os2.h:132

References __stk_forceinline, osPriorityIdle, and osPriorityISR.

Referenced by osThreadGetPriority().

Here is the caller graph for this function:

Variable Documentation

◆ g_StkKernel

◆ g_StkKernelLocked

uint32_t g_StkKernelLocked = 0
static

◆ g_TimerHost

stk::time::TimerHost* g_TimerHost = nullptr
static

◆ g_TimerHostBuf

Definition at line 304 of file cmsis_os2_stk.cpp.

Referenced by StkTimer::EnsureTimerHostCreated().