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

class  StkThread
struct  StkMutex
struct  StkSemaphore
struct  StkEventFlags
class  StkTimer
class  StkMemPool
class  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 size_t CmsisStrlen (const char str[])
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 *mem, size_t size, const 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 = 0U
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:57
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:56
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Definition stk_common.h:54
Concrete implementation of IKernel.
Definition stk.h:85

Definition at line 152 of file cmsis_os2_stk.cpp.

Function Documentation

◆ CmsisFlagsOptionsToStk()

__stk_forceinline uint32_t CmsisFlagsOptionsToStk ( uint32_t options)
static

Definition at line 492 of file cmsis_os2_stk.cpp.

493{
494 uint32_t stk_opts = stk::sync::EventFlags::OPT_WAIT_ANY; // default
495
496 if ((options & osFlagsWaitAll) != 0U)
497 {
499 }
500
501 if ((options & osFlagsNoClear) != 0U)
502 {
504 }
505
506 return stk_opts;
507}
#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 77 of file cmsis_os2_stk.cpp.

78{
79 int32_t result;
80
81 if (p <= osPriorityIdle)
82 {
83 result = 0;
84 }
85 else if (p >= osPriorityISR)
86 {
87 result = 31;
88 }
89 else
90 {
91 result = ((static_cast<int32_t>(p) * 31) / 56);
92 }
93
94 return result;
95}
@ 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:

◆ CmsisStrlen()

size_t CmsisStrlen ( const char str[])
static

Definition at line 52 of file cmsis_os2_stk.cpp.

53{
54 size_t total_len = 0U;
55
56 while (str[total_len] != '\0')
57 {
58 total_len++;
59 }
60
61 return total_len;
62}

Referenced by osKernelGetInfo().

Here is the caller graph for this function:

◆ CmsisTimeoutToStk()

__stk_forceinline stk::Timeout CmsisTimeoutToStk ( uint32_t ticks)
static

Definition at line 120 of file cmsis_os2_stk.cpp.

121{
122 stk::Timeout result;
123
124 if (ticks > static_cast<uint32_t>(stk::WAIT_INFINITE))
125 {
126 result = stk::WAIT_INFINITE;
127 }
128 else if (ticks == 0U)
129 {
130 result = stk::NO_WAIT;
131 }
132 else
133 {
134 // CMSIS ticks are kernel ticks – pass through directly as STK ticks
135 result = static_cast<stk::Timeout>(ticks);
136 }
137
138 return result;
139}
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:210
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:146
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:204

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

145{
146 return stk::hw::IsInsideISR();
147}
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:
Here is the caller graph for this function:

◆ malloc()

void * malloc ( size_t size)

◆ ObjDestroy()

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

Definition at line 479 of file cmsis_os2_stk.cpp.

480{
481 if (obj->m_cb_owned)
482 {
483 delete obj;
484 }
485 else
486 {
487 obj->~T();
488 }
489}

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 * mem,
size_t size,
const Args &... args )
static

Definition at line 456 of file cmsis_os2_stk.cpp.

457{
458 T *obj;
459
460 if ((mem != nullptr) && (size >= sizeof(T)))
461 {
462 obj = new (mem) T(args...);
463 obj->m_cb_owned = false;
464 }
465 else
466 {
467 obj = new (std::nothrow) T(args...);
468 // m_cb_owned is already true from the constructor default
469 STK_ASSERT(obj != nullptr);
470 }
471
472 return obj;
473}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409

References STK_ASSERT.

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

511{
512 uint32_t cmsis_result;
513
515 {
516 cmsis_result = result;
517 }
518 else if (result == stk::sync::EventFlags::ERROR_TIMEOUT)
519 {
520 cmsis_result = osFlagsErrorTimeout;
521 }
523 {
524 cmsis_result = osFlagsErrorParameter;
525 }
526 else if (result == stk::sync::EventFlags::ERROR_ISR)
527 {
528 cmsis_result = osFlagsErrorISR;
529 }
530 else
531 {
532 cmsis_result = osFlagsErrorUnknown;
533 }
534
535 return cmsis_result;
536}
#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) - 1U) / sizeof(stk::Word));
49}
uintptr_t Word
Native processor word type.
Definition stk_common.h:136

◆ StkPrioToCmsis()

__stk_forceinline osPriority_t StkPrioToCmsis ( int32_t p)
static

Definition at line 96 of file cmsis_os2_stk.cpp.

97{
98 // Inverse: cmsis_prio = (stk_prio * 56) / 31
99 int32_t r = (p * 56) / 31;
100 if (r < static_cast<int32_t>(osPriorityIdle))
101 {
102 r = static_cast<int32_t>(osPriorityIdle);
103 }
104
105 if (r > static_cast<int32_t>(osPriorityISR))
106 {
107 r = static_cast<int32_t>(osPriorityISR);
108 }
109
110 return static_cast<osPriority_t>(r);
111}
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 = 0U
static

◆ g_TimerHost

◆ g_TimerHostBuf

Definition at line 313 of file cmsis_os2_stk.cpp.

Referenced by StkTimer::EnsureTimerHostCreated().