SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
STK CMSIS RTOS2 API

CMSIS RTOS2 interface for C++ API of SuperTinyKernel RTOS. More...

Classes

struct  osVersion_t
 Version information. More...
struct  osThreadAttr_t
 Attributes structure for thread. More...
struct  osTimerAttr_t
 Attributes structure for timer. More...
struct  osEventFlagsAttr_t
 Attributes structure for event flags. More...
struct  osMutexAttr_t
 Attributes structure for mutex. More...
struct  osSemaphoreAttr_t
 Attributes structure for semaphore. More...
struct  osMemoryPoolAttr_t
 Attributes structure for memory pool. More...
struct  osMessageQueueAttr_t
 Attributes structure for message queue. More...

Macros

#define osWaitForever   0xFFFFFFFFU
 Wait forever timeout value.
#define osFlagsWaitAny   0x00000000U
 Wait for any flag (default).
#define osFlagsWaitAll   0x00000001U
 Wait for all flags.
#define osFlagsNoClear   0x00000002U
 Do not clear flags which have been specified to wait for.
#define osFlagsError   0x80000000U
 Error indicator.
#define osFlagsErrorUnknown   0xFFFFFFFFU
 osError (-1).
#define osFlagsErrorTimeout   0xFFFFFFFEU
 osErrorTimeout (-2).
#define osFlagsErrorResource   0xFFFFFFFDU
 osErrorResource (-3).
#define osFlagsErrorParameter   0xFFFFFFFCU
 osErrorParameter (-4).
#define osFlagsErrorISR   0xFFFFFFFAU
 osErrorISR (-6).
#define osFlagsErrorSafetyClass   0xFFFFFFF9U
 osErrorSafetyClass (-7).
#define osThreadDetached   0x00000000U
 Thread created in detached mode (default).
#define osThreadJoinable   0x00000001U
 Thread created in joinable mode.
#define osThreadUnprivileged   0x00000002U
 Thread runs in unprivileged mode.
#define osThreadPrivileged   0x00000004U
 Thread runs in privileged mode.
#define osThreadZone_Pos   8U
 MPU protected zone position.
#define osThreadZone_Msk   (0x3FUL << osThreadZone_Pos)
 MPU protected zone mask.
#define osThreadZone_Valid   (0x80UL << osThreadZone_Pos)
 MPU protected zone valid flag.
#define osThreadZone(n)
 MPU zone value in attribute bit field format.
#define osThreadProcessor(n)
 Thread processor number for SMP systems.
#define osMutexRecursive   0x00000001U
 Recursive mutex.
#define osMutexPrioInherit   0x00000002U
 Priority inherit protocol.
#define osMutexRobust   0x00000008U
 Robust mutex.
#define osSafetyClass_Pos   16U
 Safety class position.
#define osSafetyClass_Msk   (0x0FUL << osSafetyClass_Pos)
 Safety class mask.
#define osSafetyClass_Valid   (0x10UL << osSafetyClass_Pos)
 Safety class valid flag.
#define osSafetyClass(n)
 Safety class.
#define osSafetyWithSameClass   0x00000001U
 Objects with same safety class.
#define osSafetyWithLowerClass   0x00000002U
 Objects with lower safety class.
#define osErrorId   0xFFFFFFFFU
 osError (-1).
#define TZ_MODULEID_T

Typedefs

typedef void(* osThreadFunc_t) (void *argument)
 Entry point of a thread.
typedef void(* osTimerFunc_t) (void *argument)
 Timer callback function.
typedef void * osThreadId_t
typedef void * osTimerId_t
typedef void * osEventFlagsId_t
typedef void * osMutexId_t
typedef void * osSemaphoreId_t
typedef void * osMemoryPoolId_t
typedef void * osMessageQueueId_t
typedef uint32_t TZ_ModuleId_t

Enumerations

enum  osKernelState_t {
  osKernelInactive = 0 ,
  osKernelReady = 1 ,
  osKernelRunning = 2 ,
  osKernelLocked = 3 ,
  osKernelSuspended = 4 ,
  osKernelError = -1 ,
  osKernelReserved = 0x7FFFFFFF
}
 Kernel state. More...
enum  osThreadState_t {
  osThreadInactive = 0 ,
  osThreadReady = 1 ,
  osThreadRunning = 2 ,
  osThreadBlocked = 3 ,
  osThreadTerminated = 4 ,
  osThreadError = -1 ,
  osThreadReserved = 0x7FFFFFFF
}
 Thread state. More...
enum  osPriority_t {
  osPriorityNone = 0 ,
  osPriorityIdle = 1 ,
  osPriorityLow = 8 ,
  osPriorityLow1 = 8+1 ,
  osPriorityLow2 = 8+2 ,
  osPriorityLow3 = 8+3 ,
  osPriorityLow4 = 8+4 ,
  osPriorityLow5 = 8+5 ,
  osPriorityLow6 = 8+6 ,
  osPriorityLow7 = 8+7 ,
  osPriorityBelowNormal = 16 ,
  osPriorityBelowNormal1 = 16+1 ,
  osPriorityBelowNormal2 = 16+2 ,
  osPriorityBelowNormal3 = 16+3 ,
  osPriorityBelowNormal4 = 16+4 ,
  osPriorityBelowNormal5 = 16+5 ,
  osPriorityBelowNormal6 = 16+6 ,
  osPriorityBelowNormal7 = 16+7 ,
  osPriorityNormal = 24 ,
  osPriorityNormal1 = 24+1 ,
  osPriorityNormal2 = 24+2 ,
  osPriorityNormal3 = 24+3 ,
  osPriorityNormal4 = 24+4 ,
  osPriorityNormal5 = 24+5 ,
  osPriorityNormal6 = 24+6 ,
  osPriorityNormal7 = 24+7 ,
  osPriorityAboveNormal = 32 ,
  osPriorityAboveNormal1 = 32+1 ,
  osPriorityAboveNormal2 = 32+2 ,
  osPriorityAboveNormal3 = 32+3 ,
  osPriorityAboveNormal4 = 32+4 ,
  osPriorityAboveNormal5 = 32+5 ,
  osPriorityAboveNormal6 = 32+6 ,
  osPriorityAboveNormal7 = 32+7 ,
  osPriorityHigh = 40 ,
  osPriorityHigh1 = 40+1 ,
  osPriorityHigh2 = 40+2 ,
  osPriorityHigh3 = 40+3 ,
  osPriorityHigh4 = 40+4 ,
  osPriorityHigh5 = 40+5 ,
  osPriorityHigh6 = 40+6 ,
  osPriorityHigh7 = 40+7 ,
  osPriorityRealtime = 48 ,
  osPriorityRealtime1 = 48+1 ,
  osPriorityRealtime2 = 48+2 ,
  osPriorityRealtime3 = 48+3 ,
  osPriorityRealtime4 = 48+4 ,
  osPriorityRealtime5 = 48+5 ,
  osPriorityRealtime6 = 48+6 ,
  osPriorityRealtime7 = 48+7 ,
  osPriorityISR = 56 ,
  osPriorityError = -1 ,
  osPriorityReserved = 0x7FFFFFFF
}
 Priority values. More...
enum  osTimerType_t {
  osTimerOnce = 0 ,
  osTimerPeriodic = 1
}
 Timer type. More...
enum  osStatus_t {
  osOK = 0 ,
  osError = -1 ,
  osErrorTimeout = -2 ,
  osErrorResource = -3 ,
  osErrorParameter = -4 ,
  osErrorNoMemory = -5 ,
  osErrorISR = -6 ,
  osErrorSafetyClass = -7 ,
  osStatusReserved = 0x7FFFFFFF
}
 Status code values returned by CMSIS-RTOS functions. More...

Functions

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)
osStatus_t osKernelProtect (uint32_t safety_class)
osStatus_t osKernelDestroyClass (uint32_t safety_class, uint32_t mode)
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)
uint32_t osThreadGetClass (osThreadId_t thread_id)
uint32_t osThreadGetZone (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)
osStatus_t osThreadFeedWatchdog (uint32_t ticks)
osStatus_t osThreadProtectPrivileged (void)
osStatus_t osThreadSuspendClass (uint32_t safety_class, uint32_t mode)
osStatus_t osThreadResumeClass (uint32_t safety_class, uint32_t mode)
osStatus_t osThreadTerminateZone (uint32_t zone)
osStatus_t osThreadSetAffinityMask (osThreadId_t thread_id, uint32_t affinity_mask)
uint32_t osThreadGetAffinityMask (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 msg_prio, 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)
uint32_t osWatchdogAlarm_Handler (osThreadId_t thread_id)
void osZoneSetup_Callback (uint32_t zone)
void osFaultResume (void)
 Resume normal operation when exiting exception faults.

Detailed Description

CMSIS RTOS2 interface for C++ API of SuperTinyKernel RTOS.

Maps the CMSIS RTOS2 C API (cmsis_os2.h) onto the STK C++ API.

Supported:

  • Kernel management (osKernelInitialize / Start / GetState / GetInfo / GetTickCount / GetTickFreq / GetSysTimerCount / GetSysTimerFreq / Lock / Unlock / RestoreLock)
  • Thread management (osThreadNew / Delete / Yield / Delay / osDelay / GetId / GetName / GetState / GetPriority / SetPriority / GetStackSize / GetStackSpace / GetCount / Terminate / Suspend / Resume, Join, Detach)
  • Thread flags (osThreadFlagsSet / Clear / Get / Wait)
  • Event flags (osEventFlagsNew / Delete / Set / Clear / Get / Wait)
  • Mutex (osMutexNew / Delete / Acquire / Release / GetOwner)
  • Semaphore (osSemaphoreNew / Delete / Acquire / Release / GetCount)
  • Timer (osTimerNew / Delete / Start / Stop / IsRunning)
  • Message Queue (osMessageQueueNew / Delete / Put / Get / GetCapacity / GetMsgSize / GetCount / GetSpace / Reset)
  • Memory Pool (osMemoryPoolNew / Delete / Alloc / Free / GetCapacity / GetBlockSize / GetCount / GetSpace / GetName)

Design notes:

  • All objects are heap-allocated with operator new/delete. For a fully static deployment, replace with a static object-pool allocator.
  • The wrapper owns one global Kernel instance (g_StkKernel). Call osKernelInitialize() before any other API, then osKernelStart().
  • The kernel is configured with KERNEL_DYNAMIC | KERNEL_SYNC and SwitchStrategyFP32 (32 fixed-priority levels). osThread priority values (osPriorityIdle=1 .. osPriorityISR=56) are linearly mapped to STK priority levels 0..31.
  • CMSIS osWaitForever (0xFFFFFFFF) is translated to STK WAIT_INFINITE.
  • Timeout values in CMSIS are in ticks; STK Sleep/Delay also take ticks, so no conversion is required.
  • Thread flags and event flags are backed by stk::sync::EventFlags, STK's native 32-bit multi-flag synchronization primitive.
  • Message queues are backed by stk::sync::MessageQueue, STK's native fixed-capacity, fixed-message-size ring-buffer with integrated blocking semantics (Put/Get with configurable timeouts, ISR-safe TryPut/TryGet).

Limitations / deviations from the specification:

  • Priority inheritance (osMutexPrioInherit): ignored, always supported.
  • Robust mutex (osMutexRobust): will assert as unsafe code.
  • Recursive mutex (osMutexRecursive): ignored, always recursive by default.

Macro Definition Documentation

◆ osErrorId

#define osErrorId   0xFFFFFFFFU

osError (-1).

Definition at line 294 of file cmsis_os2.h.

◆ osFlagsError

#define osFlagsError   0x80000000U

Error indicator.

Definition at line 254 of file cmsis_os2.h.

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

◆ osFlagsErrorISR

#define osFlagsErrorISR   0xFFFFFFFAU

osErrorISR (-6).

Definition at line 259 of file cmsis_os2.h.

Referenced by osThreadFlagsWait(), and StkFlagsResultToCmsis().

◆ osFlagsErrorParameter

#define osFlagsErrorParameter   0xFFFFFFFCU

osErrorParameter (-4).

Definition at line 258 of file cmsis_os2.h.

Referenced by osEventFlagsClear(), osEventFlagsSet(), osEventFlagsWait(), osThreadFlagsSet(), and StkFlagsResultToCmsis().

◆ osFlagsErrorResource

#define osFlagsErrorResource   0xFFFFFFFDU

osErrorResource (-3).

Definition at line 257 of file cmsis_os2.h.

◆ osFlagsErrorSafetyClass

#define osFlagsErrorSafetyClass   0xFFFFFFF9U

osErrorSafetyClass (-7).

Definition at line 260 of file cmsis_os2.h.

◆ osFlagsErrorTimeout

#define osFlagsErrorTimeout   0xFFFFFFFEU

osErrorTimeout (-2).

Definition at line 256 of file cmsis_os2.h.

Referenced by StkFlagsResultToCmsis().

◆ osFlagsErrorUnknown

#define osFlagsErrorUnknown   0xFFFFFFFFU

osError (-1).

Definition at line 255 of file cmsis_os2.h.

Referenced by osThreadFlagsClear(), osThreadFlagsWait(), and StkFlagsResultToCmsis().

◆ osFlagsNoClear

#define osFlagsNoClear   0x00000002U

Do not clear flags which have been specified to wait for.

Definition at line 251 of file cmsis_os2.h.

Referenced by CmsisFlagsOptionsToStk().

◆ osFlagsWaitAll

#define osFlagsWaitAll   0x00000001U

Wait for all flags.

Definition at line 250 of file cmsis_os2.h.

Referenced by CmsisFlagsOptionsToStk().

◆ osFlagsWaitAny

#define osFlagsWaitAny   0x00000000U

Wait for any flag (default).

Definition at line 249 of file cmsis_os2.h.

◆ osMutexPrioInherit

#define osMutexPrioInherit   0x00000002U

Priority inherit protocol.

Definition at line 279 of file cmsis_os2.h.

◆ osMutexRecursive

#define osMutexRecursive   0x00000001U

Recursive mutex.

Definition at line 278 of file cmsis_os2.h.

Referenced by osMutexNew().

◆ osMutexRobust

#define osMutexRobust   0x00000008U

Robust mutex.

Definition at line 280 of file cmsis_os2.h.

Referenced by osMutexNew().

◆ osSafetyClass

#define osSafetyClass ( n)
Value:
#define osSafetyClass_Pos
Safety class position.
Definition cmsis_os2.h:283
#define osSafetyClass_Msk
Safety class mask.
Definition cmsis_os2.h:284
#define osSafetyClass_Valid
Safety class valid flag.
Definition cmsis_os2.h:285

Safety class.

Definition at line 286 of file cmsis_os2.h.

286#define osSafetyClass(n) ((((n) << osSafetyClass_Pos) & osSafetyClass_Msk) | \
287 osSafetyClass_Valid)

◆ osSafetyClass_Msk

#define osSafetyClass_Msk   (0x0FUL << osSafetyClass_Pos)

Safety class mask.

Definition at line 284 of file cmsis_os2.h.

◆ osSafetyClass_Pos

#define osSafetyClass_Pos   16U

Safety class position.

Definition at line 283 of file cmsis_os2.h.

◆ osSafetyClass_Valid

#define osSafetyClass_Valid   (0x10UL << osSafetyClass_Pos)

Safety class valid flag.

Definition at line 285 of file cmsis_os2.h.

◆ osSafetyWithLowerClass

