SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
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.

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

1393{
1394 osStatus_t result;
1395
1396 if (IsIrqContext())
1397 {
1398 result = osErrorISR;
1399 }
1400 else if (osKernelGetState() == osKernelInactive)
1401 {
1402 result = osError;
1403 }
1404 else
1405 {
1407 result = osOK;
1408 }
1409
1410 return result;
1411}
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:358

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

1414{
1415 osStatus_t result;
1416
1417 if (IsIrqContext())
1418 {
1419 result = osErrorISR;
1420 }
1421 else if (osKernelGetState() == osKernelInactive)
1422 {
1423 result = osError;
1424 }
1425 else
1426 {
1427 result = (stk::SleepUntil(static_cast<stk::Ticks>(ticks)) ? osOK : osError);
1428 }
1429
1430 return result;
1431}
int64_t Ticks
Ticks value.
Definition stk_common.h:151
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:383

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

1647{
1648 uint32_t result;
1649
1650 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1651 {
1652 result = osFlagsErrorParameter;
1653 }
1654 else
1655 {
1656 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Clear(flags));
1657 }
1658
1659 return result;
1660}
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 1696 of file cmsis_os2_stk.cpp.

1697{
1698 osStatus_t result;
1699
1700 if (IsIrqContext())
1701 {
1702 result = osErrorISR;
1703 }
1704 else if (ef_id == nullptr)
1705 {
1706 result = osErrorParameter;
1707 }
1708 else
1709 {
1710 ObjDestroy(static_cast<StkEventFlags *>(ef_id));
1711 result = osOK;
1712 }
1713
1714 return result;
1715}
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 1662 of file cmsis_os2_stk.cpp.

1663{
1664 uint32_t result;
1665
1666 if (ef_id == nullptr)
1667 {
1668 result = 0U;
1669 }
1670 else
1671 {
1672 result = static_cast<StkEventFlags *>(ef_id)->m_ef.Get();
1673 }
1674
1675 return result;
1676}

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

1615{
1616 const char *result;
1617
1618 if (ef_id == nullptr)
1619 {
1620 result = nullptr;
1621 }
1622 else
1623 {
1624 result = static_cast<StkEventFlags *>(ef_id)->m_ef.GetTraceName();
1625 }
1626
1627 return result;
1628}

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

1594{
1595 osEventFlagsId_t result;
1596
1597 if (IsIrqContext())
1598 {
1599 result = nullptr;
1600 }
1601 else
1602 {
1603 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1604 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1605 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1606
1607 StkEventFlags *const ef = PlacementNewOrHeap<StkEventFlags>(cb_mem, cb_sz, name);
1608 result = static_cast<osEventFlagsId_t>(ef);
1609 }
1610
1611 return result;
1612}
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 1630 of file cmsis_os2_stk.cpp.

1631{
1632 uint32_t result;
1633
1634 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1635 {
1636 result = osFlagsErrorParameter;
1637 }
1638 else
1639 {
1640 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Set(flags));
1641 }
1642
1643 return result;
1644}

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

1680{
1681 uint32_t result;
1682
1683 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1684 {
1685 result = osFlagsErrorParameter;
1686 }
1687 else
1688 {
1689 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Wait(flags,
1690 CmsisFlagsOptionsToStk(options), CmsisTimeoutToStk(timeout)));
1691 }
1692
1693 return result;
1694}
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 564 of file cmsis_os2_stk.cpp.

565{
566 if (version != nullptr)
567 {
568 version->api = STK_WRAPPER_API_VERSION;
570 }
571
572 if ((id_buf != nullptr) && (id_size > 0U))
573 {
574 const char *const id = STK_WRAPPER_KERNEL_ID;
575 size_t copy_len = id_size - 1U;
576 const size_t id_len = CmsisStrlen(id);
577 if (copy_len > id_len)
578 {
579 copy_len = id_len;
580 }
581
582 STK_MEMCPY(id_buf, id, copy_len);
583 id_buf[copy_len] = '\0';
584 }
585
586 return osOK;
587}
static __stk_forceinline void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
A wrapper for a built-in memcpy, redefine to your own if required.
Definition stk_arch.h:540
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 589 of file cmsis_os2_stk.cpp.

590{
591 osKernelState_t state;
592
593 if (g_StkKernelLocked != 0U)
594 {
595 state = osKernelLocked;
596 }
597 else
598 {
599 switch (g_StkKernel.GetState())
600 {
602 state = osKernelInactive;
603 break;
605 state = osKernelReady;
606 break;
608 state = osKernelRunning;
609 break;
611 state = osKernelSuspended;
612 break;
613 default:
614 state = osKernelError;
615 break;
616 }
617 }
618
619 return state;
620}
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 787 of file cmsis_os2_stk.cpp.

788{
789 return static_cast<uint32_t>(stk::GetSysTimerCount());
790}
static Cycles GetSysTimerCount()
Get system timer count value.
Definition stk_helper.h:338

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

793{
794 return stk::GetSysTimerCount();
795}

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

798{
800}
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:347

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

748{
749 uint32_t result;
750
752 {
753 result = 0U;
754 }
755 else
756 {
757 result = static_cast<uint32_t>(stk::GetTicks());
758 }
759
760 return result;
761}
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:313

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

