1*a8f7f3fcSMatthias Ringwald /* ---------------------------------------------------------------------- 2*a8f7f3fcSMatthias Ringwald * $Date: 5. February 2013 3*a8f7f3fcSMatthias Ringwald * $Revision: V1.02 4*a8f7f3fcSMatthias Ringwald * 5*a8f7f3fcSMatthias Ringwald * Project: CMSIS-RTOS API 6*a8f7f3fcSMatthias Ringwald * Title: cmsis_os.h template header file 7*a8f7f3fcSMatthias Ringwald * 8*a8f7f3fcSMatthias Ringwald * Version 0.02 9*a8f7f3fcSMatthias Ringwald * Initial Proposal Phase 10*a8f7f3fcSMatthias Ringwald * Version 0.03 11*a8f7f3fcSMatthias Ringwald * osKernelStart added, optional feature: main started as thread 12*a8f7f3fcSMatthias Ringwald * osSemaphores have standard behavior 13*a8f7f3fcSMatthias Ringwald * osTimerCreate does not start the timer, added osTimerStart 14*a8f7f3fcSMatthias Ringwald * osThreadPass is renamed to osThreadYield 15*a8f7f3fcSMatthias Ringwald * Version 1.01 16*a8f7f3fcSMatthias Ringwald * Support for C++ interface 17*a8f7f3fcSMatthias Ringwald * - const attribute removed from the osXxxxDef_t typedef's 18*a8f7f3fcSMatthias Ringwald * - const attribute added to the osXxxxDef macros 19*a8f7f3fcSMatthias Ringwald * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete 20*a8f7f3fcSMatthias Ringwald * Added: osKernelInitialize 21*a8f7f3fcSMatthias Ringwald * Version 1.02 22*a8f7f3fcSMatthias Ringwald * Control functions for short timeouts in microsecond resolution: 23*a8f7f3fcSMatthias Ringwald * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec 24*a8f7f3fcSMatthias Ringwald * Removed: osSignalGet 25*a8f7f3fcSMatthias Ringwald *---------------------------------------------------------------------------- 26*a8f7f3fcSMatthias Ringwald * 27*a8f7f3fcSMatthias Ringwald * Copyright (c) 2013-2017 ARM LIMITED 28*a8f7f3fcSMatthias Ringwald * 29*a8f7f3fcSMatthias Ringwald * SPDX-License-Identifier: Apache-2.0 30*a8f7f3fcSMatthias Ringwald * 31*a8f7f3fcSMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the License); you may 32*a8f7f3fcSMatthias Ringwald * not use this file except in compliance with the License. 33*a8f7f3fcSMatthias Ringwald * You may obtain a copy of the License at 34*a8f7f3fcSMatthias Ringwald * 35*a8f7f3fcSMatthias Ringwald * www.apache.org/licenses/LICENSE-2.0 36*a8f7f3fcSMatthias Ringwald * 37*a8f7f3fcSMatthias Ringwald * Unless required by applicable law or agreed to in writing, software 38*a8f7f3fcSMatthias Ringwald * distributed under the License is distributed on an AS IS BASIS, WITHOUT 39*a8f7f3fcSMatthias Ringwald * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40*a8f7f3fcSMatthias Ringwald * See the License for the specific language governing permissions and 41*a8f7f3fcSMatthias Ringwald * limitations under the License. 42*a8f7f3fcSMatthias Ringwald *---------------------------------------------------------------------------*/ 43*a8f7f3fcSMatthias Ringwald 44*a8f7f3fcSMatthias Ringwald 45*a8f7f3fcSMatthias Ringwald #ifndef _CMSIS_OS_H 46*a8f7f3fcSMatthias Ringwald #define _CMSIS_OS_H 47*a8f7f3fcSMatthias Ringwald 48*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version. 49*a8f7f3fcSMatthias Ringwald #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0]) 50*a8f7f3fcSMatthias Ringwald 51*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. 52*a8f7f3fcSMatthias Ringwald #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0]) 53*a8f7f3fcSMatthias Ringwald 54*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS. 55*a8f7f3fcSMatthias Ringwald #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string 56*a8f7f3fcSMatthias Ringwald 57*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. 58*a8f7f3fcSMatthias Ringwald #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available 59*a8f7f3fcSMatthias Ringwald #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available 60*a8f7f3fcSMatthias Ringwald #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available 61*a8f7f3fcSMatthias Ringwald #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available 62*a8f7f3fcSMatthias Ringwald #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread 63*a8f7f3fcSMatthias Ringwald #define osFeature_Semaphore 30 ///< maximum count for \ref osSemaphoreCreate function 64*a8f7f3fcSMatthias Ringwald #define osFeature_Wait 1 ///< osWait function: 1=available, 0=not available 65*a8f7f3fcSMatthias Ringwald #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available 66*a8f7f3fcSMatthias Ringwald 67*a8f7f3fcSMatthias Ringwald #include <stdint.h> 68*a8f7f3fcSMatthias Ringwald #include <stddef.h> 69*a8f7f3fcSMatthias Ringwald 70*a8f7f3fcSMatthias Ringwald #ifdef __cplusplus 71*a8f7f3fcSMatthias Ringwald extern "C" 72*a8f7f3fcSMatthias Ringwald { 73*a8f7f3fcSMatthias Ringwald #endif 74*a8f7f3fcSMatthias Ringwald 75*a8f7f3fcSMatthias Ringwald 76*a8f7f3fcSMatthias Ringwald // ==== Enumeration, structures, defines ==== 77*a8f7f3fcSMatthias Ringwald 78*a8f7f3fcSMatthias Ringwald /// Priority used for thread control. 79*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS. 80*a8f7f3fcSMatthias Ringwald typedef enum { 81*a8f7f3fcSMatthias Ringwald osPriorityIdle = -3, ///< priority: idle (lowest) 82*a8f7f3fcSMatthias Ringwald osPriorityLow = -2, ///< priority: low 83*a8f7f3fcSMatthias Ringwald osPriorityBelowNormal = -1, ///< priority: below normal 84*a8f7f3fcSMatthias Ringwald osPriorityNormal = 0, ///< priority: normal (default) 85*a8f7f3fcSMatthias Ringwald osPriorityAboveNormal = +1, ///< priority: above normal 86*a8f7f3fcSMatthias Ringwald osPriorityHigh = +2, ///< priority: high 87*a8f7f3fcSMatthias Ringwald osPriorityRealtime = +3, ///< priority: realtime (highest) 88*a8f7f3fcSMatthias Ringwald osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority 89*a8f7f3fcSMatthias Ringwald } osPriority; 90*a8f7f3fcSMatthias Ringwald 91*a8f7f3fcSMatthias Ringwald /// Timeout value. 92*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS. 93*a8f7f3fcSMatthias Ringwald #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value 94*a8f7f3fcSMatthias Ringwald 95*a8f7f3fcSMatthias Ringwald /// Status code values returned by CMSIS-RTOS functions. 96*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS. 97*a8f7f3fcSMatthias Ringwald typedef enum { 98*a8f7f3fcSMatthias Ringwald osOK = 0, ///< function completed; no error or event occurred. 99*a8f7f3fcSMatthias Ringwald osEventSignal = 0x08, ///< function completed; signal event occurred. 100*a8f7f3fcSMatthias Ringwald osEventMessage = 0x10, ///< function completed; message event occurred. 101*a8f7f3fcSMatthias Ringwald osEventMail = 0x20, ///< function completed; mail event occurred. 102*a8f7f3fcSMatthias Ringwald osEventTimeout = 0x40, ///< function completed; timeout occurred. 103*a8f7f3fcSMatthias Ringwald osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. 104*a8f7f3fcSMatthias Ringwald osErrorResource = 0x81, ///< resource not available: a specified resource was not available. 105*a8f7f3fcSMatthias Ringwald osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. 106*a8f7f3fcSMatthias Ringwald osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. 107*a8f7f3fcSMatthias Ringwald osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. 108*a8f7f3fcSMatthias Ringwald osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. 109*a8f7f3fcSMatthias Ringwald osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. 110*a8f7f3fcSMatthias Ringwald osErrorValue = 0x86, ///< value of a parameter is out of range. 111*a8f7f3fcSMatthias Ringwald osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. 112*a8f7f3fcSMatthias Ringwald os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. 113*a8f7f3fcSMatthias Ringwald } osStatus; 114*a8f7f3fcSMatthias Ringwald 115*a8f7f3fcSMatthias Ringwald 116*a8f7f3fcSMatthias Ringwald /// Timer type value for the timer definition. 117*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS. 118*a8f7f3fcSMatthias Ringwald typedef enum { 119*a8f7f3fcSMatthias Ringwald osTimerOnce = 0, ///< one-shot timer 120*a8f7f3fcSMatthias Ringwald osTimerPeriodic = 1 ///< repeating timer 121*a8f7f3fcSMatthias Ringwald } os_timer_type; 122*a8f7f3fcSMatthias Ringwald 123*a8f7f3fcSMatthias Ringwald /// Entry point of a thread. 124*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS. 125*a8f7f3fcSMatthias Ringwald typedef void (*os_pthread) (void const *argument); 126*a8f7f3fcSMatthias Ringwald 127*a8f7f3fcSMatthias Ringwald /// Entry point of a timer call back function. 128*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS. 129*a8f7f3fcSMatthias Ringwald typedef void (*os_ptimer) (void const *argument); 130*a8f7f3fcSMatthias Ringwald 131*a8f7f3fcSMatthias Ringwald // >>> the following data type definitions may shall adapted towards a specific RTOS 132*a8f7f3fcSMatthias Ringwald 133*a8f7f3fcSMatthias Ringwald /// Thread ID identifies the thread (pointer to a thread control block). 134*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS. 135*a8f7f3fcSMatthias Ringwald typedef struct os_thread_cb *osThreadId; 136*a8f7f3fcSMatthias Ringwald 137*a8f7f3fcSMatthias Ringwald /// Timer ID identifies the timer (pointer to a timer control block). 138*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS. 139*a8f7f3fcSMatthias Ringwald typedef struct os_timer_cb *osTimerId; 140*a8f7f3fcSMatthias Ringwald 141*a8f7f3fcSMatthias Ringwald /// Mutex ID identifies the mutex (pointer to a mutex control block). 142*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS. 143*a8f7f3fcSMatthias Ringwald typedef struct os_mutex_cb *osMutexId; 144*a8f7f3fcSMatthias Ringwald 145*a8f7f3fcSMatthias Ringwald /// Semaphore ID identifies the semaphore (pointer to a semaphore control block). 146*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS. 147*a8f7f3fcSMatthias Ringwald typedef struct os_semaphore_cb *osSemaphoreId; 148*a8f7f3fcSMatthias Ringwald 149*a8f7f3fcSMatthias Ringwald /// Pool ID identifies the memory pool (pointer to a memory pool control block). 150*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. 151*a8f7f3fcSMatthias Ringwald typedef struct os_pool_cb *osPoolId; 152*a8f7f3fcSMatthias Ringwald 153*a8f7f3fcSMatthias Ringwald /// Message ID identifies the message queue (pointer to a message queue control block). 154*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. 155*a8f7f3fcSMatthias Ringwald typedef struct os_messageQ_cb *osMessageQId; 156*a8f7f3fcSMatthias Ringwald 157*a8f7f3fcSMatthias Ringwald /// Mail ID identifies the mail queue (pointer to a mail queue control block). 158*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS. 159*a8f7f3fcSMatthias Ringwald typedef struct os_mailQ_cb *osMailQId; 160*a8f7f3fcSMatthias Ringwald 161*a8f7f3fcSMatthias Ringwald 162*a8f7f3fcSMatthias Ringwald /// Thread Definition structure contains startup information of a thread. 163*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. 164*a8f7f3fcSMatthias Ringwald typedef struct os_thread_def { 165*a8f7f3fcSMatthias Ringwald os_pthread pthread; ///< start address of thread function 166*a8f7f3fcSMatthias Ringwald osPriority tpriority; ///< initial thread priority 167*a8f7f3fcSMatthias Ringwald uint32_t instances; ///< maximum number of instances of that thread function 168*a8f7f3fcSMatthias Ringwald uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size 169*a8f7f3fcSMatthias Ringwald } osThreadDef_t; 170*a8f7f3fcSMatthias Ringwald 171*a8f7f3fcSMatthias Ringwald /// Timer Definition structure contains timer parameters. 172*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. 173*a8f7f3fcSMatthias Ringwald typedef struct os_timer_def { 174*a8f7f3fcSMatthias Ringwald os_ptimer ptimer; ///< start address of a timer function 175*a8f7f3fcSMatthias Ringwald } osTimerDef_t; 176*a8f7f3fcSMatthias Ringwald 177*a8f7f3fcSMatthias Ringwald /// Mutex Definition structure contains setup information for a mutex. 178*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. 179*a8f7f3fcSMatthias Ringwald typedef struct os_mutex_def { 180*a8f7f3fcSMatthias Ringwald uint32_t dummy; ///< dummy value. 181*a8f7f3fcSMatthias Ringwald } osMutexDef_t; 182*a8f7f3fcSMatthias Ringwald 183*a8f7f3fcSMatthias Ringwald /// Semaphore Definition structure contains setup information for a semaphore. 184*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. 185*a8f7f3fcSMatthias Ringwald typedef struct os_semaphore_def { 186*a8f7f3fcSMatthias Ringwald uint32_t dummy; ///< dummy value. 187*a8f7f3fcSMatthias Ringwald } osSemaphoreDef_t; 188*a8f7f3fcSMatthias Ringwald 189*a8f7f3fcSMatthias Ringwald /// Definition structure for memory block allocation. 190*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. 191*a8f7f3fcSMatthias Ringwald typedef struct os_pool_def { 192*a8f7f3fcSMatthias Ringwald uint32_t pool_sz; ///< number of items (elements) in the pool 193*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 194*a8f7f3fcSMatthias Ringwald void *pool; ///< pointer to memory for pool 195*a8f7f3fcSMatthias Ringwald } osPoolDef_t; 196*a8f7f3fcSMatthias Ringwald 197*a8f7f3fcSMatthias Ringwald /// Definition structure for message queue. 198*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. 199*a8f7f3fcSMatthias Ringwald typedef struct os_messageQ_def { 200*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 201*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 202*a8f7f3fcSMatthias Ringwald void *pool; ///< memory array for messages 203*a8f7f3fcSMatthias Ringwald } osMessageQDef_t; 204*a8f7f3fcSMatthias Ringwald 205*a8f7f3fcSMatthias Ringwald /// Definition structure for mail queue. 206*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. 207*a8f7f3fcSMatthias Ringwald typedef struct os_mailQ_def { 208*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 209*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 210*a8f7f3fcSMatthias Ringwald void *pool; ///< memory array for mail 211*a8f7f3fcSMatthias Ringwald } osMailQDef_t; 212*a8f7f3fcSMatthias Ringwald 213*a8f7f3fcSMatthias Ringwald /// Event structure contains detailed information about an event. 214*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS. 215*a8f7f3fcSMatthias Ringwald /// However the struct may be extended at the end. 216*a8f7f3fcSMatthias Ringwald typedef struct { 217*a8f7f3fcSMatthias Ringwald osStatus status; ///< status code: event or error information 218*a8f7f3fcSMatthias Ringwald union { 219*a8f7f3fcSMatthias Ringwald uint32_t v; ///< message as 32-bit value 220*a8f7f3fcSMatthias Ringwald void *p; ///< message or mail as void pointer 221*a8f7f3fcSMatthias Ringwald int32_t signals; ///< signal flags 222*a8f7f3fcSMatthias Ringwald } value; ///< event value 223*a8f7f3fcSMatthias Ringwald union { 224*a8f7f3fcSMatthias Ringwald osMailQId mail_id; ///< mail id obtained by \ref osMailCreate 225*a8f7f3fcSMatthias Ringwald osMessageQId message_id; ///< message id obtained by \ref osMessageCreate 226*a8f7f3fcSMatthias Ringwald } def; ///< event definition 227*a8f7f3fcSMatthias Ringwald } osEvent; 228*a8f7f3fcSMatthias Ringwald 229*a8f7f3fcSMatthias Ringwald 230*a8f7f3fcSMatthias Ringwald // ==== Kernel Control Functions ==== 231*a8f7f3fcSMatthias Ringwald 232*a8f7f3fcSMatthias Ringwald /// Initialize the RTOS Kernel for creating objects. 233*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 234*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. 235*a8f7f3fcSMatthias Ringwald osStatus osKernelInitialize (void); 236*a8f7f3fcSMatthias Ringwald 237*a8f7f3fcSMatthias Ringwald /// Start the RTOS Kernel. 238*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 239*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. 240*a8f7f3fcSMatthias Ringwald osStatus osKernelStart (void); 241*a8f7f3fcSMatthias Ringwald 242*a8f7f3fcSMatthias Ringwald /// Check if the RTOS kernel is already started. 243*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. 244*a8f7f3fcSMatthias Ringwald /// \return 0 RTOS is not started, 1 RTOS is started. 245*a8f7f3fcSMatthias Ringwald int32_t osKernelRunning(void); 246*a8f7f3fcSMatthias Ringwald 247*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available 248*a8f7f3fcSMatthias Ringwald 249*a8f7f3fcSMatthias Ringwald /// Get the RTOS kernel system timer counter 250*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS. 251*a8f7f3fcSMatthias Ringwald /// \return RTOS kernel system timer as 32-bit value 252*a8f7f3fcSMatthias Ringwald uint32_t osKernelSysTick (void); 253*a8f7f3fcSMatthias Ringwald 254*a8f7f3fcSMatthias Ringwald /// The RTOS kernel system timer frequency in Hz 255*a8f7f3fcSMatthias Ringwald /// \note Reflects the system timer setting and is typically defined in a configuration file. 256*a8f7f3fcSMatthias Ringwald #define osKernelSysTickFrequency 100000000 257*a8f7f3fcSMatthias Ringwald 258*a8f7f3fcSMatthias Ringwald /// Convert a microseconds value to a RTOS kernel system timer value. 259*a8f7f3fcSMatthias Ringwald /// \param microsec time value in microseconds. 260*a8f7f3fcSMatthias Ringwald /// \return time value normalized to the \ref osKernelSysTickFrequency 261*a8f7f3fcSMatthias Ringwald #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) 262*a8f7f3fcSMatthias Ringwald 263*a8f7f3fcSMatthias Ringwald #endif // System Timer available 264*a8f7f3fcSMatthias Ringwald 265*a8f7f3fcSMatthias Ringwald // ==== Thread Management ==== 266*a8f7f3fcSMatthias Ringwald 267*a8f7f3fcSMatthias Ringwald /// Create a Thread Definition with function, priority, and stack requirements. 268*a8f7f3fcSMatthias Ringwald /// \param name name of the thread function. 269*a8f7f3fcSMatthias Ringwald /// \param priority initial priority of the thread function. 270*a8f7f3fcSMatthias Ringwald /// \param instances number of possible thread instances. 271*a8f7f3fcSMatthias Ringwald /// \param stacksz stack size (in bytes) requirements for the thread function. 272*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the 273*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 274*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 275*a8f7f3fcSMatthias Ringwald #define osThreadDef(name, priority, instances, stacksz) \ 276*a8f7f3fcSMatthias Ringwald extern const osThreadDef_t os_thread_def_##name 277*a8f7f3fcSMatthias Ringwald #else // define the object 278*a8f7f3fcSMatthias Ringwald #define osThreadDef(name, priority, instances, stacksz) \ 279*a8f7f3fcSMatthias Ringwald const osThreadDef_t os_thread_def_##name = \ 280*a8f7f3fcSMatthias Ringwald { (name), (priority), (instances), (stacksz) } 281*a8f7f3fcSMatthias Ringwald #endif 282*a8f7f3fcSMatthias Ringwald 283*a8f7f3fcSMatthias Ringwald /// Access a Thread definition. 284*a8f7f3fcSMatthias Ringwald /// \param name name of the thread definition object. 285*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the 286*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 287*a8f7f3fcSMatthias Ringwald #define osThread(name) \ 288*a8f7f3fcSMatthias Ringwald &os_thread_def_##name 289*a8f7f3fcSMatthias Ringwald 290*a8f7f3fcSMatthias Ringwald /// Create a thread and add it to Active Threads and set it to state READY. 291*a8f7f3fcSMatthias Ringwald /// \param[in] thread_def thread definition referenced with \ref osThread. 292*a8f7f3fcSMatthias Ringwald /// \param[in] argument pointer that is passed to the thread function as start argument. 293*a8f7f3fcSMatthias Ringwald /// \return thread ID for reference by other functions or NULL in case of error. 294*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. 295*a8f7f3fcSMatthias Ringwald osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); 296*a8f7f3fcSMatthias Ringwald 297*a8f7f3fcSMatthias Ringwald /// Return the thread ID of the current running thread. 298*a8f7f3fcSMatthias Ringwald /// \return thread ID for reference by other functions or NULL in case of error. 299*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. 300*a8f7f3fcSMatthias Ringwald osThreadId osThreadGetId (void); 301*a8f7f3fcSMatthias Ringwald 302*a8f7f3fcSMatthias Ringwald /// Terminate execution of a thread and remove it from Active Threads. 303*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 304*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 305*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. 306*a8f7f3fcSMatthias Ringwald osStatus osThreadTerminate (osThreadId thread_id); 307*a8f7f3fcSMatthias Ringwald 308*a8f7f3fcSMatthias Ringwald /// Pass control to next thread that is in state \b READY. 309*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 310*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. 311*a8f7f3fcSMatthias Ringwald osStatus osThreadYield (void); 312*a8f7f3fcSMatthias Ringwald 313*a8f7f3fcSMatthias Ringwald /// Change priority of an active thread. 314*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 315*a8f7f3fcSMatthias Ringwald /// \param[in] priority new priority value for the thread function. 316*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 317*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. 318*a8f7f3fcSMatthias Ringwald osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); 319*a8f7f3fcSMatthias Ringwald 320*a8f7f3fcSMatthias Ringwald /// Get current priority of an active thread. 321*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 322*a8f7f3fcSMatthias Ringwald /// \return current priority value of the thread function. 323*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. 324*a8f7f3fcSMatthias Ringwald osPriority osThreadGetPriority (osThreadId thread_id); 325*a8f7f3fcSMatthias Ringwald 326*a8f7f3fcSMatthias Ringwald 327*a8f7f3fcSMatthias Ringwald // ==== Generic Wait Functions ==== 328*a8f7f3fcSMatthias Ringwald 329*a8f7f3fcSMatthias Ringwald /// Wait for Timeout (Time Delay). 330*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value 331*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 332*a8f7f3fcSMatthias Ringwald osStatus osDelay (uint32_t millisec); 333*a8f7f3fcSMatthias Ringwald 334*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available 335*a8f7f3fcSMatthias Ringwald 336*a8f7f3fcSMatthias Ringwald /// Wait for Signal, Message, Mail, or Timeout. 337*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 338*a8f7f3fcSMatthias Ringwald /// \return event that contains signal, message, or mail information or error code. 339*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. 340*a8f7f3fcSMatthias Ringwald osEvent osWait (uint32_t millisec); 341*a8f7f3fcSMatthias Ringwald 342*a8f7f3fcSMatthias Ringwald #endif // Generic Wait available 343*a8f7f3fcSMatthias Ringwald 344*a8f7f3fcSMatthias Ringwald 345*a8f7f3fcSMatthias Ringwald // ==== Timer Management Functions ==== 346*a8f7f3fcSMatthias Ringwald /// Define a Timer object. 347*a8f7f3fcSMatthias Ringwald /// \param name name of the timer object. 348*a8f7f3fcSMatthias Ringwald /// \param function name of the timer call back function. 349*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the 350*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 351*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 352*a8f7f3fcSMatthias Ringwald #define osTimerDef(name, function) \ 353*a8f7f3fcSMatthias Ringwald extern const osTimerDef_t os_timer_def_##name 354*a8f7f3fcSMatthias Ringwald #else // define the object 355*a8f7f3fcSMatthias Ringwald #define osTimerDef(name, function) \ 356*a8f7f3fcSMatthias Ringwald const osTimerDef_t os_timer_def_##name = \ 357*a8f7f3fcSMatthias Ringwald { (function) } 358*a8f7f3fcSMatthias Ringwald #endif 359*a8f7f3fcSMatthias Ringwald 360*a8f7f3fcSMatthias Ringwald /// Access a Timer definition. 361*a8f7f3fcSMatthias Ringwald /// \param name name of the timer object. 362*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the 363*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 364*a8f7f3fcSMatthias Ringwald #define osTimer(name) \ 365*a8f7f3fcSMatthias Ringwald &os_timer_def_##name 366*a8f7f3fcSMatthias Ringwald 367*a8f7f3fcSMatthias Ringwald /// Create a timer. 368*a8f7f3fcSMatthias Ringwald /// \param[in] timer_def timer object referenced with \ref osTimer. 369*a8f7f3fcSMatthias Ringwald /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. 370*a8f7f3fcSMatthias Ringwald /// \param[in] argument argument to the timer call back function. 371*a8f7f3fcSMatthias Ringwald /// \return timer ID for reference by other functions or NULL in case of error. 372*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. 373*a8f7f3fcSMatthias Ringwald osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); 374*a8f7f3fcSMatthias Ringwald 375*a8f7f3fcSMatthias Ringwald /// Start or restart a timer. 376*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 377*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. 378*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 379*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. 380*a8f7f3fcSMatthias Ringwald osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); 381*a8f7f3fcSMatthias Ringwald 382*a8f7f3fcSMatthias Ringwald /// Stop the timer. 383*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 384*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 385*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. 386*a8f7f3fcSMatthias Ringwald osStatus osTimerStop (osTimerId timer_id); 387*a8f7f3fcSMatthias Ringwald 388*a8f7f3fcSMatthias Ringwald /// Delete a timer that was created by \ref osTimerCreate. 389*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 390*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 391*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. 392*a8f7f3fcSMatthias Ringwald osStatus osTimerDelete (osTimerId timer_id); 393*a8f7f3fcSMatthias Ringwald 394*a8f7f3fcSMatthias Ringwald 395*a8f7f3fcSMatthias Ringwald // ==== Signal Management ==== 396*a8f7f3fcSMatthias Ringwald 397*a8f7f3fcSMatthias Ringwald /// Set the specified Signal Flags of an active thread. 398*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 399*a8f7f3fcSMatthias Ringwald /// \param[in] signals specifies the signal flags of the thread that should be set. 400*a8f7f3fcSMatthias Ringwald /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 401*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. 402*a8f7f3fcSMatthias Ringwald int32_t osSignalSet (osThreadId thread_id, int32_t signals); 403*a8f7f3fcSMatthias Ringwald 404*a8f7f3fcSMatthias Ringwald /// Clear the specified Signal Flags of an active thread. 405*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 406*a8f7f3fcSMatthias Ringwald /// \param[in] signals specifies the signal flags of the thread that shall be cleared. 407*a8f7f3fcSMatthias Ringwald /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. 408*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. 409*a8f7f3fcSMatthias Ringwald int32_t osSignalClear (osThreadId thread_id, int32_t signals); 410*a8f7f3fcSMatthias Ringwald 411*a8f7f3fcSMatthias Ringwald /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. 412*a8f7f3fcSMatthias Ringwald /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. 413*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 414*a8f7f3fcSMatthias Ringwald /// \return event flag information or error code. 415*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. 416*a8f7f3fcSMatthias Ringwald osEvent osSignalWait (int32_t signals, uint32_t millisec); 417*a8f7f3fcSMatthias Ringwald 418*a8f7f3fcSMatthias Ringwald 419*a8f7f3fcSMatthias Ringwald // ==== Mutex Management ==== 420*a8f7f3fcSMatthias Ringwald 421*a8f7f3fcSMatthias Ringwald /// Define a Mutex. 422*a8f7f3fcSMatthias Ringwald /// \param name name of the mutex object. 423*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the 424*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 425*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 426*a8f7f3fcSMatthias Ringwald #define osMutexDef(name) \ 427*a8f7f3fcSMatthias Ringwald extern const osMutexDef_t os_mutex_def_##name 428*a8f7f3fcSMatthias Ringwald #else // define the object 429*a8f7f3fcSMatthias Ringwald #define osMutexDef(name) \ 430*a8f7f3fcSMatthias Ringwald const osMutexDef_t os_mutex_def_##name = { 0 } 431*a8f7f3fcSMatthias Ringwald #endif 432*a8f7f3fcSMatthias Ringwald 433*a8f7f3fcSMatthias Ringwald /// Access a Mutex definition. 434*a8f7f3fcSMatthias Ringwald /// \param name name of the mutex object. 435*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the 436*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 437*a8f7f3fcSMatthias Ringwald #define osMutex(name) \ 438*a8f7f3fcSMatthias Ringwald &os_mutex_def_##name 439*a8f7f3fcSMatthias Ringwald 440*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Mutex object. 441*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_def mutex definition referenced with \ref osMutex. 442*a8f7f3fcSMatthias Ringwald /// \return mutex ID for reference by other functions or NULL in case of error. 443*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. 444*a8f7f3fcSMatthias Ringwald osMutexId osMutexCreate (const osMutexDef_t *mutex_def); 445*a8f7f3fcSMatthias Ringwald 446*a8f7f3fcSMatthias Ringwald /// Wait until a Mutex becomes available. 447*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 448*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 449*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 450*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. 451*a8f7f3fcSMatthias Ringwald osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); 452*a8f7f3fcSMatthias Ringwald 453*a8f7f3fcSMatthias Ringwald /// Release a Mutex that was obtained by \ref osMutexWait. 454*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 455*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 456*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. 457*a8f7f3fcSMatthias Ringwald osStatus osMutexRelease (osMutexId mutex_id); 458*a8f7f3fcSMatthias Ringwald 459*a8f7f3fcSMatthias Ringwald /// Delete a Mutex that was created by \ref osMutexCreate. 460*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 461*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 462*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. 463*a8f7f3fcSMatthias Ringwald osStatus osMutexDelete (osMutexId mutex_id); 464*a8f7f3fcSMatthias Ringwald 465*a8f7f3fcSMatthias Ringwald 466*a8f7f3fcSMatthias Ringwald // ==== Semaphore Management Functions ==== 467*a8f7f3fcSMatthias Ringwald 468*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available 469*a8f7f3fcSMatthias Ringwald 470*a8f7f3fcSMatthias Ringwald /// Define a Semaphore object. 471*a8f7f3fcSMatthias Ringwald /// \param name name of the semaphore object. 472*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the 473*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 474*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 475*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef(name) \ 476*a8f7f3fcSMatthias Ringwald extern const osSemaphoreDef_t os_semaphore_def_##name 477*a8f7f3fcSMatthias Ringwald #else // define the object 478*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef(name) \ 479*a8f7f3fcSMatthias Ringwald const osSemaphoreDef_t os_semaphore_def_##name = { 0 } 480*a8f7f3fcSMatthias Ringwald #endif 481*a8f7f3fcSMatthias Ringwald 482*a8f7f3fcSMatthias Ringwald /// Access a Semaphore definition. 483*a8f7f3fcSMatthias Ringwald /// \param name name of the semaphore object. 484*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the 485*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 486*a8f7f3fcSMatthias Ringwald #define osSemaphore(name) \ 487*a8f7f3fcSMatthias Ringwald &os_semaphore_def_##name 488*a8f7f3fcSMatthias Ringwald 489*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Semaphore object used for managing resources. 490*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. 491*a8f7f3fcSMatthias Ringwald /// \param[in] count number of available resources. 492*a8f7f3fcSMatthias Ringwald /// \return semaphore ID for reference by other functions or NULL in case of error. 493*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. 494*a8f7f3fcSMatthias Ringwald osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); 495*a8f7f3fcSMatthias Ringwald 496*a8f7f3fcSMatthias Ringwald /// Wait until a Semaphore token becomes available. 497*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 498*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 499*a8f7f3fcSMatthias Ringwald /// \return number of available tokens, or -1 in case of incorrect parameters. 500*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. 501*a8f7f3fcSMatthias Ringwald int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); 502*a8f7f3fcSMatthias Ringwald 503*a8f7f3fcSMatthias Ringwald /// Release a Semaphore token. 504*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 505*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 506*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. 507*a8f7f3fcSMatthias Ringwald osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); 508*a8f7f3fcSMatthias Ringwald 509*a8f7f3fcSMatthias Ringwald /// Delete a Semaphore that was created by \ref osSemaphoreCreate. 510*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 511*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 512*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. 513*a8f7f3fcSMatthias Ringwald osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); 514*a8f7f3fcSMatthias Ringwald 515*a8f7f3fcSMatthias Ringwald #endif // Semaphore available 516*a8f7f3fcSMatthias Ringwald 517*a8f7f3fcSMatthias Ringwald 518*a8f7f3fcSMatthias Ringwald // ==== Memory Pool Management Functions ==== 519*a8f7f3fcSMatthias Ringwald 520*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available 521*a8f7f3fcSMatthias Ringwald 522*a8f7f3fcSMatthias Ringwald /// \brief Define a Memory Pool. 523*a8f7f3fcSMatthias Ringwald /// \param name name of the memory pool. 524*a8f7f3fcSMatthias Ringwald /// \param no maximum number of blocks (objects) in the memory pool. 525*a8f7f3fcSMatthias Ringwald /// \param type data type of a single block (object). 526*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the 527*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 528*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 529*a8f7f3fcSMatthias Ringwald #define osPoolDef(name, no, type) \ 530*a8f7f3fcSMatthias Ringwald extern const osPoolDef_t os_pool_def_##name 531*a8f7f3fcSMatthias Ringwald #else // define the object 532*a8f7f3fcSMatthias Ringwald #define osPoolDef(name, no, type) \ 533*a8f7f3fcSMatthias Ringwald const osPoolDef_t os_pool_def_##name = \ 534*a8f7f3fcSMatthias Ringwald { (no), sizeof(type), NULL } 535*a8f7f3fcSMatthias Ringwald #endif 536*a8f7f3fcSMatthias Ringwald 537*a8f7f3fcSMatthias Ringwald /// \brief Access a Memory Pool definition. 538*a8f7f3fcSMatthias Ringwald /// \param name name of the memory pool 539*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the 540*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 541*a8f7f3fcSMatthias Ringwald #define osPool(name) \ 542*a8f7f3fcSMatthias Ringwald &os_pool_def_##name 543*a8f7f3fcSMatthias Ringwald 544*a8f7f3fcSMatthias Ringwald /// Create and Initialize a memory pool. 545*a8f7f3fcSMatthias Ringwald /// \param[in] pool_def memory pool definition referenced with \ref osPool. 546*a8f7f3fcSMatthias Ringwald /// \return memory pool ID for reference by other functions or NULL in case of error. 547*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. 548*a8f7f3fcSMatthias Ringwald osPoolId osPoolCreate (const osPoolDef_t *pool_def); 549*a8f7f3fcSMatthias Ringwald 550*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a memory pool. 551*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 552*a8f7f3fcSMatthias Ringwald /// \return address of the allocated memory block or NULL in case of no memory available. 553*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. 554*a8f7f3fcSMatthias Ringwald void *osPoolAlloc (osPoolId pool_id); 555*a8f7f3fcSMatthias Ringwald 556*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a memory pool and set memory block to zero. 557*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 558*a8f7f3fcSMatthias Ringwald /// \return address of the allocated memory block or NULL in case of no memory available. 559*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. 560*a8f7f3fcSMatthias Ringwald void *osPoolCAlloc (osPoolId pool_id); 561*a8f7f3fcSMatthias Ringwald 562*a8f7f3fcSMatthias Ringwald /// Return an allocated memory block back to a specific memory pool. 563*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 564*a8f7f3fcSMatthias Ringwald /// \param[in] block address of the allocated memory block that is returned to the memory pool. 565*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 566*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. 567*a8f7f3fcSMatthias Ringwald osStatus osPoolFree (osPoolId pool_id, void *block); 568*a8f7f3fcSMatthias Ringwald 569*a8f7f3fcSMatthias Ringwald #endif // Memory Pool Management available 570*a8f7f3fcSMatthias Ringwald 571*a8f7f3fcSMatthias Ringwald 572*a8f7f3fcSMatthias Ringwald // ==== Message Queue Management Functions ==== 573*a8f7f3fcSMatthias Ringwald 574*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available 575*a8f7f3fcSMatthias Ringwald 576*a8f7f3fcSMatthias Ringwald /// \brief Create a Message Queue Definition. 577*a8f7f3fcSMatthias Ringwald /// \param name name of the queue. 578*a8f7f3fcSMatthias Ringwald /// \param queue_sz maximum number of messages in the queue. 579*a8f7f3fcSMatthias Ringwald /// \param type data type of a single message element (for debugger). 580*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the 581*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 582*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 583*a8f7f3fcSMatthias Ringwald #define osMessageQDef(name, queue_sz, type) \ 584*a8f7f3fcSMatthias Ringwald extern const osMessageQDef_t os_messageQ_def_##name 585*a8f7f3fcSMatthias Ringwald #else // define the object 586*a8f7f3fcSMatthias Ringwald #define osMessageQDef(name, queue_sz, type) \ 587*a8f7f3fcSMatthias Ringwald const osMessageQDef_t os_messageQ_def_##name = \ 588*a8f7f3fcSMatthias Ringwald { (queue_sz), sizeof (type) } 589*a8f7f3fcSMatthias Ringwald #endif 590*a8f7f3fcSMatthias Ringwald 591*a8f7f3fcSMatthias Ringwald /// \brief Access a Message Queue Definition. 592*a8f7f3fcSMatthias Ringwald /// \param name name of the queue 593*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the 594*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 595*a8f7f3fcSMatthias Ringwald #define osMessageQ(name) \ 596*a8f7f3fcSMatthias Ringwald &os_messageQ_def_##name 597*a8f7f3fcSMatthias Ringwald 598*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Message Queue. 599*a8f7f3fcSMatthias Ringwald /// \param[in] queue_def queue definition referenced with \ref osMessageQ. 600*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 601*a8f7f3fcSMatthias Ringwald /// \return message queue ID for reference by other functions or NULL in case of error. 602*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. 603*a8f7f3fcSMatthias Ringwald osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); 604*a8f7f3fcSMatthias Ringwald 605*a8f7f3fcSMatthias Ringwald /// Put a Message to a Queue. 606*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 607*a8f7f3fcSMatthias Ringwald /// \param[in] info message information. 608*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 609*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 610*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. 611*a8f7f3fcSMatthias Ringwald osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); 612*a8f7f3fcSMatthias Ringwald 613*a8f7f3fcSMatthias Ringwald /// Get a Message or Wait for a Message from a Queue. 614*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 615*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 616*a8f7f3fcSMatthias Ringwald /// \return event information that includes status code. 617*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. 618*a8f7f3fcSMatthias Ringwald osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); 619*a8f7f3fcSMatthias Ringwald 620*a8f7f3fcSMatthias Ringwald #endif // Message Queues available 621*a8f7f3fcSMatthias Ringwald 622*a8f7f3fcSMatthias Ringwald 623*a8f7f3fcSMatthias Ringwald // ==== Mail Queue Management Functions ==== 624*a8f7f3fcSMatthias Ringwald 625*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available 626*a8f7f3fcSMatthias Ringwald 627*a8f7f3fcSMatthias Ringwald /// \brief Create a Mail Queue Definition. 628*a8f7f3fcSMatthias Ringwald /// \param name name of the queue 629*a8f7f3fcSMatthias Ringwald /// \param queue_sz maximum number of messages in queue 630*a8f7f3fcSMatthias Ringwald /// \param type data type of a single message element 631*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the 632*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 633*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 634*a8f7f3fcSMatthias Ringwald #define osMailQDef(name, queue_sz, type) \ 635*a8f7f3fcSMatthias Ringwald extern const osMailQDef_t os_mailQ_def_##name 636*a8f7f3fcSMatthias Ringwald #else // define the object 637*a8f7f3fcSMatthias Ringwald #define osMailQDef(name, queue_sz, type) \ 638*a8f7f3fcSMatthias Ringwald const osMailQDef_t os_mailQ_def_##name = \ 639*a8f7f3fcSMatthias Ringwald { (queue_sz), sizeof (type) } 640*a8f7f3fcSMatthias Ringwald #endif 641*a8f7f3fcSMatthias Ringwald 642*a8f7f3fcSMatthias Ringwald /// \brief Access a Mail Queue Definition. 643*a8f7f3fcSMatthias Ringwald /// \param name name of the queue 644*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the 645*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 646*a8f7f3fcSMatthias Ringwald #define osMailQ(name) \ 647*a8f7f3fcSMatthias Ringwald &os_mailQ_def_##name 648*a8f7f3fcSMatthias Ringwald 649*a8f7f3fcSMatthias Ringwald /// Create and Initialize mail queue. 650*a8f7f3fcSMatthias Ringwald /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ 651*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 652*a8f7f3fcSMatthias Ringwald /// \return mail queue ID for reference by other functions or NULL in case of error. 653*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. 654*a8f7f3fcSMatthias Ringwald osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); 655*a8f7f3fcSMatthias Ringwald 656*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a mail. 657*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 658*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 659*a8f7f3fcSMatthias Ringwald /// \return pointer to memory block that can be filled with mail or NULL in case of error. 660*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. 661*a8f7f3fcSMatthias Ringwald void *osMailAlloc (osMailQId queue_id, uint32_t millisec); 662*a8f7f3fcSMatthias Ringwald 663*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a mail and set memory block to zero. 664*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 665*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 666*a8f7f3fcSMatthias Ringwald /// \return pointer to memory block that can be filled with mail or NULL in case of error. 667*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. 668*a8f7f3fcSMatthias Ringwald void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); 669*a8f7f3fcSMatthias Ringwald 670*a8f7f3fcSMatthias Ringwald /// Put a mail to a queue. 671*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 672*a8f7f3fcSMatthias Ringwald /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. 673*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 674*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. 675*a8f7f3fcSMatthias Ringwald osStatus osMailPut (osMailQId queue_id, void *mail); 676*a8f7f3fcSMatthias Ringwald 677*a8f7f3fcSMatthias Ringwald /// Get a mail from a queue. 678*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 679*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 680*a8f7f3fcSMatthias Ringwald /// \return event that contains mail information or error code. 681*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. 682*a8f7f3fcSMatthias Ringwald osEvent osMailGet (osMailQId queue_id, uint32_t millisec); 683*a8f7f3fcSMatthias Ringwald 684*a8f7f3fcSMatthias Ringwald /// Free a memory block from a mail. 685*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 686*a8f7f3fcSMatthias Ringwald /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet. 687*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 688*a8f7f3fcSMatthias Ringwald /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. 689*a8f7f3fcSMatthias Ringwald osStatus osMailFree (osMailQId queue_id, void *mail); 690*a8f7f3fcSMatthias Ringwald 691*a8f7f3fcSMatthias Ringwald #endif // Mail Queues available 692*a8f7f3fcSMatthias Ringwald 693*a8f7f3fcSMatthias Ringwald 694*a8f7f3fcSMatthias Ringwald #ifdef __cplusplus 695*a8f7f3fcSMatthias Ringwald } 696*a8f7f3fcSMatthias Ringwald #endif 697*a8f7f3fcSMatthias Ringwald 698*a8f7f3fcSMatthias Ringwald #endif // _CMSIS_OS_H 699