#define osSafetyWithLowerClass   0x00000002U

Objects with lower safety class.

Definition at line 291 of file cmsis_os2.h.

◆ osSafetyWithSameClass

#define osSafetyWithSameClass   0x00000001U

Objects with same safety class.

Definition at line 290 of file cmsis_os2.h.

◆ osThreadDetached

#define osThreadDetached   0x00000000U

Thread created in detached mode (default).

Definition at line 263 of file cmsis_os2.h.

◆ osThreadJoinable

#define osThreadJoinable   0x00000001U

Thread created in joinable mode.

Definition at line 264 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadPrivileged

#define osThreadPrivileged   0x00000004U

Thread runs in privileged mode.

Definition at line 266 of file cmsis_os2.h.

◆ osThreadProcessor

#define osThreadProcessor ( n)
Value:
(1UL << (n))

Thread processor number for SMP systems.

Definition at line 275 of file cmsis_os2.h.

◆ osThreadUnprivileged

#define osThreadUnprivileged   0x00000002U

Thread runs in unprivileged mode.

Definition at line 265 of file cmsis_os2.h.

◆ osThreadZone

#define osThreadZone ( n)
Value:
#define osThreadZone_Msk
MPU protected zone mask.
Definition cmsis_os2.h:269
#define osThreadZone_Pos
MPU protected zone position.
Definition cmsis_os2.h:268
#define osThreadZone_Valid
MPU protected zone valid flag.
Definition cmsis_os2.h:270

MPU zone value in attribute bit field format.

Definition at line 271 of file cmsis_os2.h.

271#define osThreadZone(n) ((((n) << osThreadZone_Pos) & osThreadZone_Msk) | \
272 osThreadZone_Valid)

◆ osThreadZone_Msk

#define osThreadZone_Msk   (0x3FUL << osThreadZone_Pos)

MPU protected zone mask.

Definition at line 269 of file cmsis_os2.h.

◆ osThreadZone_Pos

#define osThreadZone_Pos   8U

MPU protected zone position.

Definition at line 268 of file cmsis_os2.h.

◆ osThreadZone_Valid

#define osThreadZone_Valid   (0x80UL << osThreadZone_Pos)

MPU protected zone valid flag.

Definition at line 270 of file cmsis_os2.h.

◆ osWaitForever

#define osWaitForever   0xFFFFFFFFU

Wait forever timeout value.

Definition at line 246 of file cmsis_os2.h.

◆ TZ_MODULEID_T

#define TZ_MODULEID_T

Definition at line 333 of file cmsis_os2.h.

Typedef Documentation

◆ osEventFlagsId_t

typedef void* osEventFlagsId_t

Event Flags ID identifies the event flags.

Definition at line 317 of file cmsis_os2.h.

◆ osMemoryPoolId_t

typedef void* osMemoryPoolId_t

Memory Pool ID identifies the memory pool.

Definition at line 326 of file cmsis_os2.h.

◆ osMessageQueueId_t

typedef void* osMessageQueueId_t

Message Queue ID identifies the message queue.

Definition at line 329 of file cmsis_os2.h.

◆ osMutexId_t

typedef void* osMutexId_t

Mutex ID identifies the mutex.

Definition at line 320 of file cmsis_os2.h.

◆ osSemaphoreId_t

typedef void* osSemaphoreId_t

Semaphore ID identifies the semaphore.

Definition at line 323 of file cmsis_os2.h.

◆ osThreadFunc_t

typedef void(* osThreadFunc_t) (void *argument)

Entry point of a thread.

Definition at line 234 of file cmsis_os2.h.

◆ osThreadId_t

typedef void* osThreadId_t

Thread ID identifies the thread.

Definition at line 311 of file cmsis_os2.h.

◆ osTimerFunc_t

typedef void(* osTimerFunc_t) (void *argument)

Timer callback function.

Definition at line 237 of file cmsis_os2.h.

◆ osTimerId_t

typedef void* osTimerId_t

Timer ID identifies the timer.

Definition at line 314 of file cmsis_os2.h.

◆ TZ_ModuleId_t

typedef uint32_t TZ_ModuleId_t

Data type that identifies secure software modules called by a process.

Definition at line 335 of file cmsis_os2.h.

Enumeration Type Documentation

◆ osKernelState_t

Kernel state.

Enumerator
osKernelInactive 

Inactive.

osKernelReady 

Ready.

osKernelRunning 

Running.

osKernelLocked 

Locked.

osKernelSuspended 

Suspended.

osKernelError 

Error.

osKernelReserved 

Prevents enum down-size compiler optimization.

Definition at line 155 of file cmsis_os2.h.