764{
765 uint32_t result;
766
768 {
769 result = 1000U; // default 1 kHz
770 }
771 else
772 {
773 const int32_t res_us = stk::GetTickResolution(); // us per tick
774 if (res_us <= 0)
775 {
776 result = 1000U;
777 }
778 else
779 {
780 result = (1000000U / static_cast<uint32_t>(res_us));
781 }
782 }
783
784 return result;
785}
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:247

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

544{
545 osStatus_t result;
546
547 if (IsIrqContext())
548 {
549 result = osErrorISR;
550 }
552 {
553 result = osError;
554 }
555 else
556 {
557 g_StkKernel.Initialize(); // default 1 ms tick resolution
558 result = osOK;
559 }
560
561 return result;
562}

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

646{
647 int32_t result;
648
649 if (IsIrqContext())
650 {
651 result = static_cast<int32_t>(osErrorISR);
652 }
653 else
654 {
657 result = 0;
658 }
659
660 return result;
661}
static void Enter()
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 685 of file cmsis_os2_stk.cpp.

686{
687 int32_t result;
688
689 if (IsIrqContext())
690 {
691 result = static_cast<int32_t>(osErrorISR);
692 }
693 else if (lock == 1)
694 {
697 result = lock;
698 }
699 else if (g_StkKernelLocked == 0U)
700 {
701 result = static_cast<int32_t>(osErrorResource);
702 }
703 else
704 {
707 result = lock;
708 }
709
710 return result;
711}
static void Exit()
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 734 of file cmsis_os2_stk.cpp.

735{
736#if STK_TICKLESS_IDLE
738 {
740 }
741#else
742 // Not supported in non-tickless kernel.
743 STK_UNUSED(sleep_ticks);
744#endif
745}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:608
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 622 of file cmsis_os2_stk.cpp.

623{
624 osStatus_t result;
625
626 if (IsIrqContext())
627 {
628 result = osErrorISR;
629 }
630 else if (osKernelGetState() != osKernelReady)
631 {
632 result = osError;
633 }
634 else
635 {
636 // Start() does not return for KERNEL_STATIC;
637 // for KERNEL_DYNAMIC it returns when all tasks exit.
638 g_StkKernel.Start();
639 result = osOK;
640 }
641
642 return result;
643}

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

714{
715 uint32_t result;
716
717#if STK_TICKLESS_IDLE
719 {
720 result = 0U;
721 }
722 else
723 {
724 result = static_cast<uint32_t>(stk::IKernelService::GetInstance()->Suspend());
725 }
726#else
727 // Not supported in non-tickless kernel.
728 result = 0U;
729#endif
730
731 return result;
732}
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 663 of file cmsis_os2_stk.cpp.

664{
665 int32_t result;
666
667 if (IsIrqContext())
668 {
669 result = static_cast<int32_t>(osErrorISR);
670 }
671 else if (g_StkKernelLocked == 0U)
672 {
673 result = static_cast<int32_t>(osErrorResource);
674 }
675 else
676 {
679 result = 0;
680 }
681
682 return result;
683}

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

2068{
2069 void *result;
2070
2071 if (mp_id == nullptr)
2072 {
2073 result = nullptr;
2074 }
2075 // ISR context is only valid with timeout == 0 (NO_WAIT / TryAlloc).
2076 else if (IsIrqContext() && (timeout != 0U))
2077 {
2078 result = nullptr;
2079 }
2080 else
2081 {
2082 result = static_cast<StkMemPool *>(mp_id)->m_mpool.TimedAlloc(CmsisTimeoutToStk(timeout));
2083 }
2084
2085 return result;
2086}

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

2173{
2174 osStatus_t result;
2175
2176 if (IsIrqContext())
2177 {
2178 result = osErrorISR;
2179 }
2180 else if (mp_id == nullptr)
2181 {
2182 result = osErrorParameter;
2183 }
2184 else
2185 {
2186 ObjDestroy(static_cast<StkMemPool *>(mp_id));
2187 result = osOK;
2188 }
2189
2190 return result;
2191}

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

2089{
2090 osStatus_t result;
2091
2092 if ((mp_id == nullptr) || (block == nullptr))
2093 {
2094 result = osErrorParameter;
2095 }
2096 else if (!static_cast<StkMemPool *>(mp_id)->m_mpool.Free(block))
2097 {
2098 result = osErrorParameter; // ptr not from this pool
2099 }
2100 else
2101 {
2102 result = osOK;
2103 }
2104
2105 return result;
2106}

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

2125{
2126 uint32_t result;
2127
2128 if (mp_id == nullptr)
2129 {
2130 result = 0U;
2131 }
2132 else
2133 {
2134 result = static_cast<uint32_t>(static_cast<StkMemPool *>(mp_id)->m_mpool.GetBlockSize());
2135 }
2136
2137 return result;
2138}
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 2108 of file cmsis_os2_stk.cpp.

2109{
2110 uint32_t result;
2111
2112 if (mp_id == nullptr)
2113 {
2114 result = 0U;
2115 }
2116 else
2117 {
2118 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetCapacity();
2119 }
2120
2121 return result;
2122}

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

2141{
2142 uint32_t result;
2143
2144 if (mp_id == nullptr)
2145 {
2146 result = 0U;
2147 }
2148 else
2149 {
2150 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetUsedCount();
2151 }
2152
2153 return result;
2154}

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

2052{
2053 const char *result;
2054
2055 if (mp_id == nullptr)
2056 {
2057 result = nullptr;
2058 }
2059 else
2060 {
2061 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetTraceName();
2062 }
2063
2064 return result;
2065}

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

