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

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

Classes

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

Macros

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

Typedefs

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

Enumerations

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

Functions

osStatus_t osKernelInitialize (void)
osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size)
osKernelState_t osKernelGetState (void)
osStatus_t osKernelStart (void)
int32_t osKernelLock (void)
int32_t osKernelUnlock (void)
int32_t osKernelRestoreLock (int32_t lock)
uint32_t osKernelSuspend (void)
void osKernelResume (uint32_t sleep_ticks)
osStatus_t osKernelProtect (uint32_t safety_class)
osStatus_t osKernelDestroyClass (uint32_t safety_class, uint32_t mode)
uint32_t osKernelGetTickCount (void)
uint32_t osKernelGetTickFreq (void)
uint32_t osKernelGetSysTimerCount (void)
uint64_t osKernelGetSysTimerCount64 (void)
uint32_t osKernelGetSysTimerFreq (void)
osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
const char * osThreadGetName (osThreadId_t thread_id)
uint32_t osThreadGetClass (osThreadId_t thread_id)
uint32_t osThreadGetZone (osThreadId_t thread_id)
osThreadId_t osThreadGetId (void)
osThreadState_t osThreadGetState (osThreadId_t thread_id)
uint32_t osThreadGetStackSize (osThreadId_t thread_id)
uint32_t osThreadGetStackSpace (osThreadId_t thread_id)
osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority)
osPriority_t osThreadGetPriority (osThreadId_t thread_id)
osStatus_t osThreadYield (void)
osStatus_t osThreadSuspend (osThreadId_t thread_id)
osStatus_t osThreadResume (osThreadId_t thread_id)
osStatus_t osThreadDetach (osThreadId_t thread_id)
osStatus_t osThreadJoin (osThreadId_t thread_id)
void osThreadExit (void)
 Terminate execution of current running thread.
osStatus_t osThreadTerminate (osThreadId_t thread_id)
osStatus_t osThreadFeedWatchdog (uint32_t ticks)
osStatus_t osThreadProtectPrivileged (void)
osStatus_t osThreadSuspendClass (uint32_t safety_class, uint32_t mode)
osStatus_t osThreadResumeClass (uint32_t safety_class, uint32_t mode)
osStatus_t osThreadTerminateZone (uint32_t zone)
osStatus_t osThreadSetAffinityMask (osThreadId_t thread_id, uint32_t affinity_mask)
uint32_t osThreadGetAffinityMask (osThreadId_t thread_id)
uint32_t osThreadGetCount (void)
uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items)
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags)
uint32_t osThreadFlagsClear (uint32_t flags)
uint32_t osThreadFlagsGet (void)
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)
osStatus_t osDelay (uint32_t ticks)
osStatus_t osDelayUntil (uint32_t ticks)
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
const char * osTimerGetName (osTimerId_t timer_id)
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks)
osStatus_t osTimerStop (osTimerId_t timer_id)
uint32_t osTimerIsRunning (osTimerId_t timer_id)
osStatus_t osTimerDelete (osTimerId_t timer_id)
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr)
const char * osEventFlagsGetName (osEventFlagsId_t ef_id)
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags)
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id)
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)
osMutexId_t osMutexNew (const osMutexAttr_t *attr)
const char * osMutexGetName (osMutexId_t mutex_id)
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout)
osStatus_t osMutexRelease (osMutexId_t mutex_id)
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id)
osStatus_t osMutexDelete (osMutexId_t mutex_id)
osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
const char * osSemaphoreGetName (osSemaphoreId_t semaphore_id)
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)
osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id)
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id)
osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id)
osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr)
const char * osMemoryPoolGetName (osMemoryPoolId_t mp_id)
void * osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout)
osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block)
uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id)
osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id)
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
const char * osMessageQueueGetName (osMessageQueueId_t mq_id)
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id)
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id)
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id)
uint32_t osWatchdogAlarm_Handler (osThreadId_t thread_id)
void osZoneSetup_Callback (uint32_t zone)
void osFaultResume (void)
 Resume normal operation when exiting exception faults.

Detailed Description

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

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

Supported:

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

Design notes:

  • All objects are heap-allocated with operator new/delete. For a fully static deployment, replace with a static object-pool allocator.
  • The wrapper owns one global Kernel instance (g_StkKernel). Call osKernelInitialize() before any other API, then osKernelStart().
  • The kernel is configured with KERNEL_DYNAMIC | KERNEL_SYNC and sched::SwitchStrategyFP64_NSY (64 fixed-priority levels, round-robin within a level, osThreadYield() hands over to same-priority threads only). osThread priority values (osPriorityIdle=1 .. osPriorityISR=56) are mapped to STK priority levels 0.55.
  • 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.
  • Kernel lock (osKernelLock / osKernelUnlock / osKernelRestoreLock): only task switching is disabled, the kernel tick, timeouts and ISRs keep running (osKernelGetState() reports osKernelLocked). The lock is not nested, use osKernelRestoreLock() with the value returned by osKernelLock() to emulate nesting. The lock holder must keep the CPU: osDelay, osDelayUntil, osThreadYield, any call which would have to block (e.g. a contended mutex or an empty semaphore, queue, flags with a timeout), osThreadSuspend(self), osThreadExit, osThreadTerminate(self) and returning from the thread function are invalid while locked: they assert in debug builds. In release builds the sleeping, yielding and blocking calls do nothing (a call which would block fails) and an exit releases the lock. A call which does not block (e.g. a free mutex, osThreadFlagsSet, a poll with timeout 0) is fine. Not available in the Hard Real-Time mode, osKernelSuspend() drops the lock.

Macro Definition Documentation

◆ osErrorId

#define osErrorId   0xFFFFFFFFU

osError (-1).

Definition at line 306 of file cmsis_os2.h.

Referenced by osThreadGetClass(), and osThreadGetZone().

◆ osFlagsError

#define osFlagsError   0x80000000U

Error indicator.

Definition at line 266 of file cmsis_os2.h.

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

◆ osFlagsErrorISR

#define osFlagsErrorISR   0xFFFFFFFAU

osErrorISR (-6).

Definition at line 271 of file cmsis_os2.h.

Referenced by osThreadFlagsWait().

◆ osFlagsErrorParameter

#define osFlagsErrorParameter   0xFFFFFFFCU

osErrorParameter (-4).

Definition at line 270 of file cmsis_os2.h.

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

◆ osFlagsErrorResource

#define osFlagsErrorResource   0xFFFFFFFDU

osErrorResource (-3).

Definition at line 269 of file cmsis_os2.h.

◆ osFlagsErrorSafetyClass

#define osFlagsErrorSafetyClass   0xFFFFFFF9U

osErrorSafetyClass (-7).

Definition at line 272 of file cmsis_os2.h.

◆ osFlagsErrorTimeout

#define osFlagsErrorTimeout   0xFFFFFFFEU

osErrorTimeout (-2).

Definition at line 268 of file cmsis_os2.h.

◆ osFlagsErrorUnknown

#define osFlagsErrorUnknown   0xFFFFFFFFU

osError (-1).

Definition at line 267 of file cmsis_os2.h.

Referenced by osThreadFlagsClear(), and osThreadFlagsWait().

◆ osFlagsNoClear

#define osFlagsNoClear   0x00000002U

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

Definition at line 263 of file cmsis_os2.h.

◆ osFlagsWaitAll

#define osFlagsWaitAll   0x00000001U

Wait for all flags.

Definition at line 262 of file cmsis_os2.h.

◆ osFlagsWaitAny

#define osFlagsWaitAny   0x00000000U

Wait for any flag (default).

Examples
blinky_c-cmsis-rtos2/example.c.

Definition at line 261 of file cmsis_os2.h.

Referenced by clock(), phaseA(), phaseB(), phaseC(), and phaseD().

◆ osMutexPrioInherit

#define osMutexPrioInherit   0x00000002U

Priority inherit protocol.

Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 291 of file cmsis_os2.h.

◆ osMutexRecursive

#define osMutexRecursive   0x00000001U

Recursive mutex.

Definition at line 290 of file cmsis_os2.h.

Referenced by osMutexNew().

◆ osMutexRobust

#define osMutexRobust   0x00000008U

Robust mutex.

Definition at line 292 of file cmsis_os2.h.

Referenced by osMutexNew().

◆ osSafetyClass

#define osSafetyClass ( n)
Value:
#define osSafetyClass_Pos
Safety class position.
Definition cmsis_os2.h:295
#define osSafetyClass_Msk
Safety class mask.
Definition cmsis_os2.h:296
#define osSafetyClass_Valid
Safety class valid flag.
Definition cmsis_os2.h:297

Safety class.

Definition at line 298 of file cmsis_os2.h.

298#define osSafetyClass(n) ((((n) << osSafetyClass_Pos) & osSafetyClass_Msk) | \
299 osSafetyClass_Valid)

◆ osSafetyClass_Msk

#define osSafetyClass_Msk   (0x0FUL << osSafetyClass_Pos)

Safety class mask.

Definition at line 296 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osSafetyClass_Pos

#define osSafetyClass_Pos   16U

Safety class position.

Definition at line 295 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osSafetyClass_Valid

#define osSafetyClass_Valid   (0x10UL << osSafetyClass_Pos)

Safety class valid flag.

Definition at line 297 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osSafetyWithLowerClass

#define osSafetyWithLowerClass   0x00000002U

Objects with lower safety class.

Definition at line 303 of file cmsis_os2.h.

Referenced by StkApplyToThreads(), and StkCheckClassArgs().

◆ osSafetyWithSameClass

#define osSafetyWithSameClass   0x00000001U

Objects with same safety class.

Definition at line 302 of file cmsis_os2.h.

Referenced by StkApplyToThreads(), and StkCheckClassArgs().

◆ osThreadDetached

#define osThreadDetached   0x00000000U

Thread created in detached mode (default).

Definition at line 275 of file cmsis_os2.h.

◆ osThreadJoinable

#define osThreadJoinable   0x00000001U

Thread created in joinable mode.

Definition at line 276 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadPrivileged

#define osThreadPrivileged   0x00000004U

Thread runs in privileged mode.

Definition at line 278 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadProcessor

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

Thread processor number for SMP systems.

Definition at line 287 of file cmsis_os2.h.

Referenced by osThreadGetAffinityMask(), and osThreadSetAffinityMask().

◆ osThreadUnprivileged

#define osThreadUnprivileged   0x00000002U

Thread runs in unprivileged mode.

Definition at line 277 of file cmsis_os2.h.

◆ osThreadZone

#define osThreadZone ( n)
Value:
#define osThreadZone_Msk
MPU protected zone mask.
Definition cmsis_os2.h:281
#define osThreadZone_Pos
MPU protected zone position.
Definition cmsis_os2.h:280
#define osThreadZone_Valid
MPU protected zone valid flag.
Definition cmsis_os2.h:282

MPU zone value in attribute bit field format.

Definition at line 283 of file cmsis_os2.h.

283#define osThreadZone(n) ((((n) << osThreadZone_Pos) & osThreadZone_Msk) | \
284 osThreadZone_Valid)

◆ osThreadZone_Msk

#define osThreadZone_Msk   (0x3FUL << osThreadZone_Pos)

MPU protected zone mask.

Definition at line 281 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadZone_Pos

#define osThreadZone_Pos   8U

MPU protected zone position.

Definition at line 280 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadZone_Valid

