SuperTinyKernel™ RTOS 1.06.0
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 (STK). 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 (STK).

Macro Definition Documentation

◆ osErrorId

#define osErrorId   0xFFFFFFFFU

osError (-1).

Definition at line 249 of file cmsis_os2.h.

◆ osFlagsError

#define osFlagsError   0x80000000U

Error indicator.

Definition at line 209 of file cmsis_os2.h.

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

◆ osFlagsErrorISR

#define osFlagsErrorISR   0xFFFFFFFAU

osErrorISR (-6).

Definition at line 214 of file cmsis_os2.h.

Referenced by osThreadFlagsWait(), and StkFlagsResultToCmsis().

◆ osFlagsErrorParameter

#define osFlagsErrorParameter   0xFFFFFFFCU

osErrorParameter (-4).

Definition at line 213 of file cmsis_os2.h.

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

◆ osFlagsErrorResource

#define osFlagsErrorResource   0xFFFFFFFDU

osErrorResource (-3).

Definition at line 212 of file cmsis_os2.h.

◆ osFlagsErrorSafetyClass

#define osFlagsErrorSafetyClass   0xFFFFFFF9U

osErrorSafetyClass (-7).

Definition at line 215 of file cmsis_os2.h.

◆ osFlagsErrorTimeout

#define osFlagsErrorTimeout   0xFFFFFFFEU

osErrorTimeout (-2).

Definition at line 211 of file cmsis_os2.h.

Referenced by StkFlagsResultToCmsis().

◆ osFlagsErrorUnknown

#define osFlagsErrorUnknown   0xFFFFFFFFU

osError (-1).

Definition at line 210 of file cmsis_os2.h.

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

◆ osFlagsNoClear

#define osFlagsNoClear   0x00000002U

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

Definition at line 206 of file cmsis_os2.h.

Referenced by CmsisFlagsOptionsToStk().

◆ osFlagsWaitAll

#define osFlagsWaitAll   0x00000001U

Wait for all flags.

Definition at line 205 of file cmsis_os2.h.

Referenced by CmsisFlagsOptionsToStk().

◆ osFlagsWaitAny

#define osFlagsWaitAny   0x00000000U

Wait for any flag (default).

Definition at line 204 of file cmsis_os2.h.

◆ osMutexPrioInherit

#define osMutexPrioInherit   0x00000002U

Priority inherit protocol.

Definition at line 234 of file cmsis_os2.h.

◆ osMutexRecursive

#define osMutexRecursive   0x00000001U

Recursive mutex.

Definition at line 233 of file cmsis_os2.h.

◆ osMutexRobust

#define osMutexRobust   0x00000008U

Robust mutex.

Definition at line 235 of file cmsis_os2.h.

◆ osSafetyClass

#define osSafetyClass ( n)
Value:
#define osSafetyClass_Pos
Safety class position.
Definition cmsis_os2.h:238
#define osSafetyClass_Msk
Safety class mask.
Definition cmsis_os2.h:239
#define osSafetyClass_Valid
Safety class valid flag.
Definition cmsis_os2.h:240

Safety class.

Definition at line 241 of file cmsis_os2.h.

241#define osSafetyClass(n) ((((n) << osSafetyClass_Pos) & osSafetyClass_Msk) | \
242 osSafetyClass_Valid)

◆ osSafetyClass_Msk

#define osSafetyClass_Msk   (0x0FUL << osSafetyClass_Pos)

Safety class mask.

Definition at line 239 of file cmsis_os2.h.

◆ osSafetyClass_Pos

#define osSafetyClass_Pos   16U

Safety class position.

Definition at line 238 of file cmsis_os2.h.

◆ osSafetyClass_Valid

#define osSafetyClass_Valid   (0x10UL << osSafetyClass_Pos)

Safety class valid flag.

Definition at line 240 of file cmsis_os2.h.

◆ osSafetyWithLowerClass

#define osSafetyWithLowerClass   0x00000002U

Objects with lower safety class.

Definition at line 246 of file cmsis_os2.h.

◆ osSafetyWithSameClass

#define osSafetyWithSameClass   0x00000001U

Objects with same safety class.

Definition at line 245 of file cmsis_os2.h.

◆ osThreadDetached

#define osThreadDetached   0x00000000U

Thread created in detached mode (default).

Definition at line 218 of file cmsis_os2.h.

◆ osThreadJoinable

#define osThreadJoinable   0x00000001U

Thread created in joinable mode.

Definition at line 219 of file cmsis_os2.h.

Referenced by osThreadNew().

◆ osThreadPrivileged

#define osThreadPrivileged   0x00000004U

Thread runs in privileged mode.

Definition at line 221 of file cmsis_os2.h.

◆ osThreadProcessor

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

Thread processor number for SMP systems.

Definition at line 230 of file cmsis_os2.h.

◆ osThreadUnprivileged

#define osThreadUnprivileged   0x00000002U

Thread runs in unprivileged mode.

Definition at line 220 of file cmsis_os2.h.

◆ osThreadZone

#define osThreadZone ( n)
Value:
#define osThreadZone_Msk
MPU protected zone mask.
Definition cmsis_os2.h:224
#define osThreadZone_Pos
MPU protected zone position.
Definition cmsis_os2.h:223
#define osThreadZone_Valid
MPU protected zone valid flag.
Definition cmsis_os2.h:225

MPU zone value in attribute bit field format.

Definition at line 226 of file cmsis_os2.h.

226#define osThreadZone(n) ((((n) << osThreadZone_Pos) & osThreadZone_Msk) | \
227 osThreadZone_Valid)

◆ osThreadZone_Msk

#define osThreadZone_Msk   (0x3FUL << osThreadZone_Pos)

MPU protected zone mask.

Definition at line 224 of file cmsis_os2.h.

◆ osThreadZone_Pos

#define osThreadZone_Pos   8U

MPU protected zone position.

Definition at line 223 of file cmsis_os2.h.

◆ osThreadZone_Valid

#define osThreadZone_Valid   (0x80UL << osThreadZone_Pos)

MPU protected zone valid flag.

Definition at line 225 of file cmsis_os2.h.

◆ osWaitForever

#define osWaitForever   0xFFFFFFFFU

Wait forever timeout value.

Definition at line 201 of file cmsis_os2.h.

◆ TZ_MODULEID_T

#define TZ_MODULEID_T

Definition at line 288 of file cmsis_os2.h.

Typedef Documentation

◆ osEventFlagsId_t

typedef void* osEventFlagsId_t

Event Flags ID identifies the event flags.

Definition at line 272 of file cmsis_os2.h.

◆ osMemoryPoolId_t

typedef void* osMemoryPoolId_t

Memory Pool ID identifies the memory pool.

Definition at line 281 of file cmsis_os2.h.

◆ osMessageQueueId_t

typedef void* osMessageQueueId_t

Message Queue ID identifies the message queue.

Definition at line 284 of file cmsis_os2.h.

◆ osMutexId_t

typedef void* osMutexId_t

Mutex ID identifies the mutex.

Definition at line 275 of file cmsis_os2.h.

◆ osSemaphoreId_t

typedef void* osSemaphoreId_t

Semaphore ID identifies the semaphore.

Definition at line 278 of file cmsis_os2.h.

◆ osThreadFunc_t

typedef void(* osThreadFunc_t) (void *argument)

Entry point of a thread.

Definition at line 189 of file cmsis_os2.h.

◆ osThreadId_t

typedef void* osThreadId_t

Thread ID identifies the thread.

Definition at line 266 of file cmsis_os2.h.

◆ osTimerFunc_t

typedef void(* osTimerFunc_t) (void *argument)

Timer callback function.

Definition at line 192 of file cmsis_os2.h.

◆ osTimerId_t

typedef void* osTimerId_t

Timer ID identifies the timer.

Definition at line 269 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 290 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 110 of file cmsis_os2.h.