2157{
2158 uint32_t result;
2159
2160 if (mp_id == nullptr)
2161 {
2162 result = 0U;
2163 }
2164 else
2165 {
2166 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetFreeCount();
2167 }
2168
2169 return result;
2170}

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

2002{
2003 osMemoryPoolId_t result;
2004
2005 // ISR context: forbidden per CMSIS spec.
2006 // Zero capacity or zero block size are meaningless.
2007 if (IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2008 {
2009 result = nullptr;
2010 }
2011 else
2012 {
2013 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2014 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2015 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2016 void *const mp_mem = ((attr != nullptr) ? attr->mp_mem : nullptr);
2017 const uint32_t mp_sz = ((attr != nullptr) ? attr->mp_size : 0U);
2018
2019 // Compute the aligned block size and required storage byte count.
2020 const uint32_t aligned_blk = stk::memory::BlockMemoryPool::AlignBlockSize(block_size);
2021 const uint32_t storage_required = (block_count * aligned_blk);
2022
2023 StkMemPool *pool;
2024
2025 if ((mp_mem != nullptr) && (mp_sz >= storage_required))
2026 {
2027 // Caller-supplied pool storage - BlockMemoryPool external-storage ctor.
2028 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2029 block_count, block_size, name, static_cast<uint8_t *>(mp_mem));
2030 }
2031 else
2032 {
2033 // Heap-allocated pool storage - BlockMemoryPool heap ctor.
2034 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2035 block_count, block_size, name);
2036
2037 // If the heap ctor failed to allocate storage, clean up and bail.
2038 if ((pool != nullptr) && !pool->m_mpool.IsStorageValid())
2039 {
2040 ObjDestroy(pool);
2041 pool = nullptr;
2042 }
2043 }
2044
2045 result = static_cast<osMemoryPoolId_t>(pool);
2046 }
2047
2048 return result;
2049}
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 2414 of file cmsis_os2_stk.cpp.

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

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

2297{
2298 osStatus_t result;
2299
2300 if ((mq_id == nullptr) || (msg_ptr == nullptr))
2301 {
2302 result = osErrorParameter;
2303 }
2304 else if (IsIrqContext() && (timeout != 0U))
2305 {
2306 result = osErrorISR;
2307 }
2308 else
2309 {
2310 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2311
2312 if (!static_cast<StkMessageQueue *>(mq_id)->m_mq.Get(msg_ptr, stk_timeout))
2313 {
2314 result = ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
2315 }
2316 else
2317 {
2318 if (msg_prio != nullptr)
2319 {
2320 *msg_prio = 0U; // STK queues have no priority lanes.
2321 }
2322 result = osOK;
2323 }
2324 }
2325
2326 return result;
2327}
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:210
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:146

References CmsisTimeoutToStk(), IsIrqContext(), stk::NO_WAIT, osErrorISR, osErrorParameter, osErrorResource, osErrorTimeout, and osOK.

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

2330{
2331 uint32_t result;
2332
2333 if (mq_id == nullptr)
2334 {
2335 result = 0U;
2336 }
2337 else
2338 {
2339 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCapacity());
2340 }
2341
2342 return result;
2343}
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 2361 of file cmsis_os2_stk.cpp.

2362{
2363 uint32_t result;
2364
2365 if (mq_id == nullptr)
2366 {
2367 result = 0U;
2368 }
2369 else
2370 {
2371 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCount());
2372 }
2373
2374 return result;
2375}
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 2345 of file cmsis_os2_stk.cpp.

2346{
2347 uint32_t result;
2348
2349 if (mq_id == nullptr)
2350 {
2351 result = 0U;
2352 }
2353 else
2354 {
2355 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetMsgSize());
2356 }
2357
2358 return result;
2359}
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 2249 of file cmsis_os2_stk.cpp.

2250{
2251 const char *result;
2252
2253 if (mq_id == nullptr)
2254 {
2255 result = nullptr;
2256 }
2257 else
2258 {
2259 result = static_cast<StkMessageQueue *>(mq_id)->m_mq.GetTraceName();
2260 }
2261
2262 return result;
2263}

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

2378{
2379 uint32_t result;
2380
2381 if (mq_id == nullptr)
2382 {
2383 result = 0U;
2384 }
2385 else
2386 {
2387 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetSpace());
2388 }
2389
2390 return result;
2391}
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 2198 of file cmsis_os2_stk.cpp.

2200{
2201 osMessageQueueId_t result;
2202
2203 if (IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
2205 {
2206 result = nullptr;
2207 }
2208 else
2209 {
2210 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2211 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2212 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2213 void *const ext_buf = ((attr != nullptr) ? attr->mq_mem : nullptr);
2214 const uint32_t ext_buf_size = ((attr != nullptr) ? attr->mq_size : 0U);
2215
2216 const uint32_t buf_required = (msg_count * msg_size);
2217
2218 StkMessageQueue *mq;
2219
2220 if ((ext_buf != nullptr) && (ext_buf_size >= buf_required))
2221 {
2222 // Data buffer: use caller-supplied memory.
2223 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
2224 msg_count, msg_size, name, static_cast<uint8_t *>(ext_buf));
2225 }
2226 else
2227 {
2228 // Data buffer: heap-allocated inside StkMessageQueue constructor.
2229 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
2230 msg_count, msg_size, name);
2231
2232 // Validate
2233 if (mq != nullptr)
2234 {
2235 if (mq->m_mq.GetBuffer() == nullptr)
2236 {
2237 ObjDestroy(mq);
2238 mq = nullptr;
2239 }
2240 }
2241 }
2242
2243 result = static_cast<osMessageQueueId_t>(mq);
2244 }
2245
2246 return result;
2247}
void * osMessageQueueId_t
Definition cmsis_os2.h:329
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
uint8_t * GetBuffer()
Get pointer to the message buffer.
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, stk::sync::MessageQueue::GetBuffer(), IsIrqContext(), 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 2265 of file cmsis_os2_stk.cpp.

