1*a8f7f3fcSMatthias Ringwald /* 2*a8f7f3fcSMatthias Ringwald * Copyright (c) 2013-2018 Arm Limited. All rights reserved. 3*a8f7f3fcSMatthias Ringwald * 4*a8f7f3fcSMatthias Ringwald * SPDX-License-Identifier: Apache-2.0 5*a8f7f3fcSMatthias Ringwald * 6*a8f7f3fcSMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the License); you may 7*a8f7f3fcSMatthias Ringwald * not use this file except in compliance with the License. 8*a8f7f3fcSMatthias Ringwald * You may obtain a copy of the License at 9*a8f7f3fcSMatthias Ringwald * 10*a8f7f3fcSMatthias Ringwald * www.apache.org/licenses/LICENSE-2.0 11*a8f7f3fcSMatthias Ringwald * 12*a8f7f3fcSMatthias Ringwald * Unless required by applicable law or agreed to in writing, software 13*a8f7f3fcSMatthias Ringwald * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14*a8f7f3fcSMatthias Ringwald * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15*a8f7f3fcSMatthias Ringwald * See the License for the specific language governing permissions and 16*a8f7f3fcSMatthias Ringwald * limitations under the License. 17*a8f7f3fcSMatthias Ringwald * 18*a8f7f3fcSMatthias Ringwald * ---------------------------------------------------------------------- 19*a8f7f3fcSMatthias Ringwald * 20*a8f7f3fcSMatthias Ringwald * $Date: 18. June 2018 21*a8f7f3fcSMatthias Ringwald * $Revision: V2.1.3 22*a8f7f3fcSMatthias Ringwald * 23*a8f7f3fcSMatthias Ringwald * Project: CMSIS-RTOS API 24*a8f7f3fcSMatthias Ringwald * Title: cmsis_os.h template header file 25*a8f7f3fcSMatthias Ringwald * 26*a8f7f3fcSMatthias Ringwald * Version 0.02 27*a8f7f3fcSMatthias Ringwald * Initial Proposal Phase 28*a8f7f3fcSMatthias Ringwald * Version 0.03 29*a8f7f3fcSMatthias Ringwald * osKernelStart added, optional feature: main started as thread 30*a8f7f3fcSMatthias Ringwald * osSemaphores have standard behavior 31*a8f7f3fcSMatthias Ringwald * osTimerCreate does not start the timer, added osTimerStart 32*a8f7f3fcSMatthias Ringwald * osThreadPass is renamed to osThreadYield 33*a8f7f3fcSMatthias Ringwald * Version 1.01 34*a8f7f3fcSMatthias Ringwald * Support for C++ interface 35*a8f7f3fcSMatthias Ringwald * - const attribute removed from the osXxxxDef_t typedefs 36*a8f7f3fcSMatthias Ringwald * - const attribute added to the osXxxxDef macros 37*a8f7f3fcSMatthias Ringwald * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete 38*a8f7f3fcSMatthias Ringwald * Added: osKernelInitialize 39*a8f7f3fcSMatthias Ringwald * Version 1.02 40*a8f7f3fcSMatthias Ringwald * Control functions for short timeouts in microsecond resolution: 41*a8f7f3fcSMatthias Ringwald * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec 42*a8f7f3fcSMatthias Ringwald * Removed: osSignalGet 43*a8f7f3fcSMatthias Ringwald * Version 2.0.0 44*a8f7f3fcSMatthias Ringwald * OS objects creation without macros (dynamic creation and resource allocation): 45*a8f7f3fcSMatthias Ringwald * - added: osXxxxNew functions which replace osXxxxCreate 46*a8f7f3fcSMatthias Ringwald * - added: osXxxxAttr_t structures 47*a8f7f3fcSMatthias Ringwald * - deprecated: osXxxxCreate functions, osXxxxDef_t structures 48*a8f7f3fcSMatthias Ringwald * - deprecated: osXxxxDef and osXxxx macros 49*a8f7f3fcSMatthias Ringwald * osStatus codes simplified and renamed to osStatus_t 50*a8f7f3fcSMatthias Ringwald * osEvent return structure deprecated 51*a8f7f3fcSMatthias Ringwald * Kernel: 52*a8f7f3fcSMatthias Ringwald * - added: osKernelInfo_t and osKernelGetInfo 53*a8f7f3fcSMatthias Ringwald * - added: osKernelState_t and osKernelGetState (replaces osKernelRunning) 54*a8f7f3fcSMatthias Ringwald * - added: osKernelLock, osKernelUnlock 55*a8f7f3fcSMatthias Ringwald * - added: osKernelSuspend, osKernelResume 56*a8f7f3fcSMatthias Ringwald * - added: osKernelGetTickCount, osKernelGetTickFreq 57*a8f7f3fcSMatthias Ringwald * - renamed osKernelSysTick to osKernelGetSysTimerCount 58*a8f7f3fcSMatthias Ringwald * - replaced osKernelSysTickFrequency with osKernelGetSysTimerFreq 59*a8f7f3fcSMatthias Ringwald * - deprecated osKernelSysTickMicroSec 60*a8f7f3fcSMatthias Ringwald * Thread: 61*a8f7f3fcSMatthias Ringwald * - extended number of thread priorities 62*a8f7f3fcSMatthias Ringwald * - renamed osPrioriry to osPrioriry_t 63*a8f7f3fcSMatthias Ringwald * - replaced osThreadCreate with osThreadNew 64*a8f7f3fcSMatthias Ringwald * - added: osThreadGetName 65*a8f7f3fcSMatthias Ringwald * - added: osThreadState_t and osThreadGetState 66*a8f7f3fcSMatthias Ringwald * - added: osThreadGetStackSize, osThreadGetStackSpace 67*a8f7f3fcSMatthias Ringwald * - added: osThreadSuspend, osThreadResume 68*a8f7f3fcSMatthias Ringwald * - added: osThreadJoin, osThreadDetach, osThreadExit 69*a8f7f3fcSMatthias Ringwald * - added: osThreadGetCount, osThreadEnumerate 70*a8f7f3fcSMatthias Ringwald * - added: Thread Flags (moved from Signals) 71*a8f7f3fcSMatthias Ringwald * Signals: 72*a8f7f3fcSMatthias Ringwald * - renamed osSignals to osThreadFlags (moved to Thread Flags) 73*a8f7f3fcSMatthias Ringwald * - changed return value of Set/Clear/Wait functions 74*a8f7f3fcSMatthias Ringwald * - Clear function limited to current running thread 75*a8f7f3fcSMatthias Ringwald * - extended Wait function (options) 76*a8f7f3fcSMatthias Ringwald * - added: osThreadFlagsGet 77*a8f7f3fcSMatthias Ringwald * Event Flags: 78*a8f7f3fcSMatthias Ringwald * - added new independent object for handling Event Flags 79*a8f7f3fcSMatthias Ringwald * Delay and Wait functions: 80*a8f7f3fcSMatthias Ringwald * - added: osDelayUntil 81*a8f7f3fcSMatthias Ringwald * - deprecated: osWait 82*a8f7f3fcSMatthias Ringwald * Timer: 83*a8f7f3fcSMatthias Ringwald * - replaced osTimerCreate with osTimerNew 84*a8f7f3fcSMatthias Ringwald * - added: osTimerGetName, osTimerIsRunning 85*a8f7f3fcSMatthias Ringwald * Mutex: 86*a8f7f3fcSMatthias Ringwald * - extended: attributes (Recursive, Priority Inherit, Robust) 87*a8f7f3fcSMatthias Ringwald * - replaced osMutexCreate with osMutexNew 88*a8f7f3fcSMatthias Ringwald * - renamed osMutexWait to osMutexAcquire 89*a8f7f3fcSMatthias Ringwald * - added: osMutexGetName, osMutexGetOwner 90*a8f7f3fcSMatthias Ringwald * Semaphore: 91*a8f7f3fcSMatthias Ringwald * - extended: maximum and initial token count 92*a8f7f3fcSMatthias Ringwald * - replaced osSemaphoreCreate with osSemaphoreNew 93*a8f7f3fcSMatthias Ringwald * - renamed osSemaphoreWait to osSemaphoreAcquire (changed return value) 94*a8f7f3fcSMatthias Ringwald * - added: osSemaphoreGetName, osSemaphoreGetCount 95*a8f7f3fcSMatthias Ringwald * Memory Pool: 96*a8f7f3fcSMatthias Ringwald * - using osMemoryPool prefix instead of osPool 97*a8f7f3fcSMatthias Ringwald * - replaced osPoolCreate with osMemoryPoolNew 98*a8f7f3fcSMatthias Ringwald * - extended osMemoryPoolAlloc (timeout) 99*a8f7f3fcSMatthias Ringwald * - added: osMemoryPoolGetName 100*a8f7f3fcSMatthias Ringwald * - added: osMemoryPoolGetCapacity, osMemoryPoolGetBlockSize 101*a8f7f3fcSMatthias Ringwald * - added: osMemoryPoolGetCount, osMemoryPoolGetSpace 102*a8f7f3fcSMatthias Ringwald * - added: osMemoryPoolDelete 103*a8f7f3fcSMatthias Ringwald * - deprecated: osPoolCAlloc 104*a8f7f3fcSMatthias Ringwald * Message Queue: 105*a8f7f3fcSMatthias Ringwald * - extended: fixed size message instead of a single 32-bit value 106*a8f7f3fcSMatthias Ringwald * - using osMessageQueue prefix instead of osMessage 107*a8f7f3fcSMatthias Ringwald * - replaced osMessageCreate with osMessageQueueNew 108*a8f7f3fcSMatthias Ringwald * - updated: osMessageQueuePut, osMessageQueueGet 109*a8f7f3fcSMatthias Ringwald * - added: osMessageQueueGetName 110*a8f7f3fcSMatthias Ringwald * - added: osMessageQueueGetCapacity, osMessageQueueGetMsgSize 111*a8f7f3fcSMatthias Ringwald * - added: osMessageQueueGetCount, osMessageQueueGetSpace 112*a8f7f3fcSMatthias Ringwald * - added: osMessageQueueReset, osMessageQueueDelete 113*a8f7f3fcSMatthias Ringwald * Mail Queue: 114*a8f7f3fcSMatthias Ringwald * - deprecated (superseded by extended Message Queue functionality) 115*a8f7f3fcSMatthias Ringwald * Version 2.1.0 116*a8f7f3fcSMatthias Ringwald * Support for critical and uncritical sections (nesting safe): 117*a8f7f3fcSMatthias Ringwald * - updated: osKernelLock, osKernelUnlock 118*a8f7f3fcSMatthias Ringwald * - added: osKernelRestoreLock 119*a8f7f3fcSMatthias Ringwald * Updated Thread and Event Flags: 120*a8f7f3fcSMatthias Ringwald * - changed flags parameter and return type from int32_t to uint32_t 121*a8f7f3fcSMatthias Ringwald * Version 2.1.1 122*a8f7f3fcSMatthias Ringwald * Additional functions allowed to be called from Interrupt Service Routines: 123*a8f7f3fcSMatthias Ringwald * - osKernelGetTickCount, osKernelGetTickFreq 124*a8f7f3fcSMatthias Ringwald * Changed Kernel Tick type to uint32_t: 125*a8f7f3fcSMatthias Ringwald * - updated: osKernelGetTickCount, osDelayUntil 126*a8f7f3fcSMatthias Ringwald * Version 2.1.2 127*a8f7f3fcSMatthias Ringwald * Additional functions allowed to be called from Interrupt Service Routines: 128*a8f7f3fcSMatthias Ringwald * - osKernelGetInfo, osKernelGetState 129*a8f7f3fcSMatthias Ringwald * Version 2.1.3 130*a8f7f3fcSMatthias Ringwald * Additional functions allowed to be called from Interrupt Service Routines: 131*a8f7f3fcSMatthias Ringwald * - osThreadGetId 132*a8f7f3fcSMatthias Ringwald *---------------------------------------------------------------------------*/ 133*a8f7f3fcSMatthias Ringwald 134*a8f7f3fcSMatthias Ringwald #ifndef CMSIS_OS_H_ 135*a8f7f3fcSMatthias Ringwald #define CMSIS_OS_H_ 136*a8f7f3fcSMatthias Ringwald 137*a8f7f3fcSMatthias Ringwald /// \b osCMSIS identifies the CMSIS-RTOS API version. 138*a8f7f3fcSMatthias Ringwald #define osCMSIS 0x20001U ///< API version (main[31:16].sub[15:0]) 139*a8f7f3fcSMatthias Ringwald 140*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. 141*a8f7f3fcSMatthias Ringwald #define osCMSIS_KERNEL 0x10000U ///< RTOS identification and version (main[31:16].sub[15:0]) 142*a8f7f3fcSMatthias Ringwald 143*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b osKernelSystemId identifies the underlying RTOS kernel. 144*a8f7f3fcSMatthias Ringwald #define osKernelSystemId "KERNEL V1.0" ///< RTOS identification string 145*a8f7f3fcSMatthias Ringwald 146*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b osFeature_xxx identifies RTOS features. 147*a8f7f3fcSMatthias Ringwald #define osFeature_MainThread 0 ///< main thread 1=main can be thread, 0=not available 148*a8f7f3fcSMatthias Ringwald #define osFeature_Signals 16U ///< maximum number of Signal Flags available per thread 149*a8f7f3fcSMatthias Ringwald #define osFeature_Semaphore 65535U ///< maximum count for \ref osSemaphoreCreate function 150*a8f7f3fcSMatthias Ringwald #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available 151*a8f7f3fcSMatthias Ringwald #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available 152*a8f7f3fcSMatthias Ringwald #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available 153*a8f7f3fcSMatthias Ringwald #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available 154*a8f7f3fcSMatthias Ringwald #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available 155*a8f7f3fcSMatthias Ringwald 156*a8f7f3fcSMatthias Ringwald #if (osCMSIS >= 0x20000U) 157*a8f7f3fcSMatthias Ringwald #include "cmsis_os2.h" 158*a8f7f3fcSMatthias Ringwald #else 159*a8f7f3fcSMatthias Ringwald #include <stdint.h> 160*a8f7f3fcSMatthias Ringwald #include <stddef.h> 161*a8f7f3fcSMatthias Ringwald #endif 162*a8f7f3fcSMatthias Ringwald 163*a8f7f3fcSMatthias Ringwald #ifdef __cplusplus 164*a8f7f3fcSMatthias Ringwald extern "C" 165*a8f7f3fcSMatthias Ringwald { 166*a8f7f3fcSMatthias Ringwald #endif 167*a8f7f3fcSMatthias Ringwald 168*a8f7f3fcSMatthias Ringwald 169*a8f7f3fcSMatthias Ringwald // ==== Enumerations, structures, defines ==== 170*a8f7f3fcSMatthias Ringwald 171*a8f7f3fcSMatthias Ringwald /// Priority values. 172*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 173*a8f7f3fcSMatthias Ringwald typedef enum { 174*a8f7f3fcSMatthias Ringwald osPriorityIdle = -3, ///< Priority: idle (lowest) 175*a8f7f3fcSMatthias Ringwald osPriorityLow = -2, ///< Priority: low 176*a8f7f3fcSMatthias Ringwald osPriorityBelowNormal = -1, ///< Priority: below normal 177*a8f7f3fcSMatthias Ringwald osPriorityNormal = 0, ///< Priority: normal (default) 178*a8f7f3fcSMatthias Ringwald osPriorityAboveNormal = +1, ///< Priority: above normal 179*a8f7f3fcSMatthias Ringwald osPriorityHigh = +2, ///< Priority: high 180*a8f7f3fcSMatthias Ringwald osPriorityRealtime = +3, ///< Priority: realtime (highest) 181*a8f7f3fcSMatthias Ringwald osPriorityError = 0x84, ///< System cannot determine priority or illegal priority. 182*a8f7f3fcSMatthias Ringwald osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. 183*a8f7f3fcSMatthias Ringwald } osPriority; 184*a8f7f3fcSMatthias Ringwald #else 185*a8f7f3fcSMatthias Ringwald #define osPriority osPriority_t 186*a8f7f3fcSMatthias Ringwald #endif 187*a8f7f3fcSMatthias Ringwald 188*a8f7f3fcSMatthias Ringwald /// Entry point of a thread. 189*a8f7f3fcSMatthias Ringwald typedef void (*os_pthread) (void const *argument); 190*a8f7f3fcSMatthias Ringwald 191*a8f7f3fcSMatthias Ringwald /// Entry point of a timer call back function. 192*a8f7f3fcSMatthias Ringwald typedef void (*os_ptimer) (void const *argument); 193*a8f7f3fcSMatthias Ringwald 194*a8f7f3fcSMatthias Ringwald /// Timer type. 195*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 196*a8f7f3fcSMatthias Ringwald typedef enum { 197*a8f7f3fcSMatthias Ringwald osTimerOnce = 0, ///< One-shot timer. 198*a8f7f3fcSMatthias Ringwald osTimerPeriodic = 1 ///< Repeating timer. 199*a8f7f3fcSMatthias Ringwald } os_timer_type; 200*a8f7f3fcSMatthias Ringwald #else 201*a8f7f3fcSMatthias Ringwald #define os_timer_type osTimerType_t 202*a8f7f3fcSMatthias Ringwald #endif 203*a8f7f3fcSMatthias Ringwald 204*a8f7f3fcSMatthias Ringwald /// Timeout value. 205*a8f7f3fcSMatthias Ringwald #define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. 206*a8f7f3fcSMatthias Ringwald 207*a8f7f3fcSMatthias Ringwald /// Status code values returned by CMSIS-RTOS functions. 208*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 209*a8f7f3fcSMatthias Ringwald typedef enum { 210*a8f7f3fcSMatthias Ringwald osOK = 0, ///< Function completed; no error or event occurred. 211*a8f7f3fcSMatthias Ringwald osEventSignal = 0x08, ///< Function completed; signal event occurred. 212*a8f7f3fcSMatthias Ringwald osEventMessage = 0x10, ///< Function completed; message event occurred. 213*a8f7f3fcSMatthias Ringwald osEventMail = 0x20, ///< Function completed; mail event occurred. 214*a8f7f3fcSMatthias Ringwald osEventTimeout = 0x40, ///< Function completed; timeout occurred. 215*a8f7f3fcSMatthias Ringwald osErrorParameter = 0x80, ///< Parameter error: a mandatory parameter was missing or specified an incorrect object. 216*a8f7f3fcSMatthias Ringwald osErrorResource = 0x81, ///< Resource not available: a specified resource was not available. 217*a8f7f3fcSMatthias Ringwald osErrorTimeoutResource = 0xC1, ///< Resource not available within given time: a specified resource was not available within the timeout period. 218*a8f7f3fcSMatthias Ringwald osErrorISR = 0x82, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. 219*a8f7f3fcSMatthias Ringwald osErrorISRRecursive = 0x83, ///< Function called multiple times from ISR with same object. 220*a8f7f3fcSMatthias Ringwald osErrorPriority = 0x84, ///< System cannot determine priority or thread has illegal priority. 221*a8f7f3fcSMatthias Ringwald osErrorNoMemory = 0x85, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. 222*a8f7f3fcSMatthias Ringwald osErrorValue = 0x86, ///< Value of a parameter is out of range. 223*a8f7f3fcSMatthias Ringwald osErrorOS = 0xFF, ///< Unspecified RTOS error: run-time error but no other error message fits. 224*a8f7f3fcSMatthias Ringwald osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. 225*a8f7f3fcSMatthias Ringwald } osStatus; 226*a8f7f3fcSMatthias Ringwald #else 227*a8f7f3fcSMatthias Ringwald typedef int32_t osStatus; 228*a8f7f3fcSMatthias Ringwald #define osEventSignal (0x08) 229*a8f7f3fcSMatthias Ringwald #define osEventMessage (0x10) 230*a8f7f3fcSMatthias Ringwald #define osEventMail (0x20) 231*a8f7f3fcSMatthias Ringwald #define osEventTimeout (0x40) 232*a8f7f3fcSMatthias Ringwald #define osErrorOS osError 233*a8f7f3fcSMatthias Ringwald #define osErrorTimeoutResource osErrorTimeout 234*a8f7f3fcSMatthias Ringwald #define osErrorISRRecursive (-126) 235*a8f7f3fcSMatthias Ringwald #define osErrorValue (-127) 236*a8f7f3fcSMatthias Ringwald #define osErrorPriority (-128) 237*a8f7f3fcSMatthias Ringwald #endif 238*a8f7f3fcSMatthias Ringwald 239*a8f7f3fcSMatthias Ringwald 240*a8f7f3fcSMatthias Ringwald // >>> the following data type definitions may be adapted towards a specific RTOS 241*a8f7f3fcSMatthias Ringwald 242*a8f7f3fcSMatthias Ringwald /// Thread ID identifies the thread. 243*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 244*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 245*a8f7f3fcSMatthias Ringwald typedef void *osThreadId; 246*a8f7f3fcSMatthias Ringwald #else 247*a8f7f3fcSMatthias Ringwald #define osThreadId osThreadId_t 248*a8f7f3fcSMatthias Ringwald #endif 249*a8f7f3fcSMatthias Ringwald 250*a8f7f3fcSMatthias Ringwald /// Timer ID identifies the timer. 251*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 252*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 253*a8f7f3fcSMatthias Ringwald typedef void *osTimerId; 254*a8f7f3fcSMatthias Ringwald #else 255*a8f7f3fcSMatthias Ringwald #define osTimerId osTimerId_t 256*a8f7f3fcSMatthias Ringwald #endif 257*a8f7f3fcSMatthias Ringwald 258*a8f7f3fcSMatthias Ringwald /// Mutex ID identifies the mutex. 259*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 260*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 261*a8f7f3fcSMatthias Ringwald typedef void *osMutexId; 262*a8f7f3fcSMatthias Ringwald #else 263*a8f7f3fcSMatthias Ringwald #define osMutexId osMutexId_t 264*a8f7f3fcSMatthias Ringwald #endif 265*a8f7f3fcSMatthias Ringwald 266*a8f7f3fcSMatthias Ringwald /// Semaphore ID identifies the semaphore. 267*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 268*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 269*a8f7f3fcSMatthias Ringwald typedef void *osSemaphoreId; 270*a8f7f3fcSMatthias Ringwald #else 271*a8f7f3fcSMatthias Ringwald #define osSemaphoreId osSemaphoreId_t 272*a8f7f3fcSMatthias Ringwald #endif 273*a8f7f3fcSMatthias Ringwald 274*a8f7f3fcSMatthias Ringwald /// Pool ID identifies the memory pool. 275*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 276*a8f7f3fcSMatthias Ringwald typedef void *osPoolId; 277*a8f7f3fcSMatthias Ringwald 278*a8f7f3fcSMatthias Ringwald /// Message ID identifies the message queue. 279*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 280*a8f7f3fcSMatthias Ringwald typedef void *osMessageQId; 281*a8f7f3fcSMatthias Ringwald 282*a8f7f3fcSMatthias Ringwald /// Mail ID identifies the mail queue. 283*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS. 284*a8f7f3fcSMatthias Ringwald typedef void *osMailQId; 285*a8f7f3fcSMatthias Ringwald 286*a8f7f3fcSMatthias Ringwald 287*a8f7f3fcSMatthias Ringwald /// Thread Definition structure contains startup information of a thread. 288*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. 289*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 290*a8f7f3fcSMatthias Ringwald typedef struct os_thread_def { 291*a8f7f3fcSMatthias Ringwald os_pthread pthread; ///< start address of thread function 292*a8f7f3fcSMatthias Ringwald osPriority tpriority; ///< initial thread priority 293*a8f7f3fcSMatthias Ringwald uint32_t instances; ///< maximum number of instances of that thread function 294*a8f7f3fcSMatthias Ringwald uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size 295*a8f7f3fcSMatthias Ringwald } osThreadDef_t; 296*a8f7f3fcSMatthias Ringwald #else 297*a8f7f3fcSMatthias Ringwald typedef struct os_thread_def { 298*a8f7f3fcSMatthias Ringwald os_pthread pthread; ///< start address of thread function 299*a8f7f3fcSMatthias Ringwald osThreadAttr_t attr; ///< thread attributes 300*a8f7f3fcSMatthias Ringwald } osThreadDef_t; 301*a8f7f3fcSMatthias Ringwald #endif 302*a8f7f3fcSMatthias Ringwald 303*a8f7f3fcSMatthias Ringwald /// Timer Definition structure contains timer parameters. 304*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. 305*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 306*a8f7f3fcSMatthias Ringwald typedef struct os_timer_def { 307*a8f7f3fcSMatthias Ringwald os_ptimer ptimer; ///< start address of a timer function 308*a8f7f3fcSMatthias Ringwald } osTimerDef_t; 309*a8f7f3fcSMatthias Ringwald #else 310*a8f7f3fcSMatthias Ringwald typedef struct os_timer_def { 311*a8f7f3fcSMatthias Ringwald os_ptimer ptimer; ///< start address of a timer function 312*a8f7f3fcSMatthias Ringwald osTimerAttr_t attr; ///< timer attributes 313*a8f7f3fcSMatthias Ringwald } osTimerDef_t; 314*a8f7f3fcSMatthias Ringwald #endif 315*a8f7f3fcSMatthias Ringwald 316*a8f7f3fcSMatthias Ringwald /// Mutex Definition structure contains setup information for a mutex. 317*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. 318*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 319*a8f7f3fcSMatthias Ringwald typedef struct os_mutex_def { 320*a8f7f3fcSMatthias Ringwald uint32_t dummy; ///< dummy value 321*a8f7f3fcSMatthias Ringwald } osMutexDef_t; 322*a8f7f3fcSMatthias Ringwald #else 323*a8f7f3fcSMatthias Ringwald #define osMutexDef_t osMutexAttr_t 324*a8f7f3fcSMatthias Ringwald #endif 325*a8f7f3fcSMatthias Ringwald 326*a8f7f3fcSMatthias Ringwald /// Semaphore Definition structure contains setup information for a semaphore. 327*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. 328*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 329*a8f7f3fcSMatthias Ringwald typedef struct os_semaphore_def { 330*a8f7f3fcSMatthias Ringwald uint32_t dummy; ///< dummy value 331*a8f7f3fcSMatthias Ringwald } osSemaphoreDef_t; 332*a8f7f3fcSMatthias Ringwald #else 333*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef_t osSemaphoreAttr_t 334*a8f7f3fcSMatthias Ringwald #endif 335*a8f7f3fcSMatthias Ringwald 336*a8f7f3fcSMatthias Ringwald /// Definition structure for memory block allocation. 337*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. 338*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 339*a8f7f3fcSMatthias Ringwald typedef struct os_pool_def { 340*a8f7f3fcSMatthias Ringwald uint32_t pool_sz; ///< number of items (elements) in the pool 341*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 342*a8f7f3fcSMatthias Ringwald void *pool; ///< pointer to memory for pool 343*a8f7f3fcSMatthias Ringwald } osPoolDef_t; 344*a8f7f3fcSMatthias Ringwald #else 345*a8f7f3fcSMatthias Ringwald typedef struct os_pool_def { 346*a8f7f3fcSMatthias Ringwald uint32_t pool_sz; ///< number of items (elements) in the pool 347*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 348*a8f7f3fcSMatthias Ringwald osMemoryPoolAttr_t attr; ///< memory pool attributes 349*a8f7f3fcSMatthias Ringwald } osPoolDef_t; 350*a8f7f3fcSMatthias Ringwald #endif 351*a8f7f3fcSMatthias Ringwald 352*a8f7f3fcSMatthias Ringwald /// Definition structure for message queue. 353*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. 354*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 355*a8f7f3fcSMatthias Ringwald typedef struct os_messageQ_def { 356*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 357*a8f7f3fcSMatthias Ringwald void *pool; ///< memory array for messages 358*a8f7f3fcSMatthias Ringwald } osMessageQDef_t; 359*a8f7f3fcSMatthias Ringwald #else 360*a8f7f3fcSMatthias Ringwald typedef struct os_messageQ_def { 361*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 362*a8f7f3fcSMatthias Ringwald osMessageQueueAttr_t attr; ///< message queue attributes 363*a8f7f3fcSMatthias Ringwald } osMessageQDef_t; 364*a8f7f3fcSMatthias Ringwald #endif 365*a8f7f3fcSMatthias Ringwald 366*a8f7f3fcSMatthias Ringwald /// Definition structure for mail queue. 367*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. 368*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 369*a8f7f3fcSMatthias Ringwald typedef struct os_mailQ_def { 370*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 371*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 372*a8f7f3fcSMatthias Ringwald void *pool; ///< memory array for mail 373*a8f7f3fcSMatthias Ringwald } osMailQDef_t; 374*a8f7f3fcSMatthias Ringwald #else 375*a8f7f3fcSMatthias Ringwald typedef struct os_mailQ_def { 376*a8f7f3fcSMatthias Ringwald uint32_t queue_sz; ///< number of elements in the queue 377*a8f7f3fcSMatthias Ringwald uint32_t item_sz; ///< size of an item 378*a8f7f3fcSMatthias Ringwald void *mail; ///< pointer to mail 379*a8f7f3fcSMatthias Ringwald osMemoryPoolAttr_t mp_attr; ///< memory pool attributes 380*a8f7f3fcSMatthias Ringwald osMessageQueueAttr_t mq_attr; ///< message queue attributes 381*a8f7f3fcSMatthias Ringwald } osMailQDef_t; 382*a8f7f3fcSMatthias Ringwald #endif 383*a8f7f3fcSMatthias Ringwald 384*a8f7f3fcSMatthias Ringwald 385*a8f7f3fcSMatthias Ringwald /// Event structure contains detailed information about an event. 386*a8f7f3fcSMatthias Ringwald typedef struct { 387*a8f7f3fcSMatthias Ringwald osStatus status; ///< status code: event or error information 388*a8f7f3fcSMatthias Ringwald union { 389*a8f7f3fcSMatthias Ringwald uint32_t v; ///< message as 32-bit value 390*a8f7f3fcSMatthias Ringwald void *p; ///< message or mail as void pointer 391*a8f7f3fcSMatthias Ringwald int32_t signals; ///< signal flags 392*a8f7f3fcSMatthias Ringwald } value; ///< event value 393*a8f7f3fcSMatthias Ringwald union { 394*a8f7f3fcSMatthias Ringwald osMailQId mail_id; ///< mail id obtained by \ref osMailCreate 395*a8f7f3fcSMatthias Ringwald osMessageQId message_id; ///< message id obtained by \ref osMessageCreate 396*a8f7f3fcSMatthias Ringwald } def; ///< event definition 397*a8f7f3fcSMatthias Ringwald } osEvent; 398*a8f7f3fcSMatthias Ringwald 399*a8f7f3fcSMatthias Ringwald 400*a8f7f3fcSMatthias Ringwald // ==== Kernel Management Functions ==== 401*a8f7f3fcSMatthias Ringwald 402*a8f7f3fcSMatthias Ringwald /// Initialize the RTOS Kernel for creating objects. 403*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 404*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 405*a8f7f3fcSMatthias Ringwald osStatus osKernelInitialize (void); 406*a8f7f3fcSMatthias Ringwald #endif 407*a8f7f3fcSMatthias Ringwald 408*a8f7f3fcSMatthias Ringwald /// Start the RTOS Kernel scheduler. 409*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 410*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 411*a8f7f3fcSMatthias Ringwald osStatus osKernelStart (void); 412*a8f7f3fcSMatthias Ringwald #endif 413*a8f7f3fcSMatthias Ringwald 414*a8f7f3fcSMatthias Ringwald /// Check if the RTOS kernel is already started. 415*a8f7f3fcSMatthias Ringwald /// \return 0 RTOS is not started, 1 RTOS is started. 416*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 417*a8f7f3fcSMatthias Ringwald int32_t osKernelRunning(void); 418*a8f7f3fcSMatthias Ringwald #endif 419*a8f7f3fcSMatthias Ringwald 420*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available 421*a8f7f3fcSMatthias Ringwald 422*a8f7f3fcSMatthias Ringwald /// Get the RTOS kernel system timer counter. 423*a8f7f3fcSMatthias Ringwald /// \return RTOS kernel system timer as 32-bit value 424*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 425*a8f7f3fcSMatthias Ringwald uint32_t osKernelSysTick (void); 426*a8f7f3fcSMatthias Ringwald #else 427*a8f7f3fcSMatthias Ringwald #define osKernelSysTick osKernelGetSysTimerCount 428*a8f7f3fcSMatthias Ringwald #endif 429*a8f7f3fcSMatthias Ringwald 430*a8f7f3fcSMatthias Ringwald /// The RTOS kernel system timer frequency in Hz. 431*a8f7f3fcSMatthias Ringwald /// \note Reflects the system timer setting and is typically defined in a configuration file. 432*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 433*a8f7f3fcSMatthias Ringwald #define osKernelSysTickFrequency 100000000 434*a8f7f3fcSMatthias Ringwald #endif 435*a8f7f3fcSMatthias Ringwald 436*a8f7f3fcSMatthias Ringwald /// Convert a microseconds value to a RTOS kernel system timer value. 437*a8f7f3fcSMatthias Ringwald /// \param microsec time value in microseconds. 438*a8f7f3fcSMatthias Ringwald /// \return time value normalized to the \ref osKernelSysTickFrequency 439*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 440*a8f7f3fcSMatthias Ringwald #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) 441*a8f7f3fcSMatthias Ringwald #else 442*a8f7f3fcSMatthias Ringwald #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * osKernelGetSysTimerFreq()) / 1000000) 443*a8f7f3fcSMatthias Ringwald #endif 444*a8f7f3fcSMatthias Ringwald 445*a8f7f3fcSMatthias Ringwald #endif // System Timer available 446*a8f7f3fcSMatthias Ringwald 447*a8f7f3fcSMatthias Ringwald 448*a8f7f3fcSMatthias Ringwald // ==== Thread Management Functions ==== 449*a8f7f3fcSMatthias Ringwald 450*a8f7f3fcSMatthias Ringwald /// Create a Thread Definition with function, priority, and stack requirements. 451*a8f7f3fcSMatthias Ringwald /// \param name name of the thread function. 452*a8f7f3fcSMatthias Ringwald /// \param priority initial priority of the thread function. 453*a8f7f3fcSMatthias Ringwald /// \param instances number of possible thread instances. 454*a8f7f3fcSMatthias Ringwald /// \param stacksz stack size (in bytes) requirements for the thread function. 455*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the 456*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 457*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 458*a8f7f3fcSMatthias Ringwald #define osThreadDef(name, priority, instances, stacksz) \ 459*a8f7f3fcSMatthias Ringwald extern const osThreadDef_t os_thread_def_##name 460*a8f7f3fcSMatthias Ringwald #else // define the object 461*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 462*a8f7f3fcSMatthias Ringwald #define osThreadDef(name, priority, instances, stacksz) \ 463*a8f7f3fcSMatthias Ringwald const osThreadDef_t os_thread_def_##name = \ 464*a8f7f3fcSMatthias Ringwald { (name), (priority), (instances), (stacksz) } 465*a8f7f3fcSMatthias Ringwald #else 466*a8f7f3fcSMatthias Ringwald #define osThreadDef(name, priority, instances, stacksz) \ 467*a8f7f3fcSMatthias Ringwald const osThreadDef_t os_thread_def_##name = \ 468*a8f7f3fcSMatthias Ringwald { (name), \ 469*a8f7f3fcSMatthias Ringwald { NULL, osThreadDetached, NULL, 0U, NULL, 8*((stacksz+7)/8), (priority), 0U, 0U } } 470*a8f7f3fcSMatthias Ringwald #endif 471*a8f7f3fcSMatthias Ringwald #endif 472*a8f7f3fcSMatthias Ringwald 473*a8f7f3fcSMatthias Ringwald /// Access a Thread definition. 474*a8f7f3fcSMatthias Ringwald /// \param name name of the thread definition object. 475*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the 476*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 477*a8f7f3fcSMatthias Ringwald #define osThread(name) \ 478*a8f7f3fcSMatthias Ringwald &os_thread_def_##name 479*a8f7f3fcSMatthias Ringwald 480*a8f7f3fcSMatthias Ringwald /// Create a thread and add it to Active Threads and set it to state READY. 481*a8f7f3fcSMatthias Ringwald /// \param[in] thread_def thread definition referenced with \ref osThread. 482*a8f7f3fcSMatthias Ringwald /// \param[in] argument pointer that is passed to the thread function as start argument. 483*a8f7f3fcSMatthias Ringwald /// \return thread ID for reference by other functions or NULL in case of error. 484*a8f7f3fcSMatthias Ringwald osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); 485*a8f7f3fcSMatthias Ringwald 486*a8f7f3fcSMatthias Ringwald /// Return the thread ID of the current running thread. 487*a8f7f3fcSMatthias Ringwald /// \return thread ID for reference by other functions or NULL in case of error. 488*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 489*a8f7f3fcSMatthias Ringwald osThreadId osThreadGetId (void); 490*a8f7f3fcSMatthias Ringwald #endif 491*a8f7f3fcSMatthias Ringwald 492*a8f7f3fcSMatthias Ringwald /// Change priority of a thread. 493*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 494*a8f7f3fcSMatthias Ringwald /// \param[in] priority new priority value for the thread function. 495*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 496*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 497*a8f7f3fcSMatthias Ringwald osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); 498*a8f7f3fcSMatthias Ringwald #endif 499*a8f7f3fcSMatthias Ringwald 500*a8f7f3fcSMatthias Ringwald /// Get current priority of a thread. 501*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 502*a8f7f3fcSMatthias Ringwald /// \return current priority value of the specified thread. 503*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 504*a8f7f3fcSMatthias Ringwald osPriority osThreadGetPriority (osThreadId thread_id); 505*a8f7f3fcSMatthias Ringwald #endif 506*a8f7f3fcSMatthias Ringwald 507*a8f7f3fcSMatthias Ringwald /// Pass control to next thread that is in state \b READY. 508*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 509*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 510*a8f7f3fcSMatthias Ringwald osStatus osThreadYield (void); 511*a8f7f3fcSMatthias Ringwald #endif 512*a8f7f3fcSMatthias Ringwald 513*a8f7f3fcSMatthias Ringwald /// Terminate execution of a thread. 514*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 515*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 516*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 517*a8f7f3fcSMatthias Ringwald osStatus osThreadTerminate (osThreadId thread_id); 518*a8f7f3fcSMatthias Ringwald #endif 519*a8f7f3fcSMatthias Ringwald 520*a8f7f3fcSMatthias Ringwald 521*a8f7f3fcSMatthias Ringwald // ==== Signal Management ==== 522*a8f7f3fcSMatthias Ringwald 523*a8f7f3fcSMatthias Ringwald /// Set the specified Signal Flags of an active thread. 524*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 525*a8f7f3fcSMatthias Ringwald /// \param[in] signals specifies the signal flags of the thread that should be set. 526*a8f7f3fcSMatthias Ringwald /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 527*a8f7f3fcSMatthias Ringwald int32_t osSignalSet (osThreadId thread_id, int32_t signals); 528*a8f7f3fcSMatthias Ringwald 529*a8f7f3fcSMatthias Ringwald /// Clear the specified Signal Flags of an active thread. 530*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 531*a8f7f3fcSMatthias Ringwald /// \param[in] signals specifies the signal flags of the thread that shall be cleared. 532*a8f7f3fcSMatthias Ringwald /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. 533*a8f7f3fcSMatthias Ringwald int32_t osSignalClear (osThreadId thread_id, int32_t signals); 534*a8f7f3fcSMatthias Ringwald 535*a8f7f3fcSMatthias Ringwald /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. 536*a8f7f3fcSMatthias Ringwald /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. 537*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 538*a8f7f3fcSMatthias Ringwald /// \return event flag information or error code. 539*a8f7f3fcSMatthias Ringwald osEvent osSignalWait (int32_t signals, uint32_t millisec); 540*a8f7f3fcSMatthias Ringwald 541*a8f7f3fcSMatthias Ringwald 542*a8f7f3fcSMatthias Ringwald // ==== Generic Wait Functions ==== 543*a8f7f3fcSMatthias Ringwald 544*a8f7f3fcSMatthias Ringwald /// Wait for Timeout (Time Delay). 545*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value 546*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 547*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 548*a8f7f3fcSMatthias Ringwald osStatus osDelay (uint32_t millisec); 549*a8f7f3fcSMatthias Ringwald #endif 550*a8f7f3fcSMatthias Ringwald 551*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available 552*a8f7f3fcSMatthias Ringwald 553*a8f7f3fcSMatthias Ringwald /// Wait for Signal, Message, Mail, or Timeout. 554*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 555*a8f7f3fcSMatthias Ringwald /// \return event that contains signal, message, or mail information or error code. 556*a8f7f3fcSMatthias Ringwald osEvent osWait (uint32_t millisec); 557*a8f7f3fcSMatthias Ringwald 558*a8f7f3fcSMatthias Ringwald #endif // Generic Wait available 559*a8f7f3fcSMatthias Ringwald 560*a8f7f3fcSMatthias Ringwald 561*a8f7f3fcSMatthias Ringwald // ==== Timer Management Functions ==== 562*a8f7f3fcSMatthias Ringwald 563*a8f7f3fcSMatthias Ringwald /// Define a Timer object. 564*a8f7f3fcSMatthias Ringwald /// \param name name of the timer object. 565*a8f7f3fcSMatthias Ringwald /// \param function name of the timer call back function. 566*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the 567*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 568*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 569*a8f7f3fcSMatthias Ringwald #define osTimerDef(name, function) \ 570*a8f7f3fcSMatthias Ringwald extern const osTimerDef_t os_timer_def_##name 571*a8f7f3fcSMatthias Ringwald #else // define the object 572*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 573*a8f7f3fcSMatthias Ringwald #define osTimerDef(name, function) \ 574*a8f7f3fcSMatthias Ringwald const osTimerDef_t os_timer_def_##name = { (function) } 575*a8f7f3fcSMatthias Ringwald #else 576*a8f7f3fcSMatthias Ringwald #define osTimerDef(name, function) \ 577*a8f7f3fcSMatthias Ringwald const osTimerDef_t os_timer_def_##name = \ 578*a8f7f3fcSMatthias Ringwald { (function), { NULL, 0U, NULL, 0U } } 579*a8f7f3fcSMatthias Ringwald #endif 580*a8f7f3fcSMatthias Ringwald #endif 581*a8f7f3fcSMatthias Ringwald 582*a8f7f3fcSMatthias Ringwald /// Access a Timer definition. 583*a8f7f3fcSMatthias Ringwald /// \param name name of the timer object. 584*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the 585*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 586*a8f7f3fcSMatthias Ringwald #define osTimer(name) \ 587*a8f7f3fcSMatthias Ringwald &os_timer_def_##name 588*a8f7f3fcSMatthias Ringwald 589*a8f7f3fcSMatthias Ringwald /// Create and Initialize a timer. 590*a8f7f3fcSMatthias Ringwald /// \param[in] timer_def timer object referenced with \ref osTimer. 591*a8f7f3fcSMatthias Ringwald /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. 592*a8f7f3fcSMatthias Ringwald /// \param[in] argument argument to the timer call back function. 593*a8f7f3fcSMatthias Ringwald /// \return timer ID for reference by other functions or NULL in case of error. 594*a8f7f3fcSMatthias Ringwald osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); 595*a8f7f3fcSMatthias Ringwald 596*a8f7f3fcSMatthias Ringwald /// Start or restart a timer. 597*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 598*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. 599*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 600*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 601*a8f7f3fcSMatthias Ringwald osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); 602*a8f7f3fcSMatthias Ringwald #endif 603*a8f7f3fcSMatthias Ringwald 604*a8f7f3fcSMatthias Ringwald /// Stop a timer. 605*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 606*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 607*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 608*a8f7f3fcSMatthias Ringwald osStatus osTimerStop (osTimerId timer_id); 609*a8f7f3fcSMatthias Ringwald #endif 610*a8f7f3fcSMatthias Ringwald 611*a8f7f3fcSMatthias Ringwald /// Delete a timer. 612*a8f7f3fcSMatthias Ringwald /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 613*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 614*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 615*a8f7f3fcSMatthias Ringwald osStatus osTimerDelete (osTimerId timer_id); 616*a8f7f3fcSMatthias Ringwald #endif 617*a8f7f3fcSMatthias Ringwald 618*a8f7f3fcSMatthias Ringwald 619*a8f7f3fcSMatthias Ringwald // ==== Mutex Management Functions ==== 620*a8f7f3fcSMatthias Ringwald 621*a8f7f3fcSMatthias Ringwald /// Define a Mutex. 622*a8f7f3fcSMatthias Ringwald /// \param name name of the mutex object. 623*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the 624*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 625*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 626*a8f7f3fcSMatthias Ringwald #define osMutexDef(name) \ 627*a8f7f3fcSMatthias Ringwald extern const osMutexDef_t os_mutex_def_##name 628*a8f7f3fcSMatthias Ringwald #else // define the object 629*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 630*a8f7f3fcSMatthias Ringwald #define osMutexDef(name) \ 631*a8f7f3fcSMatthias Ringwald const osMutexDef_t os_mutex_def_##name = { 0 } 632*a8f7f3fcSMatthias Ringwald #else 633*a8f7f3fcSMatthias Ringwald #define osMutexDef(name) \ 634*a8f7f3fcSMatthias Ringwald const osMutexDef_t os_mutex_def_##name = \ 635*a8f7f3fcSMatthias Ringwald { NULL, osMutexRecursive | osMutexPrioInherit | osMutexRobust, NULL, 0U } 636*a8f7f3fcSMatthias Ringwald #endif 637*a8f7f3fcSMatthias Ringwald #endif 638*a8f7f3fcSMatthias Ringwald 639*a8f7f3fcSMatthias Ringwald /// Access a Mutex definition. 640*a8f7f3fcSMatthias Ringwald /// \param name name of the mutex object. 641*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the 642*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 643*a8f7f3fcSMatthias Ringwald #define osMutex(name) \ 644*a8f7f3fcSMatthias Ringwald &os_mutex_def_##name 645*a8f7f3fcSMatthias Ringwald 646*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Mutex object. 647*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_def mutex definition referenced with \ref osMutex. 648*a8f7f3fcSMatthias Ringwald /// \return mutex ID for reference by other functions or NULL in case of error. 649*a8f7f3fcSMatthias Ringwald osMutexId osMutexCreate (const osMutexDef_t *mutex_def); 650*a8f7f3fcSMatthias Ringwald 651*a8f7f3fcSMatthias Ringwald /// Wait until a Mutex becomes available. 652*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 653*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 654*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 655*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 656*a8f7f3fcSMatthias Ringwald osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); 657*a8f7f3fcSMatthias Ringwald #else 658*a8f7f3fcSMatthias Ringwald #define osMutexWait osMutexAcquire 659*a8f7f3fcSMatthias Ringwald #endif 660*a8f7f3fcSMatthias Ringwald 661*a8f7f3fcSMatthias Ringwald /// Release a Mutex that was obtained by \ref osMutexWait. 662*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 663*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 664*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 665*a8f7f3fcSMatthias Ringwald osStatus osMutexRelease (osMutexId mutex_id); 666*a8f7f3fcSMatthias Ringwald #endif 667*a8f7f3fcSMatthias Ringwald 668*a8f7f3fcSMatthias Ringwald /// Delete a Mutex object. 669*a8f7f3fcSMatthias Ringwald /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 670*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 671*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 672*a8f7f3fcSMatthias Ringwald osStatus osMutexDelete (osMutexId mutex_id); 673*a8f7f3fcSMatthias Ringwald #endif 674*a8f7f3fcSMatthias Ringwald 675*a8f7f3fcSMatthias Ringwald 676*a8f7f3fcSMatthias Ringwald // ==== Semaphore Management Functions ==== 677*a8f7f3fcSMatthias Ringwald 678*a8f7f3fcSMatthias Ringwald #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) // Semaphore available 679*a8f7f3fcSMatthias Ringwald 680*a8f7f3fcSMatthias Ringwald /// Define a Semaphore object. 681*a8f7f3fcSMatthias Ringwald /// \param name name of the semaphore object. 682*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the 683*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 684*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 685*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef(name) \ 686*a8f7f3fcSMatthias Ringwald extern const osSemaphoreDef_t os_semaphore_def_##name 687*a8f7f3fcSMatthias Ringwald #else // define the object 688*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 689*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef(name) \ 690*a8f7f3fcSMatthias Ringwald const osSemaphoreDef_t os_semaphore_def_##name = { 0 } 691*a8f7f3fcSMatthias Ringwald #else 692*a8f7f3fcSMatthias Ringwald #define osSemaphoreDef(name) \ 693*a8f7f3fcSMatthias Ringwald const osSemaphoreDef_t os_semaphore_def_##name = \ 694*a8f7f3fcSMatthias Ringwald { NULL, 0U, NULL, 0U } 695*a8f7f3fcSMatthias Ringwald #endif 696*a8f7f3fcSMatthias Ringwald #endif 697*a8f7f3fcSMatthias Ringwald 698*a8f7f3fcSMatthias Ringwald /// Access a Semaphore definition. 699*a8f7f3fcSMatthias Ringwald /// \param name name of the semaphore object. 700*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the 701*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 702*a8f7f3fcSMatthias Ringwald #define osSemaphore(name) \ 703*a8f7f3fcSMatthias Ringwald &os_semaphore_def_##name 704*a8f7f3fcSMatthias Ringwald 705*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Semaphore object. 706*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. 707*a8f7f3fcSMatthias Ringwald /// \param[in] count maximum and initial number of available tokens. 708*a8f7f3fcSMatthias Ringwald /// \return semaphore ID for reference by other functions or NULL in case of error. 709*a8f7f3fcSMatthias Ringwald osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); 710*a8f7f3fcSMatthias Ringwald 711*a8f7f3fcSMatthias Ringwald /// Wait until a Semaphore token becomes available. 712*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 713*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 714*a8f7f3fcSMatthias Ringwald /// \return number of available tokens, or -1 in case of incorrect parameters. 715*a8f7f3fcSMatthias Ringwald int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); 716*a8f7f3fcSMatthias Ringwald 717*a8f7f3fcSMatthias Ringwald /// Release a Semaphore token. 718*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 719*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 720*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 721*a8f7f3fcSMatthias Ringwald osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); 722*a8f7f3fcSMatthias Ringwald #endif 723*a8f7f3fcSMatthias Ringwald 724*a8f7f3fcSMatthias Ringwald /// Delete a Semaphore object. 725*a8f7f3fcSMatthias Ringwald /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. 726*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 727*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 728*a8f7f3fcSMatthias Ringwald osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); 729*a8f7f3fcSMatthias Ringwald #endif 730*a8f7f3fcSMatthias Ringwald 731*a8f7f3fcSMatthias Ringwald #endif // Semaphore available 732*a8f7f3fcSMatthias Ringwald 733*a8f7f3fcSMatthias Ringwald 734*a8f7f3fcSMatthias Ringwald // ==== Memory Pool Management Functions ==== 735*a8f7f3fcSMatthias Ringwald 736*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool available 737*a8f7f3fcSMatthias Ringwald 738*a8f7f3fcSMatthias Ringwald /// \brief Define a Memory Pool. 739*a8f7f3fcSMatthias Ringwald /// \param name name of the memory pool. 740*a8f7f3fcSMatthias Ringwald /// \param no maximum number of blocks (objects) in the memory pool. 741*a8f7f3fcSMatthias Ringwald /// \param type data type of a single block (object). 742*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the 743*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 744*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 745*a8f7f3fcSMatthias Ringwald #define osPoolDef(name, no, type) \ 746*a8f7f3fcSMatthias Ringwald extern const osPoolDef_t os_pool_def_##name 747*a8f7f3fcSMatthias Ringwald #else // define the object 748*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 749*a8f7f3fcSMatthias Ringwald #define osPoolDef(name, no, type) \ 750*a8f7f3fcSMatthias Ringwald const osPoolDef_t os_pool_def_##name = \ 751*a8f7f3fcSMatthias Ringwald { (no), sizeof(type), NULL } 752*a8f7f3fcSMatthias Ringwald #else 753*a8f7f3fcSMatthias Ringwald #define osPoolDef(name, no, type) \ 754*a8f7f3fcSMatthias Ringwald const osPoolDef_t os_pool_def_##name = \ 755*a8f7f3fcSMatthias Ringwald { (no), sizeof(type), { NULL, 0U, NULL, 0U, NULL, 0U } } 756*a8f7f3fcSMatthias Ringwald #endif 757*a8f7f3fcSMatthias Ringwald #endif 758*a8f7f3fcSMatthias Ringwald 759*a8f7f3fcSMatthias Ringwald /// \brief Access a Memory Pool definition. 760*a8f7f3fcSMatthias Ringwald /// \param name name of the memory pool 761*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the 762*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 763*a8f7f3fcSMatthias Ringwald #define osPool(name) \ 764*a8f7f3fcSMatthias Ringwald &os_pool_def_##name 765*a8f7f3fcSMatthias Ringwald 766*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Memory Pool object. 767*a8f7f3fcSMatthias Ringwald /// \param[in] pool_def memory pool definition referenced with \ref osPool. 768*a8f7f3fcSMatthias Ringwald /// \return memory pool ID for reference by other functions or NULL in case of error. 769*a8f7f3fcSMatthias Ringwald osPoolId osPoolCreate (const osPoolDef_t *pool_def); 770*a8f7f3fcSMatthias Ringwald 771*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a Memory Pool. 772*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 773*a8f7f3fcSMatthias Ringwald /// \return address of the allocated memory block or NULL in case of no memory available. 774*a8f7f3fcSMatthias Ringwald void *osPoolAlloc (osPoolId pool_id); 775*a8f7f3fcSMatthias Ringwald 776*a8f7f3fcSMatthias Ringwald /// Allocate a memory block from a Memory Pool and set memory block to zero. 777*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 778*a8f7f3fcSMatthias Ringwald /// \return address of the allocated memory block or NULL in case of no memory available. 779*a8f7f3fcSMatthias Ringwald void *osPoolCAlloc (osPoolId pool_id); 780*a8f7f3fcSMatthias Ringwald 781*a8f7f3fcSMatthias Ringwald /// Return an allocated memory block back to a Memory Pool. 782*a8f7f3fcSMatthias Ringwald /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 783*a8f7f3fcSMatthias Ringwald /// \param[in] block address of the allocated memory block to be returned to the memory pool. 784*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 785*a8f7f3fcSMatthias Ringwald osStatus osPoolFree (osPoolId pool_id, void *block); 786*a8f7f3fcSMatthias Ringwald 787*a8f7f3fcSMatthias Ringwald #endif // Memory Pool available 788*a8f7f3fcSMatthias Ringwald 789*a8f7f3fcSMatthias Ringwald 790*a8f7f3fcSMatthias Ringwald // ==== Message Queue Management Functions ==== 791*a8f7f3fcSMatthias Ringwald 792*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queue available 793*a8f7f3fcSMatthias Ringwald 794*a8f7f3fcSMatthias Ringwald /// \brief Create a Message Queue Definition. 795*a8f7f3fcSMatthias Ringwald /// \param name name of the queue. 796*a8f7f3fcSMatthias Ringwald /// \param queue_sz maximum number of messages in the queue. 797*a8f7f3fcSMatthias Ringwald /// \param type data type of a single message element (for debugger). 798*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the 799*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 800*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 801*a8f7f3fcSMatthias Ringwald #define osMessageQDef(name, queue_sz, type) \ 802*a8f7f3fcSMatthias Ringwald extern const osMessageQDef_t os_messageQ_def_##name 803*a8f7f3fcSMatthias Ringwald #else // define the object 804*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 805*a8f7f3fcSMatthias Ringwald #define osMessageQDef(name, queue_sz, type) \ 806*a8f7f3fcSMatthias Ringwald const osMessageQDef_t os_messageQ_def_##name = \ 807*a8f7f3fcSMatthias Ringwald { (queue_sz), NULL } 808*a8f7f3fcSMatthias Ringwald #else 809*a8f7f3fcSMatthias Ringwald #define osMessageQDef(name, queue_sz, type) \ 810*a8f7f3fcSMatthias Ringwald const osMessageQDef_t os_messageQ_def_##name = \ 811*a8f7f3fcSMatthias Ringwald { (queue_sz), { NULL, 0U, NULL, 0U, NULL, 0U } } 812*a8f7f3fcSMatthias Ringwald #endif 813*a8f7f3fcSMatthias Ringwald #endif 814*a8f7f3fcSMatthias Ringwald 815*a8f7f3fcSMatthias Ringwald /// \brief Access a Message Queue Definition. 816*a8f7f3fcSMatthias Ringwald /// \param name name of the queue 817*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the 818*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 819*a8f7f3fcSMatthias Ringwald #define osMessageQ(name) \ 820*a8f7f3fcSMatthias Ringwald &os_messageQ_def_##name 821*a8f7f3fcSMatthias Ringwald 822*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Message Queue object. 823*a8f7f3fcSMatthias Ringwald /// \param[in] queue_def message queue definition referenced with \ref osMessageQ. 824*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 825*a8f7f3fcSMatthias Ringwald /// \return message queue ID for reference by other functions or NULL in case of error. 826*a8f7f3fcSMatthias Ringwald osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); 827*a8f7f3fcSMatthias Ringwald 828*a8f7f3fcSMatthias Ringwald /// Put a Message to a Queue. 829*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 830*a8f7f3fcSMatthias Ringwald /// \param[in] info message information. 831*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 832*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 833*a8f7f3fcSMatthias Ringwald osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); 834*a8f7f3fcSMatthias Ringwald 835*a8f7f3fcSMatthias Ringwald /// Get a Message from a Queue or timeout if Queue is empty. 836*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 837*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 838*a8f7f3fcSMatthias Ringwald /// \return event information that includes status code. 839*a8f7f3fcSMatthias Ringwald osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); 840*a8f7f3fcSMatthias Ringwald 841*a8f7f3fcSMatthias Ringwald #endif // Message Queue available 842*a8f7f3fcSMatthias Ringwald 843*a8f7f3fcSMatthias Ringwald 844*a8f7f3fcSMatthias Ringwald // ==== Mail Queue Management Functions ==== 845*a8f7f3fcSMatthias Ringwald 846*a8f7f3fcSMatthias Ringwald #if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queue available 847*a8f7f3fcSMatthias Ringwald 848*a8f7f3fcSMatthias Ringwald /// \brief Create a Mail Queue Definition. 849*a8f7f3fcSMatthias Ringwald /// \param name name of the queue. 850*a8f7f3fcSMatthias Ringwald /// \param queue_sz maximum number of mails in the queue. 851*a8f7f3fcSMatthias Ringwald /// \param type data type of a single mail element. 852*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the 853*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 854*a8f7f3fcSMatthias Ringwald #if defined (osObjectsExternal) // object is external 855*a8f7f3fcSMatthias Ringwald #define osMailQDef(name, queue_sz, type) \ 856*a8f7f3fcSMatthias Ringwald extern const osMailQDef_t os_mailQ_def_##name 857*a8f7f3fcSMatthias Ringwald #else // define the object 858*a8f7f3fcSMatthias Ringwald #if (osCMSIS < 0x20000U) 859*a8f7f3fcSMatthias Ringwald #define osMailQDef(name, queue_sz, type) \ 860*a8f7f3fcSMatthias Ringwald const osMailQDef_t os_mailQ_def_##name = \ 861*a8f7f3fcSMatthias Ringwald { (queue_sz), sizeof(type), NULL } 862*a8f7f3fcSMatthias Ringwald #else 863*a8f7f3fcSMatthias Ringwald #define osMailQDef(name, queue_sz, type) \ 864*a8f7f3fcSMatthias Ringwald static void *os_mail_p_##name[2]; \ 865*a8f7f3fcSMatthias Ringwald const osMailQDef_t os_mailQ_def_##name = \ 866*a8f7f3fcSMatthias Ringwald { (queue_sz), sizeof(type), (&os_mail_p_##name), \ 867*a8f7f3fcSMatthias Ringwald { NULL, 0U, NULL, 0U, NULL, 0U }, \ 868*a8f7f3fcSMatthias Ringwald { NULL, 0U, NULL, 0U, NULL, 0U } } 869*a8f7f3fcSMatthias Ringwald #endif 870*a8f7f3fcSMatthias Ringwald #endif 871*a8f7f3fcSMatthias Ringwald 872*a8f7f3fcSMatthias Ringwald /// \brief Access a Mail Queue Definition. 873*a8f7f3fcSMatthias Ringwald /// \param name name of the queue 874*a8f7f3fcSMatthias Ringwald /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the 875*a8f7f3fcSMatthias Ringwald /// macro body is implementation specific in every CMSIS-RTOS. 876*a8f7f3fcSMatthias Ringwald #define osMailQ(name) \ 877*a8f7f3fcSMatthias Ringwald &os_mailQ_def_##name 878*a8f7f3fcSMatthias Ringwald 879*a8f7f3fcSMatthias Ringwald /// Create and Initialize a Mail Queue object. 880*a8f7f3fcSMatthias Ringwald /// \param[in] queue_def mail queue definition referenced with \ref osMailQ. 881*a8f7f3fcSMatthias Ringwald /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 882*a8f7f3fcSMatthias Ringwald /// \return mail queue ID for reference by other functions or NULL in case of error. 883*a8f7f3fcSMatthias Ringwald osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); 884*a8f7f3fcSMatthias Ringwald 885*a8f7f3fcSMatthias Ringwald /// Allocate a memory block for mail from a mail memory pool. 886*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 887*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 888*a8f7f3fcSMatthias Ringwald /// \return pointer to memory block that can be filled with mail or NULL in case of error. 889*a8f7f3fcSMatthias Ringwald void *osMailAlloc (osMailQId queue_id, uint32_t millisec); 890*a8f7f3fcSMatthias Ringwald 891*a8f7f3fcSMatthias Ringwald /// Allocate a memory block for mail from a mail memory pool and set memory block to zero. 892*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 893*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out 894*a8f7f3fcSMatthias Ringwald /// \return pointer to memory block that can be filled with mail or NULL in case of error. 895*a8f7f3fcSMatthias Ringwald void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); 896*a8f7f3fcSMatthias Ringwald 897*a8f7f3fcSMatthias Ringwald /// Put a Mail into a Queue. 898*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 899*a8f7f3fcSMatthias Ringwald /// \param[in] mail pointer to memory with mail to put into a queue. 900*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 901*a8f7f3fcSMatthias Ringwald osStatus osMailPut (osMailQId queue_id, const void *mail); 902*a8f7f3fcSMatthias Ringwald 903*a8f7f3fcSMatthias Ringwald /// Get a Mail from a Queue or timeout if Queue is empty. 904*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 905*a8f7f3fcSMatthias Ringwald /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. 906*a8f7f3fcSMatthias Ringwald /// \return event information that includes status code. 907*a8f7f3fcSMatthias Ringwald osEvent osMailGet (osMailQId queue_id, uint32_t millisec); 908*a8f7f3fcSMatthias Ringwald 909*a8f7f3fcSMatthias Ringwald /// Free a memory block by returning it to a mail memory pool. 910*a8f7f3fcSMatthias Ringwald /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 911*a8f7f3fcSMatthias Ringwald /// \param[in] mail pointer to memory block that was obtained with \ref osMailGet. 912*a8f7f3fcSMatthias Ringwald /// \return status code that indicates the execution status of the function. 913*a8f7f3fcSMatthias Ringwald osStatus osMailFree (osMailQId queue_id, void *mail); 914*a8f7f3fcSMatthias Ringwald 915*a8f7f3fcSMatthias Ringwald #endif // Mail Queue available 916*a8f7f3fcSMatthias Ringwald 917*a8f7f3fcSMatthias Ringwald 918*a8f7f3fcSMatthias Ringwald #ifdef __cplusplus 919*a8f7f3fcSMatthias Ringwald } 920*a8f7f3fcSMatthias Ringwald #endif 921*a8f7f3fcSMatthias Ringwald 922*a8f7f3fcSMatthias Ringwald #endif // CMSIS_OS_H_ 923