110 {
111 osKernelInactive = 0,
112 osKernelReady = 1,
113 osKernelRunning = 2,
114 osKernelLocked = 3,
116 osKernelError = -1,
117 osKernelReserved = 0x7FFFFFFF
osKernelState_t
Kernel state.
Definition cmsis_os2.h:110
@ osKernelLocked
Locked.
Definition cmsis_os2.h:114
@ osKernelError
Error.
Definition cmsis_os2.h:116
@ osKernelSuspended
Suspended.
Definition cmsis_os2.h:115
@ osKernelReady
Ready.
Definition cmsis_os2.h:112
@ osKernelRunning
Running.
Definition cmsis_os2.h:113
@ osKernelReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:117
@ osKernelInactive
Inactive.
Definition cmsis_os2.h:111

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

132 {
133 osPriorityNone = 0,
134 osPriorityIdle = 1,
135 osPriorityLow = 8,
136 osPriorityLow1 = 8+1,
137 osPriorityLow2 = 8+2,
138 osPriorityLow3 = 8+3,
139 osPriorityLow4 = 8+4,
140 osPriorityLow5 = 8+5,
141 osPriorityLow6 = 8+6,
142 osPriorityLow7 = 8+7,
151 osPriorityNormal = 24,
152 osPriorityNormal1 = 24+1,
153 osPriorityNormal2 = 24+2,
154 osPriorityNormal3 = 24+3,
155 osPriorityNormal4 = 24+4,
156 osPriorityNormal5 = 24+5,
157 osPriorityNormal6 = 24+6,
158 osPriorityNormal7 = 24+7,
167 osPriorityHigh = 40,
168 osPriorityHigh1 = 40+1,
169 osPriorityHigh2 = 40+2,
170 osPriorityHigh3 = 40+3,
171 osPriorityHigh4 = 40+4,
172 osPriorityHigh5 = 40+5,
173 osPriorityHigh6 = 40+6,
174 osPriorityHigh7 = 40+7,
175 osPriorityRealtime = 48,
176 osPriorityRealtime1 = 48+1,
177 osPriorityRealtime2 = 48+2,
178 osPriorityRealtime3 = 48+3,
179 osPriorityRealtime4 = 48+4,
180 osPriorityRealtime5 = 48+5,
181 osPriorityRealtime6 = 48+6,
182 osPriorityRealtime7 = 48+7,
183 osPriorityISR = 56,
184 osPriorityError = -1,
185 osPriorityReserved = 0x7FFFFFFF
osPriority_t
Priority values.
Definition cmsis_os2.h:132
@ osPriorityNormal7
Priority: normal + 7.
Definition cmsis_os2.h:158
@ osPriorityHigh3
Priority: high + 3.
Definition cmsis_os2.h:170
@ osPriorityBelowNormal5
Priority: below normal + 5.
Definition cmsis_os2.h:148
@ osPriorityRealtime
Priority: realtime.
Definition cmsis_os2.h:175
@ osPriorityAboveNormal
Priority: above normal.
Definition cmsis_os2.h:159
@ osPriorityHigh1
Priority: high + 1.
Definition cmsis_os2.h:168
@ osPriorityBelowNormal
Priority: below normal.
Definition cmsis_os2.h:143
@ osPriorityBelowNormal3
Priority: below normal + 3.
Definition cmsis_os2.h:146
@ osPriorityNormal2
Priority: normal + 2.
Definition cmsis_os2.h:153
@ osPriorityLow3
Priority: low + 3.
Definition cmsis_os2.h:138
@ osPriorityBelowNormal4
Priority: below normal + 4.
Definition cmsis_os2.h:147
@ osPriorityISR
Reserved for ISR deferred thread.
Definition cmsis_os2.h:183
@ osPriorityNormal1
Priority: normal + 1.
Definition cmsis_os2.h:152
@ osPriorityRealtime3
Priority: realtime + 3.
Definition cmsis_os2.h:178
@ osPriorityNormal3
Priority: normal + 3.
Definition cmsis_os2.h:154
@ osPriorityHigh2
Priority: high + 2.
Definition cmsis_os2.h:169
@ osPriorityNormal
Priority: normal.
Definition cmsis_os2.h:151
@ osPriorityBelowNormal2
Priority: below normal + 2.
Definition cmsis_os2.h:145
@ osPriorityIdle
Reserved for Idle thread.
Definition cmsis_os2.h:134
@ osPriorityHigh6
Priority: high + 6.
Definition cmsis_os2.h:173
@ osPriorityHigh5
Priority: high + 5.
Definition cmsis_os2.h:172
@ osPriorityLow4
Priority: low + 4.
Definition cmsis_os2.h:139
@ osPriorityLow7
Priority: low + 7.
Definition cmsis_os2.h:142
@ osPriorityLow
Priority: low.
Definition cmsis_os2.h:135
@ osPriorityAboveNormal6
Priority: above normal + 6.
Definition cmsis_os2.h:165
@ osPriorityHigh7
Priority: high + 7.
Definition cmsis_os2.h:174
@ osPriorityNormal5
Priority: normal + 5.
Definition cmsis_os2.h:156
@ osPriorityNone
No priority (not initialized).
Definition cmsis_os2.h:133
@ osPriorityAboveNormal4
Priority: above normal + 4.
Definition cmsis_os2.h:163
@ osPriorityLow2
Priority: low + 2.
Definition cmsis_os2.h:137
@ osPriorityRealtime6
Priority: realtime + 6.
Definition cmsis_os2.h:181
@ osPriorityNormal6
Priority: normal + 6.
Definition cmsis_os2.h:157
@ osPriorityAboveNormal2
Priority: above normal + 2.
Definition cmsis_os2.h:161
@ osPriorityBelowNormal1
Priority: below normal + 1.
Definition cmsis_os2.h:144
@ osPriorityHigh
Priority: high.
Definition cmsis_os2.h:167
@ osPriorityNormal4
Priority: normal + 4.
Definition cmsis_os2.h:155
@ osPriorityRealtime7
Priority: realtime + 7.
Definition cmsis_os2.h:182
@ osPriorityBelowNormal7
Priority: below normal + 7.
Definition cmsis_os2.h:150
@ osPriorityRealtime2
Priority: realtime + 2.
Definition cmsis_os2.h:177
@ osPriorityLow1
Priority: low + 1.
Definition cmsis_os2.h:136
@ osPriorityBelowNormal6
Priority: below normal + 6.
Definition cmsis_os2.h:149
@ osPriorityAboveNormal1
Priority: above normal + 1.
Definition cmsis_os2.h:160
@ osPriorityLow6
Priority: low + 6.
Definition cmsis_os2.h:141
@ osPriorityReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:185
@ osPriorityAboveNormal3
Priority: above normal + 3.
Definition cmsis_os2.h:162
@ osPriorityLow5
Priority: low + 5.
Definition cmsis_os2.h:140
@ osPriorityAboveNormal7
Priority: above normal + 7.
Definition cmsis_os2.h:166
@ osPriorityError
System cannot determine priority or illegal priority.
Definition cmsis_os2.h:184
@ osPriorityAboveNormal5
Priority: above normal + 5.
Definition cmsis_os2.h:164
@ osPriorityRealtime4
Priority: realtime + 4.
Definition cmsis_os2.h:179
@ osPriorityRealtime1
Priority: realtime + 1.
Definition cmsis_os2.h:176
@ osPriorityHigh4
Priority: high + 4.
Definition cmsis_os2.h:171
@ osPriorityRealtime5
Priority: realtime + 5.
Definition cmsis_os2.h:180

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

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

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

121 {
122 osThreadInactive = 0,
123 osThreadReady = 1,
124 osThreadRunning = 2,
125 osThreadBlocked = 3,
127 osThreadError = -1,
128 osThreadReserved = 0x7FFFFFFF
osThreadState_t
Thread state.
Definition cmsis_os2.h:121
@ osThreadBlocked
Blocked.
Definition cmsis_os2.h:125
@ osThreadRunning
Running.
Definition cmsis_os2.h:124
@ osThreadInactive
Inactive.
Definition cmsis_os2.h:122
@ osThreadReserved
Prevents enum down-size compiler optimization.
Definition cmsis_os2.h:128
@ osThreadTerminated
Terminated.
Definition cmsis_os2.h:126
@ osThreadError
Error.
Definition cmsis_os2.h:127
@ osThreadReady
Ready.
Definition cmsis_os2.h:123

◆ osTimerType_t

Timer type.

Enumerator
osTimerOnce 

One-shot timer.

osTimerPeriodic 

Repeating timer.

Definition at line 195 of file cmsis_os2.h.

195 {
196 osTimerOnce = 0,
197 osTimerPeriodic = 1
osTimerType_t
Timer type.
Definition cmsis_os2.h:195
@ osTimerPeriodic
Repeating timer.
Definition cmsis_os2.h:197
@ osTimerOnce
One-shot timer.
Definition cmsis_os2.h:196

Function Documentation

◆ osDelay()

osStatus_t osDelay ( uint32_t ticks)

Wait for Timeout (Time Delay).

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

Definition at line 1064 of file cmsis_os2_stk.cpp.

1065{
1066 if (IsIrqContext())
1067 return osErrorISR;
1069 return osError;
1070
1071 stk::Timeout timeout = CmsisTimeoutToStk(ticks);
1072
1073 stk::Sleep(timeout);
1074 return osOK;
1075}
static __stk_forceinline bool IsIrqContext()
static __stk_forceinline stk::Timeout CmsisTimeoutToStk(uint32_t ticks)
osKernelState_t osKernelGetState(void)
void Sleep(Timeout ticks)
Put calling process into a sleep state.
Definition stk_helper.h:326
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:123

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

Here is the call graph for this function:

◆ osDelayUntil()

osStatus_t osDelayUntil ( uint32_t ticks)

Wait until specified time.

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

Definition at line 1077 of file cmsis_os2_stk.cpp.

1078{
1079 if (IsIrqContext())
1080 return osErrorISR;
1082 return osError;
1083
1084 stk::SleepUntil(static_cast<stk::Ticks>(ticks));
1085 return osOK;
1086}
int64_t Ticks
Ticks value.
Definition stk_common.h:128
void SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:350

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

Here is the call graph for this function:

◆ osEventFlagsClear()

uint32_t osEventFlagsClear ( osEventFlagsId_t ef_id,
uint32_t flags )

Clear the specified Event Flags.

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

Definition at line 1203 of file cmsis_os2_stk.cpp.

1204{
1205 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1206 return osFlagsErrorParameter;
1207
1208 uint32_t result = static_cast<StkEventFlags *>(ef_id)->m_ef.Clear(flags);
1209 return StkFlagsResultToCmsis(result);
1210}
static __stk_forceinline uint32_t StkFlagsResultToCmsis(uint32_t result)
#define osFlagsError
Error indicator.
Definition cmsis_os2.h:209
#define osFlagsErrorParameter
osErrorParameter (-4).
Definition cmsis_os2.h:213

References osFlagsError, osFlagsErrorParameter, and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osEventFlagsDelete()

osStatus_t osEventFlagsDelete ( osEventFlagsId_t ef_id)

Delete an Event Flags object.

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

Definition at line 1232 of file cmsis_os2_stk.cpp.

1233{
1234 if (IsIrqContext() || (ef_id == nullptr))
1236
1237 ObjDestroy(static_cast<StkEventFlags *>(ef_id));
1238 return osOK;
1239}
static void ObjDestroy(T *obj)

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

Here is the call graph for this function:

◆ osEventFlagsGet()

uint32_t osEventFlagsGet ( osEventFlagsId_t ef_id)

Get the current Event Flags.

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

Definition at line 1212 of file cmsis_os2_stk.cpp.

1213{
1214 if (ef_id == nullptr)
1215 return 0U;
1216
1217 return static_cast<StkEventFlags *>(ef_id)->m_ef.Get();
1218}

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

1187{
1188 if (ef_id == nullptr)
1189 return nullptr;
1190
1191 return static_cast<StkEventFlags *>(ef_id)->m_ef.GetTraceName();
1192}

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

1174{
1175 if (IsIrqContext())
1176 return nullptr;
1177
1178 const char *name = (attr != nullptr ? attr->name : nullptr);
1179 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1180 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1181
1182 StkEventFlags *ef = PlacementNewOrHeap<StkEventFlags>(cb_mem, cb_sz, name);
1183 return static_cast<osEventFlagsId_t>(ef);
1184}
static T * PlacementNewOrHeap(void *cb_mem, size_t cb_size, Args &&...args)
void * osEventFlagsId_t
Definition cmsis_os2.h:272
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:320
const char * name
name of the event flags
Definition cmsis_os2.h:317
void * cb_mem
memory for control block
Definition cmsis_os2.h:319

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

Here is the call graph for this function:

◆ osEventFlagsSet()

uint32_t osEventFlagsSet ( osEventFlagsId_t ef_id,
uint32_t flags )

Set the specified Event Flags.

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

Definition at line 1194 of file cmsis_os2_stk.cpp.

1195{
1196 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1197 return osFlagsErrorParameter;
1198
1199 uint32_t result = static_cast<StkEventFlags *>(ef_id)->m_ef.Set(flags);
1200 return StkFlagsResultToCmsis(result);
1201}

References osFlagsError, osFlagsErrorParameter, and StkFlagsResultToCmsis().

Here is the call graph for this function:

◆ osEventFlagsWait()

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

Wait for one or more Event Flags to become signaled.

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

Definition at line 1220 of file cmsis_os2_stk.cpp.

1222{
1223 if ((ef_id == nullptr) || ((flags & osFlagsError) != 0U))
1224 return osFlagsErrorParameter;
1225
1226 uint32_t result = static_cast<StkEventFlags *>(ef_id)->m_ef.Wait(flags,
1227 CmsisFlagsOptionsToStk(options), CmsisTimeoutToStk(timeout));
1228
1229 return StkFlagsResultToCmsis(result);
1230}
static __stk_forceinline uint32_t CmsisFlagsOptionsToStk(uint32_t options)

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

Here is the call graph for this function:

◆ osFaultResume()

void osFaultResume ( void )

Resume normal operation when exiting exception faults.

◆ osKernelDestroyClass()

osStatus_t osKernelDestroyClass ( uint32_t safety_class,
uint32_t mode )

Destroy objects for specified safety classes.

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

◆ osKernelGetInfo()

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

Get RTOS Kernel Information.

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

Definition at line 519 of file cmsis_os2_stk.cpp.

520{
521 if (version != nullptr)
522 {
523 version->api = STK_WRAPPER_API_VERSION;
525 }
526
527 if ((id_buf != nullptr) && (id_size > 0U))
528 {
529 const char *id = STK_WRAPPER_KERNEL_ID;
530 size_t copy_len = id_size - 1U;
531 size_t id_len = __builtin_strlen(id);
532 if (copy_len > id_len)
533 copy_len = id_len;
534
535 memcpy(id_buf, id, copy_len);
536 id_buf[copy_len] = '\0';
537 }
538
539 return osOK;
540}
#define STK_WRAPPER_KERNEL_VERSION
#define STK_WRAPPER_KERNEL_ID
#define STK_WRAPPER_API_VERSION
uint32_t api
API version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:105
uint32_t kernel
Kernel version (major.minor.rev: mmnnnrrrr dec).
Definition cmsis_os2.h:106

References osVersion_t::api, osVersion_t::kernel, osOK, STK_WRAPPER_API_VERSION, STK_WRAPPER_KERNEL_ID, and STK_WRAPPER_KERNEL_VERSION.

◆ osKernelGetState()

osKernelState_t osKernelGetState ( void )

Get the current RTOS Kernel state.

Returns
current RTOS Kernel state.

Definition at line 542 of file cmsis_os2_stk.cpp.

543{
544 if (g_StkKernelLocked != 0U)
545 return osKernelLocked;
546
547 switch (g_StkKernel.GetState())
548 {
553 default: return osKernelError;
554 }
555}
static uint32_t g_StkKernelLocked
static StkKernel g_StkKernel
@ STATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
Definition stk_common.h:968
@ STATE_READY
Ready to start, IKernel::Start() must be called.
Definition stk_common.h:969
@ STATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
Definition stk_common.h:971
@ STATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
Definition stk_common.h:970

References g_StkKernel, g_StkKernelLocked, osKernelError, osKernelInactive, osKernelLocked, osKernelReady, osKernelRunning, osKernelSuspended, stk::IKernel::STATE_INACTIVE, stk::IKernel::STATE_READY, stk::IKernel::STATE_RUNNING, and stk::IKernel::STATE_SUSPENDED.

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

Here is the caller graph for this function:

◆ osKernelGetSysTimerCount()

uint32_t osKernelGetSysTimerCount ( void )

Get the RTOS kernel system timer count.

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

Definition at line 659 of file cmsis_os2_stk.cpp.

660{
661 return static_cast<uint32_t>(stk::GetSysTimerCount());
662}
Cycles GetSysTimerCount()
Get system timer count value.
Definition stk_helper.h:306

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

665{
666 return stk::GetSysTimerCount();
667}

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

670{
672}
uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:315

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

640{
642 return 0U;
643
644 return static_cast<uint32_t>(stk::GetTicks());
645}
Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:258

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

Here is the call graph for this function:

◆ osKernelGetTickFreq()

uint32_t osKernelGetTickFreq ( void )

Get the RTOS kernel tick frequency.

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

Definition at line 647 of file cmsis_os2_stk.cpp.

648{
650 return 1000U; // default 1 kHz
651
652 int32_t res_us = stk::GetTickResolution(); // us per tick
653 if (res_us <= 0)
654 return 1000U;
655
656 return (1000000U / static_cast<uint32_t>(res_us));
657}
int32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:268

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

Here is the call graph for this function:

◆ osKernelInitialize()

osStatus_t osKernelInitialize ( void )

Initialize the RTOS Kernel.

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

Definition at line 507 of file cmsis_os2_stk.cpp.

508{
509 if (IsIrqContext())
510 return osErrorISR;
511
513 return osError;
514
515 g_StkKernel.Initialize(); // default 1 ms tick resolution
516 return osOK;
517}

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

Here is the call graph for this function:

◆ osKernelLock()

int32_t osKernelLock ( void )

Lock the RTOS Kernel scheduler.

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

Definition at line 571 of file cmsis_os2_stk.cpp.

572{
573 if (IsIrqContext())
574 return static_cast<int32_t>(osErrorISR);
575
578 return 0;
579}
static void Enter()
Enter a critical section.

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

Here is the call graph for this function:

◆ osKernelProtect()

osStatus_t osKernelProtect ( uint32_t safety_class)

Protect the RTOS Kernel scheduler access.

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

◆ osKernelRestoreLock()

int32_t osKernelRestoreLock ( int32_t lock)

Restore the RTOS Kernel scheduler lock state.

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

Definition at line 593 of file cmsis_os2_stk.cpp.

594{
595 if (IsIrqContext())
596 return static_cast<int32_t>(osErrorISR);
597
598 if (lock == 1)
599 {
602 }
603 else
604 {
605 if (g_StkKernelLocked == 0U)
606 return osErrorResource;
607
610 }
611
612 return lock;
613}
static void Exit()
Exit a critical section.

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

Here is the call graph for this function:

◆ osKernelResume()

void osKernelResume ( uint32_t sleep_ticks)

Resume the RTOS Kernel scheduler.

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

Definition at line 628 of file cmsis_os2_stk.cpp.

629{
630#if STK_TICKLESS_IDLE
632 return stk::IKernelService::GetInstance()->Resume(sleep_ticks);
633#else
634 // Not supported in non-tickless kernel.
635 STK_UNUSED(sleep_ticks);
636#endif
637}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:524
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual void Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.

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

Here is the call graph for this function:

◆ osKernelStart()

osStatus_t osKernelStart ( void )

Start the RTOS Kernel scheduler.

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

Definition at line 557 of file cmsis_os2_stk.cpp.

558{
559 if (IsIrqContext())
560 return osErrorISR;
561
563 return osError;
564
565 // Start() does not return for KERNEL_STATIC;
566 // for KERNEL_DYNAMIC it returns when all tasks exit.
567 g_StkKernel.Start();
568 return osOK;
569}

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

Here is the call graph for this function:

◆ osKernelSuspend()

uint32_t osKernelSuspend ( void )

Suspend the RTOS Kernel scheduler.

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

Definition at line 615 of file cmsis_os2_stk.cpp.

616{
617#if STK_TICKLESS_IDLE
619 return 0U;
620
622#else
623 // Not supported in non-tickless kernel.
624 return 0U;
625#endif
626}
virtual Timeout Suspend()=0
Suspend scheduling.

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

Here is the call graph for this function:

◆ osKernelUnlock()

int32_t osKernelUnlock ( void )

Unlock the RTOS Kernel scheduler.

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

Definition at line 581 of file cmsis_os2_stk.cpp.

582{
583 if (IsIrqContext())
584 return static_cast<int32_t>(osErrorISR);
585 if (g_StkKernelLocked == 0U)
586 return osErrorResource;
587
590 return 0;
591}

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

Here is the call graph for this function:

◆ osMemoryPoolAlloc()

void * osMemoryPoolAlloc ( osMemoryPoolId_t mp_id,
uint32_t timeout )

Allocate a memory block from a Memory Pool.

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

Definition at line 1454 of file cmsis_os2_stk.cpp.

1455{
1456 if (mp_id == nullptr)
1457 return nullptr;
1458
1459 // ISR context is only valid with timeout == 0 (NO_WAIT / TryAlloc).
1460 if (IsIrqContext() && (timeout != 0U))
1461 return nullptr;
1462
1463 return static_cast<StkMemPool *>(mp_id)->m_mpool.TimedAlloc(CmsisTimeoutToStk(timeout));
1464}

References CmsisTimeoutToStk(), and IsIrqContext().

Here is the call graph for this function:

◆ osMemoryPoolDelete()

osStatus_t osMemoryPoolDelete ( osMemoryPoolId_t mp_id)

Delete a Memory Pool object.

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

Definition at line 1509 of file cmsis_os2_stk.cpp.

1510{
1511 if (IsIrqContext() || (mp_id == nullptr))
1513
1514 ObjDestroy(static_cast<StkMemPool *>(mp_id));
1515
1516 return osOK;
1517}

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

Here is the call graph for this function:

◆ osMemoryPoolFree()

osStatus_t osMemoryPoolFree ( osMemoryPoolId_t mp_id,
void * block )

Return an allocated memory block back to a Memory Pool.

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

Definition at line 1466 of file cmsis_os2_stk.cpp.

1467{
1468 if ((mp_id == nullptr) || (block == nullptr))
1469 return osErrorParameter;
1470
1471 if (!static_cast<StkMemPool *>(mp_id)->m_mpool.Free(block))
1472 return osErrorParameter; // ptr not from this pool
1473
1474 return osOK;
1475}

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

1486{
1487 if (mp_id == nullptr)
1488 return 0U;
1489
1490 return static_cast<uint32_t>(static_cast<StkMemPool *>(mp_id)->m_mpool.GetBlockSize());
1491}
stk::memory::BlockMemoryPool m_mpool

References StkMemPool::m_mpool.

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

1478{
1479 if (mp_id == nullptr)
1480 return 0U;
1481
1482 return static_cast<StkMemPool *>(mp_id)->m_mpool.GetCapacity();
1483}

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

1494{
1495 if (mp_id == nullptr)
1496 return 0U;
1497
1498 return static_cast<StkMemPool *>(mp_id)->m_mpool.GetUsedCount();
1499}

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

1447{
1448 if (mp_id == nullptr)
1449 return nullptr;
1450
1451 return static_cast<StkMemPool *>(mp_id)->m_mpool.GetTraceName();
1452}

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

1502{
1503 if (mp_id == nullptr)
1504 return 0U;
1505
1506 return static_cast<StkMemPool *>(mp_id)->m_mpool.GetFreeCount();
1507}

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

1402{
1403 // ISR context: forbidden per CMSIS spec.
1404 if (IsIrqContext())
1405 return nullptr;
1406
1407 // Zero capacity or zero block size are meaningless.
1408 if ((block_count == 0U) || (block_size == 0U))
1409 return nullptr;
1410
1411 const char *name = (attr != nullptr ? attr->name : nullptr);
1412 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1413 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1414 void *mp_mem = (attr != nullptr ? attr->mp_mem : nullptr);
1415 uint32_t mp_sz = (attr != nullptr ? attr->mp_size : 0U);
1416
1417 // Compute the aligned block size and required storage byte count.
1418 const uint32_t aligned_blk = stk::memory::BlockMemoryPool::AlignBlockSize(block_size);
1419 const uint32_t storage_required = (block_count * aligned_blk);
1420
1421 StkMemPool *pool = nullptr;
1422
1423 if ((mp_mem != nullptr) && (mp_sz >= storage_required))
1424 {
1425 // Caller-supplied pool storage - BlockMemoryPool external-storage ctor.
1426 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
1427 block_count, block_size, name, static_cast<uint8_t *>(mp_mem));
1428 }
1429 else
1430 {
1431 // Heap-allocated pool storage - BlockMemoryPool heap ctor.
1432 pool = PlacementNewOrHeap<StkMemPool>(cb_mem, cb_sz,
1433 block_count, block_size, name);
1434
1435 // If the heap ctor failed to allocate storage, clean up and bail.
1436 if ((pool != nullptr) && !pool->m_mpool.IsStorageValid())
1437 {
1438 ObjDestroy(pool);
1439 return nullptr;
1440 }
1441 }
1442
1443 return static_cast<osMemoryPoolId_t>(pool);
1444}
void * osMemoryPoolId_t
Definition cmsis_os2.h:281
uint32_t mp_size
size of provided memory for data storage
Definition cmsis_os2.h:346
const char * name
name of the memory pool
Definition cmsis_os2.h:341
void * cb_mem
memory for control block
Definition cmsis_os2.h:343
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:344
void * mp_mem
memory for data storage
Definition cmsis_os2.h:345

References osMemoryPoolAttr_t::cb_mem, osMemoryPoolAttr_t::cb_size, IsIrqContext(), StkMemPool::m_mpool, osMemoryPoolAttr_t::mp_mem, osMemoryPoolAttr_t::mp_size, osMemoryPoolAttr_t::name, ObjDestroy(), and PlacementNewOrHeap().

Here is the call graph for this function:

◆ osMessageQueueDelete()

osStatus_t osMessageQueueDelete ( osMessageQueueId_t mq_id)

Delete a Message Queue object.

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

Definition at line 1650 of file cmsis_os2_stk.cpp.

1651{
1652 if (IsIrqContext() || (mq_id == nullptr))
1654
1655 ObjDestroy(static_cast<StkMessageQueue *>(mq_id));
1656
1657 return osOK;
1658}

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

Here is the call graph for this function:

◆ osMessageQueueGet()

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

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

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

Definition at line 1589 of file cmsis_os2_stk.cpp.

1591{
1592 if (!mq_id || !msg_ptr)
1593 return osErrorParameter;
1594 if (IsIrqContext() && (timeout != 0U))
1595 return osErrorISR;
1596
1597 stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1598
1599 if (!static_cast<StkMessageQueue *>(mq_id)->m_mq.Get(msg_ptr, stk_timeout))
1600 return ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1601
1602 if (msg_prio)
1603 *msg_prio = 0U; // STK queues have no priority lanes.
1604
1605 return osOK;
1606}
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:177

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

Here is the call graph for this function:

◆ osMessageQueueGetCapacity()

uint32_t osMessageQueueGetCapacity ( osMessageQueueId_t mq_id)

Get maximum number of messages in a Message Queue.

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

Definition at line 1608 of file cmsis_os2_stk.cpp.

1609{
1610 if (mq_id == nullptr)
1611 return 0U;
1612
1613 return static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCapacity());
1614}
size_t GetCapacity() const
Get the maximum number of messages the queue can hold.
stk::sync::MessageQueue m_mq

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

Here is the call graph for this function:

◆ osMessageQueueGetCount()

uint32_t osMessageQueueGetCount ( osMessageQueueId_t mq_id)

Get number of queued messages in a Message Queue.

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

Definition at line 1624 of file cmsis_os2_stk.cpp.

1625{
1626 if (mq_id == nullptr)
1627 return 0U;
1628
1629 return static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetCount());
1630}
size_t GetCount() const
Get the current number of messages in the queue.

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

Here is the call graph for this function:

◆ osMessageQueueGetMsgSize()

uint32_t osMessageQueueGetMsgSize ( osMessageQueueId_t mq_id)

Get maximum message size in a Message Queue.

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

Definition at line 1616 of file cmsis_os2_stk.cpp.

1617{
1618 if (mq_id == nullptr)
1619 return 0U;
1620
1621 return static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetMsgSize());
1622}
size_t GetMsgSize() const
Get the size of each message in bytes.

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

