SuperTinyKernel™ RTOS 1.06.x
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 "stk.h"
#include "sync/stk_sync.h"
#include "time/stk_time.h"
#include "memory/stk_memory.h"
#include "cmsis_os2.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 ()
void * malloc (size_t size)
void free (void *ptr)
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 39 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew().

◆ CMSIS_STK_MAX_THREADS

#define CMSIS_STK_MAX_THREADS   16U

Definition at line 34 of file cmsis_os2_stk.cpp.

◆ CMSIS_STK_MIN_STACK_WORDS

#define CMSIS_STK_MIN_STACK_WORDS   STK_STACK_SIZE_MIN

Definition at line 43 of file cmsis_os2_stk.cpp.

Referenced by osThreadNew().

◆ STK_WRAPPER_API_VERSION

#define STK_WRAPPER_API_VERSION   20030000UL

Definition at line 23 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 25 of file cmsis_os2_stk.cpp.

Referenced by osKernelGetInfo().

◆ STK_WRAPPER_KERNEL_VERSION

#define STK_WRAPPER_KERNEL_VERSION   20030000UL

Definition at line 24 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_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
Definition stk_common.h:46
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:45
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Definition stk_common.h:43
Concrete implementation of IKernel.
Definition stk.h:85

Definition at line 116 of file cmsis_os2_stk.cpp.

Function Documentation

◆ CmsisFlagsOptionsToStk()

__stk_forceinline uint32_t CmsisFlagsOptionsToStk ( uint32_t options)
static

Definition at line 435 of file cmsis_os2_stk.cpp.

436{
437 uint32_t stk_opts = stk::sync::EventFlags::OPT_WAIT_ANY; // default
438
439 if (options & osFlagsWaitAll)
441
442 if (options & osFlagsNoClear)
444
445 return stk_opts;
446}
#define osFlagsWaitAll
Wait for all flags.
Definition cmsis_os2.h:250
#define osFlagsNoClear
Do not clear flags which have been specified to wait for.
Definition cmsis_os2.h:251
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 64 of file cmsis_os2_stk.cpp.

65{
66 if (p <= osPriorityIdle)
67 return 0;
68 if (p >= osPriorityISR)
69 return 31;
70
71 return (static_cast<int32_t>(p) * 31) / 56;
72}
@ osPriorityISR
Reserved for ISR deferred thread.
Definition cmsis_os2.h:228
@ osPriorityIdle
Reserved for Idle thread.
Definition cmsis_os2.h:179

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 93 of file cmsis_os2_stk.cpp.

94{
95 if (ticks > stk::WAIT_INFINITE)
96 return stk::WAIT_INFINITE;
97
98 if (ticks == 0U)
99 return stk::NO_WAIT;
100
101 // CMSIS ticks are kernel ticks – pass through directly as STK ticks
102 return static_cast<stk::Timeout>(ticks);
103}
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:189
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:125
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:183

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:

◆ free()

void free ( void * ptr)

◆ IsIrqContext()

__stk_forceinline bool IsIrqContext ( )
static

Definition at line 108 of file cmsis_os2_stk.cpp.

109{
110 return stk::hw::IsInsideISR();
111}
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).

References __stk_forceinline, and stk::hw::IsInsideISR().

Referenced by osDelay(), osDelayUntil(), osEventFlagsDelete(), osEventFlagsNew(), osKernelInitialize(), osKernelLock(), osKernelRestoreLock(), osKernelStart(), osKernelUnlock(), osMemoryPoolAlloc(), osMemoryPoolDelete(), osMemoryPoolNew(), osMessageQueueDelete(), osMessageQueueGet(), osMessageQueueNew(), osMessageQueuePut(), osMessageQueueReset(), osMutexAcquire(), osMutexDelete(), osMutexNew(), osMutexRelease(), osSemaphoreAcquire(), osSemaphoreDelete(), osSemaphoreNew(), osThreadDetach(), osThreadFlagsWait(), osThreadGetId(), osThreadGetPriority(), osThreadGetState(), osThreadJoin(), osThreadNew(), osThreadResume(), osThreadSetPriority(), osThreadSuspend(), osThreadYield(), osTimerDelete(), osTimerNew(), osTimerStart(), osTimerStop(), ulTaskNotifyTakeIndexed(), vTaskDelay(), xEventGroupCreate(), xEventGroupCreateStatic(), xEventGroupSync(), xEventGroupWaitBits(), xMessageBufferReceive(), xQueueCreate(), xQueueCreateSet(), xQueueCreateStatic(), xQueuePeek(), xQueueReceive(), xQueueSelectFromSet(), xQueueSend(), xQueueSendToFront(), xSemaphoreTake(), xStreamBufferReceive(), xTaskDelayUntil(), xTaskGetCurrentTaskHandle(), xTaskNotifyWaitIndexed(), xTimerCreate(), xTimerCreateStatic(), xTimerPendFunctionCall(), xTimerStart(), and xTimerStop().

Here is the call graph for this function:

◆ malloc()

void * malloc ( size_t size)

◆ ObjDestroy()

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

Definition at line 425 of file cmsis_os2_stk.cpp.

426{
427 if (!obj) return;
428 if (obj->m_cb_owned)
429 delete obj;
430 else
431 obj->~T();
432}

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 402 of file cmsis_os2_stk.cpp.

403{
404 T *obj = nullptr;
405
406 if ((cb_mem != nullptr) && (cb_size >= sizeof(T)))
407 {
408 obj = new (cb_mem) T(static_cast<Args &&>(args)...);
409 obj->m_cb_owned = false;
410 return obj;
411 }
412 else
413 {
414 obj = new (std::nothrow) T(static_cast<Args &&>(args)...);
415 // m_cb_owned is already true from the constructor default
416 }
417
418 return obj;
419}

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 449 of file cmsis_os2_stk.cpp.

450{
452 return result;
453
455 return osFlagsErrorTimeout;
456
459
461 return osFlagsErrorISR;
462
463 return osFlagsErrorUnknown;
464}
#define osFlagsErrorTimeout
osErrorTimeout (-2).
Definition cmsis_os2.h:256
#define osFlagsErrorUnknown
osError (-1).
Definition cmsis_os2.h:255
#define osFlagsErrorParameter
osErrorParameter (-4).
Definition cmsis_os2.h:258
#define osFlagsErrorISR
osErrorISR (-6).
Definition cmsis_os2.h:259
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 46 of file cmsis_os2_stk.cpp.

47{
48 return ((sizeof(T) + sizeof(stk::Word) - 1) / sizeof(stk::Word));
49}
uintptr_t Word
Native processor word type.
Definition stk_common.h:115

◆ StkPrioToCmsis()

__stk_forceinline osPriority_t StkPrioToCmsis ( int32_t p)
static

Definition at line 73 of file cmsis_os2_stk.cpp.

74{
75 // Inverse: cmsis_prio = (stk_prio * 56) / 31
76 int32_t r = (p * 56) / 31;
77 if (r < static_cast<int32_t>(osPriorityIdle))
78 r = static_cast<int32_t>(osPriorityIdle);
79
80 if (r > static_cast<int32_t>(osPriorityISR))
81 r = static_cast<int32_t>(osPriorityISR);
82
83 return static_cast<osPriority_t>(r);
84}
osPriority_t
Priority values.
Definition cmsis_os2.h:177

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

◆ g_TimerHostBuf

Definition at line 268 of file cmsis_os2_stk.cpp.

Referenced by StkTimer::EnsureTimerHostCreated().