#define osThreadZone_Valid   (0x80UL << osThreadZone_Pos)

MPU protected zone valid flag.

Definition at line 282 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osWaitForever

#define osWaitForever   0xFFFFFFFFU

Wait forever timeout value.

Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 258 of file cmsis_os2.h.

Referenced by app_main(), clock(), HighPrioThread(), LowPrioThread(), phaseA(), phaseB(), phaseC(), and phaseD().

◆ TZ_MODULEID_T

#define TZ_MODULEID_T

Definition at line 345 of file cmsis_os2.h.

Typedef Documentation

◆ osEventFlagsId_t

typedef void* osEventFlagsId_t

Event Flags ID identifies the event flags.

Definition at line 329 of file cmsis_os2.h.

◆ osMemoryPoolId_t

typedef void* osMemoryPoolId_t

Memory Pool ID identifies the memory pool.

Definition at line 338 of file cmsis_os2.h.

◆ osMessageQueueId_t

typedef void* osMessageQueueId_t

Message Queue ID identifies the message queue.

Definition at line 341 of file cmsis_os2.h.

◆ osMutexId_t

typedef void* osMutexId_t

Mutex ID identifies the mutex.

Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 332 of file cmsis_os2.h.

◆ osSemaphoreId_t

typedef void* osSemaphoreId_t

Semaphore ID identifies the semaphore.

Definition at line 335 of file cmsis_os2.h.

◆ osThreadFunc_t

typedef void(* osThreadFunc_t) (void *argument)

Entry point of a thread.

Definition at line 246 of file cmsis_os2.h.

◆ osThreadId_t

typedef void* osThreadId_t

Thread ID identifies the thread.

Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 323 of file cmsis_os2.h.

◆ osTimerFunc_t

typedef void(* osTimerFunc_t) (void *argument)

Timer callback function.

Definition at line 249 of file cmsis_os2.h.

◆ osTimerId_t

typedef void* osTimerId_t

Timer ID identifies the timer.

Definition at line 326 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 347 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 167 of file cmsis_os2.h.