2267{
2268 osStatus_t result;
2269
2270 if ((mq_id == nullptr) || (msg_ptr == nullptr))
2271 {
2272 result = osErrorParameter;
2273 }
2274 else if (IsIrqContext() && (timeout != 0U))
2275 {
2276 result = osErrorISR;
2277 }
2278 else
2279 {
2280 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2281
2282 if (!static_cast<StkMessageQueue *>(mq_id)->m_mq.Put(msg_ptr, stk_timeout))
2283 {
2284 result = ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
2285 }
2286 else
2287 {
2288 result = osOK;
2289 }
2290 }
2291
2292 return result;
2293}

References CmsisTimeoutToStk(), IsIrqContext(), stk::NO_WAIT, osErrorISR, osErrorParameter, osErrorResource, osErrorTimeout, and osOK.

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

2394{
2395 osStatus_t result;
2396
2397 if (IsIrqContext())
2398 {
2399 result = osErrorISR;
2400 }
2401 else if (mq_id == nullptr)
2402 {
2403 result = osErrorParameter;
2404 }
2405 else
2406 {
2407 static_cast<StkMessageQueue *>(mq_id)->m_mq.Reset();
2408 result = osOK;
2409 }
2410
2411 return result;
2412}

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

1773{
1774 osStatus_t result;
1775
1776 if (IsIrqContext())
1777 {
1778 result = osErrorISR;
1779 }
1780 else if (mutex_id == nullptr)
1781 {
1782 result = osErrorParameter;
1783 }
1784 else
1785 {
1786 StkMutex *m = static_cast<StkMutex *>(mutex_id);
1787 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1788
1789 const bool acquired = m->m_mutex.TimedLock(stk_timeout);
1790 if (!acquired)
1791 {
1792 result = ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1793 }
1794 else
1795 {
1796 result = osOK;
1797 }
1798 }
1799
1800 return result;
1801}
bool TimedLock(Timeout timeout_ticks)
Acquire lock.
stk::sync::Mutex m_mutex

References CmsisTimeoutToStk(), IsIrqContext(), StkMutex::m_mutex, stk::NO_WAIT, osErrorISR, osErrorParameter, osErrorResource, osErrorTimeout, osOK, and stk::sync::Mutex::TimedLock().

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

1842{
1843 osStatus_t result;
1844
1845 if (IsIrqContext())
1846 {
1847 result = osErrorISR;
1848 }
1849 else if (mutex_id == nullptr)
1850 {
1851 result = osErrorParameter;
1852 }
1853 else
1854 {
1855 ObjDestroy(static_cast<StkMutex *>(mutex_id));
1856 result = osOK;
1857 }
1858
1859 return result;
1860}

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

1757{
1758 const char *result;
1759
1760 if (mutex_id == nullptr)
1761 {
1762 result = nullptr;
1763 }
1764 else
1765 {
1766 result = static_cast<StkMutex *>(mutex_id)->m_mutex.GetTraceName();
1767 }
1768
1769 return result;
1770}

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

1825{
1826 osThreadId_t result;
1827
1828 if (mutex_id == nullptr)
1829 {
1830 result = nullptr;
1831 }
1832 else
1833 {
1835 static_cast<StkMutex *>(mutex_id)->m_mutex.GetOwner());
1836 }
1837
1838 return result;
1839}
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 1722 of file cmsis_os2_stk.cpp.

1723{
1724 osMutexId_t result;
1725
1726 if (IsIrqContext())
1727 {
1728 result = nullptr;
1729 }
1730 else
1731 {
1732 // osMutexPrioInherit: ignored, supported by default.
1733 // osMutexRecursive: ignored, sync::Mutex is always recursive.
1734 // osMutexRobust: will assert as unsafe code.
1735 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1736 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1737 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1738 const bool robust = ((attr != nullptr) && ((attr->attr_bits & osMutexRobust) != 0U));
1739
1740 // disallow osMutexRobust
1741 STK_ASSERT(!robust);
1742 if (robust)
1743 {
1744 result = nullptr;
1745 }
1746 else
1747 {
1748 StkMutex *const m = PlacementNewOrHeap<StkMutex>(cb_mem, cb_sz, name);
1749 result = static_cast<osMutexId_t>(m);
1750 }
1751 }
1752
1753 return result;
1754}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
void * osMutexId_t
Definition cmsis_os2.h:320
#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, osMutexRobust, PlacementNewOrHeap(), and STK_ASSERT.

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

1804{
1805 osStatus_t result;
1806
1807 if (IsIrqContext())
1808 {
1809 result = osErrorISR;
1810 }
1811 else if (mutex_id == nullptr)
1812 {
1813 result = osErrorParameter;
1814 }
1815 else
1816 {
1817 static_cast<StkMutex *>(mutex_id)->m_mutex.Unlock();
1818 result = osOK;
1819 }
1820
1821 return result;
1822}

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

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