Here is the call graph for this function:

◆ osMessageQueueGetName()

const char * osMessageQueueGetName ( osMessageQueueId_t mq_id)

Get name of a Message Queue object.

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

Definition at line 1565 of file cmsis_os2_stk.cpp.

1566{
1567 if (mq_id == nullptr)
1568 return nullptr;
1569
1570 return static_cast<StkMessageQueue *>(mq_id)->m_mq.GetTraceName();
1571}

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

1633{
1634 if (mq_id == nullptr)
1635 return 0U;
1636
1637 return static_cast<uint32_t>(static_cast<StkMessageQueue *>(mq_id)->m_mq.GetSpace());
1638}
size_t GetSpace() const
Get the number of free slots currently available.

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

Here is the call graph for this function:

◆ osMessageQueueNew()

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

Create and Initialize a Message Queue object.

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

Definition at line 1524 of file cmsis_os2_stk.cpp.

1526{
1527 if (IsIrqContext() || (msg_count == 0U) || (msg_size == 0U))
1528 return nullptr;
1529
1531 return nullptr;
1532
1533 const char *name = (attr != nullptr ? attr->name : nullptr);
1534 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1535 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1536 void *ext_buf = (attr != nullptr ? attr->mq_mem : nullptr);
1537 uint32_t ext_buf_size = (attr != nullptr ? attr->mq_size : 0U);
1538
1539 const uint32_t buf_required = msg_count * msg_size;
1540
1541 StkMessageQueue *mq = nullptr;
1542
1543 if ((ext_buf != nullptr) && (ext_buf_size >= buf_required))
1544 {
1545 // Data buffer: use caller-supplied memory.
1546 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
1547 msg_count, msg_size, name, static_cast<uint8_t *>(ext_buf));
1548 }
1549 else
1550 {
1551 // Data buffer: heap-allocated inside StkMessageQueue constructor.
1552 mq = PlacementNewOrHeap<StkMessageQueue>(cb_mem, cb_sz,
1553 msg_count, msg_size, name);
1554
1555 if ((mq != nullptr) && (mq->m_mq.GetBuffer() == nullptr))
1556 {
1557 ObjDestroy(mq);
1558 return nullptr;
1559 }
1560 }
1561
1562 return static_cast<osMessageQueueId_t>(mq);
1563}
void * osMessageQueueId_t
Definition cmsis_os2.h:284
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
uint8_t * GetBuffer()
Get pointer to the message buffer.
const char * name
name of the message queue
Definition cmsis_os2.h:351
void * cb_mem
memory for control block
Definition cmsis_os2.h:353
uint32_t mq_size
size of provided memory for data storage
Definition cmsis_os2.h:356
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:354
void * mq_mem
memory for data storage
Definition cmsis_os2.h:355

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

