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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

566{
567 if (version != nullptr)
568 {
569 version->api = STK_WRAPPER_API_VERSION;
571 }
572
573 if ((id_buf != nullptr) && (id_size > 0U))
574 {
575 const char *const id = STK_WRAPPER_KERNEL_ID;
576 size_t copy_len = id_size - 1U;
577 const size_t id_len = CmsisStrlen(id);
578 if (copy_len > id_len)
579 {
580 copy_len = id_len;
581 }
582
583 STK_MEMCPY(id_buf, id, copy_len);
584 id_buf[copy_len] = '\0';
585 }
586
587 return osOK;
588}
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:534
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 590 of file cmsis_os2_stk.cpp.

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

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

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

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

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

799{
801}
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:353

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

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

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

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

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

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

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

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

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

736{
737#if STK_TICKLESS_IDLE
739 {
741 }
742#else
743 // Not supported in non-tickless kernel.
744 STK_UNUSED(sleep_ticks);
745#endif
746}
#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 623 of file cmsis_os2_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1724{
1725 osMutexId_t result;
1726
1727 if (IsIrqContext())
1728 {
1729 result = nullptr;
1730 }
1731 else
1732 {
1733 // osMutexPrioInherit: ignored, supported by default.
1734 // osMutexRecursive: ignored, sync::Mutex is always recursive.
1735 // osMutexRobust: will assert as unsafe code.
1736 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
1737 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1738 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
1739 const bool robust = ((attr != nullptr) && ((attr->attr_bits & osMutexRobust) != 0U));
1740
1741 // disallow osMutexRobust
1742 STK_ASSERT(!robust);
1743 if (robust)
1744 {
1745 result = nullptr;
1746 }
1747 else
1748 {
1749 StkMutex *const m = PlacementNewOrHeap<StkMutex>(cb_mem, cb_sz, name);
1750 result = static_cast<osMutexId_t>(m);
1751 }
1752 }
1753
1754 return result;
1755}
#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 1804 of file cmsis_os2_stk.cpp.

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

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

1911{
1912 osStatus_t result;
1913
1914 if (semaphore_id == nullptr)
1915 {
1916 result = osErrorParameter;
1917 }
1918 else if (IsIrqContext() && (timeout != 0U))
1919 {
1920 result = osErrorISR;
1921 }
1922 else
1923 {
1924 StkSemaphore *sem = static_cast<StkSemaphore *>(semaphore_id);
1925 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1926
1927 const bool acquired = sem->m_semaphore.Wait(stk_timeout);
1928 if (!acquired)
1929 {
1930 result = ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1931 }
1932 else
1933 {
1934 result = osOK;
1935 }
1936 }
1937
1938 return result;
1939}
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 1975 of file cmsis_os2_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

949{
950 uint32_t result;
951
952 if (thread_id == nullptr)
953 {
954 result = 0U;
955 }
956 else
957 {
958 StkThread *const th = static_cast<StkThread *>(thread_id);
959 result = static_cast<uint32_t>(th->GetStackSizeBytes());
960 }
961
962 return result;
963}
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.

References StkThread::GetStackSizeBytes().

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

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

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

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

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

1163{
1164 osStatus_t result;
1165
1166 if (IsIrqContext())
1167 {
1168 result = osErrorISR;
1169 }
1170 else if (thread_id == nullptr)
1171 {
1172 result = osErrorParameter;
1173 }
1174 // Self-join is undefined behavior per POSIX / CMSIS spec.
1175 else if (thread_id == osThreadGetId())
1176 {
1177 result = osErrorParameter;
1178 }
1179 else
1180 {
1181 StkThread *th = static_cast<StkThread *>(thread_id);
1182
1184
1185 // Only joinable threads can be joined.
1187 {
1188 result = osError;
1189 }
1190 // Double-join: second caller always gets an error.
1192 {
1193 result = osError;
1194 }
1195 else
1196 {
1198
1199 // Block until OnExit() fires (transitions state to Exited).
1200 // m_join_cv.Wait() atomically releases m_join_mutex and suspends.
1202 {
1203 // WAIT_INFINITE - CMSIS osThreadJoin has no timeout parameter.
1205 }
1206
1207 // At this point m_join_state == Exited (or Detached if someone
1208 // raced osThreadDetach - treat that as an error).
1210 {
1211 result = osError;
1212 }
1213 else
1214 {
1215 // Free the control block - the kernel has already freed the slot.
1216 ObjDestroy(th);
1217 result = osOK;
1218 }
1219 }
1220 }
1221
1222 return result;
1223}
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:183
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 808 of file cmsis_os2_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.