1910{
1911 osStatus_t result;
1912
1913 if (semaphore_id == nullptr)
1914 {
1915 result = osErrorParameter;
1916 }
1917 else if (IsIrqContext() && (timeout != 0U))
1918 {
1919 result = osErrorISR;
1920 }
1921 else
1922 {
1923 StkSemaphore *sem = static_cast<StkSemaphore *>(semaphore_id);
1924 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1925
1926 const bool acquired = sem->m_semaphore.Wait(stk_timeout);
1927 if (!acquired)
1928 {
1929 result = ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1930 }
1931 else
1932 {
1933 result = osOK;
1934 }
1935 }
1936
1937 return result;
1938}
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter).
stk::sync::Semaphore m_semaphore

References CmsisTimeoutToStk(), IsIrqContext(), StkSemaphore::m_semaphore, stk::NO_WAIT, osErrorISR, osErrorParameter, osErrorResource, osErrorTimeout, osOK, and stk::sync::Semaphore::Wait().

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

1975{
1976 osStatus_t result;
1977
1978 if (IsIrqContext())
1979 {
1980 result = osErrorISR;
1981 }
1982 else if (semaphore_id == nullptr)
1983 {
1984 result = osErrorParameter;
1985 }
1986 else
1987 {
1988 ObjDestroy(static_cast<StkSemaphore *>(semaphore_id));
1989 result = osOK;
1990 }
1991
1992 return result;
1993}

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

1958{
1959 uint32_t result;
1960
1961 if (semaphore_id == nullptr)
1962 {
1963 result = 0U;
1964 }
1965 else
1966 {
1967 result = static_cast<uint32_t>(
1968 static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetCount());
1969 }
1970
1971 return result;
1972}
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 1893 of file cmsis_os2_stk.cpp.

1894{
1895 const char *result;
1896
1897 if (semaphore_id == nullptr)
1898 {
1899 result = nullptr;
1900 }
1901 else
1902 {
1903 result = static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetTraceName();
1904 }
1905
1906 return result;
1907}

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

1869{
1870 osSemaphoreId_t result;
1871
1872 if (IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
1873 {
1874 result = nullptr;
1875 }
1876 else
1877 {
1878 // STK Semaphore uses uint16_t counters, clamp to stk::sync::Semaphore::COUNT_MAX.
1879 const uint16_t mc = static_cast<uint16_t>(stk::Min(max_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX)));
1880 const uint16_t ic = static_cast<uint16_t>(stk::Min(initial_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX)));
1881
1882 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1883 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1884 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1885
1886 StkSemaphore *const sem = PlacementNewOrHeap<StkSemaphore>(cb_mem, cb_sz, ic, mc, name);
1887 result = static_cast<osSemaphoreId_t>(sem);
1888 }
1889
1890 return result;
1891}
void * osSemaphoreId_t
Definition cmsis_os2.h:323
static constexpr T Min(T a, T b)
Compile-time minimum of two values.
Definition stk_defs.h:639
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 1940 of file cmsis_os2_stk.cpp.

1941{
1942 osStatus_t result;
1943
1944 if (semaphore_id == nullptr)
1945 {
1946 result = osErrorParameter;
1947 }
1948 else
1949 {
1950 static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.Signal();
1951 result = osOK;
1952 }
1953
1954 return result;
1955}

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

1109{
1110 osStatus_t result;
1111
1112 if (IsIrqContext())
1113 {
1114 result = osErrorISR;
1115 }
1116 else if (thread_id == nullptr)
1117 {
1118 result = osErrorParameter;
1119 }
1120 else
1121 {
1122 StkThread *const th = static_cast<StkThread *>(thread_id);
1123
1125
1126 switch (th->m_join_state)
1127 {
1129 // already detached - CMSIS spec says this is an error
1130 result = osError;
1131 break;
1132
1134 // already joined - cannot detach
1135 result = osError;
1136 break;
1137
1139 // thread finished but nobody joined yet, transition to Detached
1140 // and free the control block now, since no joiner will ever do it
1142 ObjDestroy(th); // safe: task slot already freed by the kernel
1143 result = osOK;
1144 break;
1145
1147 // normal case: thread is still running or just hasn't been joined
1149 result = osOK;
1150 break;
1151
1152 default:
1153 result = osError;
1154 break;
1155 }
1156 }
1157
1158 return result;
1159}
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 1283 of file cmsis_os2_stk.cpp.

1284{
1285 uint32_t result_count = 0U;
1286 const osKernelState_t kstate = osKernelGetState();
1287
1288 // kernel must be active and buffer must be valid
1289 if ((kstate != osKernelInactive) && (thread_array != nullptr) && (array_items != 0U))
1290 {
1291 // cast the raw pointer array to the expected ITask* destination type
1292 stk::ITask **const tasks_destination = reinterpret_cast<stk::ITask **>(
1293 reinterpret_cast<void *>(thread_array));
1294
1295 // bind raw destination buffer into a temporary ArrayView object
1296 const size_t count = g_StkKernel.EnumerateTasks(
1297 stk::ArrayView<stk::ITask *>(tasks_destination, static_cast<size_t>(array_items)));
1298
1299 result_count = static_cast<uint32_t>(count);
1300 }
1301
1302 return result_count;
1303}
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:247
Interface for a user task.
Definition stk_common.h:670

