Skip to content

file cmsis_os2.h

Types

Name
structosTimerAttr_t
Attributes structure for timer.
structosThreadAttr_t
Attributes structure for thread.
structosEventFlagsAttr_t
Attributes structure for event flags.
structosMutexAttr_t
Attributes structure for mutex.
structosSemaphoreAttr_t
structosMessageQueueAttr_t
Attributes structure for message queue.
enumosStatus_t
typedef void *osThreadId_t
typedef void *osTimerId_t
typedef void *osEventFlagsId_t
typedef void *osMutexId_t
typedef void *osSemaphoreId_t
typedef void *osMessageQueueId_t
typedef uint32_tTZ_ModuleId_t

Defines

Name
__NO_RETURN
TZ_MODULEID_T

Types Documentation

enum osStatus_t

EnumeratorDescription
osOKOperation completed successfully.
osErrorUnspecified RTOS error: run-time error but no other error message fits.
osErrorTimeoutOperation not completed within the timeout period.
osErrorResourceResource not available.
osErrorParameterParameter error.
osErrorNoMemorySystem is out of memory: it was impossible to allocate or reserve memory for the operation.
osErrorISRNot allowed in ISR context: the function cannot be called from interrupt service routines.

Status code values returned by threading functions

typedef osThreadId_t

cpp
typedef void* osThreadId_t;

Thread ID identifies the thread.

typedef osTimerId_t

cpp
typedef void* osTimerId_t;

Timer ID identifies the timer.

typedef osEventFlagsId_t

cpp
typedef void* osEventFlagsId_t;

Event Flags ID identifies the event flags.

typedef osMutexId_t

cpp
typedef void* osMutexId_t;

Mutex ID identifies the mutex.

typedef osSemaphoreId_t

cpp
typedef void* osSemaphoreId_t;

Semaphore ID identifies the semaphore.

typedef osMessageQueueId_t

cpp
typedef void* osMessageQueueId_t;

Message Queue ID identifies the message queue.

typedef TZ_ModuleId_t

cpp
typedef uint32_t TZ_ModuleId_t;

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

Macros Documentation

define __NO_RETURN

cpp
#define __NO_RETURN

define TZ_MODULEID_T

cpp
#define TZ_MODULEID_T

Source code

cpp
/*
 * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ----------------------------------------------------------------------
 *
 * $Date:        18. June 2018
 * $Revision:    V2.1.3
 *
 * Project:      CMSIS-RTOS2 API
 * Title:        cmsis_os2.h header file
 *
 * Version 2.1.3
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osThreadGetId
 * Version 2.1.2
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osKernelGetInfo, osKernelGetState
 * Version 2.1.1
 *    Additional functions allowed to be called from Interrupt Service Routines:
 *    - osKernelGetTickCount, osKernelGetTickFreq
 *    Changed Kernel Tick type to uint32_t:
 *    - updated: osKernelGetTickCount, osDelayUntil
 * Version 2.1.0
 *    Support for critical and uncritical sections (nesting safe):
 *    - updated: osKernelLock, osKernelUnlock
 *    - added: osKernelRestoreLock
 *    Updated Thread and Event Flags:
 *    - changed flags parameter and return type from int32_t to uint32_t
 * Version 2.0.0
 *    Initial Release
 *---------------------------------------------------------------------------*/
/********************************************************************************
 * @file    cmsis_os2.h
 * @license    This file is part of the ImagineOn Coldwave eOS software package
 *             licensed under the ImagineOn software-licensing terms available
 *             under https://www.imagineon.de/de/info/licensing-terms
 * @copyright  Copyright (c) 2023. ImagineOn GmbH. www.imagineon.de.
 ********************************************************************************/

#ifndef CMSIS_OS2_H_
#define CMSIS_OS2_H_

// NOLINTBEGIN(bugprone-reserved-identifier) — Toolchain-Macro (CMSIS-RTOS2 ABI), siehe compliance/sast_baseline/rationale.md §3.7.1
#ifndef __NO_RETURN
#if defined(__CC_ARM)
#define __NO_RETURN __declspec(noreturn)
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__GNUC__)
#define __NO_RETURN __attribute__((__noreturn__))
#elif defined(__ICCARM__)
#define __NO_RETURN __noreturn
#else
#define __NO_RETURN
#endif
#endif
// NOLINTEND(bugprone-reserved-identifier) — Block-Ende (siehe Block-Header oben + compliance/sast_baseline/rationale.md §3.7)
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef EXCLUDE_FROM_DOCS

    //  ==== Enumerations, structures, defines ====

    typedef struct
    {
        uint32_t api;    
        uint32_t kernel; 
    } osVersion_t;

    typedef enum
    {
        osKernelInactive = 0,         
        osKernelReady = 1,            
        osKernelRunning = 2,          
        osKernelLocked = 3,           
        osKernelSuspended = 4,        
        osKernelError = -1,           
        osKernelReserved = 0x7FFFFFFF 
    } osKernelState_t;