Here is the call graph for this function:

◆ osMessageQueuePut()

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

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

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

Definition at line 1573 of file cmsis_os2_stk.cpp.

1575{
1576 if (!mq_id || !msg_ptr)
1577 return osErrorParameter;
1578 if (IsIrqContext() && (timeout != 0U))
1579 return osErrorISR;
1580
1581 stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1582
1583 if (!static_cast<StkMessageQueue *>(mq_id)->m_mq.Put(msg_ptr, stk_timeout))
1584 return ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1585
1586 return osOK;
1587}

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

Here is the call graph for this function:

◆ osMessageQueueReset()

osStatus_t osMessageQueueReset ( osMessageQueueId_t mq_id)

Reset a Message Queue to initial empty state.

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

Definition at line 1640 of file cmsis_os2_stk.cpp.

1641{
1642 if (IsIrqContext() || (mq_id == nullptr))
1644
1645 static_cast<StkMessageQueue *>(mq_id)->m_mq.Reset();
1646
1647 return osOK;
1648}

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

Here is the call graph for this function:

◆ osMutexAcquire()

osStatus_t osMutexAcquire ( osMutexId_t mutex_id,
uint32_t timeout )

Acquire a Mutex or timeout if it is locked.

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

Definition at line 1269 of file cmsis_os2_stk.cpp.