References g_StkKernel, osKernelGetState(), and osKernelInactive.

Here is the call graph for this function:

◆ osThreadExit()

void osThreadExit ( void )

Terminate execution of current running thread.

Definition at line 1224 of file cmsis_os2_stk.cpp.

1225{
1226 StkThread *const th = static_cast<StkThread *>(osThreadGetId());
1227
1228 g_StkKernel.ScheduleTaskRemoval(th);
1229
1230 // Wait for removal.
1231 for (;;)
1232 {
1233 stk::Yield();
1234 }
1235}
osThreadId_t osThreadGetId(void)
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:402

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

Here is the call 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 1326 of file cmsis_os2_stk.cpp.

1327{
1328 uint32_t result;
1329
1330 osThreadId_t const self = osThreadGetId();
1331 if (self == nullptr)
1332 {
1333 result = osFlagsErrorUnknown;
1334 }
1335 else
1336 {
1337 StkThread *th = static_cast<StkThread *>(self);
1338 result = StkFlagsResultToCmsis(th->m_thread_flags.Clear(flags));
1339 }
1340
1341 return result;
1342}
#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 1344 of file cmsis_os2_stk.cpp.

1345{
1346 uint32_t result;
1347
1348 osThreadId_t const self = osThreadGetId();
1349 if (self == nullptr)
1350 {
1351 result = 0U;
1352 }
1353 else
1354 {
1355 result = static_cast<StkThread *>(self)->m_thread_flags.Get();
1356 }
1357
1358 return result;
1359}

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

1310{
1311 uint32_t result;
1312
1313 if ((thread_id == nullptr) || ((flags & osFlagsError) != 0U))
1314 {
1315 result = osFlagsErrorParameter;
1316 }
1317 else
1318 {
1319 StkThread *th = static_cast<StkThread *>(thread_id);
1320 result = StkFlagsResultToCmsis(th->m_thread_flags.Set(flags));
1321 }
1322
1323 return result;
1324}
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 1361 of file cmsis_os2_stk.cpp.

1362{
1363 uint32_t result;
1364
1365 if (IsIrqContext())
1366 {
1367 result = osFlagsErrorISR;
1368 }
1369 else
1370 {
1371 osThreadId_t const self = osThreadGetId();
1372 if (self == nullptr)
1373 {
1374 result = osFlagsErrorUnknown;
1375 }
1376 else
1377 {
1378 StkThread *th = static_cast<StkThread *>(self);
1379 result = StkFlagsResultToCmsis(th->m_thread_flags.Wait(flags,
1380 CmsisFlagsOptionsToStk(options), CmsisTimeoutToStk(timeout)));
1381 }
1382 }
1383
1384 return result;
1385}
#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 1268 of file cmsis_os2_stk.cpp.

1269{
1270 uint32_t count = 0U;
1271
1273 {
1274 // avoid race with OnTick
1276
1277 count = static_cast<uint32_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
1278 }
1279
1280 return count;
1281}

References g_StkKernel, osKernelGetState(), and osKernelInactive.

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

907{
908 osThreadId_t threadId = nullptr;
909
910 const osKernelState_t kernel_state = osKernelGetState();
911 const bool is_irq = IsIrqContext();
912
913 if ((kernel_state != osKernelInactive) && !is_irq)
914 {
915 // STK's GetTid() returns the ITask pointer cast to Word.
917 }
918
919 return threadId;
920}
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:237

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

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

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

891{
892 const char *result;
893
894 if (thread_id == nullptr)
895 {
896 result = nullptr;
897 }
898 else
899 {
900 result = static_cast<StkThread *>(thread_id)->m_name;
901 }
902
903 return result;
904}

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

1008{
1009 osPriority_t result;
1010
1011 if (IsIrqContext() || (thread_id == nullptr))
1012 {
1013 result = osPriorityError;
1014 }
1015 else
1016 {
1017 StkThread *const th = static_cast<StkThread *>(thread_id);
1018 result = StkPrioToCmsis(th->m_stk_priority);
1019 }
1020
1021 return result;
1022}
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 947 of file cmsis_os2_stk.cpp.

948{
949 uint32_t result;
950
951 if (thread_id == nullptr)
952 {
953 result = 0U;
954 }
955 else
956 {
957 StkThread *const th = static_cast<StkThread *>(thread_id);
958 result = static_cast<uint32_t>(th->GetStackSize()) * sizeof(stk::Word);
959 }
960
961 return result;
962}
uintptr_t Word
Native processor word type.
Definition stk_common.h:136
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 964 of file cmsis_os2_stk.cpp.

965{
966 uint32_t result;
967
968 if (thread_id == nullptr)
969 {
970 result = 0U;
971 }
972 else
973 {
974 StkThread *const th = static_cast<StkThread *>(thread_id);
975 result = static_cast<uint32_t>(th->GetStackSpace() * sizeof(stk::Word));
976 }
977
978 return result;
979}
virtual size_t GetStackSpace() const
Get available stack space.
Definition stk_common.h:336

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

923{
924 osThreadState_t threadState = osThreadError;
925
926 if (!IsIrqContext() && (thread_id != nullptr))
927 {
928 const StkThread *const th = static_cast<StkThread *>(thread_id);
929
930 if (th->m_suspended)
931 {
932 threadState = osThreadBlocked;
933 }
934 else if (thread_id == osThreadGetId())
935 {
936 threadState = osThreadRunning;
937 }
938 else
939 {
940 threadState = osThreadReady;
941 }
942 }
943
944 return threadState;
945}

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