167 {
168 osKernelInactive = 0,
169 osKernelReady = 1,
170 osKernelRunning = 2,
171 osKernelLocked = 3,
173 osKernelError = -1,
174 osKernelReserved = 0x7FFFFFFF
osKernelState_t
Kernel state.
Definition cmsis_os2.h:167
@ osKernelLocked
Locked.
Definition cmsis_os2.h:171
@ osKernelError
Error.
Definition cmsis_os2.h:173
@ osKernelSuspended
Suspended.
Definition cmsis_os2.h:172
@ osKernelReady
Ready.
Definition cmsis_os2.h:169
@ osKernelRunning
Running.
Definition cmsis_os2.h:170
@ osKernelReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:174
@ osKernelInactive
Inactive.
Definition cmsis_os2.h:168

◆ 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 189 of file cmsis_os2.h.

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

◆ 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 309 of file cmsis_os2.h.

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

◆ 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 178 of file cmsis_os2.h.

178 {
179 osThreadInactive = 0,
180 osThreadReady = 1,
181 osThreadRunning = 2,
182 osThreadBlocked = 3,
184 osThreadError = -1,
185 osThreadReserved = 0x7FFFFFFF
osThreadState_t
Thread state.
Definition cmsis_os2.h:178
@ osThreadBlocked
Blocked.
Definition cmsis_os2.h:182
@ osThreadRunning
Running.
Definition cmsis_os2.h:181
@ osThreadInactive
Inactive.
Definition cmsis_os2.h:179
@ osThreadReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:185
@ osThreadTerminated
Terminated.
Definition cmsis_os2.h:183
@ osThreadError
Error.
Definition cmsis_os2.h:184
@ osThreadReady
Ready.
Definition cmsis_os2.h:180

◆ osTimerType_t

Timer type.

Enumerator
osTimerOnce 

One-shot timer.

osTimerPeriodic 

Repeating timer.

Definition at line 252 of file cmsis_os2.h.

252 {
253 osTimerOnce = 0,
254 osTimerPeriodic = 1
osTimerType_t
Timer type.
Definition cmsis_os2.h:252
@ osTimerPeriodic
Repeating timer.
Definition cmsis_os2.h:254
@ osTimerOnce
One-shot timer.
Definition cmsis_os2.h:253

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.
Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 2251 of file cmsis_os2_stk.cpp.

2252{
2253 osStatus_t result;
2254
2255 if (IsIrqContext())
2256 {
2257 result = osErrorISR;
2258 }
2259 else if (!IsKernelRunning())
2260 {
2261 result = osError;
2262 }
2263 else
2264 {
2265 stk::Sleep(CmsisTimeoutToStk(ticks));
2266 result = osOK;
2267 }
2268
2269 return result;
2270}
static bool Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:495

References osError, osErrorISR, osOK, and stk::Sleep().

Referenced by app_main(), clock(), HighPrioThread(), LowPrioThread(), MidPrioThread(), and signal_func().

Here is the call graph for this function:
Here is the caller 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 2272 of file cmsis_os2_stk.cpp.

2273{
2274 osStatus_t result;
2275
2276 if (IsIrqContext())
2277 {
2278 result = osErrorISR;
2279 }
2280 else if (!IsKernelRunning())
2281 {
2282 result = osError;
2283 }
2284 else
2285 {
2286 // 32-bit tick arithmetic: wrap-safe, a target in the past (or now) is a parameter error
2287 const uint32_t delta = ticks - static_cast<uint32_t>(stk::GetTicks());
2288
2289 if ((delta == 0U) || (delta >= 0x80000000UL))
2290 {
2291 result = osErrorParameter;
2292 }
2293 else
2294 {
2295 stk::Sleep(static_cast<stk::Ticks>(delta));
2296 result = osOK;
2297 }
2298 }
2299
2300 return result;
2301}
int64_t Ticks
Ticks value.
Definition stk_common.h:221
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:448

References stk::GetTicks(), osError, osErrorISR, osErrorParameter, osOK, and stk::Sleep().

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

2550{
2551 uint32_t result;
2552
2553 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
2554 {
2555 result = osFlagsErrorParameter;
2556 }
2557 else
2558 {
2559 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Clear(flags));
2560 }
2561
2562 return result;
2563}
#define osFlagsError
Error indicator.
Definition cmsis_os2.h:266
#define osFlagsErrorParameter
osErrorParameter (-4).
Definition cmsis_os2.h:270

References osFlagsError, and osFlagsErrorParameter.

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

2599{
2600 osStatus_t result;
2601
2602 if (IsIrqContext())
2603 {
2604 result = osErrorISR;
2605 }
2606 else if (ef_id == nullptr)
2607 {
2608 result = osErrorParameter;
2609 }
2610 else
2611 {
2612 ObjDestroy(static_cast<StkEventFlags *>(ef_id));
2613 result = osOK;
2614 }
2615
2616 return result;
2617}

References osErrorISR, osErrorParameter, and osOK.

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

2566{
2567 uint32_t result;
2568
2569 if (ef_id == nullptr)
2570 {
2571 result = 0U;
2572 }
2573 else
2574 {
2575 result = static_cast<StkEventFlags *>(ef_id)->m_ef.Get();
2576 }
2577
2578 return result;
2579}

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

2518{
2519 const char *result;
2520
2521 if (ef_id == nullptr)
2522 {
2523 result = nullptr;
2524 }
2525 else
2526 {
2527 result = static_cast<StkEventFlags *>(ef_id)->m_ef.GetTraceName();
2528 }
2529
2530 return result;
2531}

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

2497{
2498 osEventFlagsId_t result;
2499
2500 if (IsIrqContext())
2501 {
2502 result = nullptr;
2503 }
2504 else
2505 {
2506 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2507 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2508 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2509
2510 StkEventFlags *const ef = PlacementNewOrHeap<StkEventFlags>(cb_mem, cb_sz, name);
2511 result = static_cast<osEventFlagsId_t>(ef);
2512 }
2513
2514 return result;
2515}
void * osEventFlagsId_t
Definition cmsis_os2.h:329
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:377
const char * name
name of the event flags
Definition cmsis_os2.h:374
void * cb_mem
memory for control block
Definition cmsis_os2.h:376

References osEventFlagsAttr_t::cb_mem, osEventFlagsAttr_t::cb_size, and osEventFlagsAttr_t::name.

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

2534{
2535 uint32_t result;
2536
2537 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
2538 {
2539 result = osFlagsErrorParameter;
2540 }
2541 else
2542 {
2543 result = StkFlagsResultToCmsis(static_cast<StkEventFlags *>(ef_id)->m_ef.Set(flags));
2544 }
2545
2546 return result;
2547}

References osFlagsError, and osFlagsErrorParameter.

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

2583{
2584 uint32_t result;
2585
2586 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
2587 {
2588 result = osFlagsErrorParameter;
2589 }
2590 else
2591 {
2592 result = CmsisFlagsWait(static_cast<StkEventFlags *>(ef_id)->m_ef, flags, options, timeout);
2593 }
2594
2595 return result;
2596}

References osFlagsError, and osFlagsErrorParameter.

◆ osFaultResume()

void osFaultResume ( void )

Resume normal operation when exiting exception faults.

Definition at line 1872 of file cmsis_os2_stk.cpp.

1873{
1874 // no MPU / exception fault handling in the wrapper: nothing to resume
1875}

◆ 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.

Definition at line 2048 of file cmsis_os2_stk.cpp.

2049{
2050 const osStatus_t chk = StkCheckClassArgs(safety_class, mode);
2051 return ((chk != osOK) ? chk : StkApplyToThreads(ACT_TERMINATE, false, safety_class, mode));
2052}
@ ACT_TERMINATE
static osStatus_t StkCheckClassArgs(uint32_t safety_class, uint32_t mode)
static osStatus_t StkApplyToThreads(StkThreadAction action, bool by_zone, uint32_t key, uint32_t mode)

References ACT_TERMINATE, osOK, StkApplyToThreads(), and StkCheckClassArgs().

Here is the call graph for this 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 946 of file cmsis_os2_stk.cpp.

947{
948 if (version != nullptr)
949 {
950 version->api = STK_WRAPPER_API_VERSION;
952 }
953
954 if ((id_buf != nullptr) && (id_size > 0U))
955 {
956 const char *const id = STK_WRAPPER_KERNEL_ID;
957 size_t copy_len = id_size - 1U;
958 const size_t id_len = CmsisStrlen(id);
959 if (copy_len > id_len)
960 {
961 copy_len = id_len;
962 }
963
964 stk::STK_MEMCPY(id_buf, id, copy_len);
965 id_buf[copy_len] = '\0';
966 }
967
968 return osOK;
969}
#define STK_WRAPPER_KERNEL_VERSION
#define STK_WRAPPER_KERNEL_ID
#define STK_WRAPPER_API_VERSION
void STK_MEMCPY(void *const dest, const void *const src, size_t size)
Implementation of STK_MEMCPY.
Definition stk_arch.h:788
uint32_t api
API version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:162
uint32_t kernel
Kernel version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:163

References osVersion_t::api, osVersion_t::kernel, osOK, stk::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.
Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 971 of file cmsis_os2_stk.cpp.

972{
973 osKernelState_t state;
974
975 switch (g_StkKernel.GetState())
976 {
978 state = osKernelInactive;
979 break;
981 state = osKernelReady;
982 break;
984 state = osKernelRunning;
985 break;
987 state = osKernelLocked;
988 break;
990 state = osKernelSuspended;
991 break;
992 default:
993 state = osKernelError;
994 break;
995 }
996
997 return state;
998}
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
@ KSTATE_LOCKED
Running, but task switching is disabled with IKernelService::LockScheduler(). Ticks,...
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
@ KSTATE_READY
Ready to start, IKernel::Start() must be called.

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

Referenced by app_run(), osKernelInitialize(), osKernelResume(), osKernelStart(), osKernelSuspend(), osThreadEnumerate(), osThreadGetCount(), osThreadNew(), 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 1149 of file cmsis_os2_stk.cpp.

1150{
1151 return static_cast<uint32_t>(stk::GetSysTimerCount());
1152}
static Cycles GetSysTimerCount()
Get system timer count value.
Definition stk_helper.h:473

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

1155{
1156 return stk::GetSysTimerCount();
1157}

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

1160{
1162}
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:482

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

1110{
1111 uint32_t result;
1112
1113 if (!IsKernelRunning())
1114 {
1115 result = 0U;
1116 }
1117 else
1118 {
1119 result = static_cast<uint32_t>(stk::GetTicks());
1120 }
1121
1122 return result;
1123}

References stk::GetTicks().

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

1126{
1127 uint32_t result;
1128
1129 if (!IsKernelRunning())
1130 {
1131 result = 1000U; // default 1 kHz
1132 }
1133 else
1134 {
1135 const int32_t res_us = stk::GetTickResolution(); // us per tick
1136 if (res_us <= 0)
1137 {
1138 result = 1000U;
1139 }
1140 else
1141 {
1142 result = (1000000U / static_cast<uint32_t>(res_us));
1143 }
1144 }
1145
1146 return result;
1147}
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:384

References stk::GetTickResolution().

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.
Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 925 of file cmsis_os2_stk.cpp.

926{
927 osStatus_t result;
928
929 if (IsIrqContext())
930 {
931 result = osErrorISR;
932 }
934 {
935 result = osError;
936 }
937 else
938 {
939 g_StkKernel.Initialize(); // default 1 ms tick resolution
940 result = osOK;
941 }
942
943 return result;
944}
osKernelState_t osKernelGetState(void)

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

Referenced by app_run().

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

◆ osKernelLock()

int32_t osKernelLock ( void )

Lock the RTOS Kernel scheduler.

Disables task switching only, the kernel tick, timeouts and ISRs keep running. The lock holder must not block, sleep, yield or exit while the scheduler is locked.

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

Definition at line 1025 of file cmsis_os2_stk.cpp.

1026{
1027 // returns the previous state (0/1) or a negative error code
1028 return StkLockResultToCmsis(g_StkKernel.SetSchedulerLock(true));
1029}

◆ 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.

Definition at line 1877 of file cmsis_os2_stk.cpp.

1878{
1879 osStatus_t result;
1880
1881 if (IsIrqContext())
1882 {
1883 result = osErrorISR;
1884 }
1885 else if (safety_class > 0x0FU)
1886 {
1887 result = osErrorParameter;
1888 }
1889 else
1890 {
1891 // recorded only: there is no MPU to restrict kernel access with
1893 g_KernelProtectClass = safety_class;
1894 g_KernelProtected = true;
1895 result = osOK;
1896 }
1897
1898 return result;
1899}
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:58

References osErrorISR, osErrorParameter, and osOK.

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

1038{
1039 int32_t result;
1040
1041 if ((lock == 0) || (lock == 1))
1042 {
1043 // bring the kernel to the requested state, return the NEW state (0/1)
1044 result = StkLockResultToCmsis(g_StkKernel.SetSchedulerLock(lock == 1));
1045
1046 if (result >= 0)
1047 {
1048 result = lock;
1049 }
1050 }
1051 else if (IsIrqContext())
1052 {
1053 result = static_cast<int32_t>(osErrorISR);
1054 }
1055 else
1056 {
1057 // any other value is treated as "unchanged": report the current state
1058 switch (g_StkKernel.GetState())
1059 {
1061 result = 1;
1062 break;
1064 result = 0;
1065 break;
1066 default:
1067 result = static_cast<int32_t>(osError);
1068 break;
1069 }
1070 }
1071
1072 return result;
1073}

References stk::IKernel::KSTATE_LOCKED, stk::IKernel::KSTATE_RUNNING, osError, and osErrorISR.

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

1097{
1098#if STK_TICKLESS_IDLE
1100 {
1102 }
1103#else
1104 // Not supported in non-tickless kernel.
1105 STK_UNUSED(sleep_ticks);
1106#endif
1107}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual void Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.

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

Here is the call graph for this function:

◆ osKernelStart()

osStatus_t osKernelStart ( void )

Start the RTOS Kernel scheduler.

Returns
status code that indicates the execution status of the function.
Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 1000 of file cmsis_os2_stk.cpp.

1001{
1002 osStatus_t result;
1003
1004 if (IsIrqContext())
1005 {
1006 result = osErrorISR;
1007 }
1008 else if (osKernelGetState() != osKernelReady)
1009 {
1010 result = osError;
1011 }
1012 else
1013 {
1014 // Start() does not return for KERNEL_STATIC;
1015 // for KERNEL_DYNAMIC it returns when all tasks exit.
1016 g_StkKernel.Start();
1017 result = osOK;
1018 }
1019
1020 return result;
1021}

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

Referenced by app_run().

Here is the call graph for this function:
Here is the caller 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 1075 of file cmsis_os2_stk.cpp.

1076{
1077 uint32_t result;
1078
1079#if STK_TICKLESS_IDLE
1081 {
1082 result = 0U;
1083 }
1084 else
1085 {
1086 result = static_cast<uint32_t>(stk::IKernelService::GetInstance()->Suspend());
1087 }
1088#else
1089 // Not supported in non-tickless kernel.
1090 result = 0U;
1091#endif
1092
1093 return result;
1094}
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.

A thread made ready during the lock is switched in on the next kernel tick.

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

Definition at line 1031 of file cmsis_os2_stk.cpp.

1032{
1033 // returns the previous state (0/1) or a negative error code
1034 return StkLockResultToCmsis(g_StkKernel.SetSchedulerLock(false));
1035}

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

2969{
2970 void *result;
2971
2972 if (mp_id == nullptr)
2973 {
2974 result = nullptr;
2975 }
2976 // ISR context is only valid with timeout == 0 (NO_WAIT / TryAlloc).
2977 else if (IsIrqContext() && (timeout != 0U))
2978 {
2979 result = nullptr;
2980 }
2981 else
2982 {
2983 result = static_cast<StkMemPool *>(mp_id)->m_mpool.TimedAlloc(CmsisTimeoutToStk(timeout));
2984 }
2985
2986 return result;
2987}

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

3074{
3075 osStatus_t result;
3076
3077 if (IsIrqContext())
3078 {
3079 result = osErrorISR;
3080 }
3081 else if (mp_id == nullptr)
3082 {
3083 result = osErrorParameter;
3084 }
3085 else
3086 {
3087 ObjDestroy(static_cast<StkMemPool *>(mp_id));
3088 result = osOK;
3089 }
3090
3091 return result;
3092}

References osErrorISR, osErrorParameter, and osOK.

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

2990{
2991 osStatus_t result;
2992
2993 if ((mp_id == nullptr) || (block == nullptr))
2994 {
2995 result = osErrorParameter;
2996 }
2997 else if (!static_cast<StkMemPool *>(mp_id)->m_mpool.Free(block))
2998 {
2999 result = osErrorParameter; // ptr not from this pool
3000 }
3001 else
3002 {
3003 result = osOK;
3004 }
3005
3006 return result;
3007}

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

3026{
3027 uint32_t result;
3028
3029 if (mp_id == nullptr)
3030 {
3031 result = 0U;
3032 }
3033 else
3034 {
3035 result = static_cast<uint32_t>(static_cast<StkMemPool *>(mp_id)->m_mpool.GetBlockSize());
3036 }
3037
3038 return result;
3039}

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

3010{
3011 uint32_t result;
3012
3013 if (mp_id == nullptr)
3014 {
3015 result = 0U;
3016 }
3017 else
3018 {
3019 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetCapacity();
3020 }
3021
3022 return result;
3023}

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

3042{
3043 uint32_t result;
3044
3045 if (mp_id == nullptr)
3046 {
3047 result = 0U;
3048 }
3049 else
3050 {
3051 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetUsedCount();
3052 }
3053
3054 return result;
3055}

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

2953{
2954 const char *result;
2955
2956 if (mp_id == nullptr)
2957 {
2958 result = nullptr;
2959 }
2960 else
2961 {
2962 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetTraceName();
2963 }
2964
2965 return result;
2966}

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

3058{
3059 uint32_t result;
3060
3061 if (mp_id == nullptr)
3062 {
3063 result = 0U;
3064 }
3065 else
3066 {
3067 result = static_cast<StkMemPool *>(mp_id)->m_mpool.GetFreeCount();
3068 }
3069
3070 return result;
3071}

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

2903{
2904 osMemoryPoolId_t result;
2905
2906 // ISR context: forbidden per CMSIS spec.
2907 // Zero capacity or zero block size are meaningless.
2908 if (IsIrqContext() || (block_count == 0U) || (block_size == 0U))
2909 {
2910 result = nullptr;
2911 }
2912 else
2913 {
2914 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2915 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2916 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2917 void *const mp_mem = ((attr != nullptr) ? attr->mp_mem : nullptr);
2918 const uint32_t mp_sz = ((attr != nullptr) ? attr->mp_size : 0U);
2919
2920 // Compute the aligned block size and required storage byte count.
2921 const uint32_t aligned_blk = stk::memory::BlockMemoryPool::AlignBlockSize(block_size);
2922 const uint32_t storage_required = (block_count * aligned_blk);
2923
2924 StkMemPool *pool;
2925
2926 if ((mp_mem != nullptr) && (mp_sz >= storage_required))
2927 {
2928 // Caller-supplied pool storage - BlockMemoryPool external-storage ctor.
2929 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2930 block_count, block_size, name, static_cast<uint8_t *>(mp_mem));
2931 }
2932 else
2933 {
2934 // Heap-allocated pool storage - BlockMemoryPool heap ctor.
2935 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
2936 block_count, block_size, name);
2937
2938 // If the heap ctor failed to allocate storage, clean up and bail.
2939 if ((pool != nullptr) && !pool->m_mpool.IsStorageValid())
2940 {
2941 ObjDestroy(pool);
2942 pool = nullptr;
2943 }
2944 }
2945
2946 result = static_cast<osMemoryPoolId_t>(pool);
2947 }
2948
2949 return result;
2950}
void * osMemoryPoolId_t
Definition cmsis_os2.h:338
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, size_t alignment=ALIGN_DEFAULT)
Round a raw block size up to the nearest multiple of alignment.
uint32_t mp_size
size of provided memory for data storage
Definition cmsis_os2.h:403
const char * name
name of the memory pool
Definition cmsis_os2.h:398
void * cb_mem
memory for control block
Definition cmsis_os2.h:400
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:401
void * mp_mem
memory for data storage
Definition cmsis_os2.h:402

References stk::memory::BlockMemoryPool::AlignBlockSize(), osMemoryPoolAttr_t::cb_mem, osMemoryPoolAttr_t::cb_size, stk::memory::BlockMemoryPool::IsStorageValid(), osMemoryPoolAttr_t::mp_mem, osMemoryPoolAttr_t::mp_size, and osMemoryPoolAttr_t::name.

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