155 {
156 osKernelInactive = 0,
157 osKernelReady = 1,
158 osKernelRunning = 2,
159 osKernelLocked = 3,
161 osKernelError = -1,
162 osKernelReserved = 0x7FFFFFFF
osKernelState_t
Kernel state.
Definition cmsis_os2.h:155
@ osKernelLocked
Locked.
Definition cmsis_os2.h:159
@ osKernelError
Error.
Definition cmsis_os2.h:161
@ osKernelSuspended
Suspended.
Definition cmsis_os2.h:160
@ osKernelReady
Ready.
Definition cmsis_os2.h:157
@ osKernelRunning
Running.
Definition cmsis_os2.h:158
@ osKernelReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:162
@ osKernelInactive
Inactive.
Definition cmsis_os2.h:156

◆ osPriority_t

Priority values.

Enumerator
osPriorityNone 

No priority (not initialized).

osPriorityIdle 

Reserved for Idle thread.

osPriorityLow 

Priority: low.

osPriorityLow1 

Priority: low + 1.

osPriorityLow2 

Priority: low + 2.

osPriorityLow3 

Priority: low + 3.

osPriorityLow4 

Priority: low + 4.

osPriorityLow5 

Priority: low + 5.

osPriorityLow6 

Priority: low + 6.

osPriorityLow7 

Priority: low + 7.

osPriorityBelowNormal 

Priority: below normal.

osPriorityBelowNormal1 

Priority: below normal + 1.

osPriorityBelowNormal2 

Priority: below normal + 2.

osPriorityBelowNormal3 

Priority: below normal + 3.

osPriorityBelowNormal4 

Priority: below normal + 4.

osPriorityBelowNormal5 

Priority: below normal + 5.

osPriorityBelowNormal6 

Priority: below normal + 6.

osPriorityBelowNormal7 

Priority: below normal + 7.

osPriorityNormal 

Priority: normal.

osPriorityNormal1 

Priority: normal + 1.

osPriorityNormal2 

Priority: normal + 2.

osPriorityNormal3 

Priority: normal + 3.

osPriorityNormal4 

Priority: normal + 4.

osPriorityNormal5 

Priority: normal + 5.

osPriorityNormal6 

Priority: normal + 6.

osPriorityNormal7 

Priority: normal + 7.

osPriorityAboveNormal 

Priority: above normal.

osPriorityAboveNormal1 

Priority: above normal + 1.

osPriorityAboveNormal2 

Priority: above normal + 2.

osPriorityAboveNormal3 

Priority: above normal + 3.

osPriorityAboveNormal4 

Priority: above normal + 4.

osPriorityAboveNormal5 

Priority: above normal + 5.

osPriorityAboveNormal6 

Priority: above normal + 6.

osPriorityAboveNormal7 

Priority: above normal + 7.

osPriorityHigh 

Priority: high.

osPriorityHigh1 

Priority: high + 1.

osPriorityHigh2 

Priority: high + 2.

osPriorityHigh3 

Priority: high + 3.

osPriorityHigh4 

Priority: high + 4.

osPriorityHigh5 

Priority: high + 5.

osPriorityHigh6 

Priority: high + 6.

osPriorityHigh7 

Priority: high + 7.

osPriorityRealtime 

Priority: realtime.

osPriorityRealtime1 

Priority: realtime + 1.

osPriorityRealtime2 

Priority: realtime + 2.

osPriorityRealtime3 

Priority: realtime + 3.

osPriorityRealtime4 

Priority: realtime + 4.

osPriorityRealtime5 

Priority: realtime + 5.

osPriorityRealtime6 

Priority: realtime + 6.

osPriorityRealtime7 

Priority: realtime + 7.

osPriorityISR 

Reserved for ISR deferred thread.

osPriorityError 

System cannot determine priority or illegal priority.

osPriorityReserved 

Prevents enum down-size compiler optimization.

Definition at line 177 of file cmsis_os2.h.

177 {
178 osPriorityNone = 0,
179 osPriorityIdle = 1,
180 osPriorityLow = 8,
181 osPriorityLow1 = 8+1,
182 osPriorityLow2 = 8+2,
183 osPriorityLow3 = 8+3,
184 osPriorityLow4 = 8+4,
185 osPriorityLow5 = 8+5,
186 osPriorityLow6 = 8+6,
187 osPriorityLow7 = 8+7,
196 osPriorityNormal = 24,
197 osPriorityNormal1 = 24+1,
198 osPriorityNormal2 = 24+2,
199 osPriorityNormal3 = 24+3,
200 osPriorityNormal4 = 24+4,
201 osPriorityNormal5 = 24+5,
202 osPriorityNormal6 = 24+6,
203 osPriorityNormal7 = 24+7,
212 osPriorityHigh = 40,
213 osPriorityHigh1 = 40+1,
214 osPriorityHigh2 = 40+2,
215 osPriorityHigh3 = 40+3,
216 osPriorityHigh4 = 40+4,
217 osPriorityHigh5 = 40+5,
218 osPriorityHigh6 = 40+6,
219 osPriorityHigh7 = 40+7,
220 osPriorityRealtime = 48,
221 osPriorityRealtime1 = 48+1,
222 osPriorityRealtime2 = 48+2,
223 osPriorityRealtime3 = 48+3,
224 osPriorityRealtime4 = 48+4,
225 osPriorityRealtime5 = 48+5,
226 osPriorityRealtime6 = 48+6,
227 osPriorityRealtime7 = 48+7,
228 osPriorityISR = 56,
229 osPriorityError = -1,
230 osPriorityReserved = 0x7FFFFFFF
osPriority_t
Priority values.
Definition cmsis_os2.h:177
@ osPriorityNormal7
Priority: normal + 7.
Definition cmsis_os2.h:203
@ osPriorityHigh3
Priority: high + 3.
Definition cmsis_os2.h:215
@ osPriorityBelowNormal5
Priority: below normal + 5.
Definition cmsis_os2.h:193
@ osPriorityRealtime
Priority: realtime.
Definition cmsis_os2.h:220
@ osPriorityAboveNormal
Priority: above normal.
Definition cmsis_os2.h:204
@ osPriorityHigh1
Priority: high + 1.
Definition cmsis_os2.h:213
@ osPriorityBelowNormal
Priority: below normal.
Definition cmsis_os2.h:188
@ osPriorityBelowNormal3
Priority: below normal + 3.
Definition cmsis_os2.h:191
@ osPriorityNormal2
Priority: normal + 2.
Definition cmsis_os2.h:198
@ osPriorityLow3
Priority: low + 3.
Definition cmsis_os2.h:183
@ osPriorityBelowNormal4
Priority: below normal + 4.
Definition cmsis_os2.h:192
@ osPriorityISR
Reserved for ISR deferred thread.
Definition cmsis_os2.h:228
@ osPriorityNormal1
Priority: normal + 1.
Definition cmsis_os2.h:197
@ osPriorityRealtime3
Priority: realtime + 3.
Definition cmsis_os2.h:223
@ osPriorityNormal3
Priority: normal + 3.
Definition cmsis_os2.h:199
@ osPriorityHigh2
Priority: high + 2.
Definition cmsis_os2.h:214
@ osPriorityNormal
Priority: normal.
Definition cmsis_os2.h:196
@ osPriorityBelowNormal2
Priority: below normal + 2.
Definition cmsis_os2.h:190
@ osPriorityIdle
Reserved for Idle thread.
Definition cmsis_os2.h:179
@ osPriorityHigh6
Priority: high + 6.
Definition cmsis_os2.h:218
@ osPriorityHigh5
Priority: high + 5.
Definition cmsis_os2.h:217
@ osPriorityLow4
Priority: low + 4.
Definition cmsis_os2.h:184
@ osPriorityLow7
Priority: low + 7.
Definition cmsis_os2.h:187
@ osPriorityLow
Priority: low.
Definition cmsis_os2.h:180
@ osPriorityAboveNormal6
Priority: above normal + 6.
Definition cmsis_os2.h:210
@ osPriorityHigh7
Priority: high + 7.
Definition cmsis_os2.h:219
@ osPriorityNormal5
Priority: normal + 5.
Definition cmsis_os2.h:201
@ osPriorityNone
No priority (not initialized).
Definition cmsis_os2.h:178
@ osPriorityAboveNormal4
Priority: above normal + 4.
Definition cmsis_os2.h:208
@ osPriorityLow2
Priority: low + 2.
Definition cmsis_os2.h:182
@ osPriorityRealtime6
Priority: realtime + 6.
Definition cmsis_os2.h:226
@ osPriorityNormal6
Priority: normal + 6.
Definition cmsis_os2.h:202
@ osPriorityAboveNormal2
Priority: above normal + 2.
Definition cmsis_os2.h:206
@ osPriorityBelowNormal1
Priority: below normal + 1.
Definition cmsis_os2.h:189
@ osPriorityHigh
Priority: high.
Definition cmsis_os2.h:212
@ osPriorityNormal4
Priority: normal + 4.
Definition cmsis_os2.h:200
@ osPriorityRealtime7
Priority: realtime + 7.
Definition cmsis_os2.h:227
@ osPriorityBelowNormal7
Priority: below normal + 7.
Definition cmsis_os2.h:195
@ osPriorityRealtime2
Priority: realtime + 2.
Definition cmsis_os2.h:222
@ osPriorityLow1
Priority: low + 1.
Definition cmsis_os2.h:181
@ osPriorityBelowNormal6
Priority: below normal + 6.
Definition cmsis_os2.h:194
@ osPriorityAboveNormal1
Priority: above normal + 1.
Definition cmsis_os2.h:205
@ osPriorityLow6
Priority: low + 6.
Definition cmsis_os2.h:186
@ osPriorityReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:230
@ osPriorityAboveNormal3
Priority: above normal + 3.
Definition cmsis_os2.h:207
@ osPriorityLow5
Priority: low + 5.
Definition cmsis_os2.h:185
@ osPriorityAboveNormal7
Priority: above normal + 7.
Definition cmsis_os2.h:211
@ osPriorityError
System cannot determine priority or illegal priority.
Definition cmsis_os2.h:229
@ osPriorityAboveNormal5
Priority: above normal + 5.
Definition cmsis_os2.h:209
@ osPriorityRealtime4
Priority: realtime + 4.
Definition cmsis_os2.h:224
@ osPriorityRealtime1
Priority: realtime + 1.
Definition cmsis_os2.h:221
@ osPriorityHigh4
Priority: high + 4.
Definition cmsis_os2.h:216
@ osPriorityRealtime5
Priority: realtime + 5.
Definition cmsis_os2.h:225

◆ osStatus_t

enum osStatus_t

Status code values returned by CMSIS-RTOS functions.

Enumerator
osOK 

Operation completed successfully.

osError 

Unspecified RTOS error: run-time error but no other error message fits.

osErrorTimeout 

Operation not completed within the timeout period.

osErrorResource 

Resource not available.

osErrorParameter 

Parameter error.

osErrorNoMemory 

System is out of memory: it was impossible to allocate or reserve memory for the operation.

osErrorISR 

Not allowed in ISR context: the function cannot be called from interrupt service routines.

osErrorSafetyClass 

Operation denied because of safety class violation.

osStatusReserved 

Prevents enum down-size compiler optimization.

Definition at line 297 of file cmsis_os2.h.

297 {
298 osOK = 0,
299 osError = -1,
300 osErrorTimeout = -2,
301 osErrorResource = -3,
302 osErrorParameter = -4,
303 osErrorNoMemory = -5,
304 osErrorISR = -6,
305 osErrorSafetyClass = -7,
306 osStatusReserved = 0x7FFFFFFF
307} osStatus_t;
osStatus_t
Status code values returned by CMSIS-RTOS functions.
Definition cmsis_os2.h:297
@ osErrorISR
Not allowed in ISR context: the function cannot be called from interrupt service routines.
Definition cmsis_os2.h:304
@ osStatusReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:306
@ osErrorResource
Resource not available.
Definition cmsis_os2.h:301
@ osErrorTimeout
Operation not completed within the timeout period.
Definition cmsis_os2.h:300
@ osOK
Operation completed successfully.
Definition cmsis_os2.h:298
@ osError
Unspecified RTOS error: run-time error but no other error message fits.
Definition cmsis_os2.h:299
@ osErrorParameter
Parameter error.
Definition cmsis_os2.h:302
@ osErrorNoMemory
System is out of memory: it was impossible to allocate or reserve memory for the operation.
Definition cmsis_os2.h:303
@ osErrorSafetyClass
Operation denied because of safety class violation.
Definition cmsis_os2.h:305

◆ osThreadState_t

Thread state.

Enumerator
osThreadInactive 

Inactive.

osThreadReady 

Ready.

osThreadRunning 

Running.

osThreadBlocked 

Blocked.

osThreadTerminated 

Terminated.

osThreadError 

Error.

osThreadReserved 

Prevents enum down-size compiler optimization.

Definition at line 166 of file cmsis_os2.h.

166 {
167 osThreadInactive = 0,
168 osThreadReady = 1,
169 osThreadRunning = 2,
170 osThreadBlocked = 3,
172 osThreadError = -1,
173 osThreadReserved = 0x7FFFFFFF
osThreadState_t
Thread state.
Definition cmsis_os2.h:166
@ osThreadBlocked
Blocked.
Definition cmsis_os2.h:170
@ osThreadRunning
Running.
Definition cmsis_os2.h:169
@ osThreadInactive
Inactive.
Definition cmsis_os2.h:167
@ osThreadReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:173
@ osThreadTerminated
Terminated.
Definition cmsis_os2.h:171
@ osThreadError
Error.
Definition cmsis_os2.h:172
@ osThreadReady
Ready.
Definition cmsis_os2.h:168

◆ osTimerType_t

Timer type.

Enumerator
osTimerOnce 

One-shot timer.

osTimerPeriodic 

Repeating timer.

Definition at line 240 of file cmsis_os2.h.

240 {
241 osTimerOnce = 0,
242 osTimerPeriodic = 1
osTimerType_t
Timer type.
Definition cmsis_os2.h:240
@ osTimerPeriodic
Repeating timer.
Definition cmsis_os2.h:242
@ osTimerOnce
One-shot timer.
Definition cmsis_os2.h:241

Function Documentation

◆ osDelay()

osStatus_t osDelay ( uint32_t ticks)

Wait for Timeout (Time Delay).

Parameters
[in]tickstime ticks value
Returns
status code that indicates the execution status of the function.

Definition at line 1636 of file cmsis_os2_stk.cpp.

1637{
1638 osStatus_t result;
1639
1640 if (IsIrqContext())
1641 {
1642 result = osErrorISR;
1643 }
1644 else if (osKernelGetState() == osKernelInactive)
1645 {
1646 result = osError;
1647 }
1648 else
1649 {
1651 result = osOK;
1652 }
1653
1654 return result;
1655}
static __stk_forceinline bool IsIrqContext()
static __stk_forceinline stk::Timeout CmsisTimeoutToStk(uint32_t ticks)
osKernelState_t osKernelGetState(void)
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:497

References CmsisTimeoutToStk(), IsIrqContext(), osError, osErrorISR, osKernelGetState(), osKernelInactive, osOK, and stk::Sleep().

Here is the call graph for this function:

◆ osDelayUntil()

osStatus_t osDelayUntil ( uint32_t ticks)

Wait until specified time.

Parameters
[in]ticksabsolute time in ticks
Returns
status code that indicates the execution status of the function.

Definition at line 1657 of file cmsis_os2_stk.cpp.

1658{
1659 osStatus_t result;
1660
1661 if (IsIrqContext())
1662 {
1663 result = osErrorISR;
1664 }
1665 else if (osKernelGetState() == osKernelInactive)
1666 {
1667 result = osError;
1668 }
1669 else
1670 {
1671 result = (stk::SleepUntil(static_cast<stk::Ticks>(ticks)) ? osOK : osError);
1672 }
1673
1674 return result;
1675}
int64_t Ticks
Ticks value.
Definition stk_common.h:175
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:522

References IsIrqContext(), osError, osErrorISR, osKernelGetState(), osKernelInactive, osOK, and stk::SleepUntil().

Here is the call graph for this function:

◆ osEventFlagsClear()

uint32_t osEventFlagsClear ( osEventFlagsId_t ef_id,
uint32_t flags )

Clear the specified Event Flags.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
[in]flagsspecifies the flags that shall be cleared.
Returns
event flags before clearing or error code if highest bit set.

Definition at line 1890 of file cmsis_os2_stk.cpp.

1891{
1892 uint32_t result;
1893
1894 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1895 {
1896 result = osFlagsErrorParameter;
1897 }
1898 else
1899 {
1900 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Clear(flags));
1901 }
1902
1903 return result;
1904}
static __stk_forceinline uint32_t StkFlagsResultToCmsis(uint32_t result)
#define osFlagsError
Error indicator.
Definition cmsis_os2.h:254
#define osFlagsErrorParameter
osErrorParameter (-4).
Definition cmsis_os2.h:258

References osFlagsError, osFlagsErrorParameter, and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osEventFlagsDelete()

osStatus_t osEventFlagsDelete ( osEventFlagsId_t ef_id)

Delete an Event Flags object.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
Returns
status code that indicates the execution status of the function.

Definition at line 1940 of file cmsis_os2_stk.cpp.

1941{
1942 osStatus_t result;
1943
1944 if (IsIrqContext())
1945 {
1946 result = osErrorISR;
1947 }
1948 else if (ef_id == nullptr)
1949 {
1950 result = osErrorParameter;
1951 }
1952 else
1953 {
1954 ObjDestroy(static_cast<StkEventFlags *>(ef_id));
1955 result = osOK;
1956 }
1957
1958 return result;
1959}
static void ObjDestroy(T *obj)

References IsIrqContext(), ObjDestroy(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osEventFlagsGet()

uint32_t osEventFlagsGet ( osEventFlagsId_t ef_id)

Get the current Event Flags.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
Returns
current event flags.

Definition at line 1906 of file cmsis_os2_stk.cpp.

1907{
1908 uint32_t result;
1909
1910 if (ef_id == nullptr)
1911 {
1912 result = 0U;
1913 }
1914 else
1915 {
1916 result = static_cast<StkEventFlags *>(ef_id)->m_ef.Get();
1917 }
1918
1919 return result;
1920}

◆ osEventFlagsGetName()

const char * osEventFlagsGetName ( osEventFlagsId_t ef_id)

Get name of an Event Flags object.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
Returns
name as null-terminated string.

Definition at line 1858 of file cmsis_os2_stk.cpp.

1859{
1860 const char *result;
1861
1862 if (ef_id == nullptr)
1863 {
1864 result = nullptr;
1865 }
1866 else
1867 {
1868 result = static_cast<StkEventFlags *>(ef_id)->m_ef.GetTraceName();
1869 }
1870
1871 return result;
1872}

◆ osEventFlagsNew()

osEventFlagsId_t osEventFlagsNew ( const osEventFlagsAttr_t * attr)

Create and Initialize an Event Flags object.

Parameters
[in]attrevent flags attributes; NULL: default values.
Returns
event flags ID for reference by other functions or NULL in case of error.

Definition at line 1837 of file cmsis_os2_stk.cpp.

1838{
1839 osEventFlagsId_t result;
1840
1841 if (IsIrqContext())
1842 {
1843 result = nullptr;
1844 }
1845 else
1846 {
1847 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1848 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1849 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1850
1851 StkEventFlags *const ef = PlacementNewOrHeap<StkEventFlags>(cb_mem, cb_sz, name);
1852 result = static_cast<osEventFlagsId_t>(ef);
1853 }
1854
1855 return result;
1856}
static T * PlacementNewOrHeap(void *mem, size_t size, const Args &... args)
void * osEventFlagsId_t
Definition cmsis_os2.h:317
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:365
const char * name
name of the event flags
Definition cmsis_os2.h:362
void * cb_mem
memory for control block
Definition cmsis_os2.h:364

References osEventFlagsAttr_t::cb_mem, osEventFlagsAttr_t::cb_size, IsIrqContext(), osEventFlagsAttr_t::name, and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osEventFlagsSet()

uint32_t osEventFlagsSet ( osEventFlagsId_t ef_id,
uint32_t flags )

Set the specified Event Flags.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
[in]flagsspecifies the flags that shall be set.
Returns
event flags after setting or error code if highest bit set.

Definition at line 1874 of file cmsis_os2_stk.cpp.

1875{
1876 uint32_t result;
1877
1878 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1879 {
1880 result = osFlagsErrorParameter;
1881 }
1882 else
1883 {
1884 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Set(flags));
1885 }
1886
1887 return result;
1888}

References osFlagsError, osFlagsErrorParameter, and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osEventFlagsWait()

uint32_t osEventFlagsWait ( osEventFlagsId_t ef_id,
uint32_t flags,
uint32_t options,
uint32_t timeout )

Wait for one or more Event Flags to become signaled.

Parameters
[in]ef_idevent flags ID obtained by osEventFlagsNew.
[in]flagsspecifies the flags to wait for.
[in]optionsspecifies flags options (osFlagsXxxx).
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
event flags before clearing or error code if highest bit set.

Definition at line 1922 of file cmsis_os2_stk.cpp.

1924{
1925 uint32_t result;
1926
1927 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1928 {
1929 result = osFlagsErrorParameter;
1930 }
1931 else
1932 {
1933 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Wait(flags,
1934 CmsisFlagsOptionsToStk(options), CmsisTimeoutToStk(timeout)));
1935 }
1936
1937 return result;
1938}
static __stk_forceinline uint32_t CmsisFlagsOptionsToStk(uint32_t options)

References CmsisFlagsOptionsToStk(), CmsisTimeoutToStk(), osFlagsError, osFlagsErrorParameter, and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osFaultResume()

void osFaultResume ( void )

Resume normal operation when exiting exception faults.

◆ osKernelDestroyClass()

osStatus_t osKernelDestroyClass ( uint32_t safety_class,
uint32_t mode )

Destroy objects for specified safety classes.

Parameters
[in]safety_classsafety class.
[in]modesafety mode.
Returns
status code that indicates the execution status of the function.

◆ osKernelGetInfo()

osStatus_t osKernelGetInfo ( osVersion_t * version,
char * id_buf,
uint32_t id_size )

Get RTOS Kernel Information.

Parameters
[out]versionpointer to buffer for retrieving version information.
[out]id_bufpointer to buffer for retrieving kernel identification string.
[in]id_sizesize of buffer for kernel identification string.
Returns
status code that indicates the execution status of the function.

Definition at line 727 of file cmsis_os2_stk.cpp.

728{
729 if (version != nullptr)
730 {
731 version->api = STK_WRAPPER_API_VERSION;
733 }
734
735 if ((id_buf != nullptr) && (id_size > 0U))
736 {
737 const char *const id = STK_WRAPPER_KERNEL_ID;
738 size_t copy_len = id_size - 1U;
739 const size_t id_len = CmsisStrlen(id);
740 if (copy_len > id_len)
741 {
742 copy_len = id_len;
743 }
744
745 STK_MEMCPY(id_buf, id, copy_len);
746 id_buf[copy_len] = '\0';
747 }
748
749 return osOK;
750}
static void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
Implementation of STK_MEMCPY.
Definition stk_arch.h:731
static size_t CmsisStrlen(const char str[])
#define STK_WRAPPER_KERNEL_VERSION
#define STK_WRAPPER_KERNEL_ID
#define STK_WRAPPER_API_VERSION
uint32_t api
API version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:150
uint32_t kernel
Kernel version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:151

References osVersion_t::api, CmsisStrlen(), osVersion_t::kernel, osOK, STK_MEMCPY(), STK_WRAPPER_API_VERSION, STK_WRAPPER_KERNEL_ID, and STK_WRAPPER_KERNEL_VERSION.

Here is the call graph for this function:

◆ osKernelGetState()

osKernelState_t osKernelGetState ( void )

Get the current RTOS Kernel state.

Returns
current RTOS Kernel state.

Definition at line 752 of file cmsis_os2_stk.cpp.

753{
754 osKernelState_t state;
755
756 if (g_StkKernelLocked != 0U)
757 {
758 state = osKernelLocked;
759 }
760 else
761 {
762 switch (g_StkKernel.GetState())
763 {
765 state = osKernelInactive;
766 break;
768 state = osKernelReady;
769 break;
771 state = osKernelRunning;
772 break;
774 state = osKernelSuspended;
775 break;
776 default:
777 state = osKernelError;
778 break;
779 }
780 }
781
782 return state;
783}
static uint32_t g_StkKernelLocked
static StkKernel g_StkKernel
@ 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.

References g_StkKernel, g_StkKernelLocked, stk::IKernel::KSTATE_INACTIVE, stk::IKernel::KSTATE_READY, stk::IKernel::KSTATE_RUNNING, stk::IKernel::KSTATE_SUSPENDED, osKernelError, osKernelInactive, osKernelLocked, osKernelReady, osKernelRunning, and osKernelSuspended.

Referenced by osDelay(), osDelayUntil(), osKernelGetTickCount(), osKernelGetTickFreq(), osKernelInitialize(), osKernelResume(), osKernelStart(), osKernelSuspend(), osThreadEnumerate(), osThreadGetCount(), osThreadGetId(), osThreadNew(), osThreadResume(), osThreadSuspend(), osThreadTerminate(), osThreadYield(), and osTimerNew().

Here is the caller graph for this function:

◆ osKernelGetSysTimerCount()

uint32_t osKernelGetSysTimerCount ( void )

Get the RTOS kernel system timer count.

Returns
RTOS kernel current system timer count as 32-bit value.

Definition at line 950 of file cmsis_os2_stk.cpp.

951{
952 return static_cast<uint32_t>(stk::GetSysTimerCount());
953}
static Cycles GetSysTimerCount()
Get system timer count value.
Definition stk_helper.h:477

References stk::GetSysTimerCount().

Here is the call graph for this function:

◆ osKernelGetSysTimerCount64()

uint64_t osKernelGetSysTimerCount64 ( void )

Get the RTOS kernel system timer count.

Returns
RTOS kernel current system timer count as 64-bit value.

Definition at line 955 of file cmsis_os2_stk.cpp.

956{
957 return stk::GetSysTimerCount();
958}

References stk::GetSysTimerCount().

Here is the call graph for this function:

◆ osKernelGetSysTimerFreq()

uint32_t osKernelGetSysTimerFreq ( void )

Get the RTOS kernel system timer frequency.

Returns
frequency of the system timer in hertz, i.e. timer ticks per second.

Definition at line 960 of file cmsis_os2_stk.cpp.

961{
963}
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:486

References stk::GetSysTimerFrequency().

Here is the call graph for this function:

◆ osKernelGetTickCount()

uint32_t osKernelGetTickCount ( void )

Get the RTOS kernel tick count.

Returns
RTOS kernel current tick count.

Definition at line 910 of file cmsis_os2_stk.cpp.

911{
912 uint32_t result;
913
915 {
916 result = 0U;
917 }
918 else
919 {
920 result = static_cast<uint32_t>(stk::GetTicks());
921 }
922
923 return result;
924}
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:452

References stk::GetTicks(), osKernelGetState(), and osKernelInactive.

Here is the call graph for this function:

◆ osKernelGetTickFreq()

uint32_t osKernelGetTickFreq ( void )

Get the RTOS kernel tick frequency.

Returns
frequency of the kernel tick in hertz, i.e. kernel ticks per second.

Definition at line 926 of file cmsis_os2_stk.cpp.

927{
928 uint32_t result;
929
931 {
932 result = 1000U; // default 1 kHz
933 }
934 else
935 {
936 const int32_t res_us = stk::GetTickResolution(); // us per tick
937 if (res_us <= 0)
938 {
939 result = 1000U;
940 }
941 else
942 {
943 result = (1000000U / static_cast<uint32_t>(res_us));
944 }
945 }
946
947 return result;
948}
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:386

References stk::GetTickResolution(), osKernelGetState(), and osKernelInactive.

Here is the call graph for this function:

◆ osKernelInitialize()

osStatus_t osKernelInitialize ( void )

Initialize the RTOS Kernel.

Returns
status code that indicates the execution status of the function.

Definition at line 706 of file cmsis_os2_stk.cpp.

707{
708 osStatus_t result;
709
710 if (IsIrqContext())
711 {
712 result = osErrorISR;
713 }
715 {
716 result = osError;
717 }
718 else
719 {
720 g_StkKernel.Initialize(); // default 1 ms tick resolution
721 result = osOK;
722 }
723
724 return result;
725}

References g_StkKernel, IsIrqContext(), osError, osErrorISR, osKernelGetState(), osKernelInactive, and osOK.

Here is the call graph for this function:

◆ osKernelLock()

int32_t osKernelLock ( void )

Lock the RTOS Kernel scheduler.

Returns
previous lock state (1 - locked, 0 - not locked, error code if negative).

Definition at line 808 of file cmsis_os2_stk.cpp.

809{
810 int32_t result;
811
812 if (IsIrqContext())
813 {
814 result = static_cast<int32_t>(osErrorISR);
815 }
816 else
817 {
820 result = 0;
821 }
822
823 return result;
824}
static Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.

References stk::hw::CriticalSection::Enter(), g_StkKernelLocked, IsIrqContext(), and osErrorISR.

Here is the call graph for this function:

◆ osKernelProtect()

osStatus_t osKernelProtect ( uint32_t safety_class)

Protect the RTOS Kernel scheduler access.

Parameters
[in]safety_classsafety class.
Returns
status code that indicates the execution status of the function.

◆ osKernelRestoreLock()

int32_t osKernelRestoreLock ( int32_t lock)

Restore the RTOS Kernel scheduler lock state.

Parameters
[in]locklock state obtained by osKernelLock or osKernelUnlock.
Returns
new lock state (1 - locked, 0 - not locked, error code if negative).

Definition at line 848 of file cmsis_os2_stk.cpp.

849{
850 int32_t result;
851
852 if (IsIrqContext())
853 {
854 result = static_cast<int32_t>(osErrorISR);
855 }
856 else if (lock == 1)
857 {
860 result = lock;
861 }
862 else if (g_StkKernelLocked == 0U)
863 {
864 result = static_cast<int32_t>(osErrorResource);
865 }
866 else
867 {
870 result = lock;
871 }
872
873 return result;
874}
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.

References stk::hw::CriticalSection::Enter(), stk::hw::CriticalSection::Exit(), g_StkKernelLocked, IsIrqContext(), osErrorISR, and osErrorResource.

Here is the call graph for this function:

◆ osKernelResume()

void osKernelResume ( uint32_t sleep_ticks)

Resume the RTOS Kernel scheduler.

Parameters
[in]sleep_tickstime in ticks for how long the system was in sleep or power-down mode.

Definition at line 897 of file cmsis_os2_stk.cpp.

898{
899#if STK_TICKLESS_IDLE
901 {
903 }
904#else
905 // Not supported in non-tickless kernel.
906 STK_UNUSED(sleep_ticks);
907#endif
908}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715
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.

References stk::IKernelService::GetInstance(), osKernelGetState(), osKernelInactive, stk::IKernelService::Resume(), and STK_UNUSED.

Here is the call graph for this function:

◆ osKernelStart()

osStatus_t osKernelStart ( void )

Start the RTOS Kernel scheduler.

Returns
status code that indicates the execution status of the function.

Definition at line 785 of file cmsis_os2_stk.cpp.

786{
787 osStatus_t result;
788
789 if (IsIrqContext())
790 {
791 result = osErrorISR;
792 }
793 else if (osKernelGetState() != osKernelReady)
794 {
795 result = osError;
796 }
797 else
798 {
799 // Start() does not return for KERNEL_STATIC;
800 // for KERNEL_DYNAMIC it returns when all tasks exit.
801 g_StkKernel.Start();
802 result = osOK;
803 }
804
805 return result;
806}

References g_StkKernel, IsIrqContext(), osError, osErrorISR, osKernelGetState(), osKernelReady, and osOK.

Here is the call graph for this function:

◆ osKernelSuspend()

uint32_t osKernelSuspend ( void )

Suspend the RTOS Kernel scheduler.

Returns
time in ticks, for how long the system can sleep or power-down.

Definition at line 876 of file cmsis_os2_stk.cpp.

877{
878 uint32_t result;
879
880#if STK_TICKLESS_IDLE
882 {
883 result = 0U;
884 }
885 else
886 {
887 result = static_cast<uint32_t>(stk::IKernelService::GetInstance()->Suspend());
888 }
889#else
890 // Not supported in non-tickless kernel.
891 result = 0U;
892#endif
893
894 return result;
895}
virtual Timeout Suspend()=0
Suspend scheduling.

References stk::IKernelService::GetInstance(), osKernelGetState(), osKernelInactive, and stk::IKernelService::Suspend().

Here is the call graph for this function:

◆ osKernelUnlock()

int32_t osKernelUnlock ( void )

Unlock the RTOS Kernel scheduler.

Returns
previous lock state (1 - locked, 0 - not locked, error code if negative).

Definition at line 826 of file cmsis_os2_stk.cpp.

827{
828 int32_t result;
829
830 if (IsIrqContext())
831 {
832 result = static_cast<int32_t>(osErrorISR);
833 }
834 else if (g_StkKernelLocked == 0U)
835 {
836 result = static_cast<int32_t>(osErrorResource);
837 }
838 else
839 {
842 result = 0;
843 }
844
845 return result;
846}

References stk::hw::CriticalSection::Exit(), g_StkKernelLocked, IsIrqContext(), osErrorISR, and osErrorResource.

Here is the call graph for this function:

◆ osMemoryPoolAlloc()

void * osMemoryPoolAlloc ( osMemoryPoolId_t mp_id,
uint32_t timeout )

Allocate a memory block from a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
address of the allocated memory block or NULL in case of no memory is available.

Definition at line 2311 of file cmsis_os2_stk.cpp.

2312{
2313 void *result;
2314
2315 if (mp_id == nullptr)
2316 {
2317 result = nullptr;
2318 }
2319 // ISR context is only valid with timeout == 0 (NO_WAIT / TryAlloc).
2320 else if (IsIrqContext() && (timeout != 0U))
2321 {
2322 result = nullptr;
2323 }
2324 else
2325 {
2326 result = static_cast<StkMemPool *>(mp_id)->m_mpool.TimedAlloc(CmsisTimeoutToStk(timeout));
2327 }
2328
2329 return result;
2330}

References CmsisTimeoutToStk(), and IsIrqContext().

Here is the call graph for this function:

◆ osMemoryPoolDelete()

osStatus_t osMemoryPoolDelete ( osMemoryPoolId_t mp_id)

Delete a Memory Pool object.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2416 of file cmsis_os2_stk.cpp.

2417{
2418 osStatus_t result;
2419
2420 if (IsIrqContext())
2421 {
2422 result = osErrorISR;
2423 }
2424 else if (mp_id == nullptr)
2425 {
2426 result = osErrorParameter;
2427 }
2428 else
2429 {
2430 ObjDestroy(static_cast<StkMemPool *>(mp_id));
2431 result = osOK;
2432 }
2433
2434 return result;
2435}

References IsIrqContext(), ObjDestroy(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osMemoryPoolFree()

osStatus_t osMemoryPoolFree ( osMemoryPoolId_t mp_id,
void * block )

Return an allocated memory block back to a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
[in]blockaddress of the allocated memory block to be returned to the memory pool.
Returns
status code that indicates the execution status of the function.

Definition at line 2332 of file cmsis_os2_stk.cpp.

2333{
2334 osStatus_t result;
2335
2336 if ((mp_id == nullptr) || (block == nullptr))
2337 {
2338 result = osErrorParameter;
2339 }
2340 else if (!static_cast<StkMemPool *>(mp_id)->m_mpool.Free(block))
2341 {
2342 result = osErrorParameter; // ptr not from this pool
2343 }
2344 else
2345 {
2346 result = osOK;
2347 }
2348
2349 return result;
2350}

References osErrorParameter, and osOK.

◆ osMemoryPoolGetBlockSize()

uint32_t osMemoryPoolGetBlockSize ( osMemoryPoolId_t mp_id)

Get memory block size in a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
memory block size in bytes.

Definition at line 2368 of file cmsis_os2_stk.cpp.

2369{
2370 uint32_t result;
2371
2372 if (mp_id == nullptr)
2373 {
2374 result = 0U;
2375 }
2376 else
2377 {
2378 result = static_cast<uint32_t>(static_cast<StkMemPool *>(mp_id)->m_mpool.GetBlockSize());
2379 }
2380
2381 return result;
2382}
size_t GetBlockSize() const
Get the aligned block size used internally by the allocator.
stk::memory::BlockMemoryPool m_mpool

References stk::memory::BlockMemoryPool::GetBlockSize(), and StkMemPool::m_mpool.

Here is the call graph for this function:

◆ osMemoryPoolGetCapacity()

uint32_t osMemoryPoolGetCapacity ( osMemoryPoolId_t mp_id)

Get maximum number of memory blocks in a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
maximum number of memory blocks.

Definition at line 2352 of file cmsis_os2_stk.cpp.

2353{
2354 uint32_t result;
2355
2356 if (mp_id == nullptr)
2357 {
2358 result = 0U;
2359 }
2360 else
2361 {
2362 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetCapacity();
2363 }
2364
2365 return result;
2366}

◆ osMemoryPoolGetCount()

uint32_t osMemoryPoolGetCount ( osMemoryPoolId_t mp_id)

Get number of memory blocks used in a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
number of memory blocks used.

Definition at line 2384 of file cmsis_os2_stk.cpp.

2385{
2386 uint32_t result;
2387
2388 if (mp_id == nullptr)
2389 {
2390 result = 0U;
2391 }
2392 else
2393 {
2394 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetUsedCount();
2395 }
2396
2397 return result;
2398}

◆ osMemoryPoolGetName()

const char * osMemoryPoolGetName ( osMemoryPoolId_t mp_id)

Get name of a Memory Pool object.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
name as null-terminated string.

Definition at line 2295 of file cmsis_os2_stk.cpp.

2296{
2297 const char *result;
2298
2299 if (mp_id == nullptr)
2300 {
2301 result = nullptr;
2302 }
2303 else
2304 {
2305 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetTraceName();
2306 }
2307
2308 return result;
2309}

◆ osMemoryPoolGetSpace()

uint32_t osMemoryPoolGetSpace ( osMemoryPoolId_t mp_id)

Get number of memory blocks available in a Memory Pool.

Parameters
[in]mp_idmemory pool ID obtained by osMemoryPoolNew.
Returns
number of memory blocks available.

Definition at line 2400 of file cmsis_os2_stk.cpp.

2401{
2402 uint32_t result;
2403
2404 if (mp_id == nullptr)
2405 {
2406 result = 0U;
2407 }
2408 else
2409 {
2410 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetFreeCount();
2411 }
2412
2413 return result;
2414}

◆ osMemoryPoolNew()

osMemoryPoolId_t osMemoryPoolNew ( uint32_t block_count,
uint32_t block_size,
const osMemoryPoolAttr_t * attr )

Create and Initialize a Memory Pool object.

Parameters
[in]block_countmaximum number of memory blocks in memory pool.
[in]block_sizememory block size in bytes.
[in]attrmemory pool attributes; NULL: default values.
Returns
memory pool ID for reference by other functions or NULL in case of error.

Definition at line 2244 of file cmsis_os2_stk.cpp.

2246{
2247 osMemoryPoolId_t result;
2248
2249 // ISR context: forbidden per CMSIS spec.
2250 // Zero capacity or zero block size are meaningless.
2251 if (IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2252 {
2253 result = nullptr;
2254 }
2255 else
2256 {
2257 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2258 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2259 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2260 void *const mp_mem = ((attr != nullptr) ? attr->mp_mem : nullptr);
2261 const uint32_t mp_sz = ((attr != nullptr) ? attr->mp_size : 0U);
2262
2263 // Compute the aligned block size and required storage byte count.
2264 const uint32_t aligned_blk = stk::memory::BlockMemoryPool::AlignBlockSize(block_size);
2265 const uint32_t storage_required = (block_count * aligned_blk);
2266
2267 StkMemPool *pool;
2268
2269 if ((mp_mem != nullptr) && (mp_sz >= storage_required))
2270 {
2271 // Caller-supplied pool storage - BlockMemoryPool external-storage ctor.
2272 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2273 block_count, block_size, name, static_cast<uint8_t *>(mp_mem));
2274 }
2275 else
2276 {
2277 // Heap-allocated pool storage - BlockMemoryPool heap ctor.
2278 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2279 block_count, block_size, name);
2280
2281 // If the heap ctor failed to allocate storage, clean up and bail.
2282 if ((pool != nullptr) && !pool->m_mpool.IsStorageValid())
2283 {
2284 ObjDestroy(pool);
2285 pool = nullptr;
2286 }
2287 }
2288
2289 result = static_cast<osMemoryPoolId_t>(pool);
2290 }
2291
2292 return result;
2293}
void * osMemoryPoolId_t
Definition cmsis_os2.h:326
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.
uint32_t mp_size
size of provided memory for data storage
Definition cmsis_os2.h:391
const char * name
name of the memory pool
Definition cmsis_os2.h:386
void * cb_mem
memory for control block
Definition cmsis_os2.h:388
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:389
void * mp_mem
memory for data storage
Definition cmsis_os2.h:390

References stk::memory::BlockMemoryPool::AlignBlockSize(), osMemoryPoolAttr_t::cb_mem, osMemoryPoolAttr_t::cb_size, IsIrqContext(), stk::memory::BlockMemoryPool::IsStorageValid(), StkMemPool::m_mpool, osMemoryPoolAttr_t::mp_mem, osMemoryPoolAttr_t::mp_size, osMemoryPoolAttr_t::name, ObjDestroy(), and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osMessageQueueDelete()

osStatus_t osMessageQueueDelete ( osMessageQueueId_t mq_id)

Delete a Message Queue object.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2647 of file cmsis_os2_stk.cpp.

2648{
2649 osStatus_t result;
2650
2651 if (IsIrqContext())
2652 {
2653 result = osErrorISR;
2654 }
2655 else if (mq_id == nullptr)
2656 {
2657 result = osErrorParameter;
2658 }
2659 else
2660 {
2661 ObjDestroy(static_cast<StkMessageQueue *>(mq_id));
2662 result = osOK;
2663 }
2664
2665 return result;
2666}

References IsIrqContext(), ObjDestroy(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osMessageQueueGet()

osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id,
void * msg_ptr,
uint8_t * msg_prio,
uint32_t timeout )

Get a Message from a Queue or timeout if Queue is empty.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
[out]msg_ptrpointer to buffer for message to get from a queue.
[out]msg_priopointer to buffer for message priority or NULL.
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
status code that indicates the execution status of the function.

Definition at line 2533 of file cmsis_os2_stk.cpp.

2535{
2536 osStatus_t result;
2537
2538 if ((mq_id == nullptr) || (msg_ptr == nullptr))
2539 {
2540 result = osErrorParameter;
2541 }
2542 else if (IsIrqContext() && (timeout != 0U))
2543 {
2544 result = osErrorISR;
2545 }
2546 else
2547 {
2548 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2549
2550 result = StkWaitResultToCmsis(
2551 static_cast<StkMessageQueue *>(mq_id)->m_mq.GetEx(msg_ptr, stk_timeout), stk_timeout);
2552
2553 if ((result == osOK) && (msg_prio != nullptr))
2554 {
2555 *msg_prio = 0U; // STK queues have no priority lanes.
2556 }
2557 }
2558
2559 return result;
2560}
static __stk_forceinline osStatus_t StkWaitResultToCmsis(stk::EWaitResult wr, stk::Timeout timeout)
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:170

References CmsisTimeoutToStk(), IsIrqContext(), osErrorISR, osErrorParameter, osOK, and StkWaitResultToCmsis().

Here is the call graph for this function:

◆ osMessageQueueGetCapacity()

uint32_t osMessageQueueGetCapacity ( osMessageQueueId_t mq_id)

Get maximum number of messages in a Message Queue.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
maximum number of messages.

Definition at line 2562 of file cmsis_os2_stk.cpp.

2563{
2564 uint32_t result;
2565
2566 if (mq_id == nullptr)
2567 {
2568 result = 0U;
2569 }
2570 else
2571 {
2572 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCapacity());
2573 }
2574
2575 return result;
2576}
size_t GetCapacity() const
Get the maximum number of messages the queue can hold.
stk::sync::MessageQueue m_mq

References stk::sync::MessageQueue::GetCapacity(), and StkMessageQueue::m_mq.

Here is the call graph for this function:

◆ osMessageQueueGetCount()

uint32_t osMessageQueueGetCount ( osMessageQueueId_t mq_id)

Get number of queued messages in a Message Queue.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
number of queued messages.

Definition at line 2594 of file cmsis_os2_stk.cpp.

2595{
2596 uint32_t result;
2597
2598 if (mq_id == nullptr)
2599 {
2600 result = 0U;
2601 }
2602 else
2603 {
2604 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCount());
2605 }
2606
2607 return result;
2608}
size_t GetCount() const
Get the current number of messages in the queue.