#endif

    typedef enum
    {
        osThreadInactive = 0,         
        osThreadReady = 1,            
        osThreadRunning = 2,          
        osThreadBlocked = 3,          
        osThreadTerminated = 4,       
        osThreadError = -1,           
        osThreadReserved = 0x7FFFFFFF 
    } osThreadState_t;

    typedef enum
    {
        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  
    } osPriority_t;

    typedef void (*osThreadFunc_t)(void* argument);

    typedef void (*osTimerFunc_t)(void* argument);

    typedef enum
    {
        osTimerOnce = 0,    
        osTimerPeriodic = 1 
    } osTimerType_t;

    typedef struct
    {
        const char* name;   
        uint32_t attr_bits; 
        void* cb_mem;       
        uint32_t cb_size;   
    } osTimerAttr_t;

// Timeout value.
#define osWaitForever 0xFFFFFFFFU 

// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
#define osFlagsWaitAny 0x00000000U 
#define osFlagsWaitAll 0x00000001U 
#define osFlagsNoClear 0x00000002U 

// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
#define osFlagsError 0x80000000U          
#define osFlagsErrorUnknown 0xFFFFFFFFU   
#define osFlagsErrorTimeout 0xFFFFFFFEU   
#define osFlagsErrorResource 0xFFFFFFFDU  
#define osFlagsErrorParameter 0xFFFFFFFCU 
#define osFlagsErrorISR 0xFFFFFFFAU       

// Mutex attributes (attr_bits in \ref osMutexAttr_t).
#define osMutexRecursive 0x00000001U   
#define osMutexPrioInherit 0x00000002U 
#define osMutexRobust 0x00000008U      

    typedef enum
    {
        osOK = 0,              
        osError = -1,          
        osErrorTimeout = -2,   
        osErrorResource = -3,  
        osErrorParameter = -4, 
        osErrorNoMemory = -5,  
        osErrorISR = -6,       
#ifndef EXCLUDE_FROM_DOCS
        osStatusReserved = 0x7FFFFFFF 
#endif
    } osStatus_t;

    typedef void* osThreadId_t;

    typedef void* osTimerId_t;

    typedef void* osEventFlagsId_t;

    typedef void* osMutexId_t;

    typedef void* osSemaphoreId_t;

    typedef void* osMessageQueueId_t;

#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T
    typedef uint32_t TZ_ModuleId_t;
#endif

    typedef struct
    {
        const char* name;        
        uint32_t attr_bits;      
        void* cb_mem;            
        uint32_t cb_size;        
        void* stack_mem;         
        uint32_t stack_size;     
        osPriority_t priority;   
        TZ_ModuleId_t tz_module; 
        uint32_t reserved;       
    } osThreadAttr_t;

    typedef struct
    {
        const char* name;   
        uint32_t attr_bits; 
        void* cb_mem;       
        uint32_t cb_size;   
    } osEventFlagsAttr_t;

    typedef struct
    {
        const char* name;   
        uint32_t attr_bits; 
        void* cb_mem;       
        uint32_t cb_size;   
    } osMutexAttr_t;

    // Attributes structure for semaphore.
    typedef struct
    {
        const char* name;   
        uint32_t attr_bits; 
        void* cb_mem;       
        uint32_t cb_size;   
    } osSemaphoreAttr_t;

    typedef struct
    {
        const char* name;   
        uint32_t attr_bits; 
        void* cb_mem;       
        uint32_t cb_size;   
        void* mq_mem;       
        uint32_t mq_size;   
    } osMessageQueueAttr_t;

    //  ==== Thread Management Functions ====

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

    const char* osThreadGetName(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);

    __NO_RETURN void osThreadExit(void);

    osStatus_t osThreadTerminate(osThreadId_t thread_id);

    uint32_t osThreadGetCount(void);

    uint32_t osThreadEnumerate(osThreadId_t* thread_array, uint32_t array_items);

    //  ==== Thread Flags Functions ====

    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);

    //  ==== Event Flags Management Functions ====

    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);

    //  ==== Mutex Management Functions ====

    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);

    //  ==== Semaphore Management Functions ====

    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);

    uint32_t osSemaphoreReset(osSemaphoreId_t semaphore_id);

    //  ==== Message Queue Management Functions ====

    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);

#ifndef EXCLUDE_FROM_DOCS

    //  ==== Kernel Management 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 osKernelGetSysTimerCount(void);

    uint32_t osKernelGetSysTimerFreq(void);
#endif

    uint32_t osKernelGetTickCount(void);

    uint32_t osKernelGetTickFreq(void);

    //  ==== Timer Management Functions ====

    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);

    //  ==== Generic Wait Functions ====

    osStatus_t osDelay(uint32_t ticks);

    osStatus_t osDelayUntil(uint32_t ticks);

    osStatus_t osDelayUs(uint32_t microseconds);

#ifdef __cplusplus
}
#endif

#endif // CMSIS_OS2_H_