1270{
1271 if (IsIrqContext())
1272 return osErrorISR;
1273 if (mutex_id == nullptr)
1274 return osErrorParameter;
1275
1276 StkMutex *m = static_cast<StkMutex *>(mutex_id);
1277 stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1278
1279 bool acquired = m->m_mutex.TimedLock(stk_timeout);
1280 if (!acquired)
1281 return ((stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout);
1282
1283 return osOK;
1284}
bool TimedLock(Timeout timeout)
Acquire lock.
stk::sync::Mutex m_mutex

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

Here is the call graph for this function:

◆ osMutexDelete()

osStatus_t osMutexDelete ( osMutexId_t mutex_id)

Delete a Mutex object.

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

Definition at line 1309 of file cmsis_os2_stk.cpp.

1310{
1311 if (IsIrqContext() || (mutex_id == nullptr))
1313
1314 ObjDestroy(static_cast<StkMutex *>(mutex_id));
1315 return osOK;
1316}

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

Here is the call graph for this function:

◆ osMutexGetName()

const char * osMutexGetName ( osMutexId_t mutex_id)

Get name of a Mutex object.

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

Definition at line 1261 of file cmsis_os2_stk.cpp.

1262{
1263 if (mutex_id == nullptr)
1264 return nullptr;
1265
1266 return static_cast<StkMutex *>(mutex_id)->m_mutex.GetTraceName();
1267}

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

1298{
1299 if (mutex_id == nullptr)
1300 return nullptr;
1301
1302 stk::TId tid = static_cast<StkMutex *>(mutex_id)->m_mutex.GetOwner();
1303
1304 // tid is hw::PtrToWord(this) where 'this' is the StkThread* - cast it back.
1305 return reinterpret_cast<osThreadId_t>(static_cast<void *>(
1306 reinterpret_cast<StkThread *>(static_cast<uintptr_t>(tid))));
1307}
void * osThreadId_t
Definition cmsis_os2.h:266
Word TId
Definition stk_common.h:118

◆ osMutexNew()

osMutexId_t osMutexNew ( const osMutexAttr_t * attr)

Create and Initialize a Mutex object.

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

Definition at line 1246 of file cmsis_os2_stk.cpp.

1247{
1248 if (IsIrqContext())
1249 return nullptr;
1250
1251 // osMutexPrioInherit / osMutexRobust: accepted but silently ignored.
1252 // osMutexRecursive: STK Mutex is always recursive.
1253 const char *name = (attr != nullptr ? attr->name : nullptr);
1254 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1255 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1256
1257 StkMutex *m = PlacementNewOrHeap<StkMutex>(cb_mem, cb_sz, name);
1258 return static_cast<osMutexId_t>(m);
1259}
void * osMutexId_t
Definition cmsis_os2.h:275
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:328
const char * name
name of the mutex
Definition cmsis_os2.h:325
void * cb_mem
memory for control block
Definition cmsis_os2.h:327

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

Here is the call graph for this function:

◆ osMutexRelease()

osStatus_t osMutexRelease ( osMutexId_t mutex_id)

Release a Mutex that was acquired by osMutexAcquire.

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

Definition at line 1286 of file cmsis_os2_stk.cpp.

1287{
1288 if (IsIrqContext())
1289 return osErrorISR;
1290 if (mutex_id == nullptr)
1291 return osErrorParameter;
1292
1293 static_cast<StkMutex *>(mutex_id)->m_mutex.Unlock();
1294 return osOK;
1295}

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

Here is the call graph for this function:

◆ osSemaphoreAcquire()

osStatus_t osSemaphoreAcquire ( osSemaphoreId_t semaphore_id,
uint32_t timeout )

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

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

Definition at line 1352 of file cmsis_os2_stk.cpp.

1353{
1354 if (semaphore_id == nullptr)
1355 return osErrorParameter;
1356 if (IsIrqContext() && (timeout != 0U))
1357 return osErrorISR;
1358
1359 StkSemaphore *s = static_cast<StkSemaphore *>(semaphore_id);
1360 stk::Timeout stk_timeout = CmsisTimeoutToStk(timeout);
1361
1362 bool acquired = s->m_semaphore.Wait(stk_timeout);
1363 if (!acquired)
1364 return (stk_timeout == stk::NO_WAIT) ? osErrorResource : osErrorTimeout;
1365
1366 return osOK;
1367}
bool Wait(Timeout timeout=WAIT_INFINITE)
Wait for a signal (decrement counter).
stk::sync::Semaphore m_semaphore

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

Here is the call graph for this function:

◆ osSemaphoreDelete()

osStatus_t osSemaphoreDelete ( osSemaphoreId_t semaphore_id)

Delete a Semaphore object.

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

Definition at line 1386 of file cmsis_os2_stk.cpp.

1387{
1388 if (IsIrqContext() || (semaphore_id == nullptr))
1390
1391 ObjDestroy(static_cast<StkSemaphore *>(semaphore_id));
1392 return osOK;
1393}

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

Here is the call graph for this function:

◆ osSemaphoreGetCount()

uint32_t osSemaphoreGetCount ( osSemaphoreId_t semaphore_id)

Get current Semaphore token count.

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

Definition at line 1378 of file cmsis_os2_stk.cpp.

1379{
1380 if (semaphore_id == nullptr)
1381 return 0U;
1382
1383 return static_cast<uint32_t>(static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetCount());
1384}
uint16_t GetCount() const
Get current counter value.

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

Here is the call graph for this function:

◆ osSemaphoreGetName()

const char * osSemaphoreGetName ( osSemaphoreId_t semaphore_id)

Get name of a Semaphore object.

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

Definition at line 1344 of file cmsis_os2_stk.cpp.

1345{
1346 if (semaphore_id == nullptr)
1347 return nullptr;
1348
1349 return static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.GetTraceName();
1350}

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

1325{
1326 if (IsIrqContext())
1327 return nullptr;
1328
1329 if ((max_count == 0U) || (initial_count > max_count))
1330 return nullptr;
1331
1332 // STK Semaphore uses uint16_t counters, clamp to stk::sync::Semaphore::COUNT_MAX.
1333 uint16_t mc = stk::Min(max_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX));
1334 uint16_t ic = stk::Min(initial_count, static_cast<uint32_t>(stk::sync::Semaphore::COUNT_MAX));
1335
1336 const char *name = (attr != nullptr ? attr->name : nullptr);
1337 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1338 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1339
1340 StkSemaphore *s = PlacementNewOrHeap<StkSemaphore>(cb_mem, cb_sz, ic, mc, name);
1341 return static_cast<osSemaphoreId_t>(s);
1342}
void * osSemaphoreId_t
Definition cmsis_os2.h:278
static constexpr T Min(T a, T b)
Compile-time minimum of two values.
Definition stk_defs.h:535
static const size_t COUNT_MAX
Max count supported.
const char * name
name of the semaphore
Definition cmsis_os2.h:333
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:336
void * cb_mem
memory for control block
Definition cmsis_os2.h:335

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