References stk::sync::MessageQueue::GetCount(), and StkMessageQueue::m_mq.

Here is the call graph for this function:

◆ osMessageQueueGetMsgSize()

uint32_t osMessageQueueGetMsgSize ( osMessageQueueId_t mq_id)

Get maximum message size in a Message Queue.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
maximum message size in bytes.

Definition at line 2578 of file cmsis_os2_stk.cpp.

2579{
2580 uint32_t result;
2581
2582 if (mq_id == nullptr)
2583 {
2584 result = 0U;
2585 }
2586 else
2587 {
2588 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetMsgSize());
2589 }
2590
2591 return result;
2592}
size_t GetMsgSize() const
Get the size of each message in bytes.

References stk::sync::MessageQueue::GetMsgSize(), and StkMessageQueue::m_mq.

Here is the call graph for this function:

◆ osMessageQueueGetName()

const char * osMessageQueueGetName ( osMessageQueueId_t mq_id)

Get name of a Message Queue object.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
name as null-terminated string.

Definition at line 2493 of file cmsis_os2_stk.cpp.

2494{
2495 const char *result;
2496
2497 if (mq_id == nullptr)
2498 {
2499 result = nullptr;
2500 }
2501 else
2502 {
2503 result = static_cast<StkMessageQueue *>(mq_id)->m_mq.GetTraceName();
2504 }
2505
2506 return result;
2507}