3305{
3306 osStatus_t result;
3307
3308 if (IsIrqContext())
3309 {
3310 result = osErrorISR;
3311 }
3312 else if (mq_id == nullptr)
3313 {
3314 result = osErrorParameter;
3315 }
3316 else
3317 {
3318 ObjDestroy(static_cast<StkMessageQueue *>(mq_id));
3319 result = osOK;
3320 }
3321
3322 return result;
3323}

References osErrorISR, osErrorParameter, and osOK.

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

3192{
3193 osStatus_t result;
3194
3195 if ((mq_id == nullptr) || (msg_ptr == nullptr))
3196 {
3197 result = osErrorParameter;
3198 }
3199 else if (IsIrqContext() && (timeout != 0U))
3200 {
3201 result = osErrorISR;
3202 }
3203 else
3204 {
3205 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
3206
3207 result = StkWaitResultToCmsis(
3208 static_cast<StkMessageQueue *>(mq_id)->m_mq.GetEx(msg_ptr, stk_timeout), stk_timeout);
3209
3210 if ((result == osOK) && (msg_prio != nullptr))
3211 {
3212 *msg_prio = 0U; // STK queues have no priority lanes.
3213 }
3214 }
3215
3216 return result;
3217}
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:216

References osErrorISR, osErrorParameter, and osOK.

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

3220{
3221 uint32_t result;
3222
3223 if (mq_id == nullptr)
3224 {
3225 result = 0U;
3226 }
3227 else
3228 {
3229 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCapacity());
3230 }
3231
3232 return result;
3233}

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

3252{
3253 uint32_t result;
3254
3255 if (mq_id == nullptr)
3256 {
3257 result = 0U;
3258 }
3259 else
3260 {
3261 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCount());
3262 }
3263
3264 return result;
3265}

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

3236{
3237 uint32_t result;
3238
3239 if (mq_id == nullptr)
3240 {
3241 result = 0U;
3242 }
3243 else
3244 {
3245 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetMsgSize());
3246 }
3247
3248 return result;
3249}

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

3151{
3152 const char *result;
3153
3154 if (mq_id == nullptr)
3155 {
3156 result = nullptr;
3157 }
3158 else
3159 {
3160 result = static_cast<StkMessageQueue *>(mq_id)->m_mq.GetTraceName();
3161 }
3162
3163 return result;
3164}

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

3268{
3269 uint32_t result;
3270
3271 if (mq_id == nullptr)
3272 {
3273 result = 0U;
3274 }
3275 else
3276 {
3277 result = static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetSpace());
3278 }
3279
3280 return result;
3281}

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

3101{
3102 osMessageQueueId_t result;
3103
3104 if (IsIrqContext() || (msg_count == 0U) || (msg_size == 0U) ||
3106 {
3107 result = nullptr;
3108 }
3109 else
3110 {
3111 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
3112 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
3113 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
3114 void *const ext_buf = ((attr != nullptr) ? attr->mq_mem : nullptr);
3115 const uint32_t ext_buf_size = ((attr != nullptr) ? attr->mq_size : 0U);
3116
3117 const uint32_t buf_required = (msg_count * msg_size);
3118
3119 StkMessageQueue *mq;
3120
3121 if ((ext_buf != nullptr) && (ext_buf_size >= buf_required))
3122 {
3123 // Data buffer: use caller-supplied memory.
3124 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
3125 msg_count, msg_size, name, static_cast<uint8_t *>(ext_buf));
3126 }
3127 else
3128 {
3129 // Data buffer: heap-allocated inside StkMessageQueue constructor.
3130 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
3131 msg_count, msg_size, name);
3132
3133 // Validate
3134 if (mq != nullptr)
3135 {
3136 if (!mq->m_mq.IsStorageValid())
3137 {
3138 ObjDestroy(mq);
3139 mq = nullptr;
3140 }
3141 }
3142 }
3143
3144 result = static_cast<osMessageQueueId_t>(mq);
3145 }
3146
3147 return result;
3148}
void * osMessageQueueId_t
Definition cmsis_os2.h:341
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
const char * name
name of the message queue
Definition cmsis_os2.h:408
void * cb_mem
memory for control block
Definition cmsis_os2.h:410
uint32_t mq_size
size of provided memory for data storage
Definition cmsis_os2.h:413
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:411
void * mq_mem
memory for data storage
Definition cmsis_os2.h:412

References stk::sync::MessageQueue::CAPACITY_MAX, osMessageQueueAttr_t::cb_mem, osMessageQueueAttr_t::cb_size, stk::sync::MessageQueue::IsStorageValid(), osMessageQueueAttr_t::mq_mem, osMessageQueueAttr_t::mq_size, and osMessageQueueAttr_t::name.

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

3168{
3169 osStatus_t result;
3170
3171 if ((mq_id == nullptr) || (msg_ptr == nullptr))
3172 {
3173 result = osErrorParameter;
3174 }
3175 else if (IsIrqContext() && (timeout != 0U))
3176 {
3177 result = osErrorISR;
3178 }
3179 else
3180 {
3181 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
3182
3183 result = StkWaitResultToCmsis(
3184 static_cast<StkMessageQueue *>(mq_id)->m_mq.PutEx(msg_ptr, stk_timeout), stk_timeout);
3185 }
3186
3187 return result;
3188}

References osErrorISR, and osErrorParameter.

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

3284{
3285 osStatus_t result;
3286
3287 if (IsIrqContext())
3288 {
3289 result = osErrorISR;
3290 }
3291 else if (mq_id == nullptr)
3292 {
3293 result = osErrorParameter;
3294 }
3295 else
3296 {
3297 static_cast<StkMessageQueue *>(mq_id)->m_mq.Reset();
3298 result = osOK;
3299 }
3300
3301 return result;
3302}

References osErrorISR, osErrorParameter, and osOK.

◆ 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.
Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 2685 of file cmsis_os2_stk.cpp.

2686{
2687 osStatus_t result;
2688
2689 if (IsIrqContext())
2690 {
2691 result = osErrorISR;
2692 }
2693 else if (mutex_id == nullptr)
2694 {
2695 result = osErrorParameter;
2696 }
2697 else
2698 {
2699 result = static_cast<StkMutexBase *>(mutex_id)->Acquire(CmsisTimeoutToStk(timeout));
2700 }
2701
2702 return result;
2703}
static osMutexId_t mutex_id

References mutex_id, osErrorISR, and osErrorParameter.

Referenced by HighPrioThread(), and LowPrioThread().

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

2757{
2758 osStatus_t result;
2759
2760 if (IsIrqContext())
2761 {
2762 result = osErrorISR;
2763 }
2764 else if (mutex_id == nullptr)
2765 {
2766 result = osErrorParameter;
2767 }
2768 else
2769 {
2770 ObjDestroy(static_cast<StkMutexBase *>(mutex_id));
2771 result = osOK;
2772 }
2773
2774 return result;
2775}

References mutex_id, osErrorISR, osErrorParameter, and osOK.

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

2670{
2671 const char *result;
2672
2673 if (mutex_id == nullptr)
2674 {
2675 result = nullptr;
2676 }
2677 else
2678 {
2679 result = static_cast<const StkMutexBase *>(mutex_id)->GetTraceName();
2680 }
2681
2682 return result;
2683}

References mutex_id.

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

2737{
2738 osThreadId_t result;
2739
2740 if (mutex_id == nullptr)
2741 {
2742 result = nullptr;
2743 }
2744 else
2745 {
2746 const stk::TId owner = static_cast<const StkMutexBase *>(mutex_id)->GetOwner();
2747
2748 // the owner can be a timer callback (TimerHost task), which is not a CMSIS thread
2749 result = ((owner == stk::TID_NONE) || StkIsTimerHostTid(owner)) ?
2750 nullptr : StkThread::ConvertTIdToThreadId(owner);
2751 }
2752
2753 return result;
2754}
void * osThreadId_t
Definition cmsis_os2.h:323
static constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Definition stk_common.h:268
Word TId
Task (thread) id.
Definition stk_common.h:211

References mutex_id, and stk::TID_NONE.

◆ 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.
Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 2625 of file cmsis_os2_stk.cpp.

2626{
2627 osMutexId_t result;
2628
2629 if (IsIrqContext())
2630 {
2631 result = nullptr;
2632 }
2633 else
2634 {
2635 // osMutexPrioInherit: ignored, supported by default.
2636 // osMutexRecursive: sync::Mutex if set, otherwise sync::FastMutex (non-recursive) unless
2637 // STK_CMSIS_USE_FAST_MUTEX is 0, in which case sync::Mutex is always used.
2638 // osMutexRobust: will assert as unsafe code.
2639 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2640 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2641 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2642 const bool robust = ((attr != nullptr) && ((attr->attr_bits & osMutexRobust) != 0U));
2643 const bool recursive = ((STK_CMSIS_USE_FAST_MUTEX == 0) ||
2644 ((attr != nullptr) && ((attr->attr_bits & osMutexRecursive) != 0U)));
2645
2646 // disallow osMutexRobust
2647 STK_ASSERT(!robust);
2648 if (robust)
2649 {
2650 result = nullptr;
2651 }
2652 else
2653 {
2654 // convert to the common base pointer first: osMutexId_t always holds a StkMutexBase pointer
2655 StkMutexBase *mb;
2656
2657 if (recursive)
2658 mb = PlacementNewOrHeap<StkMutex>(cb_mem, cb_sz, name);
2659 else
2660 mb = PlacementNewOrHeap<StkFastMutex>(cb_mem, cb_sz, name);
2661
2662 result = static_cast<osMutexId_t>(mb);
2663 }
2664 }
2665
2666 return result;
2667}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
#define STK_CMSIS_USE_FAST_MUTEX
void * osMutexId_t
Definition cmsis_os2.h:332
#define osMutexRecursive
Recursive mutex.
Definition cmsis_os2.h:290
#define osMutexRobust
Robust mutex.
Definition cmsis_os2.h:292
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:385
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:383
const char * name
name of the mutex
Definition cmsis_os2.h:382
void * cb_mem
memory for control block
Definition cmsis_os2.h:384

References osMutexAttr_t::attr_bits, osMutexAttr_t::cb_mem, osMutexAttr_t::cb_size, osMutexAttr_t::name, osMutexRecursive, osMutexRobust, STK_ASSERT, and STK_CMSIS_USE_FAST_MUTEX.

Referenced by app_main().

Here is the caller 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.
Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 2705 of file cmsis_os2_stk.cpp.

2706{
2707 osStatus_t result;
2708
2709 if (IsIrqContext())
2710 {
2711 result = osErrorISR;
2712 }
2713 else if (mutex_id == nullptr)
2714 {
2715 result = osErrorParameter;
2716 }
2717 else
2718 {
2719 StkMutexBase *const mb = static_cast<StkMutexBase *>(mutex_id);
2720
2721 // CMSIS-RTOS2: releasing a mutex which is not owned by the caller fails with osErrorResource
2722 if (mb->GetOwner() != stk::GetTid())
2723 {
2724 result = osErrorResource;
2725 }
2726 else
2727 {
2728 mb->Unlock();
2729 result = osOK;
2730 }
2731 }
2732
2733 return result;
2734}
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:374

References stk::GetTid(), mutex_id, osErrorISR, osErrorParameter, osErrorResource, and osOK.