Here is the call graph for this function:

◆ osSemaphoreRelease()

osStatus_t osSemaphoreRelease ( osSemaphoreId_t semaphore_id)

Release a Semaphore token up to the initial maximum count.

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

Definition at line 1369 of file cmsis_os2_stk.cpp.

1370{
1371 if (semaphore_id == nullptr)
1372 return osErrorParameter;
1373
1374 static_cast<StkSemaphore *>(semaphore_id)->m_semaphore.Signal();
1375 return osOK;
1376}

References osErrorParameter, and osOK.

◆ osThreadDetach()

osStatus_t osThreadDetach ( osThreadId_t thread_id)

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

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

Definition at line 872 of file cmsis_os2_stk.cpp.

873{
874 if (IsIrqContext() || (thread_id == nullptr))
876
877 StkThread *t = static_cast<StkThread *>(thread_id);
878
880
881 switch (t->m_join_state)
882 {
884 // already detached - CMSIS spec says this is an error
885 return osError;
886
888 // already joined - cannot detach
889 return osError;
890
892 // thread finished but nobody joined yet, transition to Detached
893 // and free the control block now, since no joiner will ever do it
895 ObjDestroy(t); // safe: task slot already freed by the kernel
896 return osOK;
897
899 // normal case: thread is still running or just hasn't been joined
901 return osOK;
902 }
903
904 return osError;
905}
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:54
volatile JoinState m_join_state

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

Here is the call graph for this function:

◆ osThreadEnumerate()

uint32_t osThreadEnumerate ( osThreadId_t * thread_array,
uint32_t array_items )

Enumerate active threads.

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

Definition at line 996 of file cmsis_os2_stk.cpp.

997{
999 return 0U;
1000
1001 // osThreadId_t maps directly to stk::ITask (see StkThread)
1002 return g_StkKernel.EnumerateTasks(reinterpret_cast<stk::ITask **>(thread_array), array_items);
1003}
Interface for a user task.
Definition stk_common.h:491

References g_StkKernel, osKernelGetState(), and osKernelInactive.

Here is the call graph for this function:

◆ osThreadExit()

void osThreadExit ( void )

Terminate execution of current running thread.

Definition at line 949 of file cmsis_os2_stk.cpp.

950{
951 StkThread *t = static_cast<StkThread *>(osThreadGetId());
952
953 g_StkKernel.ScheduleTaskRemoval(t);
954
955 // Wait for removal.
956 for (;;)
957 stk::Yield();
958}
osThreadId_t osThreadGetId(void)
void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:359

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

Here is the call graph for this function:

◆ osThreadFeedWatchdog()

osStatus_t osThreadFeedWatchdog ( uint32_t ticks)

Feed watchdog of the current running thread.

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

◆ osThreadFlagsClear()

uint32_t osThreadFlagsClear ( uint32_t flags)

Clear the specified Thread Flags of current running thread.

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

Definition at line 1021 of file cmsis_os2_stk.cpp.

1022{
1023 osThreadId_t self = osThreadGetId();
1024 if (self == nullptr)
1025 return osFlagsErrorUnknown;
1026
1027 StkThread *t = static_cast<StkThread *>(self);
1028
1029 uint32_t result = t->m_thread_flags.Clear(flags);
1030 return StkFlagsResultToCmsis(result);
1031}
#define osFlagsErrorUnknown
osError (-1).
Definition cmsis_os2.h:210
uint32_t Clear(uint32_t flags)
Clear one or more flags.
stk::sync::EventFlags m_thread_flags

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

Here is the call graph for this function:

◆ osThreadFlagsGet()

uint32_t osThreadFlagsGet ( void )

Get the current Thread Flags of current running thread.

Returns
current thread flags.

Definition at line 1033 of file cmsis_os2_stk.cpp.

1034{
1035 osThreadId_t self = osThreadGetId();
1036 if (self == nullptr)
1037 return 0U;
1038
1039 return static_cast<StkThread *>(self)->m_thread_flags.Get();
1040}

References osThreadGetId().

Here is the call graph for this function:

◆ osThreadFlagsSet()

uint32_t osThreadFlagsSet ( osThreadId_t thread_id,
uint32_t flags )

Set the specified Thread Flags of a thread.

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

Definition at line 1010 of file cmsis_os2_stk.cpp.

1011{
1012 if ((thread_id == nullptr) || ((flags & osFlagsError) != 0))
1013 return osFlagsErrorParameter;
1014
1015 StkThread *t = static_cast<StkThread *>(thread_id);
1016
1017 uint32_t result = t->m_thread_flags.Set(flags);
1018 return StkFlagsResultToCmsis(result);
1019}
uint32_t Set(uint32_t flags)
Set one or more flags.

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