1162{
1163 osStatus_t result;
1164
1165 if (IsIrqContext())
1166 {
1167 result = osErrorISR;
1168 }
1169 else if (thread_id == nullptr)
1170 {
1171 result = osErrorParameter;
1172 }
1173 // Self-join is undefined behavior per POSIX / CMSIS spec.
1174 else if (thread_id == osThreadGetId())
1175 {
1176 result = osErrorParameter;
1177 }
1178 else
1179 {
1180 StkThread *th = static_cast<StkThread *>(thread_id);
1181
1183
1184 // Only joinable threads can be joined.
1186 {
1187 result = osError;
1188 }
1189 // Double-join: second caller always gets an error.
1191 {
1192 result = osError;
1193 }
1194 else
1195 {
1197
1198 // Block until OnExit() fires (transitions state to Exited).
1199 // m_join_cv.Wait() atomically releases m_join_mutex and suspends.
1201 {
1202 // WAIT_INFINITE - CMSIS osThreadJoin has no timeout parameter.
1204 }
1205
1206 // At this point m_join_state == Exited (or Detached if someone
1207 // raced osThreadDetach - treat that as an error).
1209 {
1210 result = osError;
1211 }
1212 else
1213 {
1214 // Free the control block - the kernel has already freed the slot.
1215 ObjDestroy(th);
1216 result = osOK;
1217 }
1218 }
1219 }
1220
1221 return result;
1222}
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:204
bool Wait(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal.
stk::sync::ConditionVariable m_join_cv

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

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

808{
809 osThreadId_t result = nullptr;
810
811 const bool is_irq = IsIrqContext();
812 const osKernelState_t kernel_state = osKernelGetState();
813
814 // validate environment and arguments
815 bool is_valid = (!is_irq && (func != nullptr) && (kernel_state != osKernelInactive));
816
817 // validate priority value
818 osPriority_t cmsis_prio = osPriorityNormal;
819 if (is_valid && (attr != nullptr))
820 {
821 if (attr->priority != osPriorityNone)
822 {
823 cmsis_prio = attr->priority;
824 }
825
826 if ((cmsis_prio < osPriorityIdle) || (cmsis_prio > osPriorityISR))
827 {
828 is_valid = false; // invalidate object creation
829 }
830 }
831
832 if (is_valid)
833 {
834 const bool is_joinable = (attr != nullptr) && ((attr->attr_bits & osThreadJoinable) != 0U);
835 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
836 const uint32_t cb_size = ((attr != nullptr) ? attr->cb_size : 0U);
837
838 StkThread *th = PlacementNewOrHeap<StkThread>(cb_mem, cb_size);
839 if (th != nullptr)
840 {
841 th->m_func = func;
842 th->m_argument = argument;
843 th->m_name = (attr != nullptr) ? attr->name : nullptr;
845
846 // stack configuration
847 if (attr != nullptr)
848 {
849 if ((attr->stack_mem != nullptr) && (attr->stack_size != 0U))
850 {
851 th->m_stack = static_cast<stk::Word *>(attr->stack_mem);
853 th->m_stack_owned = false;
854 }
855 }
856
857 // allocate stack memory if not caller-provided
858 if (th->m_stack == nullptr)
859 {
860 const size_t stack_words = CMSIS_STK_DEFAULT_STACK_WORDS;
861
862 th->m_stack = new (std::nothrow) stk::Word[stack_words];
863 STK_ASSERT(th->m_stack != nullptr);
864
865 if (th->m_stack == nullptr)
866 {
867 ObjDestroy(th);
868 th = nullptr;
869 }
870 else
871 {
872 th->m_stack_size = stack_words;
873 th->m_stack_owned = true;
874 }
875 }
876
877 // finalize and register the thread
878 if (th != nullptr)
879 {
880 th->m_stk_priority = CmsisPrioToStk(cmsis_prio);
881 g_StkKernel.AddTask(th);
882 result = static_cast<osThreadId_t>(th);
883 }
884 }
885 }
886
887 return result; // The solitary exit point
888}
#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)
Compile-time maximum of two values.
Definition stk_defs.h:645
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, and STK_ASSERT.

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

1072{
1073 osStatus_t result;
1074
1075 if (IsIrqContext())
1076 {
1077 result = osErrorISR;
1078 }
1079 else if (thread_id == nullptr)
1080 {
1081 result = osErrorParameter;
1082 }
1083 else if (osKernelGetState() == osKernelInactive)
1084 {
1085 result = osErrorParameter;
1086 }
1087 else
1088 {
1089 StkThread *const th = static_cast<StkThread *>(thread_id);
1090
1092
1093 if (!th->m_suspended)
1094 {
1095 result = osOK; // not suspended, nothing to do
1096 }
1097 else
1098 {
1099 g_StkKernel.ResumeTask(th);
1100 th->m_suspended = false;
1101 result = osOK;
1102 }
1103 }
1104
1105 return result;
1106}

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

982{
983 osStatus_t result;
984
985 if (IsIrqContext())
986 {
987 result = osErrorISR;
988 }
989 else if (thread_id == nullptr)
990 {
991 result = osErrorParameter;
992 }
993 else if ((priority < osPriorityIdle) || (priority > osPriorityISR))
994 {
995 result = osErrorParameter;
996 }
997 else
998 {
999 StkThread *const th = static_cast<StkThread *>(thread_id);
1000 th->m_stk_priority = CmsisPrioToStk(priority);
1001 result = osOK;
1002 }
1003
1004 return result;
1005}

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

1046{
1047 osStatus_t result;
1048
1049 if (IsIrqContext())
1050 {
1051 result = osErrorISR;
1052 }
1053 else if (thread_id == nullptr)
1054 {
1055 result = osErrorParameter;
1056 }
1057 else if (osKernelGetState() == osKernelInactive)
1058 {
1059 result = osErrorParameter;
1060 }
1061 else
1062 {
1063 StkThread *const th = static_cast<StkThread *>(thread_id);
1064 g_StkKernel.SuspendTask(th, th->m_suspended);
1065 result = osOK;
1066 }
1067
1068 return result;
1069}

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

1238{
1240 const bool is_active = (osKernelGetState() != osKernelInactive);
1241
1242 if ((thread_id != nullptr) && !is_active)
1243 {
1244 StkThread *const th = static_cast<StkThread *>(thread_id);
1245
1246 // avoid race conditions during termination
1248
1249 // RemoveTask triggers the STATE_REMOVE_PENDING path in the kernel,
1250 // which will call OnExit() before freeing the slot.
1251 g_StkKernel.ScheduleTaskRemoval(th);
1252
1253 // For detached threads, free immediately (no joiner expected).
1254 // For joinable threads, OnExit() will wake the joiner; the joiner
1255 // calls ObjDestroy(). Do NOT free here.
1257 {
1258 ObjDestroy(th);
1259 }
1260 // else: joiner owns the lifetime
1261
1262 status = osOK;
1263 }
1264
1265 return status;
1266}

References StkThread::Detached, g_StkKernel, StkThread::m_join_state, ObjDestroy(), osErrorParameter, osKernelGetState(), osKernelInactive, and osOK.

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

1025{
1026 osStatus_t result;
1027
1028 if (IsIrqContext())
1029 {
1030 result = osErrorISR;
1031 }
1032 else if (osKernelGetState() == osKernelInactive)
1033 {
1034 result = osError;
1035 }
1036 else
1037 {
1038 stk::Yield();
1039 result = osOK;
1040 }
1041
1042 return result;
1043}

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

1554{
1555 osStatus_t result;
1556
1557 if (IsIrqContext())
1558 {
1559 result = osErrorISR;
1560 }
1561 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1562 {
1563 result = osErrorParameter;
1564 }
1565 else
1566 {
1567 result = osOK;
1568
1569 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1570
1571 if (tmr->IsActive())
1572 {
1573 if (!g_TimerHost->Stop(*tmr))
1574 {
1575 result = osError;
1576 }
1577 }
1578
1579 if (result == osOK)
1580 {
1581 ObjDestroy(tmr);
1582 }
1583 }
1584
1585 return result;
1586}
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 1466 of file cmsis_os2_stk.cpp.

1467{
1468 const char *result;
1469
1470 if (timer_id == nullptr)
1471 {
1472 result = nullptr;
1473 }
1474 else
1475 {
1476 result = static_cast<StkTimer *>(timer_id)->m_name;
1477 }
1478
1479 return result;
1480}

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

1538{
1539 uint32_t result;
1540
1541 if (timer_id == nullptr)
1542 {
1543 result = 0U;
1544 }
1545 else
1546 {
1547 result = (static_cast<StkTimer *>(timer_id)->IsActive() ? 1U : 0U);
1548 }
1549
1550 return result;
1551}

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

1440{
1441 osTimerId_t result;
1442
1443 if (IsIrqContext() || (func == nullptr))
1444 {
1445 result = nullptr;
1446 }
1447 else if (osKernelGetState() == osKernelInactive)
1448 {
1449 result = nullptr;
1450 }
1451 else
1452 {
1453 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1454 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1455 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1456
1458
1459 StkTimer *const tmr = PlacementNewOrHeap<StkTimer>(cb_mem, cb_sz, func, type, argument, name);
1460 result = static_cast<osTimerId_t>(tmr);
1461 }
1462
1463 return result;
1464}
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 1482 of file cmsis_os2_stk.cpp.

1483{
1484 osStatus_t result;
1485
1486 if (IsIrqContext())
1487 {
1488 result = osErrorISR;
1489 }
1490 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1491 {
1492 result = osErrorParameter;
1493 }
1494 else
1495 {
1496 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1497
1498 const uint32_t period_ticks = ((tmr->m_type == osTimerPeriodic) ? ticks : 0U);
1499 tmr->m_period_ticks = period_ticks;
1500
1501 const bool ok = g_TimerHost->Restart(*tmr, ticks, period_ticks);
1502 result = (ok ? osOK : osError);
1503 }
1504
1505 return result;
1506}
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 1508 of file cmsis_os2_stk.cpp.

1509{
1510 osStatus_t result;
1511
1512 if (IsIrqContext())
1513 {
1514 result = osErrorISR;
1515 }
1516 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
1517 {
1518 result = osErrorParameter;
1519 }
1520 else
1521 {
1522 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
1523
1524 if (!tmr->IsActive())
1525 {
1526 result = osErrorResource;
1527 }
1528 else
1529 {
1530 result = (g_TimerHost->Stop(*tmr) ? osOK : osError);
1531 }
1532 }
1533
1534 return result;
1535}

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.