Referenced by HighPrioThread(), and LowPrioThread().

Here is the call graph for this function:
Here is the caller 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 2819 of file cmsis_os2_stk.cpp.

2820{
2821 osStatus_t result;
2822
2823 if (semaphore_id == nullptr)
2824 {
2825 result = osErrorParameter;
2826 }
2827 else if (IsIrqContext() && (timeout != 0U))
2828 {
2829 result = osErrorISR;
2830 }
2831 else
2832 {
2833 StkSemaphore *sem = static_cast<StkSemaphore *>(semaphore_id);
2834 const stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
2835
2836 result = StkWaitResultToCmsis(sem->m_semaphore.WaitEx(stk_timeout), stk_timeout);
2837 }
2838
2839 return result;
2840}
EWaitResult WaitEx(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter), preserving the full wait outcome.

References osErrorISR, osErrorParameter, and stk::sync::SemaphoreT< T >::WaitEx().

Here is the call graph for this function:

◆ osSemaphoreDelete()

osStatus_t osSemaphoreDelete ( osSemaphoreId_t semaphore_id)

Delete a Semaphore object.

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

Definition at line 2875 of file cmsis_os2_stk.cpp.

2876{
2877 osStatus_t result;
2878
2879 if (IsIrqContext())
2880 {
2881 result = osErrorISR;
2882 }
2883 else if (semaphore_id == nullptr)
2884 {
2885 result = osErrorParameter;
2886 }
2887 else
2888 {
2889 ObjDestroy(static_cast<StkSemaphore *>(semaphore_id));
2890 result = osOK;
2891 }
2892
2893 return result;
2894}

References osErrorISR, osErrorParameter, and osOK.

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

2860{
2861 uint32_t result;
2862
2863 if (semaphore_id == nullptr)
2864 {
2865 result = 0U;
2866 }
2867 else
2868 {
2869 result = static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetCount();
2870 }
2871
2872 return result;
2873}

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

2804{
2805 const char *result;
2806
2807 if (semaphore_id == nullptr)
2808 {
2809 result = nullptr;
2810 }
2811 else
2812 {
2813 result = static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetTraceName();
2814 }
2815
2816 return result;
2817}

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

2783{
2784 osSemaphoreId_t result;
2785
2786 if (IsIrqContext() || (max_count == 0U) || (initial_count > max_count))
2787 {
2788 result = nullptr;
2789 }
2790 else
2791 {
2792 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2793 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2794 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2795
2796 StkSemaphore *const sem = PlacementNewOrHeap<StkSemaphore>(cb_mem, cb_sz, initial_count, max_count, name);
2797 result = static_cast<osSemaphoreId_t>(sem);
2798 }
2799
2800 return result;
2801}
void * osSemaphoreId_t
Definition cmsis_os2.h:335
const char * name
name of the semaphore
Definition cmsis_os2.h:390
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:393
void * cb_mem
memory for control block
Definition cmsis_os2.h:392

References osSemaphoreAttr_t::cb_mem, osSemaphoreAttr_t::cb_size, and osSemaphoreAttr_t::name.

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

2843{
2844 osStatus_t result;
2845
2846 if (semaphore_id == nullptr)
2847 {
2848 result = osErrorParameter;
2849 }
2850 else
2851 {
2852 // TrySignal() reports a saturated semaphore (count == max) instead of asserting
2853 result = (static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.TrySignal() ? osOK : osErrorResource);
2854 }
2855
2856 return result;
2857}

References osErrorParameter, osErrorResource, 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 1577 of file cmsis_os2_stk.cpp.

1578{
1579 osStatus_t result;
1580
1581 if (IsIrqContext())
1582 {
1583 result = osErrorISR;
1584 }
1585 else if (thread_id == nullptr)
1586 {
1587 result = osErrorParameter;
1588 }
1589 else
1590 {
1591 StkThread *const th = static_cast<StkThread *>(thread_id);
1592 bool destroy = false;
1593
1594 {
1596
1597 switch (th->m_join_state)
1598 {
1599 case StkThread::JoinState::Detached:
1600 // already detached - CMSIS spec says this is an error
1601 result = osError;
1602 break;
1603
1604 case StkThread::JoinState::Joined:
1605 // already joined - cannot detach
1606 result = osError;
1607 break;
1608
1609 case StkThread::JoinState::Exited:
1610 // thread finished but nobody joined yet, transition to Detached
1611 // and free the control block now, since no joiner will ever do it
1612 th->m_join_state = StkThread::JoinState::Detached;
1613 destroy = true; // safe: task slot already freed by the kernel, freed below outside of the critical section
1614 result = osOK;
1615 break;
1616
1617 case StkThread::JoinState::Joinable:
1618 // normal case: thread is still running or just hasn't been joined
1619 th->m_join_state = StkThread::JoinState::Detached;
1620 result = osOK;
1621 break;
1622
1623 default:
1624 result = osError;
1625 break;
1626 }
1627 }
1628
1629 if (destroy)
1630 {
1631 ObjDestroy(th);
1632 }
1633 }
1634
1635 return result;
1636}

References osError, osErrorISR, osErrorParameter, and osOK.

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

2130{
2131 uint32_t result_count = 0U;
2132 const osKernelState_t kstate = osKernelGetState();
2133
2134 // kernel must be active and buffer must be valid
2135 if ((kstate != osKernelInactive) && (thread_array != nullptr) && (array_items != 0U))
2136 {
2137 // release resources of detached threads that have already been removed by the kernel
2138 if (!IsIrqContext())
2139 {
2140 StkReapZombieThreads();
2141 }
2142
2143 // cast the raw pointer array to the expected ITask* destination type
2144 stk::ITask **const tasks_destination = reinterpret_cast<stk::ITask **>(
2145 reinterpret_cast<void *>(thread_array));
2146
2147 // bind raw destination buffer into a temporary ArrayView object
2148 const size_t count = g_StkKernel.EnumerateTasks(
2149 stk::ArrayView<stk::ITask *>(tasks_destination, static_cast<size_t>(array_items)));
2150
2151 // compact the array in place: drop the TimerHost tasks, they are not CMSIS threads
2152 for (size_t i = 0U; i < count; ++i)
2153 {
2154 if (!StkIsTimerHostTid(stk::GetTidFromUserTask(tasks_destination[i])))
2155 {
2156 thread_array[result_count] = thread_array[i];
2157 ++result_count;
2158 }
2159 }
2160 }
2161
2162 return result_count;
2163}
TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:775
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:323
Interface for a user task.
Definition stk_common.h:886

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

Referenced by StkApplyToThreads().

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

◆ osThreadExit()

void osThreadExit ( void )

Terminate execution of current running thread.

Definition at line 1724 of file cmsis_os2_stk.cpp.

1725{
1726 // Schedules the removal of the calling thread and switches it out, OnExit() fires when the kernel is done.
1727 stk::ExitTask();
1728
1729 for (;;)
1730 {
1731 // unreachable: ExitTask() does not return
1732 }
1733}
static void ExitTask()
Terminate the calling task: schedule its removal and switch it out. Does not return.
Definition stk_helper.h:578

References __NO_RETURN, and stk::ExitTask().

Referenced by osThreadTerminate().

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

◆ osThreadFeedWatchdog()

osStatus_t osThreadFeedWatchdog ( uint32_t ticks)

Feed watchdog of the current running thread.

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

Definition at line 1782 of file cmsis_os2_stk.cpp.

1783{
1784 osStatus_t result;
1785
1786 if (IsIrqContext())
1787 {
1788 result = osErrorISR;
1789 }
1790 else if (!IsKernelRunning() || (ticks > stk::WAIT_INFINITE))
1791 {
1792 result = osError;
1793 }
1794 else if (!StkTimer::EnsureTimerHostCreated())
1795 {
1796 result = osError;
1797 }
1798 else
1799 {
1800 StkThread *const th = static_cast<StkThread *>(osThreadGetId());
1801
1802 if (th == nullptr)
1803 {
1804 result = osError;
1805 }
1806 else
1807 {
1808 int32_t slot;
1809
1810 {
1812
1813 slot = th->m_wd_slot;
1814
1815 if ((slot < 0) && (ticks != 0U))
1816 {
1817 for (uint32_t i = 0U; (i < CMSIS_STK_MAX_THREADS) && (slot < 0); ++i)
1818 {
1819 if (g_Watchdogs[i].m_thread == nullptr)
1820 {
1821 g_Watchdogs[i].m_thread = th;
1822 th->m_wd_slot = static_cast<int8_t>(i);
1823 slot = static_cast<int32_t>(i);
1824 }
1825 }
1826 }
1827 }
1828
1829 if (ticks == 0U)
1830 {
1831 if (slot >= 0)
1832 {
1833 th->m_wd_slot = -1;
1834 g_Watchdogs[slot].m_thread = nullptr;
1835
1836 const stk::time::TimerHost::EResult r = g_TimerHost->StopSync(g_Watchdogs[slot]);
1839 }
1840 else
1841 {
1842 result = osOK; // not armed, nothing to stop
1843 }
1844 }
1845 else if (slot < 0)
1846 {
1847 result = osErrorResource; // no free watchdog slot
1848 }
1849 else
1850 {
1851 const stk::time::TimerHost::EResult r = g_TimerHost->RestartSync(g_Watchdogs[slot], ticks, 0U);
1853 }
1854 }
1855 }
1856
1857 return result;
1858}
#define CMSIS_STK_MAX_THREADS
osThreadId_t osThreadGetId(void)
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:274
EResult
Outcome of a command: returned by the asynchronous API (Start(), Stop(), ...) and by the synchronous ...
@ RES_QUEUED
The calling context can not wait: the command was queued asynchronously, its outcome is unknown.
@ RES_INACTIVE
The timer is not active, but the command requires it to be active (stop, reset).
@ RES_OK
Sync: the command was executed. Async: the command was accepted into the command queue.

References CMSIS_STK_MAX_THREADS, osError, osErrorISR, osErrorResource, osOK, osThreadGetId(), stk::time::TimerHost::RES_INACTIVE, stk::time::TimerHost::RES_OK, stk::time::TimerHost::RES_QUEUED, stk::time::TimerHost::RestartSync(), stk::time::TimerHost::StopSync(), and stk::WAIT_INFINITE.

Here is the call graph for this 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 2186 of file cmsis_os2_stk.cpp.

2187{
2188 uint32_t result;
2189
2190 osThreadId_t const self = osThreadGetId();
2191 if (self == nullptr)
2192 {
2193 result = osFlagsErrorUnknown;
2194 }
2195 else
2196 {
2197 StkThread *th = static_cast<StkThread *>(self);
2198 result = StkFlagsResultToCmsis(th->m_thread_flags.Clear(flags));
2199 }
2200
2201 return result;
2202}
#define osFlagsErrorUnknown
osError (-1).
Definition cmsis_os2.h:267
T Clear(T flags)
Clear one or more flags.

References stk::sync::EventFlagsT< T >::Clear(), osFlagsErrorUnknown, and osThreadGetId().

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

2205{
2206 uint32_t result;
2207
2208 osThreadId_t const self = osThreadGetId();
2209 if (self == nullptr)
2210 {
2211 result = 0U;
2212 }
2213 else
2214 {
2215 result = static_cast<StkThread *>(self)->m_thread_flags.Get();
2216 }
2217
2218 return result;
2219}

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.
Examples
blinky_c-cmsis-rtos2/example.c.