Here is the call graph for this function:

◆ osThreadFlagsWait()

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

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

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

Definition at line 1042 of file cmsis_os2_stk.cpp.

1043{
1044 if (IsIrqContext())
1045 return osFlagsErrorISR;
1046
1047 osThreadId_t self = osThreadGetId();
1048 if (self == nullptr)
1049 return osFlagsErrorUnknown;
1050
1051 StkThread *t = static_cast<StkThread *>(self);
1052
1053 uint32_t result = t->m_thread_flags.Wait(flags, CmsisFlagsOptionsToStk(options),
1054 CmsisTimeoutToStk(timeout));
1055
1056 return StkFlagsResultToCmsis(result);
1057}
#define osFlagsErrorISR
osErrorISR (-6).
Definition cmsis_os2.h:214
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout=WAIT_INFINITE)
Wait for one or more flags to be set.

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

Here is the call graph for this function:

◆ osThreadGetAffinityMask()

uint32_t osThreadGetAffinityMask ( osThreadId_t thread_id)

Get current processor affinity mask of a thread.

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

◆ osThreadGetClass()

uint32_t osThreadGetClass ( osThreadId_t thread_id)

Get safety class of a thread.

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

◆ osThreadGetCount()

uint32_t osThreadGetCount ( void )

Get number of active threads.

Returns
number of active threads.

Definition at line 985 of file cmsis_os2_stk.cpp.

986{
988 return 0U;
989
990 // avoid race with OnTick
992
993 return static_cast<uint32_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
994}

References g_StkKernel, osKernelGetState(), and osKernelInactive.

Here is the call graph for this function:

◆ osThreadGetId()

osThreadId_t osThreadGetId ( void )

Return the thread ID of the current running thread.

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

Definition at line 761 of file cmsis_os2_stk.cpp.

762{
764 return nullptr;
765
766 // STK's GetTid() returns the ITask pointer cast to Word.
767 stk::TId tid = stk::GetTid();
768
769 // tid is hw::PtrToWord(this) where 'this' is the StkThread* - cast it back.
770 return reinterpret_cast<osThreadId_t>(static_cast<void *>(
771 reinterpret_cast<StkThread *>(static_cast<uintptr_t>(tid))));
772}
TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:227

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

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

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

◆ osThreadGetName()

const char * osThreadGetName ( osThreadId_t thread_id)

Get name of a thread.

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

Definition at line 753 of file cmsis_os2_stk.cpp.

754{
755 if (thread_id == nullptr)
756 return nullptr;
757
758 return static_cast<StkThread *>(thread_id)->m_name;
759}

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

823{
824 if (IsIrqContext() || (thread_id == nullptr))
825 return osPriorityError;
826
827 StkThread *t = static_cast<StkThread *>(thread_id);
829}
static __stk_forceinline osPriority_t StkPrioToCmsis(int32_t p)
volatile int32_t m_stk_priority

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

Here is the call graph for this function:

◆ osThreadGetStackSize()

uint32_t osThreadGetStackSize ( osThreadId_t thread_id)

Get stack size of a thread.

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

Definition at line 790 of file cmsis_os2_stk.cpp.

791{
792 if (thread_id == nullptr)
793 return 0U;
794
795 StkThread *t = static_cast<StkThread *>(thread_id);
796 return static_cast<uint32_t>(t->GetStackSizeBytes());
797}
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.

References StkThread::GetStackSizeBytes().

Here is the call graph for this function:

◆ osThreadGetStackSpace()

uint32_t osThreadGetStackSpace ( osThreadId_t thread_id)

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

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

Definition at line 799 of file cmsis_os2_stk.cpp.

800{
801 if (thread_id == nullptr)
802 return 0U;
803
804 StkThread *t = static_cast<StkThread *>(thread_id);
805 return static_cast<uint32_t>(t->GetStackSpace() * sizeof(stk::Word));
806}
uintptr_t Word
Native processor word type.
Definition stk_common.h:113
virtual size_t GetStackSpace()
Get available stack space.
Definition stk_common.h:252

References stk::IStackMemory::GetStackSpace().

Here is the call graph for this function:

◆ osThreadGetState()

osThreadState_t osThreadGetState ( osThreadId_t thread_id)

Get current thread state of a thread.

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

Definition at line 774 of file cmsis_os2_stk.cpp.

775{
776 if (IsIrqContext() || (thread_id == nullptr))
777 return osThreadError;
778
779 StkThread *t = static_cast<StkThread *>(thread_id);
780
781 if (t->m_suspended)
782 return osThreadBlocked;
783
784 if (thread_id == osThreadGetId())
785 return osThreadRunning;
786
787 return osThreadReady;
788}

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

Here is the call graph for this function:

◆ osThreadGetZone()

uint32_t osThreadGetZone ( osThreadId_t thread_id)

Get MPU protected zone of a thread.

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

References __NO_RETURN.

◆ osThreadJoin()

osStatus_t osThreadJoin ( osThreadId_t thread_id)

Wait for specified thread to terminate.

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

Definition at line 907 of file cmsis_os2_stk.cpp.

908{
909 if (IsIrqContext() || (thread_id == nullptr))
911
912 // Self-join is undefined behavior per POSIX / CMSIS spec.
913 if (thread_id == osThreadGetId())
914 return osErrorParameter;
915
916 StkThread *t = static_cast<StkThread *>(thread_id);
917
919
920 // Only joinable threads can be joined.
922 return osError;
923
924 // Double-join: second caller always gets an error.
926 return osError;
927
929
930 // Block until OnExit() fires (transitions state to Exited).
931 // m_join_cv.Wait() atomically releases m_join_mutex and suspends.
933 {
934 // WAIT_INFINITE - CMSIS osThreadJoin has no timeout parameter.
936 }
937
938 // At this point m_join_state == Exited (or Detached if someone
939 // raced osThreadDetach - treat that as an error).
941 return osError;
942
943 // Free the control block - the kernel has already freed the slot.
944 ObjDestroy(t);
945
946 return osOK;
947}
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:171
bool Wait(IMutex &mutex, Timeout timeout=WAIT_INFINITE)
Wait for a signal.
stk::sync::ConditionVariable m_join_cv

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

Here is the call graph for this function:

◆ osThreadNew()

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

Create a thread and add it to Active Threads.

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

Definition at line 679 of file cmsis_os2_stk.cpp.

680{
681 if (IsIrqContext() || (func == nullptr) || (osKernelGetState() == osKernelInactive))
682 return nullptr;
683
684 bool joinable = (attr != nullptr) && (attr->attr_bits & osThreadJoinable);
685 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
686 uint32_t cb_size = (attr != nullptr ? attr->cb_size : 0U);
687
688 StkThread *t = PlacementNewOrHeap<StkThread>(cb_mem, cb_size);
689 if (t == nullptr)
690 return nullptr;
691
692 t->m_func = func;
693 t->m_argument = argument;
694 t->m_name = nullptr;
696
697 osPriority_t cmsis_prio = osPriorityNormal;
698 size_t stack_words = CMSIS_STK_DEFAULT_STACK_WORDS;
699
700 if (attr != nullptr)
701 {
702 t->m_name = attr->name;
703
704 if (attr->priority != osPriorityNone)
705 cmsis_prio = attr->priority;
706
707 if ((cmsis_prio < osPriorityIdle) || (cmsis_prio > osPriorityISR))
708 {
709 ObjDestroy(t);
710 return nullptr;
711 }
712
713 // Stack: prefer caller-provided memory.
714 if ((attr->stack_mem != nullptr) && (attr->stack_size > 0U))
715 {
716 size_t words = attr->stack_size / sizeof(stk::Word);
717 if (words < CMSIS_STK_MIN_STACK_WORDS)
719
720 t->m_stack = static_cast<stk::Word *>(attr->stack_mem);
721 t->m_stack_size = words;
722 t->m_stack_owned = false;
723 }
724 else
725 if (attr->stack_size > 0U)
726 {
727 stack_words = attr->stack_size / sizeof(stk::Word);
728 if (stack_words < CMSIS_STK_MIN_STACK_WORDS)
729 stack_words = CMSIS_STK_MIN_STACK_WORDS;
730 }
731 }
732
733 // Allocate stack if not caller-provided.
734 if (t->m_stack == nullptr)
735 {
736 t->m_stack = new (std::nothrow) stk::Word[stack_words];
737 if (t->m_stack == nullptr)
738 {
739 ObjDestroy(t);
740 return nullptr;
741 }
742 t->m_stack_size = stack_words;
743 t->m_stack_owned = true;
744 }
745
746 t->m_stk_priority = CmsisPrioToStk(cmsis_prio);
747
748 g_StkKernel.AddTask(t);
749
750 return static_cast<osThreadId_t>(t);
751}
#define CMSIS_STK_MIN_STACK_WORDS
#define CMSIS_STK_DEFAULT_STACK_WORDS
static __stk_forceinline int32_t CmsisPrioToStk(osPriority_t p)
#define osThreadJoinable
Thread created in joinable mode.
Definition cmsis_os2.h:219
void * cb_mem
memory for control block
Definition cmsis_os2.h:298
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:297
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:299
void * stack_mem
memory for stack
Definition cmsis_os2.h:300
osPriority_t priority
initial thread priority (default: osPriorityNormal)
Definition cmsis_os2.h:302
uint32_t stack_size
size of stack
Definition cmsis_os2.h:301
const char * name
name of the thread
Definition cmsis_os2.h:296
stk::Word * m_stack
size_t m_stack_size
osThreadFunc_t m_func
const char * m_name
void * m_argument

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