◆ osMessageQueueGetSpace()

uint32_t osMessageQueueGetSpace ( osMessageQueueId_t mq_id)

Get number of available slots for messages in a Message Queue.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
number of available slots for messages.

Definition at line 2610 of file cmsis_os2_stk.cpp.

2611{
2612 uint32_t result;
2613
2614 if (mq_id == nullptr)
2615 {
2616 result = 0U;
2617 }
2618 else
2619 {
2620 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetSpace());
2621 }
2622
2623 return result;
2624}
size_t GetSpace() const
Get the number of free slots currently available.

References stk::sync::MessageQueue::GetSpace(), and StkMessageQueue::m_mq.

Here is the call graph for this function:

◆ osMessageQueueNew()

osMessageQueueId_t osMessageQueueNew ( uint32_t msg_count,
uint32_t msg_size,
const osMessageQueueAttr_t * attr )

Create and Initialize a Message Queue object.

Parameters
[in]msg_countmaximum number of messages in queue.
[in]msg_sizemaximum message size in bytes.
[in]attrmessage queue attributes; NULL: default values.
Returns
message queue ID for reference by other functions or NULL in case of error.

Definition at line 2442 of file cmsis_os2_stk.cpp.

2444{
2445 osMessageQueueId_t result;
2446
2447 if (IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
2449 {
2450 result = nullptr;
2451 }
2452 else
2453 {
2454 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2455 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2456 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2457 void *const ext_buf = ((attr != nullptr) ? attr->mq_mem : nullptr);
2458 const uint32_t ext_buf_size = ((attr != nullptr) ? attr->mq_size : 0U);
2459
2460 const uint32_t buf_required = (msg_count * msg_size);
2461
2462 StkMessageQueue *mq;
2463
2464 if ((ext_buf != nullptr) && (ext_buf_size >= buf_required))
2465 {
2466 // Data buffer: use caller-supplied memory.
2467 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
2468 msg_count, msg_size, name, static_cast<uint8_t *>(ext_buf));
2469 }
2470 else
2471 {
2472 // Data buffer: heap-allocated inside StkMessageQueue constructor.
2473 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
2474 msg_count, msg_size, name);
2475
2476 // Validate
2477 if (mq != nullptr)
2478 {
2479 if (!mq->m_mq.IsStorageValid())
2480 {
2481 ObjDestroy(mq);
2482 mq = nullptr;
2483 }
2484 }
2485 }
2486
2487 result = static_cast<osMessageQueueId_t>(mq);
2488 }
2489
2490 return result;
2491}
void * osMessageQueueId_t
Definition cmsis_os2.h:329
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
const char * name
name of the message queue
Definition cmsis_os2.h:396
void * cb_mem
memory for control block
Definition cmsis_os2.h:398
uint32_t mq_size
size of provided memory for data storage
Definition cmsis_os2.h:401
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:399
void * mq_mem
memory for data storage
Definition cmsis_os2.h:400

References stk::sync::MessageQueue::CAPACITY_MAX, osMessageQueueAttr_t::cb_mem, osMessageQueueAttr_t::cb_size, IsIrqContext(), stk::sync::MessageQueue::IsStorageValid(), StkMessageQueue::m_mq, osMessageQueueAttr_t::mq_mem, osMessageQueueAttr_t::mq_size, osMessageQueueAttr_t::name, ObjDestroy(), and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osMessageQueuePut()

osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id,
const void * msg_ptr,
uint8_t msg_prio,
uint32_t timeout )

Put a Message into a Queue or timeout if Queue is full.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
[in]msg_ptrpointer to buffer with message to put into a queue.
[in]msg_priomessage priority.
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
status code that indicates the execution status of the function.

Definition at line 2509 of file cmsis_os2_stk.cpp.

2511{
2512 osStatus_t result;
2513
2514 if ((mq_id == nullptr) || (msg_ptr == nullptr))
2515 {
2516 result = osErrorParameter;
2517 }
2518 else if (IsIrqContext() && (timeout != 0U))
2519 {
2520 result = osErrorISR;
2521 }
2522 else
2523 {
2524 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2525
2526 result = StkWaitResultToCmsis(
2527 static_cast<StkMessageQueue *>(mq_id)->m_mq.PutEx(msg_ptr, stk_timeout), stk_timeout);
2528 }
2529
2530 return result;
2531}

References CmsisTimeoutToStk(), IsIrqContext(), osErrorISR, osErrorParameter, and StkWaitResultToCmsis().

Here is the call graph for this function:

◆ osMessageQueueReset()

osStatus_t osMessageQueueReset ( osMessageQueueId_t mq_id)

Reset a Message Queue to initial empty state.

Parameters
[in]mq_idmessage queue ID obtained by osMessageQueueNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2626 of file cmsis_os2_stk.cpp.

2627{
2628 osStatus_t result;
2629
2630 if (IsIrqContext())
2631 {
2632 result = osErrorISR;
2633 }
2634 else if (mq_id == nullptr)
2635 {
2636 result = osErrorParameter;
2637 }
2638 else
2639 {
2640 static_cast<StkMessageQueue *>(mq_id)->m_mq.Reset();
2641 result = osOK;
2642 }
2643
2644 return result;
2645}