Definition at line 2169 of file cmsis_os2_stk.cpp.

2170{
2171 uint32_t result;
2172
2173 if ((thread_id == nullptr) || ((flags & osFlagsError) != 0U))
2174 {
2175 result = osFlagsErrorParameter;
2176 }
2177 else
2178 {
2179 StkThread *th = static_cast<StkThread *>(thread_id);
2180 result = StkFlagsResultToCmsis(th->m_thread_flags.Set(flags));
2181 }
2182
2183 return result;
2184}
T Set(T flags)
Set one or more flags.

References osFlagsError, osFlagsErrorParameter, and stk::sync::EventFlagsT< T >::Set().

Referenced by app_main(), and signal_func().

Here is the call graph for this function:
Here is the caller 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.
Examples
blinky_c-cmsis-rtos2/example.c.

Definition at line 2221 of file cmsis_os2_stk.cpp.

2222{
2223 uint32_t result;
2224
2225 if (IsIrqContext())
2226 {
2227 result = osFlagsErrorISR;
2228 }
2229 else
2230 {
2231 osThreadId_t const self = osThreadGetId();
2232 if (self == nullptr)
2233 {
2234 result = osFlagsErrorUnknown;
2235 }
2236 else
2237 {
2238 StkThread *th = static_cast<StkThread *>(self);
2239 result = CmsisFlagsWait(th->m_thread_flags, flags, options, timeout);
2240 }
2241 }
2242
2243 return result;
2244}
#define osFlagsErrorISR
osErrorISR (-6).
Definition cmsis_os2.h:271

References osFlagsErrorISR, osFlagsErrorUnknown, and osThreadGetId().

Referenced by clock(), phaseA(), phaseB(), phaseC(), and phaseD().

Here is the call graph for this function:
Here is the caller 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.

Definition at line 2095 of file cmsis_os2_stk.cpp.

2096{
2097 return ((IsIrqContext() || (thread_id == nullptr)) ? 0U : osThreadProcessor(0));
2098}
#define osThreadProcessor(n)
Thread processor number for SMP systems.
Definition cmsis_os2.h:287

References osThreadProcessor.

◆ 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.

Definition at line 1918 of file cmsis_os2_stk.cpp.

1919{
1920 return ((IsIrqContext() || (thread_id == nullptr)) ? osErrorId :
1921 static_cast<uint32_t>(static_cast<StkThread *>(thread_id)->m_safety_class));
1922}
#define osErrorId
osError (-1).
Definition cmsis_os2.h:306

References osErrorId.

◆ osThreadGetCount()

uint32_t osThreadGetCount ( void )

Get number of active threads.

Returns
number of active threads.

Definition at line 2100 of file cmsis_os2_stk.cpp.

2101{
2102 uint32_t count = 0U;
2103
2105 {
2106 // release resources of detached threads that have already been removed by the kernel
2107 // (task context only: osThreadGetCount() may not be called from ISR per CMSIS, and the reap is skipped there)
2108 if (!IsIrqContext())
2109 {
2110 StkReapZombieThreads();
2111 }
2112
2113 // avoid race with OnTick
2115
2116 count = static_cast<uint32_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
2117
2118 // the TimerHost tasks are kernel tasks but not CMSIS threads
2119 if (g_TimerHost != nullptr)
2120 {
2121 const uint32_t host_tasks = static_cast<uint32_t>(stk::time::TimerHost::TASK_COUNT);
2122 count = ((count > host_tasks) ? (count - host_tasks) : 0U);
2123 }
2124 }
2125
2126 return count;
2127}
@ TASK_COUNT
total number of tasks serving this instance

References osKernelGetState(), osKernelInactive, and stk::time::TimerHost::TASK_COUNT.

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

1327{
1328 osThreadId_t threadId = nullptr;
1329
1330 if (IsKernelRunning() && !IsIrqContext())
1331 {
1332 // STK's GetTid() returns the ITask pointer cast to Word.
1333 const stk::TId tid = stk::GetTid();
1334
1335 // a timer callback runs in a TimerHost task which is not a CMSIS thread: report "no thread"
1336 if (!StkIsTimerHostTid(tid))
1337 {
1338 threadId = StkThread::ConvertTIdToThreadId(tid);
1339 }
1340 }
1341
1342 return threadId;
1343}

References stk::GetTid().

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

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

1311{
1312 const char *result;
1313
1314 if (thread_id == nullptr)
1315 {
1316 result = nullptr;
1317 }
1318 else
1319 {
1320 result = static_cast<StkThread *>(thread_id)->m_name;
1321 }
1322
1323 return result;
1324}

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

1459{
1460 osPriority_t result;
1461
1462 if (IsIrqContext() || (thread_id == nullptr))
1463 {
1464 result = osPriorityError;
1465 }
1466 else
1467 {
1468 StkThread *const th = static_cast<StkThread *>(thread_id);
1469 result = th->m_cmsis_priority;
1470 }
1471
1472 return result;
1473}

References osPriorityError.

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

1371{
1372 uint32_t result;
1373
1374 if (thread_id == nullptr)
1375 {
1376 result = 0U;
1377 }
1378 else
1379 {
1380 StkThread *const th = static_cast<StkThread *>(thread_id);
1381 result = static_cast<uint32_t>(th->GetStackSize()) * sizeof(stk::Word);
1382 }
1383
1384 return result;
1385}
uintptr_t Word
Native processor word type.
Definition stk_common.h:206

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

1388{
1389 uint32_t result;
1390
1391 if (thread_id == nullptr)
1392 {
1393 result = 0U;
1394 }
1395 else
1396 {
1397 StkThread *const th = static_cast<StkThread *>(thread_id);
1398 result = static_cast<uint32_t>(th->GetStackSpace() * sizeof(stk::Word));
1399 }
1400
1401 return result;
1402}

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

1346{
1347 osThreadState_t threadState = osThreadError;
1348
1349 if (!IsIrqContext() && (thread_id != nullptr))
1350 {
1351 const StkThread *const th = static_cast<StkThread *>(thread_id);
1352
1353 if (th->m_suspended)
1354 {
1355 threadState = osThreadBlocked;
1356 }
1357 else if (thread_id == osThreadGetId())
1358 {
1359 threadState = osThreadRunning;
1360 }
1361 else
1362 {
1363 threadState = osThreadReady;
1364 }
1365 }
1366
1367 return threadState;
1368}

References 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.

Definition at line 1924 of file cmsis_os2_stk.cpp.

1925{
1926 return ((IsIrqContext() || (thread_id == nullptr)) ? osErrorId :
1927 static_cast<uint32_t>(static_cast<StkThread *>(thread_id)->m_zone));
1928}

References osErrorId.

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