Here is the call graph for this function:

◆ osThreadProtectPrivileged()

osStatus_t osThreadProtectPrivileged ( void )

Protect creation of privileged threads.

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

◆ osThreadResume()

osStatus_t osThreadResume ( osThreadId_t thread_id)

Resume execution of a thread.

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

Definition at line 854 of file cmsis_os2_stk.cpp.

855{
856 if (IsIrqContext() || (thread_id == nullptr) || (osKernelGetState() == osKernelInactive))
858
859 StkThread *t = static_cast<StkThread *>(thread_id);
860
862
863 if (!t->m_suspended)
864 return osOK; // not suspended, nothing to do
865
866 g_StkKernel.ResumeTask(t);
867 t->m_suspended = false;
868
869 return osOK;
870}

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

Here is the call graph for this function:

◆ osThreadResumeClass()

osStatus_t osThreadResumeClass ( uint32_t safety_class,
uint32_t mode )

Resume execution of threads for specified safety classes.

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

◆ osThreadSetAffinityMask()

osStatus_t osThreadSetAffinityMask ( osThreadId_t thread_id,
uint32_t affinity_mask )

Set processor affinity mask of a thread.

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

◆ osThreadSetPriority()

osStatus_t osThreadSetPriority ( osThreadId_t thread_id,
osPriority_t priority )

Change priority of a thread.

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

Definition at line 808 of file cmsis_os2_stk.cpp.

809{
810 if (IsIrqContext() || (thread_id == nullptr))
812
813 if ((priority < osPriorityIdle) || (priority > osPriorityISR))
814 return osErrorParameter;
815
816 StkThread *t = static_cast<StkThread *>(thread_id);
817 t->m_stk_priority = CmsisPrioToStk(priority);
818
819 return osOK;
820}

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

Here is the call graph for this function:

◆ osThreadSuspend()

osStatus_t osThreadSuspend ( osThreadId_t thread_id)

Suspend execution of a thread.

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

Definition at line 842 of file cmsis_os2_stk.cpp.

843{
844 if (IsIrqContext() || (thread_id == nullptr) || (osKernelGetState() == osKernelInactive))
846
847 StkThread *t = static_cast<StkThread *>(thread_id);
848
849 g_StkKernel.SuspendTask(t, t->m_suspended);
850
851 return osOK;
852}

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

Here is the call graph for this function:

◆ osThreadSuspendClass()

osStatus_t osThreadSuspendClass ( uint32_t safety_class,
uint32_t mode )

Suspend execution of threads for specified safety classes.

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

◆ osThreadTerminate()

osStatus_t osThreadTerminate ( osThreadId_t thread_id)

Terminate execution of a thread.

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

Definition at line 960 of file cmsis_os2_stk.cpp.

961{
962 if ((thread_id == nullptr) || (osKernelGetState() == osKernelInactive))
963 return osErrorParameter;
964
965 StkThread *t = static_cast<StkThread *>(thread_id);
966
968
969 // RemoveTask triggers the STATE_REMOVE_PENDING path in the kernel,
970 // which will call OnExit() before freeing the slot.
971 g_StkKernel.ScheduleTaskRemoval(t);
972
973 // For detached threads, free immediately (no joiner expected).
974 // For joinable threads, OnExit() will wake the joiner; the joiner
975 // calls ObjDestroy(). Do NOT free here.
976 {
978 ObjDestroy(t);
979 // else: joiner owns the lifetime
980 }
981
982 return osOK;
983}

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

Here is the call graph for this function:

◆ osThreadTerminateZone()

osStatus_t osThreadTerminateZone ( uint32_t zone)

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

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

◆ osThreadYield()

osStatus_t osThreadYield ( void )

Pass control to next thread that is in state READY.

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

Definition at line 831 of file cmsis_os2_stk.cpp.

832{
833 if (IsIrqContext())
834 return osErrorISR;
836 return osError;
837
838 stk::Yield();
839 return osOK;
840}

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

Here is the call graph for this function:

◆ osTimerDelete()

osStatus_t osTimerDelete ( osTimerId_t timer_id)

Delete a timer.

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

Definition at line 1154 of file cmsis_os2_stk.cpp.

1155{
1156 if (IsIrqContext() || (timer_id == nullptr))
1158
1159 StkTimer *timer = static_cast<StkTimer *>(timer_id);
1160
1161 if ((g_TimerHost != nullptr) && timer->IsActive())
1162 g_TimerHost->Stop(*timer);
1163
1164 ObjDestroy(timer);
1165 return osOK;
1166}
static stk::time::TimerHost * g_TimerHost

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

Here is the call graph for this function:

◆ osTimerGetName()

const char * osTimerGetName ( osTimerId_t timer_id)

Get name of a timer.

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

Definition at line 1110 of file cmsis_os2_stk.cpp.

1111{
1112 if (timer_id == nullptr)
1113 return nullptr;
1114
1115 return static_cast<StkTimer *>(timer_id)->m_name;
1116}

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

1147{
1148 if (timer_id == nullptr)
1149 return 0U;
1150
1151 return (static_cast<StkTimer *>(timer_id)->IsActive() ? 1U : 0U);
1152}

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

1095{
1096 if (IsIrqContext() || (func == nullptr) || (osKernelGetState() == osKernelInactive))
1097 return nullptr;
1098
1100 return nullptr;
1101
1102 const char *name = (attr != nullptr ? attr->name : nullptr);
1103 void *cb_mem = (attr != nullptr ? attr->cb_mem : nullptr);
1104 uint32_t cb_sz = (attr != nullptr ? attr->cb_size : 0U);
1105
1106 StkTimer *timer = PlacementNewOrHeap<StkTimer>(cb_mem, cb_sz, func, type, argument, name);
1107 return static_cast<osTimerId_t>(timer);
1108}
void * osTimerId_t
Definition cmsis_os2.h:269
void * cb_mem
memory for control block
Definition cmsis_os2.h:311
const char * name
name of the timer
Definition cmsis_os2.h:309
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:312
static bool EnsureTimerHostCreated()

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

Here is the call graph for this function:

◆ osTimerStart()

osStatus_t osTimerStart ( osTimerId_t timer_id,
uint32_t ticks )

Start or restart a timer.

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

Definition at line 1118 of file cmsis_os2_stk.cpp.

1119{
1120 if (IsIrqContext() || (timer_id == nullptr) || (g_TimerHost == nullptr))
1122
1123 StkTimer *timer = static_cast<StkTimer *>(timer_id);
1124
1125 uint32_t period = (timer->m_type == osTimerPeriodic) ? ticks : 0U;
1126 timer->m_period_ticks = period;
1127
1128 bool ok = g_TimerHost->Restart(*timer, ticks, period);
1129 return (ok ? osOK : osError);
1130}
osTimerType_t m_type
uint32_t m_period_ticks

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

Here is the call graph for this function:

◆ osTimerStop()

osStatus_t osTimerStop ( osTimerId_t timer_id)

Stop a timer.

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

Definition at line 1132 of file cmsis_os2_stk.cpp.

1133{
1134 if (IsIrqContext() || (timer_id == nullptr) || (g_TimerHost == nullptr))
1136
1137 StkTimer *timer = static_cast<StkTimer *>(timer_id);
1138
1139 if (!timer->IsActive())
1140 return osErrorResource;
1141
1142 bool ok = g_TimerHost->Stop(*timer);
1143 return (ok ? osOK : osError);
1144}

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

Here is the call graph for this function:

◆ osWatchdogAlarm_Handler()

uint32_t osWatchdogAlarm_Handler ( osThreadId_t thread_id)

Handler for expired thread watchdogs.

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

◆ osZoneSetup_Callback()

void osZoneSetup_Callback ( uint32_t zone)

Setup MPU protected zone (called when zone changes).

Parameters
[in]zonezone number.