References IsIrqContext(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osMutexAcquire()

osStatus_t osMutexAcquire ( osMutexId_t mutex_id,
uint32_t timeout )

Acquire a Mutex or timeout if it is locked.

Parameters
[in]mutex_idmutex ID obtained by osMutexNew.
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
status code that indicates the execution status of the function.

Definition at line 2027 of file cmsis_os2_stk.cpp.

2028{
2029 osStatus_t result;
2030
2031 if (IsIrqContext())
2032 {
2033 result = osErrorISR;
2034 }
2035 else if (mutex_id == nullptr)
2036 {
2037 result = osErrorParameter;
2038 }
2039 else
2040 {
2041 result = static_cast<StkMutexBase *>(mutex_id)->Acquire(CmsisTimeoutToStk(timeout));
2042 }
2043
2044 return result;
2045}

References CmsisTimeoutToStk(), IsIrqContext(), osErrorISR, and osErrorParameter.

Here is the call graph for this function:

◆ osMutexDelete()

osStatus_t osMutexDelete ( osMutexId_t mutex_id)

Delete a Mutex object.

Parameters
[in]mutex_idmutex ID obtained by osMutexNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2094 of file cmsis_os2_stk.cpp.

2095{
2096 osStatus_t result;
2097
2098 if (IsIrqContext())
2099 {
2100 result = osErrorISR;
2101 }
2102 else if (mutex_id == nullptr)
2103 {
2104 result = osErrorParameter;
2105 }
2106 else
2107 {
2108 ObjDestroy(static_cast<StkMutexBase *>(mutex_id));
2109 result = osOK;
2110 }
2111
2112 return result;
2113}

References IsIrqContext(), ObjDestroy(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osMutexGetName()

const char * osMutexGetName ( osMutexId_t mutex_id)

Get name of a Mutex object.

Parameters
[in]mutex_idmutex ID obtained by osMutexNew.
Returns
name as null-terminated string.

Definition at line 2011 of file cmsis_os2_stk.cpp.

2012{
2013 const char *result;
2014
2015 if (mutex_id == nullptr)
2016 {
2017 result = nullptr;
2018 }
2019 else
2020 {
2021 result = static_cast<const StkMutexBase *>(mutex_id)->GetTraceName();
2022 }
2023
2024 return result;
2025}

◆ osMutexGetOwner()

osThreadId_t osMutexGetOwner ( osMutexId_t mutex_id)

Get Thread which owns a Mutex object.

Parameters
[in]mutex_idmutex ID obtained by osMutexNew.
Returns
thread ID of owner thread or NULL when mutex was not acquired.

Definition at line 2078 of file cmsis_os2_stk.cpp.

2079{
2080 osThreadId_t result;
2081
2082 if (mutex_id == nullptr)
2083 {
2084 result = nullptr;
2085 }
2086 else
2087 {
2088 result = StkThread::ConvertTIdToThreadId(static_cast<const StkMutexBase *>(mutex_id)->GetOwner());
2089 }
2090
2091 return result;
2092}
void * osThreadId_t
Definition cmsis_os2.h:311
static osThreadId_t ConvertTIdToThreadId(const stk::TId tid)

References StkThread::ConvertTIdToThreadId().

Here is the call graph for this function:

◆ osMutexNew()

osMutexId_t osMutexNew ( const osMutexAttr_t * attr)

Create and Initialize a Mutex object.

Parameters
[in]attrmutex attributes; NULL: default values.
Returns
mutex ID for reference by other functions or NULL in case of error.

Definition at line 1967 of file cmsis_os2_stk.cpp.

1968{
1969 osMutexId_t result;
1970
1971 if (IsIrqContext())
1972 {
1973 result = nullptr;
1974 }
1975 else
1976 {
1977 // osMutexPrioInherit: ignored, supported by default.
1978 // osMutexRecursive: sync::Mutex if set, otherwise sync::FastMutex (non-recursive) unless
1979 // STK_CMSIS_USE_FAST_MUTEX is 0, in which case sync::Mutex is always used.
1980 // osMutexRobust: will assert as unsafe code.
1981 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1982 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1983 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1984 const bool robust = ((attr != nullptr) && ((attr->attr_bits & osMutexRobust) != 0U));
1985 const bool recursive = ((STK_CMSIS_USE_FAST_MUTEX == 0) ||
1986 ((attr != nullptr) && ((attr->attr_bits & osMutexRecursive) != 0U)));
1987
1988 // disallow osMutexRobust
1989 STK_ASSERT(!robust);
1990 if (robust)
1991 {
1992 result = nullptr;
1993 }
1994 else
1995 {
1996 // convert to the common base pointer first: osMutexId_t always holds a StkMutexBase pointer
1997 StkMutexBase *mb;
1998
1999 if (recursive)
2000 mb = PlacementNewOrHeap<StkMutex>(cb_mem, cb_sz, name);
2001 else
2002 mb = PlacementNewOrHeap<StkFastMutex>(cb_mem, cb_sz, name);
2003
2004 result = static_cast<osMutexId_t>(mb);
2005 }
2006 }
2007
2008 return result;
2009}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:516
#define STK_CMSIS_USE_FAST_MUTEX
void * osMutexId_t
Definition cmsis_os2.h:320
#define osMutexRecursive
Recursive mutex.
Definition cmsis_os2.h:278
#define osMutexRobust
Robust mutex.
Definition cmsis_os2.h:280
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:373
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:371
const char * name
name of the mutex
Definition cmsis_os2.h:370
void * cb_mem
memory for control block
Definition cmsis_os2.h:372

References osMutexAttr_t::attr_bits, osMutexAttr_t::cb_mem, osMutexAttr_t::cb_size, IsIrqContext(), osMutexAttr_t::name, osMutexRecursive, osMutexRobust, PlacementNewOrHeap(), STK_ASSERT, and STK_CMSIS_USE_FAST_MUTEX.

Here is the call graph for this function:

◆ osMutexRelease()

osStatus_t osMutexRelease ( osMutexId_t mutex_id)

Release a Mutex that was acquired by osMutexAcquire.

Parameters
[in]mutex_idmutex ID obtained by osMutexNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2047 of file cmsis_os2_stk.cpp.

2048{
2049 osStatus_t result;
2050
2051 if (IsIrqContext())
2052 {
2053 result = osErrorISR;
2054 }
2055 else if (mutex_id == nullptr)
2056 {
2057 result = osErrorParameter;
2058 }
2059 else
2060 {
2061 StkMutexBase *const mb = static_cast<StkMutexBase *>(mutex_id);
2062
2063 // CMSIS-RTOS2: releasing a mutex which is not owned by the caller fails with osErrorResource
2064 if (mb->GetOwner() != stk::GetTid())
2065 {
2066 result = osErrorResource;
2067 }
2068 else
2069 {
2070 mb->Unlock();
2071 result = osOK;
2072 }
2073 }
2074
2075 return result;
2076}
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:376
virtual stk::TId GetOwner() const =0
virtual void Unlock()=0

References StkMutexBase::GetOwner(), stk::GetTid(), IsIrqContext(), osErrorISR, osErrorParameter, osErrorResource, osOK, and StkMutexBase::Unlock().

Here is the call graph for this function:

◆ osSemaphoreAcquire()

osStatus_t osSemaphoreAcquire ( osSemaphoreId_t semaphore_id,
uint32_t timeout )

Acquire a Semaphore token or timeout if no tokens are available.

Parameters
[in]semaphore_idsemaphore ID obtained by osSemaphoreNew.
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
status code that indicates the execution status of the function.

Definition at line 2161 of file cmsis_os2_stk.cpp.

2162{
2163 osStatus_t result;
2164
2165 if (semaphore_id == nullptr)
2166 {
2167 result = osErrorParameter;
2168 }
2169 else if (IsIrqContext() && (timeout != 0U))
2170 {
2171 result = osErrorISR;
2172 }
2173 else
2174 {
2175 StkSemaphore *sem = static_cast<StkSemaphore *>(semaphore_id);
2176 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2177
2178 result = StkWaitResultToCmsis(sem->m_semaphore.WaitEx(stk_timeout), stk_timeout);
2179 }
2180
2181 return result;
2182}
EWaitResult WaitEx(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter), preserving the full wait outcome.
stk::sync::Semaphore m_semaphore

References CmsisTimeoutToStk(), IsIrqContext(), StkSemaphore::m_semaphore, osErrorISR, osErrorParameter, StkWaitResultToCmsis(), and stk::sync::Semaphore::WaitEx().

Here is the call graph for this function:

◆ osSemaphoreDelete()

osStatus_t osSemaphoreDelete ( osSemaphoreId_t semaphore_id)

Delete a Semaphore object.

Parameters
[in]semaphore_idsemaphore ID obtained by osSemaphoreNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2218 of file cmsis_os2_stk.cpp.

2219{
2220 osStatus_t result;
2221
2222 if (IsIrqContext())
2223 {
2224 result = osErrorISR;
2225 }
2226 else if (semaphore_id == nullptr)
2227 {
2228 result = osErrorParameter;
2229 }
2230 else
2231 {
2232 ObjDestroy(static_cast<StkSemaphore *>(semaphore_id));
2233 result = osOK;
2234 }
2235
2236 return result;
2237}

References IsIrqContext(), ObjDestroy(), osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osSemaphoreGetCount()

uint32_t osSemaphoreGetCount ( osSemaphoreId_t semaphore_id)

Get current Semaphore token count.

Parameters
[in]semaphore_idsemaphore ID obtained by osSemaphoreNew.
Returns
number of tokens available.

Definition at line 2201 of file cmsis_os2_stk.cpp.

2202{
2203 uint32_t result;
2204
2205 if (semaphore_id == nullptr)
2206 {
2207 result = 0U;
2208 }
2209 else
2210 {
2211 result = static_cast<uint32_t>(
2212 static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetCount());
2213 }
2214
2215 return result;
2216}
uint16_t GetCount() const
Get current counter value.

References stk::sync::Semaphore::GetCount(), and StkSemaphore::m_semaphore.

Here is the call graph for this function:

◆ osSemaphoreGetName()

const char * osSemaphoreGetName ( osSemaphoreId_t semaphore_id)

Get name of a Semaphore object.

Parameters
[in]semaphore_idsemaphore ID obtained by osSemaphoreNew.
Returns
name as null-terminated string.

Definition at line 2145 of file cmsis_os2_stk.cpp.

2146{
2147 const char *result;
2148
2149 if (semaphore_id == nullptr)
2150 {
2151 result = nullptr;
2152 }
2153 else
2154 {
2155 result = static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetTraceName();
2156 }
2157
2158 return result;
2159}

◆ osSemaphoreNew()

osSemaphoreId_t osSemaphoreNew ( uint32_t max_count,
uint32_t initial_count,
const osSemaphoreAttr_t * attr )

Create and Initialize a Semaphore object.

Parameters
[in]max_countmaximum number of available tokens.
[in]initial_countinitial number of available tokens.
[in]attrsemaphore attributes; NULL: default values.
Returns
semaphore ID for reference by other functions or NULL in case of error.

Definition at line 2119 of file cmsis_os2_stk.cpp.

2121{
2122 osSemaphoreId_t result;
2123
2124 if (IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
2125 {
2126 result = nullptr;
2127 }
2128 else
2129 {
2130 // STK Semaphore uses uint16_t counters, clamp to stk::sync::Semaphore::COUNT_MAX.
2131 const uint16_t mc = static_cast<uint16_t>(stk::Min(max_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX)));
2132 const uint16_t ic = static_cast<uint16_t>(stk::Min(initial_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX)));
2133
2134 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2135 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2136 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2137
2138 StkSemaphore *const sem = PlacementNewOrHeap<StkSemaphore>(cb_mem, cb_sz, ic, mc, name);
2139 result = static_cast<osSemaphoreId_t>(sem);
2140 }
2141
2142 return result;
2143}
void * osSemaphoreId_t
Definition cmsis_os2.h:323
static constexpr T Min(T a, T b) noexcept
Compile-time minimum of two values.
Definition stk_defs.h:753
static const uint16_t COUNT_MAX
Max count value supported.
const char * name
name of the semaphore
Definition cmsis_os2.h:378
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:381
void * cb_mem
memory for control block
Definition cmsis_os2.h:380

References osSemaphoreAttr_t::cb_mem, osSemaphoreAttr_t::cb_size, stk::sync::Semaphore::COUNT_MAX, IsIrqContext(), stk::Min(), osSemaphoreAttr_t::name, and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osSemaphoreRelease()

osStatus_t osSemaphoreRelease ( osSemaphoreId_t semaphore_id)

Release a Semaphore token up to the initial maximum count.

Parameters
[in]semaphore_idsemaphore ID obtained by osSemaphoreNew.
Returns
status code that indicates the execution status of the function.

Definition at line 2184 of file cmsis_os2_stk.cpp.

2185{
2186 osStatus_t result;
2187
2188 if (semaphore_id == nullptr)
2189 {
2190 result = osErrorParameter;
2191 }
2192 else
2193 {
2194 static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.Signal();
2195 result = osOK;
2196 }
2197
2198 return result;
2199}

References osErrorParameter, and osOK.

◆ osThreadDetach()

osStatus_t osThreadDetach ( osThreadId_t thread_id)

Detach a thread (thread storage can be reclaimed when thread terminates).

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
status code that indicates the execution status of the function.

Definition at line 1301 of file cmsis_os2_stk.cpp.

1302{
1303 osStatus_t result;
1304
1305 if (IsIrqContext())
1306 {
1307 result = osErrorISR;
1308 }
1309 else if (thread_id == nullptr)
1310 {
1311 result = osErrorParameter;
1312 }
1313 else
1314 {
1315 StkThread *const th = static_cast<StkThread *>(thread_id);
1316
1318
1319 switch (th->m_join_state)
1320 {
1322 // already detached - CMSIS spec says this is an error
1323 result = osError;
1324 break;
1325
1327 // already joined - cannot detach
1328 result = osError;
1329 break;
1330
1332 // thread finished but nobody joined yet, transition to Detached
1333 // and free the control block now, since no joiner will ever do it
1335 ObjDestroy(th); // safe: task slot already freed by the kernel
1336 result = osOK;
1337 break;
1338
1340 // normal case: thread is still running or just hasn't been joined
1342 result = osOK;
1343 break;
1344
1345 default:
1346 result = osError;
1347 break;
1348 }
1349 }
1350
1351 return result;
1352}
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:54
volatile JoinState m_join_state

References StkThread::Detached, StkThread::Exited, IsIrqContext(), StkThread::Joinable, StkThread::Joined, StkThread::m_join_state, ObjDestroy(), osError, osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osThreadEnumerate()

uint32_t osThreadEnumerate ( osThreadId_t * thread_array,
uint32_t array_items )

Enumerate active threads.

Parameters
[out]thread_arraypointer to array for retrieving thread IDs.
[in]array_itemsmaximum number of items in array for retrieving thread IDs.
Returns
number of enumerated threads.

Definition at line 1521 of file cmsis_os2_stk.cpp.

1522{
1523 uint32_t result_count = 0U;
1524 const osKernelState_t kstate = osKernelGetState();
1525
1526 // kernel must be active and buffer must be valid
1527 if ((kstate != osKernelInactive) && (thread_array != nullptr) && (array_items != 0U))
1528 {
1529 // release resources of detached threads that have already been removed by the kernel
1530 if (!IsIrqContext())
1531 {
1533 }
1534
1535 // cast the raw pointer array to the expected ITask* destination type
1536 stk::ITask **const tasks_destination = reinterpret_cast<stk::ITask **>(
1537 reinterpret_cast<void *>(thread_array));
1538
1539 // bind raw destination buffer into a temporary ArrayView object
1540 const size_t count = g_StkKernel.EnumerateTasks(
1541 stk::ArrayView<stk::ITask *>(tasks_destination, static_cast<size_t>(array_items)));
1542
1543 result_count = static_cast<uint32_t>(count);
1544 }
1545
1546 return result_count;
1547}
static void StkReapZombieThreads()
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:277
Interface for a user task.
Definition stk_common.h:824

References g_StkKernel, IsIrqContext(), osKernelGetState(), osKernelInactive, and StkReapZombieThreads().

Here is the call graph for this function:

◆ osThreadExit()

void osThreadExit ( void )

Terminate execution of current running thread.

Definition at line 1447 of file cmsis_os2_stk.cpp.

1448{
1449 StkThread *const th = static_cast<StkThread *>(osThreadGetId());
1450
1451 g_StkKernel.ScheduleTaskRemoval(th);
1452
1453 // Wait for removal.
1454 for (;;)
1455 {
1456 stk::Yield();
1457 }
1458}
osThreadId_t osThreadGetId(void)
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:560

References __NO_RETURN, g_StkKernel, osThreadGetId(), and stk::Yield().

Referenced by osThreadTerminate().

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

◆ osThreadFeedWatchdog()

osStatus_t osThreadFeedWatchdog ( uint32_t ticks)

Feed watchdog of the current running thread.

Parameters
[in]ticksinterval in kernel ticks until the thread watchdog expires, or 0 to stop the watchdog
Returns
status code that indicates the execution status of the function.

◆ osThreadFlagsClear()

uint32_t osThreadFlagsClear ( uint32_t flags)

Clear the specified Thread Flags of current running thread.

Parameters
[in]flagsspecifies the flags of the thread that shall be cleared.
Returns
thread flags before clearing or error code if highest bit set.

Definition at line 1570 of file cmsis_os2_stk.cpp.

1571{
1572 uint32_t result;
1573
1574 osThreadId_t const self = osThreadGetId();
1575 if (self == nullptr)
1576 {
1577 result = osFlagsErrorUnknown;
1578 }
1579 else
1580 {
1581 StkThread *th = static_cast<StkThread *>(self);
1582 result = StkFlagsResultToCmsis(th->m_thread_flags.Clear(flags));
1583 }
1584
1585 return result;
1586}
#define osFlagsErrorUnknown
osError (-1).
Definition cmsis_os2.h:255
uint32_t Clear(uint32_t flags)
Clear one or more flags.
stk::sync::EventFlags m_thread_flags

References stk::sync::EventFlags::Clear(), StkThread::m_thread_flags, osFlagsErrorUnknown, osThreadGetId(), and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osThreadFlagsGet()

uint32_t osThreadFlagsGet ( void )

Get the current Thread Flags of current running thread.

Returns
current thread flags.

Definition at line 1588 of file cmsis_os2_stk.cpp.

1589{
1590 uint32_t result;
1591
1592 osThreadId_t const self = osThreadGetId();
1593 if (self == nullptr)
1594 {
1595 result = 0U;
1596 }
1597 else
1598 {
1599 result = static_cast<StkThread *>(self)->m_thread_flags.Get();
1600 }
1601
1602 return result;
1603}

References osThreadGetId().

Here is the call graph for this function:

◆ osThreadFlagsSet()

uint32_t osThreadFlagsSet ( osThreadId_t thread_id,
uint32_t flags )

Set the specified Thread Flags of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
[in]flagsspecifies the flags of the thread that shall be set.
Returns
thread flags after setting or error code if highest bit set.

Definition at line 1553 of file cmsis_os2_stk.cpp.

1554{
1555 uint32_t result;
1556
1557 if ((thread_id == nullptr) || ((flags & osFlagsError) != 0U))
1558 {
1559 result = osFlagsErrorParameter;
1560 }
1561 else
1562 {
1563 StkThread *th = static_cast<StkThread *>(thread_id);
1564 result = StkFlagsResultToCmsis(th->m_thread_flags.Set(flags));
1565 }
1566
1567 return result;
1568}
uint32_t Set(uint32_t flags)
Set one or more flags.

References StkThread::m_thread_flags, osFlagsError, osFlagsErrorParameter, stk::sync::EventFlags::Set(), and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osThreadFlagsWait()

uint32_t osThreadFlagsWait ( uint32_t flags,
uint32_t options,
uint32_t timeout )

Wait for one or more Thread Flags of the current running thread to become signaled.

Parameters
[in]flagsspecifies the flags to wait for.
[in]optionsspecifies flags options (osFlagsXxxx).
[in]timeoutCMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
Returns
thread flags before clearing or error code if highest bit set.

Definition at line 1605 of file cmsis_os2_stk.cpp.

1606{
1607 uint32_t result;
1608
1609 if (IsIrqContext())
1610 {
1611 result = osFlagsErrorISR;
1612 }
1613 else
1614 {
1615 osThreadId_t const self = osThreadGetId();
1616 if (self == nullptr)
1617 {
1618 result = osFlagsErrorUnknown;
1619 }
1620 else
1621 {
1622 StkThread *th = static_cast<StkThread *>(self);
1623 result = StkFlagsResultToCmsis(th->m_thread_flags.Wait(flags,
1624 CmsisFlagsOptionsToStk(options), CmsisTimeoutToStk(timeout)));
1625 }
1626 }
1627
1628 return result;
1629}
#define osFlagsErrorISR
osErrorISR (-6).
Definition cmsis_os2.h:259
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.

References CmsisFlagsOptionsToStk(), CmsisTimeoutToStk(), IsIrqContext(), StkThread::m_thread_flags, osFlagsErrorISR, osFlagsErrorUnknown, osThreadGetId(), StkFlagsResultToCmsis(), and stk::sync::EventFlags::Wait().

Here is the call graph for this function:

◆ osThreadGetAffinityMask()

uint32_t osThreadGetAffinityMask ( osThreadId_t thread_id)

Get current processor affinity mask of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
current processor affinity mask of the specified thread.

◆ osThreadGetClass()

uint32_t osThreadGetClass ( osThreadId_t thread_id)

Get safety class of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
safety class of the specified thread.

◆ osThreadGetCount()

uint32_t osThreadGetCount ( void )

Get number of active threads.

Returns
number of active threads.

Definition at line 1499 of file cmsis_os2_stk.cpp.

1500{
1501 uint32_t count = 0U;
1502
1504 {
1505 // release resources of detached threads that have already been removed by the kernel
1506 // (task context only: osThreadGetCount() may not be called from ISR per CMSIS, and the reap is skipped there)
1507 if (!IsIrqContext())
1508 {
1510 }
1511
1512 // avoid race with OnTick
1514
1515 count = static_cast<uint32_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
1516 }
1517
1518 return count;
1519}

References g_StkKernel, IsIrqContext(), osKernelGetState(), osKernelInactive, and StkReapZombieThreads().

Here is the call graph for this function:

◆ osThreadGetId()

osThreadId_t osThreadGetId ( void )

Return the thread ID of the current running thread.

Returns
thread ID for reference by other functions or NULL in case of error.

Definition at line 1099 of file cmsis_os2_stk.cpp.

1100{
1101 osThreadId_t threadId = nullptr;
1102
1103 const osKernelState_t kernel_state = osKernelGetState();
1104 const bool is_irq = IsIrqContext();
1105
1106 if ((kernel_state != osKernelInactive) && !is_irq)
1107 {
1108 // STK's GetTid() returns the ITask pointer cast to Word.
1110 }
1111
1112 return threadId;
1113}

References StkThread::ConvertTIdToThreadId(), stk::GetTid(), IsIrqContext(), osKernelGetState(), and osKernelInactive.

Referenced by osThreadExit(), osThreadFlagsClear(), osThreadFlagsGet(), osThreadFlagsWait(), osThreadGetState(), osThreadJoin(), and osThreadTerminate().

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

◆ osThreadGetName()

const char * osThreadGetName ( osThreadId_t thread_id)

Get name of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
name as null-terminated string.

Definition at line 1083 of file cmsis_os2_stk.cpp.

1084{
1085 const char *result;
1086
1087 if (thread_id == nullptr)
1088 {
1089 result = nullptr;
1090 }
1091 else
1092 {
1093 result = static_cast<StkThread *>(thread_id)->m_name;
1094 }
1095
1096 return result;
1097}

◆ osThreadGetPriority()

osPriority_t osThreadGetPriority ( osThreadId_t thread_id)

Get current priority of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
current priority value of the specified thread.

Definition at line 1200 of file cmsis_os2_stk.cpp.

1201{
1202 osPriority_t result;
1203
1204 if (IsIrqContext() || (thread_id == nullptr))
1205 {
1206 result = osPriorityError;
1207 }
1208 else
1209 {
1210 StkThread *const th = static_cast<StkThread *>(thread_id);
1211 result = StkPrioToCmsis(th->m_stk_priority);
1212 }
1213
1214 return result;
1215}
static __stk_forceinline osPriority_t StkPrioToCmsis(int32_t p)
volatile int32_t m_stk_priority

References IsIrqContext(), StkThread::m_stk_priority, osPriorityError, and StkPrioToCmsis().

Here is the call graph for this function:

◆ osThreadGetStackSize()

uint32_t osThreadGetStackSize ( osThreadId_t thread_id)

Get stack size of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
stack size in bytes.

Definition at line 1140 of file cmsis_os2_stk.cpp.

1141{
1142 uint32_t result;
1143
1144 if (thread_id == nullptr)
1145 {
1146 result = 0U;
1147 }
1148 else
1149 {
1150 StkThread *const th = static_cast<StkThread *>(thread_id);
1151 result = static_cast<uint32_t>(th->GetStackSize()) * sizeof(stk::Word);
1152 }
1153
1154 return result;
1155}
uintptr_t Word
Native processor word type.
Definition stk_common.h:160
size_t GetStackSize() const override
Get number of elements of the stack memory array.

References StkThread::GetStackSize().

Here is the call graph for this function:

◆ osThreadGetStackSpace()

uint32_t osThreadGetStackSpace ( osThreadId_t thread_id)

Get available stack space of a thread based on stack watermark recording during execution.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
remaining stack space in bytes.

Definition at line 1157 of file cmsis_os2_stk.cpp.

1158{
1159 uint32_t result;
1160
1161 if (thread_id == nullptr)
1162 {
1163 result = 0U;
1164 }
1165 else
1166 {
1167 StkThread *const th = static_cast<StkThread *>(thread_id);
1168 result = static_cast<uint32_t>(th->GetStackSpace() * sizeof(stk::Word));
1169 }
1170
1171 return result;
1172}
virtual size_t GetStackSpace() const
Get available stack space.
Definition stk_common.h:465

References stk::IStackMemory::GetStackSpace().

Here is the call graph for this function:

◆ osThreadGetState()

osThreadState_t osThreadGetState ( osThreadId_t thread_id)

Get current thread state of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
current thread state of the specified thread.

Definition at line 1115 of file cmsis_os2_stk.cpp.

1116{
1117 osThreadState_t threadState = osThreadError;
1118
1119 if (!IsIrqContext() && (thread_id != nullptr))
1120 {
1121 const StkThread *const th = static_cast<StkThread *>(thread_id);
1122
1123 if (th->m_suspended)
1124 {
1125 threadState = osThreadBlocked;
1126 }
1127 else if (thread_id == osThreadGetId())
1128 {
1129 threadState = osThreadRunning;
1130 }
1131 else
1132 {
1133 threadState = osThreadReady;
1134 }
1135 }
1136
1137 return threadState;
1138}

References IsIrqContext(), StkThread::m_suspended, osThreadBlocked, osThreadError, osThreadGetId(), osThreadReady, and osThreadRunning.

Here is the call graph for this function:

◆ osThreadGetZone()

uint32_t osThreadGetZone ( osThreadId_t thread_id)

Get MPU protected zone of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
MPU protected zone of the specified thread.

References __NO_RETURN.

◆ osThreadJoin()

osStatus_t osThreadJoin ( osThreadId_t thread_id)

Wait for specified thread to terminate.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
status code that indicates the execution status of the function.

Definition at line 1354 of file cmsis_os2_stk.cpp.

1355{
1356 osStatus_t result;
1357
1358 if (IsIrqContext())
1359 {
1360 result = osErrorISR;
1361 }
1362 else if (thread_id == nullptr)
1363 {
1364 result = osErrorParameter;
1365 }
1366 // Self-join is undefined behavior per POSIX / CMSIS spec.
1367 else if (thread_id == osThreadGetId())
1368 {
1369 result = osErrorParameter;
1370 }
1371 else
1372 {
1373 StkThread *th = static_cast<StkThread *>(thread_id);
1374 bool destroy = false;
1375
1376 {
1378
1379 // Only joinable threads can be joined.
1381 {
1382 result = osError;
1383 }
1384 // Double-join: second caller always gets an error.
1386 {
1387 result = osError;
1388 }
1389 else
1390 {
1391 // Only wait if the thread has not exited yet: if OnExit() already set Exited, its notification
1392 // has already happened and waiting for it would block forever.
1394 {
1396
1397 // Block until OnExit() fires (transitions state to Exited).
1398 // m_join_cv.Wait() atomically releases the critical section and suspends.
1400 {
1401 // WAIT_INFINITE - CMSIS osThreadJoin has no timeout parameter.
1402 // A cancelled wait is harmless (the predicate is re-checked), but a rejected one
1403 // (WAIT_RESULT_FAIL) returns at once without releasing cs_: bail out instead of
1404 // spinning with interrupts disabled. The state check below turns it into osError.
1406 {
1407 break;
1408 }
1409 }
1410 }
1411 // else Exited: OnExit() already fired, nothing to wait for
1412
1413 // At this point m_join_state == Exited (or Detached if someone
1414 // raced osThreadDetach - treat that as an error).
1416 {
1417 result = osError;
1418 }
1419 else
1420 {
1421 // Claim the control block: any further join/detach on it now fails with an error
1422 // instead of racing with the destruction below.
1424 destroy = true;
1425 result = osOK;
1426 }
1427 }
1428 }
1429
1430 if (destroy)
1431 {
1432 // OnExit() notifies m_join_cv from the kernel tick, which empties its wait list, but the kernel unlinks
1433 // the (now idle) condition variable from its active sync list only on the NEXT tick. If the joiner is
1434 // woken within the same tick it must not destroy the control block yet, otherwise that sync list would
1435 // reference freed memory. Sleeping one tick guarantees the kernel has processed it. Done outside of the
1436 // critical section, as sleeping inside of it would block the tick.
1437 stk::Sleep(1);
1438
1439 // Free the control block - the kernel has already freed the slot.
1440 ObjDestroy(th);
1441 }
1442 }
1443
1444 return result;
1445}
@ WAIT_RESULT_FAIL
IKernelService::Wait returned with error without waiting.
Definition stk_common.h:138
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:228
EWaitResult WaitEx(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal, preserving the full wait outcome.
stk::sync::ConditionVariable m_join_cv

References StkThread::Detached, StkThread::Exited, IsIrqContext(), StkThread::Joinable, StkThread::Joined, StkThread::m_join_cv, StkThread::m_join_state, ObjDestroy(), osError, osErrorISR, osErrorParameter, osOK, osThreadGetId(), stk::Sleep(), stk::WAIT_INFINITE, stk::WAIT_RESULT_FAIL, and stk::sync::ConditionVariable::WaitEx().

Here is the call graph for this function:

◆ osThreadNew()

osThreadId_t osThreadNew ( osThreadFunc_t func,
void * argument,
const osThreadAttr_t * attr )

Create a thread and add it to Active Threads.

Parameters
[in]functhread function.
[in]argumentpointer that is passed to the thread function as start argument.
[in]attrthread attributes; NULL: default values.
Returns
thread ID for reference by other functions or NULL in case of error.

Definition at line 970 of file cmsis_os2_stk.cpp.

971{
972 osThreadId_t result = nullptr;
973
974 const bool is_irq = IsIrqContext();
975 const osKernelState_t kernel_state = osKernelGetState();
976
977 // validate environment and arguments
978 bool is_valid = (!is_irq && (func != nullptr) && (kernel_state != osKernelInactive));
979
980 // validate priority value
981 osPriority_t cmsis_prio = osPriorityNormal;
982 if (is_valid && (attr != nullptr))
983 {
984 if (attr->priority != osPriorityNone)
985 {
986 cmsis_prio = attr->priority;
987 }
988
989 if ((cmsis_prio < osPriorityIdle) || (cmsis_prio > osPriorityISR))
990 {
991 is_valid = false; // invalidate object creation
992 }
993 }
994
995 // validate stack configuration:
996 // - caller-supplied stack (stack_mem != nullptr): used as-is, never silently enlarged beyond the buffer
997 // the caller gave us, so a zero/too small size or a misaligned address fails the call;
998 // - otherwise heap-allocated: stack_size is honored (never below the minimum), 0 -> default size.
999 stk::Word *stack_mem = nullptr;
1000 size_t stack_words = CMSIS_STK_DEFAULT_STACK_WORDS;
1001 if (is_valid && (attr != nullptr))
1002 {
1003 const size_t req_words = (attr->stack_size / sizeof(stk::Word)); // rounds down: never exceeds the buffer
1004
1005 if (attr->stack_mem != nullptr)
1006 {
1007 if ((req_words < static_cast<size_t>(CMSIS_STK_MIN_STACK_WORDS)) ||
1008 ((reinterpret_cast<uintptr_t>(attr->stack_mem) % alignof(stk::Word)) != 0U))
1009 {
1010 is_valid = false; // invalidate object creation
1011 }
1012 else
1013 {
1014 stack_mem = static_cast<stk::Word *>(attr->stack_mem);
1015 stack_words = req_words;
1016 }
1017 }
1018 else if (attr->stack_size != 0U)
1019 {
1020 stack_words = stk::Max<size_t>(req_words, CMSIS_STK_MIN_STACK_WORDS);
1021 }
1022 else
1023 {
1024 // noop: default heap-allocated stack size
1025 }
1026 }
1027
1028 if (is_valid)
1029 {
1030 // release resources of detached threads that have exited since the last call
1032
1033 const bool is_joinable = (attr != nullptr) && ((attr->attr_bits & osThreadJoinable) != 0U);
1034 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1035 const uint32_t cb_size = ((attr != nullptr) ? attr->cb_size : 0U);
1036
1037 StkThread *th = PlacementNewOrHeap<StkThread>(cb_mem, cb_size);
1038 if (th != nullptr)
1039 {
1040 th->m_func = func;
1041 th->m_argument = argument;
1042 th->m_name = (attr != nullptr) ? attr->name : nullptr;
1044
1045 // stack configuration (validated above)
1046 if (stack_mem != nullptr)
1047 {
1048 th->m_stack = stack_mem;
1049 th->m_stack_size = stack_words;
1050 th->m_stack_owned = false;
1051 }
1052 // allocate stack memory if not caller-provided
1053 else
1054 {
1055 th->m_stack = new (std::nothrow) stk::Word[stack_words];
1056 STK_ASSERT(th->m_stack != nullptr);
1057
1058 if (th->m_stack == nullptr)
1059 {
1060 ObjDestroy(th);
1061 th = nullptr;
1062 }
1063 else
1064 {
1065 th->m_stack_size = stack_words;
1066 th->m_stack_owned = true;
1067 }
1068 }
1069
1070 // finalize and register the thread
1071 if (th != nullptr)
1072 {
1073 th->m_stk_priority = CmsisPrioToStk(cmsis_prio);
1074 g_StkKernel.AddTask(th);
1075 result = static_cast<osThreadId_t>(th);
1076 }
1077 }
1078 }
1079
1080 return result; // The solitary exit point
1081}
#define CMSIS_STK_MIN_STACK_WORDS
#define CMSIS_STK_DEFAULT_STACK_WORDS
static __stk_forceinline int32_t CmsisPrioToStk(osPriority_t p)
#define osThreadJoinable
Thread created in joinable mode.
Definition cmsis_os2.h:264
static constexpr T Max(T a, T b) noexcept
Compile-time maximum of two values.
Definition stk_defs.h:759
void * cb_mem
memory for control block
Definition cmsis_os2.h:343
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:342
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:344
void * stack_mem
memory for stack
Definition cmsis_os2.h:345
osPriority_t priority
initial thread priority (default: osPriorityNormal)
Definition cmsis_os2.h:347
uint32_t stack_size
size of stack
Definition cmsis_os2.h:346
const char * name
name of the thread
Definition cmsis_os2.h:341
stk::Word * m_stack
size_t m_stack_size
osThreadFunc_t m_func
const char * m_name
void * m_argument

References osThreadAttr_t::attr_bits, osThreadAttr_t::cb_mem, osThreadAttr_t::cb_size, CMSIS_STK_DEFAULT_STACK_WORDS, CMSIS_STK_MIN_STACK_WORDS, CmsisPrioToStk(), StkThread::Detached, g_StkKernel, IsIrqContext(), StkThread::Joinable, StkThread::m_argument, StkThread::m_func, StkThread::m_join_state, StkThread::m_name, StkThread::m_stack, StkThread::m_stack_owned, StkThread::m_stack_size, StkThread::m_stk_priority, stk::Max(), osThreadAttr_t::name, ObjDestroy(), osKernelGetState(), osKernelInactive, osPriorityIdle, osPriorityISR, osPriorityNone, osPriorityNormal, osThreadJoinable, PlacementNewOrHeap(), osThreadAttr_t::priority, osThreadAttr_t::stack_mem, osThreadAttr_t::stack_size, STK_ASSERT, and StkReapZombieThreads().

Here is the call graph for this function:

◆ osThreadProtectPrivileged()

osStatus_t osThreadProtectPrivileged ( void )

Protect creation of privileged threads.

Returns
status code that indicates the execution status of the function.

◆ osThreadResume()

osStatus_t osThreadResume ( osThreadId_t thread_id)

Resume execution of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
status code that indicates the execution status of the function.

Definition at line 1264 of file cmsis_os2_stk.cpp.

1265{
1266 osStatus_t result;
1267
1268 if (IsIrqContext())
1269 {
1270 result = osErrorISR;
1271 }
1272 else if (thread_id == nullptr)
1273 {
1274 result = osErrorParameter;
1275 }
1276 else if (osKernelGetState() == osKernelInactive)
1277 {
1278 result = osErrorParameter;
1279 }
1280 else
1281 {
1282 StkThread *const th = static_cast<StkThread *>(thread_id);
1283
1285
1286 if (!th->m_suspended)
1287 {
1288 result = osOK; // not suspended, nothing to do
1289 }
1290 else
1291 {
1292 g_StkKernel.ResumeTask(th);
1293 th->m_suspended = false;
1294 result = osOK;
1295 }
1296 }
1297
1298 return result;
1299}

References g_StkKernel, IsIrqContext(), StkThread::m_suspended, osErrorISR, osErrorParameter, osKernelGetState(), osKernelInactive, and osOK.

Here is the call graph for this function:

◆ osThreadResumeClass()

osStatus_t osThreadResumeClass ( uint32_t safety_class,
uint32_t mode )

Resume execution of threads for specified safety classes.

Parameters
[in]safety_classsafety class.
[in]modesafety mode.
Returns
status code that indicates the execution status of the function.

◆ osThreadSetAffinityMask()

osStatus_t osThreadSetAffinityMask ( osThreadId_t thread_id,
uint32_t affinity_mask )

Set processor affinity mask of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
[in]affinity_maskprocessor affinity mask for the thread.
Returns
status code that indicates the execution status of the function.

◆ osThreadSetPriority()

osStatus_t osThreadSetPriority ( osThreadId_t thread_id,
osPriority_t priority )

Change priority of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
[in]prioritynew priority value for the thread function.
Returns
status code that indicates the execution status of the function.

Definition at line 1174 of file cmsis_os2_stk.cpp.

1175{
1176 osStatus_t result;
1177
1178 if (IsIrqContext())
1179 {
1180 result = osErrorISR;
1181 }
1182 else if (thread_id == nullptr)
1183 {
1184 result = osErrorParameter;
1185 }
1186 else if ((priority < osPriorityIdle) || (priority > osPriorityISR))
1187 {
1188 result = osErrorParameter;
1189 }
1190 else
1191 {
1192 StkThread *const th = static_cast<StkThread *>(thread_id);
1193 th->m_stk_priority = CmsisPrioToStk(priority);
1194 result = osOK;
1195 }
1196
1197 return result;
1198}

References CmsisPrioToStk(), IsIrqContext(), StkThread::m_stk_priority, osErrorISR, osErrorParameter, osOK, osPriorityIdle, and osPriorityISR.

Here is the call graph for this function:

◆ osThreadSuspend()

osStatus_t osThreadSuspend ( osThreadId_t thread_id)

Suspend execution of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
status code that indicates the execution status of the function.

Definition at line 1238 of file cmsis_os2_stk.cpp.

1239{
1240 osStatus_t result;
1241
1242 if (IsIrqContext())
1243 {
1244 result = osErrorISR;
1245 }
1246 else if (thread_id == nullptr)
1247 {
1248 result = osErrorParameter;
1249 }
1250 else if (osKernelGetState() == osKernelInactive)
1251 {
1252 result = osErrorParameter;
1253 }
1254 else
1255 {
1256 StkThread *const th = static_cast<StkThread *>(thread_id);
1257 g_StkKernel.SuspendTask(th, th->m_suspended);
1258 result = osOK;
1259 }
1260
1261 return result;
1262}

References g_StkKernel, IsIrqContext(), StkThread::m_suspended, osErrorISR, osErrorParameter, osKernelGetState(), osKernelInactive, and osOK.

Here is the call graph for this function:

◆ osThreadSuspendClass()

osStatus_t osThreadSuspendClass ( uint32_t safety_class,
uint32_t mode )

Suspend execution of threads for specified safety classes.

Parameters
[in]safety_classsafety class.
[in]modesafety mode.
Returns
status code that indicates the execution status of the function.

◆ osThreadTerminate()

osStatus_t osThreadTerminate ( osThreadId_t thread_id)

Terminate execution of a thread.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
status code that indicates the execution status of the function.

Definition at line 1460 of file cmsis_os2_stk.cpp.

1461{
1463 const bool is_active = (osKernelGetState() != osKernelInactive);
1464
1465 if ((thread_id != nullptr) && is_active)
1466 {
1467 // Terminating the calling thread: ScheduleTaskRemoval() only marks it, and the thread would keep
1468 // running until the next tick, so route it through the exit path instead.
1469 if (thread_id == osThreadGetId())
1470 {
1471 osThreadExit(); // does not return
1472 }
1473
1474 // release resources of detached threads that have already been removed by the kernel
1475 if (!IsIrqContext())
1476 {
1478 }
1479
1480 StkThread *const th = static_cast<StkThread *>(thread_id);
1481
1482 // avoid race conditions during termination
1484
1485 // RemoveTask triggers the STATE_REMOVE_PENDING path in the kernel,
1486 // which will call OnExit() before freeing the slot.
1487 g_StkKernel.ScheduleTaskRemoval(th);
1488
1489 // Do NOT free here: the kernel still references the control block (and the stack, which may be
1490 // in use until the task is switched out) and calls OnExit() on it from the tick.
1491 // Detached threads are queued by OnExit() and freed by StkReapZombieThreads(),
1492 // for joinable threads OnExit() wakes the joiner, which calls ObjDestroy().
1493 status = osOK;
1494 }
1495
1496 return status;
1497}
void osThreadExit(void)
Terminate execution of current running thread.

References g_StkKernel, IsIrqContext(), osErrorParameter, osKernelGetState(), osKernelInactive, osOK, osThreadExit(), osThreadGetId(), and StkReapZombieThreads().

Here is the call graph for this function:

◆ osThreadTerminateZone()

osStatus_t osThreadTerminateZone ( uint32_t zone)

Terminate execution of threads assigned to a specified MPU protected zone.

Parameters
[in]zoneMPU protected zone.
Returns
status code that indicates the execution status of the function.

◆ osThreadYield()

osStatus_t osThreadYield ( void )

Pass control to next thread that is in state READY.

Returns
status code that indicates the execution status of the function.

Definition at line 1217 of file cmsis_os2_stk.cpp.

1218{
1219 osStatus_t result;
1220
1221 if (IsIrqContext())
1222 {
1223 result = osErrorISR;
1224 }
1225 else if (osKernelGetState() == osKernelInactive)
1226 {
1227 result = osError;
1228 }
1229 else
1230 {
1231 stk::Yield();
1232 result = osOK;
1233 }
1234
1235 return result;
1236}

References IsIrqContext(), osError, osErrorISR, osKernelGetState(), osKernelInactive, osOK, and stk::Yield().

Here is the call graph for this function:

◆ osTimerDelete()

osStatus_t osTimerDelete ( osTimerId_t timer_id)

Delete a timer.

Parameters
[in]timer_idtimer ID obtained by osTimerNew.
Returns
status code that indicates the execution status of the function.

Definition at line 1797 of file cmsis_os2_stk.cpp.

1798{
1799 osStatus_t result;
1800
1801 if (IsIrqContext())
1802 {
1803 result = osErrorISR;
1804 }
1805 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1806 {
1807 result = osErrorParameter;
1808 }
1809 else
1810 {
1811 result = osOK;
1812
1813 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1814
1815 if (tmr->IsActive())
1816 {
1817 if (!g_TimerHost->Stop(*tmr))
1818 {
1819 result = osError;
1820 }
1821 }
1822
1823 if (result == osOK)
1824 {
1825 ObjDestroy(tmr);
1826 }
1827 }
1828
1829 return result;
1830}
static stk::time::TimerHost * g_TimerHost
bool IsActive() const
Check whether the timer is currently active.

References g_TimerHost, stk::time::TimerHost::Timer::IsActive(), IsIrqContext(), ObjDestroy(), osError, osErrorISR, osErrorParameter, and osOK.

Here is the call graph for this function:

◆ osTimerGetName()

const char * osTimerGetName ( osTimerId_t timer_id)

Get name of a timer.

Parameters
[in]timer_idtimer ID obtained by osTimerNew.
Returns
name as null-terminated string.

Definition at line 1710 of file cmsis_os2_stk.cpp.

1711{
1712 const char *result;
1713
1714 if (timer_id == nullptr)
1715 {
1716 result = nullptr;
1717 }
1718 else
1719 {
1720 result = static_cast<StkTimer *>(timer_id)->m_name;
1721 }
1722
1723 return result;
1724}

◆ osTimerIsRunning()

uint32_t osTimerIsRunning ( osTimerId_t timer_id)

Check if a timer is running.

Parameters
[in]timer_idtimer ID obtained by osTimerNew.
Returns
0 not running, 1 running.

Definition at line 1781 of file cmsis_os2_stk.cpp.

1782{
1783 uint32_t result;
1784
1785 if (timer_id == nullptr)
1786 {
1787 result = 0U;
1788 }
1789 else
1790 {
1791 result = (static_cast<StkTimer *>(timer_id)->IsActive() ? 1U : 0U);
1792 }
1793
1794 return result;
1795}

References stk::time::TimerHost::Timer::IsActive().

Here is the call graph for this function:

◆ osTimerNew()

osTimerId_t osTimerNew ( osTimerFunc_t func,
osTimerType_t type,
void * argument,
const osTimerAttr_t * attr )

Create and Initialize a timer.

Parameters
[in]funcfunction pointer to callback function.
[in]typeosTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
[in]argumentargument to the timer callback function.
[in]attrtimer attributes; NULL: default values.
Returns
timer ID for reference by other functions or NULL in case of error.

Definition at line 1682 of file cmsis_os2_stk.cpp.

1684{
1685 osTimerId_t result;
1686
1687 if (IsIrqContext() || (func == nullptr))
1688 {
1689 result = nullptr;
1690 }
1691 else if (osKernelGetState() == osKernelInactive)
1692 {
1693 result = nullptr;
1694 }
1695 else
1696 {
1697 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1698 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1699 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1700
1702
1703 StkTimer *const tmr = PlacementNewOrHeap<StkTimer>(cb_mem, cb_sz, func, type, argument, name);
1704 result = static_cast<osTimerId_t>(tmr);
1705 }
1706
1707 return result;
1708}
void * osTimerId_t
Definition cmsis_os2.h:314
void * cb_mem
memory for control block
Definition cmsis_os2.h:356
const char * name
name of the timer
Definition cmsis_os2.h:354
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:357
static void EnsureTimerHostCreated()

References osTimerAttr_t::cb_mem, osTimerAttr_t::cb_size, StkTimer::EnsureTimerHostCreated(), IsIrqContext(), osTimerAttr_t::name, osKernelGetState(), osKernelInactive, and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osTimerStart()

osStatus_t osTimerStart ( osTimerId_t timer_id,
uint32_t ticks )

Start or restart a timer.

Parameters
[in]timer_idtimer ID obtained by osTimerNew.
[in]tickstime ticks value of the timer.
Returns
status code that indicates the execution status of the function.

Definition at line 1726 of file cmsis_os2_stk.cpp.

1727{
1728 osStatus_t result;
1729
1730 if (IsIrqContext())
1731 {
1732 result = osErrorISR;
1733 }
1734 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1735 {
1736 result = osErrorParameter;
1737 }
1738 else
1739 {
1740 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1741
1742 const uint32_t period_ticks = ((tmr->m_type == osTimerPeriodic) ? ticks : 0U);
1743 tmr->m_period_ticks = period_ticks;
1744
1745 const bool ok = g_TimerHost->Restart(*tmr, ticks, period_ticks);
1746 result = (ok ? osOK : osError);
1747 }
1748
1749 return result;
1750}
osTimerType_t m_type
uint32_t m_period_ticks

References g_TimerHost, IsIrqContext(), StkTimer::m_period_ticks, StkTimer::m_type, osError, osErrorISR, osErrorParameter, osOK, and osTimerPeriodic.

Here is the call graph for this function:

◆ osTimerStop()

osStatus_t osTimerStop ( osTimerId_t timer_id)

Stop a timer.

Parameters
[in]timer_idtimer ID obtained by osTimerNew.
Returns
status code that indicates the execution status of the function.

Definition at line 1752 of file cmsis_os2_stk.cpp.

1753{
1754 osStatus_t result;
1755
1756 if (IsIrqContext())
1757 {
1758 result = osErrorISR;
1759 }
1760 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1761 {
1762 result = osErrorParameter;
1763 }
1764 else
1765 {
1766 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1767
1768 if (!tmr->IsActive())
1769 {
1770 result = osErrorResource;
1771 }
1772 else
1773 {
1774 result = (g_TimerHost->Stop(*tmr) ? osOK : osError);
1775 }
1776 }
1777
1778 return result;
1779}

References g_TimerHost, stk::time::TimerHost::Timer::IsActive(), IsIrqContext(), osError, osErrorISR, osErrorParameter, osErrorResource, and osOK.

Here is the call graph for this function:

◆ osWatchdogAlarm_Handler()

uint32_t osWatchdogAlarm_Handler ( osThreadId_t thread_id)

Handler for expired thread watchdogs.

Parameters
[in]thread_idthread ID obtained by osThreadNew or osThreadGetId.
Returns
new watchdog reload value or 0 to stop the watchdog.

◆ osZoneSetup_Callback()

void osZoneSetup_Callback ( uint32_t zone)

Setup MPU protected zone (called when zone changes).

Parameters
[in]zonezone number.