1639{
1640 osStatus_t result;
1641
1642 if (IsIrqContext())
1643 {
1644 result = osErrorISR;
1645 }
1646 else if (thread_id == nullptr)
1647 {
1648 result = osErrorParameter;
1649 }
1650 // Self-join is undefined behavior per POSIX / CMSIS spec.
1651 else if (thread_id == osThreadGetId())
1652 {
1653 result = osErrorParameter;
1654 }
1655 else
1656 {
1657 StkThread *th = static_cast<StkThread *>(thread_id);
1658 bool destroy = false;
1659
1660 {
1662
1663 // Only joinable threads can be joined.
1664 if (th->m_join_state == StkThread::JoinState::Detached)
1665 {
1666 result = osError;
1667 }
1668 // Double-join: second caller always gets an error.
1669 else if (th->m_join_state == StkThread::JoinState::Joined)
1670 {
1671 result = osError;
1672 }
1673 else
1674 {
1675 // Only wait if the thread has not exited yet: if OnExit() already set Exited, its notification
1676 // has already happened and waiting for it would block forever.
1677 if (th->m_join_state == StkThread::JoinState::Joinable)
1678 {
1679 th->m_join_state = StkThread::JoinState::Joined;
1680
1681 // Block until OnExit() fires (transitions state to Exited).
1682 // m_join_cv.Wait() atomically releases the critical section and suspends.
1683 bool wait_ok = true;
1684
1685 while (wait_ok && (th->m_join_state == StkThread::JoinState::Joined))
1686 {
1687 // WAIT_INFINITE - CMSIS osThreadJoin has no timeout parameter.
1688 // A cancelled wait is harmless (the predicate is re-checked), but a rejected one
1689 // (WAIT_RESULT_FAIL) returns at once without releasing cs_: bail out instead of
1690 // spinning with interrupts disabled. The state check below turns it into osError.
1691 wait_ok = (th->m_join_cv.WaitEx(cs_, stk::WAIT_INFINITE) != stk::WAIT_RESULT_FAIL);
1692 }
1693 }
1694 // else Exited: OnExit() already fired, nothing to wait for
1695
1696 // At this point m_join_state == Exited (or Detached if someone
1697 // raced osThreadDetach - treat that as an error).
1698 if (th->m_join_state != StkThread::JoinState::Exited)
1699 {
1700 result = osError;
1701 }
1702 else
1703 {
1704 // Claim the control block: any further join/detach on it now fails with an error
1705 // instead of racing with the destruction below.
1706 th->m_join_state = StkThread::JoinState::Joined;
1707 destroy = true;
1708 result = osOK;
1709 }
1710 }
1711 }
1712
1713 if (destroy)
1714 {
1715 // Free the control block - the kernel has already freed the slot (the destructor of the condition
1716 // variable unlinks it from the kernel sync list, so no extra tick delay is needed).
1717 ObjDestroy(th);
1718 }
1719 }
1720
1721 return result;
1722}
@ WAIT_RESULT_FAIL
IKernelService::Wait returned with error without waiting.
Definition stk_common.h:139
EWaitResult WaitEx(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal, preserving the full wait outcome.

References osError, osErrorISR, osErrorParameter, osOK, osThreadGetId(), stk::WAIT_INFINITE, stk::WAIT_RESULT_FAIL, and stk::sync::ConditionVariable::WaitEx().

Here is the call graph for this function:

◆ osThreadNew()

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

Create a thread and add it to Active Threads.

Parameters
[in]functhread function.
[in]argumentpointer that is passed to the thread function as start argument.
[in]attrthread attributes; NULL: default values.
Returns
thread ID for reference by other functions or NULL in case of error.
Examples
blinky_c-cmsis-rtos2-prio/example.c, and blinky_c-cmsis-rtos2/example.c.

Definition at line 1169 of file cmsis_os2_stk.cpp.

1170{
1171 osThreadId_t result = nullptr;
1172
1173 const bool is_irq = IsIrqContext();
1174 const osKernelState_t kernel_state = osKernelGetState();
1175
1176 // validate environment and arguments
1177 bool is_valid = (!is_irq && (func != nullptr) && (kernel_state != osKernelInactive));
1178
1179 // validate priority value
1180 osPriority_t cmsis_prio = osPriorityNormal;
1181 if (is_valid && (attr != nullptr))
1182 {
1183 if (attr->priority != osPriorityNone)
1184 {
1185 cmsis_prio = attr->priority;
1186 }
1187
1188 if ((cmsis_prio < osPriorityIdle) || (cmsis_prio > osPriorityISR))
1189 {
1190 is_valid = false; // invalidate object creation
1191 }
1192 }
1193
1194 // validate stack configuration:
1195 // - caller-supplied stack (stack_mem != nullptr): used as-is, never silently enlarged beyond the buffer
1196 // the caller gave us, so a zero/too small size or a misaligned address fails the call;
1197 // - otherwise heap-allocated: stack_size is honored (never below the minimum), 0 -> default size.
1198 stk::Word *stack_mem = nullptr;
1199 size_t stack_words = CMSIS_STK_DEFAULT_STACK_WORDS;
1200 if (is_valid && (attr != nullptr))
1201 {
1202 const size_t req_words = (attr->stack_size / sizeof(stk::Word)); // rounds down: never exceeds the buffer
1203
1204 if (attr->stack_mem != nullptr)
1205 {
1206 if ((req_words < static_cast<size_t>(CMSIS_STK_MIN_STACK_WORDS)) ||
1207 ((reinterpret_cast<uintptr_t>(attr->stack_mem) % alignof(stk::Word)) != 0U))
1208 {
1209 is_valid = false; // invalidate object creation
1210 }
1211 else
1212 {
1213 stack_mem = static_cast<stk::Word *>(attr->stack_mem);
1214 stack_words = req_words;
1215 }
1216 }
1217 else if (attr->stack_size != 0U)
1218 {
1219 stack_words = stk::Max<size_t>(req_words, CMSIS_STK_MIN_STACK_WORDS);
1220 }
1221 else
1222 {
1223 // noop: default heap-allocated stack size
1224 }
1225 }
1226
1227 if (is_valid)
1228 {
1229 // release resources of detached threads that have exited since the last call
1230 StkReapZombieThreads();
1231
1232 const bool is_joinable = (attr != nullptr) && ((attr->attr_bits & osThreadJoinable) != 0U);
1233 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
1234 const uint32_t cb_size = ((attr != nullptr) ? attr->cb_size : 0U);
1235
1236 // osThreadProtectPrivileged(): creation of privileged threads is no longer allowed
1237 const bool priv_blocked = g_PrivilegedThreadsBlocked && (attr != nullptr) &&
1238 ((attr->attr_bits & osThreadPrivileged) != 0U);
1239
1240 StkThread *th = (priv_blocked ? nullptr : PlacementNewOrHeap<StkThread>(cb_mem, cb_size));
1241 if (th != nullptr)
1242 {
1243 if (attr != nullptr)
1244 {
1245 if ((attr->attr_bits & osSafetyClass_Valid) != 0U)
1246 {
1247 th->m_safety_class = static_cast<uint8_t>((attr->attr_bits & osSafetyClass_Msk) >> osSafetyClass_Pos);
1248 }
1249 if ((attr->attr_bits & osThreadZone_Valid) != 0U)
1250 {
1251 th->m_zone = static_cast<uint8_t>((attr->attr_bits & osThreadZone_Msk) >> osThreadZone_Pos);
1252 }
1253 }
1254
1255 th->m_func = func;
1256 th->m_argument = argument;
1257 th->m_name = (attr != nullptr) ? attr->name : nullptr;
1258 th->m_join_state = (is_joinable ? StkThread::JoinState::Joinable : StkThread::JoinState::Detached);
1259
1260 // stack configuration (validated above)
1261 if (stack_mem != nullptr)
1262 {
1263 th->m_stack = stack_mem;
1264 th->m_stack_size = stack_words;
1265 th->m_stack_owned = false;
1266 }
1267 // allocate stack memory if not caller-provided
1268 else
1269 {
1271 STK_ASSERT(th->m_stack != nullptr);
1272
1273 if (th->m_stack == nullptr)
1274 {
1275 ObjDestroy(th);
1276 th = nullptr;
1277 }
1278 else
1279 {
1280 th->m_stack_size = stack_words;
1281 th->m_stack_owned = true;
1282 }
1283 }
1284
1285 // finalize and register the thread
1286 if (th != nullptr)
1287 {
1288 th->m_stk_priority = CmsisPrioToStk(cmsis_prio);
1289 th->m_cmsis_priority = cmsis_prio;
1290
1291 // KERNEL_DYNAMIC: a failure (e.g. out of kernel task slots: increase CMSIS_STK_MAX_THREADS)
1292 // is returned and not asserted, CMSIS requires NULL to be returned in this case
1293 if (g_StkKernel.AddTask(th) == stk::ADD_OK)
1294 {
1295 result = static_cast<osThreadId_t>(th);
1296 }
1297 else
1298 {
1299 // the kernel is not changed and never referenced the thread: release the control block
1300 // and the stack (if owned) right away
1301 ObjDestroy(th);
1302 }
1303 }
1304 }
1305 }
1306
1307 return result; // The solitary exit point
1308}
#define CMSIS_STK_MIN_STACK_WORDS
#define CMSIS_STK_DEFAULT_STACK_WORDS
#define osThreadJoinable
Thread created in joinable mode.
Definition cmsis_os2.h:276
#define osThreadPrivileged
Thread runs in privileged mode.
Definition cmsis_os2.h:278
@ ADD_OK
Task was added.
Definition stk_common.h:153
constexpr T Max(T a, T b) noexcept
Compile-time maximum of two values.
Definition stk_defs.h:758
static TElement * AllocateArrayT(size_t count, TArgs &&...args)
Allocate an array of elements and default/copy-construct each one.
void * cb_mem
memory for control block
Definition cmsis_os2.h:355
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:354
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:356
void * stack_mem
memory for stack
Definition cmsis_os2.h:357
osPriority_t priority
initial thread priority (default: osPriorityNormal)
Definition cmsis_os2.h:359
uint32_t stack_size
size of stack
Definition cmsis_os2.h:358
const char * name
name of the thread
Definition cmsis_os2.h:353

References stk::ADD_OK, stk::memory::MemoryAllocator::AllocateArrayT(), osThreadAttr_t::attr_bits, osThreadAttr_t::cb_mem, osThreadAttr_t::cb_size, CMSIS_STK_DEFAULT_STACK_WORDS, CMSIS_STK_MIN_STACK_WORDS, stk::Max(), osThreadAttr_t::name, osKernelGetState(), osKernelInactive, osPriorityIdle, osPriorityISR, osPriorityNone, osPriorityNormal, osSafetyClass_Msk, osSafetyClass_Pos, osSafetyClass_Valid, osThreadJoinable, osThreadPrivileged, osThreadZone_Msk, osThreadZone_Pos, osThreadZone_Valid, osThreadAttr_t::priority, osThreadAttr_t::stack_mem, osThreadAttr_t::stack_size, and STK_ASSERT.

Referenced by app_main(), and app_run().

Here is the call graph for this function:
Here is the caller 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.

Definition at line 1901 of file cmsis_os2_stk.cpp.

1902{
1903 osStatus_t result;
1904
1905 if (IsIrqContext())
1906 {
1907 result = osErrorISR;
1908 }
1909 else
1910 {
1911 g_PrivilegedThreadsBlocked = true;
1912 result = osOK;
1913 }
1914
1915 return result;
1916}

References osErrorISR, and osOK.

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

1539{
1540 osStatus_t result;
1541
1542 if (IsIrqContext())
1543 {
1544 result = osErrorISR;
1545 }
1546 else if (thread_id == nullptr)
1547 {
1548 result = osErrorParameter;
1549 }
1550 else if (!IsKernelRunning())
1551 {
1552 result = osErrorParameter;
1553 }
1554 else
1555 {
1556 StkThread *const th = static_cast<StkThread *>(thread_id);
1557
1558 const bool was_suspended = th->m_suspended;
1559 th->m_suspended = false;
1560
1561 const stk::EResumeResult rr = g_StkKernel.ResumeTask(th);
1562
1563 if ((rr == stk::RESUME_DONE) || (rr == stk::RESUME_LIFTED))
1564 {
1565 result = osOK;
1566 }
1567 else
1568 {
1569 th->m_suspended = was_suspended;
1570 result = osErrorResource; // not suspended, or the thread is not bound to the kernel
1571 }
1572 }
1573
1574 return result;
1575}
EResumeResult
Result of IKernel::ResumeTask().
Definition stk_common.h:183
@ RESUME_LIFTED
Deferred suspension was cancelled before it took effect.
Definition stk_common.h:187
@ RESUME_DONE
Suspended task has been resumed.
Definition stk_common.h:186

References osErrorISR, osErrorParameter, osErrorResource, osOK, stk::RESUME_DONE, and stk::RESUME_LIFTED.

Referenced by StkApplyToThreads().

Here is the caller 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.

Definition at line 2041 of file cmsis_os2_stk.cpp.

2042{
2043 const osStatus_t chk = StkCheckClassArgs(safety_class, mode);
2044 return ((chk != osOK) ? chk : StkApplyToThreads(ACT_RESUME, false, safety_class, mode));
2045}
@ ACT_RESUME

References ACT_RESUME, osOK, StkApplyToThreads(), and StkCheckClassArgs().

Here is the call graph for this 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.

Definition at line 2075 of file cmsis_os2_stk.cpp.

2076{
2077 osStatus_t result;
2078
2079 if (IsIrqContext())
2080 {
2081 result = osErrorISR;
2082 }
2083 else if ((thread_id == nullptr) || ((affinity_mask != 0U) && ((affinity_mask & osThreadProcessor(0)) == 0U)))
2084 {
2085 result = osErrorParameter;
2086 }
2087 else
2088 {
2089 result = osOK;
2090 }
2091
2092 return result;
2093}

References osErrorISR, osErrorParameter, osOK, and osThreadProcessor.

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

1405{
1406 osStatus_t result;
1407
1408 if (IsIrqContext())
1409 {
1410 result = osErrorISR;
1411 }
1412 else if (thread_id == nullptr)
1413 {
1414 result = osErrorParameter;
1415 }
1416 else if ((priority < osPriorityIdle) || (priority > osPriorityISR))
1417 {
1418 result = osErrorParameter;
1419 }
1420 else
1421 {
1422 StkThread *const th = static_cast<StkThread *>(thread_id);
1423 const int32_t new_weight = CmsisPrioToStk(priority);
1424
1425 if (IsKernelRunning())
1426 {
1427 // applies at run-time (requires a strategy with WEIGHT_API and PRIORITY_INHERITANCE_API)
1428 stk::SetWeight(stk::GetTidFromUserTask(th), static_cast<stk::Weight>(new_weight));
1429 th->m_stk_priority = new_weight;
1430 th->m_cmsis_priority = priority;
1431 result = osOK;
1432 }
1433 else
1434 {
1435 // kernel is not running: re-register the task so that the strategy picks up the new weight
1436 const int32_t old_weight = th->m_stk_priority;
1437
1438 g_StkKernel.RemoveTask(th);
1439 th->m_stk_priority = new_weight;
1440
1441 if (g_StkKernel.AddTask(th) == stk::ADD_OK)
1442 {
1443 th->m_cmsis_priority = priority;
1444 result = osOK;
1445 }
1446 else
1447 {
1448 th->m_stk_priority = old_weight;
1449 (void)g_StkKernel.AddTask(th); // restore, a slot has just been freed
1450 result = osError;
1451 }
1452 }
1453 }
1454
1455 return result;
1456}
static Weight SetWeight(TId tid, Weight weight)
Change the base scheduling weight of a task at run-time.
Definition stk_helper.h:655
int32_t Weight
Weight value (aka priority).
Definition stk_common.h:236

References stk::ADD_OK, stk::GetTidFromUserTask(), osError, osErrorISR, osErrorParameter, osOK, osPriorityIdle, osPriorityISR, and stk::SetWeight().

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

1497{
1498 osStatus_t result;
1499
1500 if (IsIrqContext())
1501 {
1502 result = osErrorISR;
1503 }
1504 else if (thread_id == nullptr)
1505 {
1506 result = osErrorParameter;
1507 }
1508 else if (!IsKernelRunning())
1509 {
1510 result = osErrorParameter;
1511 }
1512 else
1513 {
1514 StkThread *const th = static_cast<StkThread *>(thread_id);
1515
1516 // Set the flag first: a self-suspend does not return until resumed (and must not be called inside
1517 // of a critical section), so it can not be set afterwards.
1518 const bool was_suspended = th->m_suspended;
1519 th->m_suspended = true;
1520
1521 const stk::ESuspendResult sr = g_StkKernel.SuspendTask(th);
1522
1523 if (sr == stk::SUSPEND_FAIL)
1524 {
1525 th->m_suspended = was_suspended;
1526 result = osError;
1527 }
1528 else
1529 {
1530 // DONE, DEFERRED (sleeping/waiting: parked when the wait ends) and ALREADY are all fine
1531 result = osOK;
1532 }
1533 }
1534
1535 return result;
1536}
ESuspendResult
Result of IKernel::SuspendTask().
Definition stk_common.h:172
@ SUSPEND_FAIL
Task is not bound to the kernel, or is exiting.
Definition stk_common.h:173

References osError, osErrorISR, osErrorParameter, osOK, and stk::SUSPEND_FAIL.

Referenced by StkApplyToThreads().

Here is the caller 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.

Definition at line 2035 of file cmsis_os2_stk.cpp.

2036{
2037 const osStatus_t chk = StkCheckClassArgs(safety_class, mode);
2038 return ((chk != osOK) ? chk : StkApplyToThreads(ACT_SUSPEND, false, safety_class, mode));
2039}
@ ACT_SUSPEND

References ACT_SUSPEND, osOK, StkApplyToThreads(), and StkCheckClassArgs().

Here is the call graph for this 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 1735 of file cmsis_os2_stk.cpp.

1736{
1738
1739 if (IsIrqContext())
1740 {
1741 status = osErrorISR;
1742 }
1743 else if ((thread_id != nullptr) && IsKernelRunning())
1744 {
1745 // Terminating the calling thread: ScheduleTaskRemoval() only marks it, and the thread would keep
1746 // running until the next tick, so route it through the exit path instead.
1747 if (thread_id == osThreadGetId())
1748 {
1749 osThreadExit(); // does not return
1750 }
1751
1752 // release resources of detached threads that have already been removed by the kernel
1753 StkReapZombieThreads();
1754
1755 StkThread *const th = static_cast<StkThread *>(thread_id);
1756
1757 // avoid race conditions during termination
1759
1760 // RemoveTask triggers the STATE_REMOVE_PENDING path in the kernel,
1761 // which will call OnExit() before freeing the slot.
1762 g_StkKernel.ScheduleTaskRemoval(th);
1763
1764 // Do NOT free here: the kernel still references the control block (and the stack, which may be
1765 // in use until the task is switched out) and calls OnExit() on it from the tick.
1766 // Detached threads are queued by OnExit() and freed by StkReapZombieThreads(),
1767 // for joinable threads OnExit() wakes the joiner, which calls ObjDestroy().
1768 status = osOK;
1769 }
1770 else
1771 {
1772 // osErrorParameter: invalid thread id or the kernel is not running
1773 }
1774
1775 return status;
1776}
void osThreadExit(void)
Terminate execution of current running thread.

References osErrorISR, osErrorParameter, osOK, osThreadExit(), and osThreadGetId().

Referenced by StkApplyToThreads().

Here is the call graph for this function:
Here is the caller 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.

Definition at line 2054 of file cmsis_os2_stk.cpp.

2055{
2056 osStatus_t result;
2057
2058 if (IsIrqContext())
2059 {
2060 result = osErrorISR;
2061 }
2062 else if (zone > 0x3FU)
2063 {
2064 result = osErrorParameter;
2065 }
2066 else
2067 {
2068 result = StkApplyToThreads(ACT_TERMINATE, true, zone, 0U);
2069 }
2070
2071 return result;
2072}

References ACT_TERMINATE, osErrorISR, osErrorParameter, and StkApplyToThreads().

Here is the call graph for this 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.
Examples
blinky_c-cmsis-rtos2-prio/example.c.

Definition at line 1475 of file cmsis_os2_stk.cpp.

1476{
1477 osStatus_t result;
1478
1479 if (IsIrqContext())
1480 {
1481 result = osErrorISR;
1482 }
1483 else if (!IsKernelRunning())
1484 {
1485 result = osError;
1486 }
1487 else
1488 {
1489 stk::Yield();
1490 result = osOK;
1491 }
1492
1493 return result;
1494}
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:562

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

Referenced by MidPrioThread().

Here is the call graph for this function:
Here is the caller 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 2450 of file cmsis_os2_stk.cpp.

2451{
2452 osStatus_t result;
2453
2454 if (IsIrqContext())
2455 {
2456 result = osErrorISR;
2457 }
2458 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
2459 {
2460 result = osErrorParameter;
2461 }
2462 else
2463 {
2464 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
2465
2466 result = osOK;
2467
2468 // A timer which was never started is unknown to the host and can be destroyed right away. Otherwise
2469 // StopSync() guarantees that no command, ready-list node or running callback references the timer
2470 // after it returned RES_OK / RES_INACTIVE. RES_QUEUED (the caller can not wait) gives no such
2471 // guarantee, so the timer must not be destroyed in that case.
2472 if (tmr->m_started)
2473 {
2474 const stk::time::TimerHost::EResult res = g_TimerHost->StopSync(*tmr);
2475
2477 {
2478 result = osError;
2479 }
2480 }
2481
2482 if (result == osOK)
2483 {
2484 ObjDestroy(tmr);
2485 }
2486 }
2487
2488 return result;
2489}

References osError, osErrorISR, osErrorParameter, osOK, stk::time::TimerHost::RES_INACTIVE, stk::time::TimerHost::RES_OK, and stk::time::TimerHost::StopSync().

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

2342{
2343 const char *result;
2344
2345 if (timer_id == nullptr)
2346 {
2347 result = nullptr;
2348 }
2349 else
2350 {
2351 result = static_cast<StkTimer *>(timer_id)->m_name;
2352 }
2353
2354 return result;
2355}

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

2435{
2436 uint32_t result;
2437
2438 if (timer_id == nullptr)
2439 {
2440 result = 0U;
2441 }
2442 else
2443 {
2444 result = (static_cast<StkTimer *>(timer_id)->IsActive() ? 1U : 0U);
2445 }
2446
2447 return result;
2448}

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

2310{
2311 osTimerId_t result;
2312
2313 if (IsIrqContext() || (func == nullptr))
2314 {
2315 result = nullptr;
2316 }
2317 else if (osKernelGetState() == osKernelInactive)
2318 {
2319 result = nullptr;
2320 }
2321 else
2322 {
2323 const char *const name = ((attr != nullptr) ? attr->name : nullptr);
2324 void *const cb_mem = ((attr != nullptr) ? attr->cb_mem : nullptr);
2325 const uint32_t cb_sz = ((attr != nullptr) ? attr->cb_size : 0U);
2326
2327 if (!StkTimer::EnsureTimerHostCreated())
2328 {
2329 result = nullptr; // host could not be created (e.g. no free kernel task slots)
2330 }
2331 else
2332 {
2333 StkTimer *const tmr = PlacementNewOrHeap<StkTimer>(cb_mem, cb_sz, func, type, argument, name);
2334 result = static_cast<osTimerId_t>(tmr);
2335 }
2336 }
2337
2338 return result;
2339}
void * osTimerId_t
Definition cmsis_os2.h:326
void * cb_mem
memory for control block
Definition cmsis_os2.h:368
const char * name
name of the timer
Definition cmsis_os2.h:366
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:369

References osTimerAttr_t::cb_mem, osTimerAttr_t::cb_size, osTimerAttr_t::name, osKernelGetState(), and osKernelInactive.

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

2358{
2359 osStatus_t result;
2360
2361 if (IsIrqContext())
2362 {
2363 result = osErrorISR;
2364 }
2365 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
2366 {
2367 result = osErrorParameter;
2368 }
2369 else
2370 {
2371 // 0 ticks would turn a periodic timer into a one-shot one, osWaitForever (and anything above
2372 // WAIT_INFINITE) is not a valid timer interval
2373 if ((ticks == 0U) || (ticks > static_cast<uint32_t>(stk::WAIT_INFINITE)))
2374 {
2375 result = osErrorParameter;
2376 }
2377 else
2378 {
2379 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
2380
2381 const uint32_t period_ticks = ((tmr->m_type == osTimerPeriodic) ? ticks : 0U);
2382 tmr->m_period_ticks = period_ticks;
2383 tmr->m_started = true;
2384
2385 // RestartSync(): atomic stop + start, the outcome is exact. RES_QUEUED: the caller can not wait (kernel
2386 // not started yet), the command is queued and executed once the tick task runs.
2387 const stk::time::TimerHost::EResult res = g_TimerHost->RestartSync(*tmr, ticks, period_ticks);
2388 result = ((res == stk::time::TimerHost::RES_OK) || (res == stk::time::TimerHost::RES_QUEUED)) ?
2389 osOK : osError;
2390 }
2391 }
2392
2393 return result;
2394}

References osError, osErrorISR, osErrorParameter, osOK, osTimerPeriodic, stk::time::TimerHost::RES_OK, stk::time::TimerHost::RES_QUEUED, stk::time::TimerHost::RestartSync(), and stk::WAIT_INFINITE.

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

2397{
2398 osStatus_t result;
2399
2400 if (IsIrqContext())
2401 {
2402 result = osErrorISR;
2403 }
2404 else if ((timer_id == nullptr) || (g_TimerHost == nullptr))
2405 {
2406 result = osErrorParameter;
2407 }
2408 else
2409 {
2410 StkTimer *const tmr = static_cast<StkTimer *>(timer_id);
2411
2412 // StopSync() judges the state in the tick task (no race with an expiring one-shot): RES_INACTIVE means
2413 // the timer was not running, which CMSIS reports as osErrorResource
2414 switch (g_TimerHost->StopSync(*tmr))
2415 {
2418 result = osOK;
2419 break;
2420
2422 result = osErrorResource;
2423 break;
2424
2425 default:
2426 result = osError;
2427 break;
2428 }
2429 }
2430
2431 return result;
2432}

References osError, osErrorISR, osErrorParameter, osErrorResource, osOK, stk::time::TimerHost::RES_INACTIVE, stk::time::TimerHost::RES_OK, stk::time::TimerHost::RES_QUEUED, and stk::time::TimerHost::StopSync().

Here is the call graph for this function:

◆ osWatchdogAlarm_Handler()

__stk_weak 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.

Definition at line 1861 of file cmsis_os2_stk.cpp.

1862{
1863 (void)thread_id;
1864 return 0U;
1865}

References __stk_weak.

◆ osZoneSetup_Callback()

void osZoneSetup_Callback ( uint32_t zone)

Setup MPU protected zone (called when zone changes).

Parameters
[in]zonezone number.

Definition at line 1867 of file cmsis_os2_stk.cpp.

1868{
1869 (void)zone; // no MPU support: zones are only recorded
1870}

References __stk_weak.