Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Committer:
mbed_official
Date:
Thu May 05 20:45:13 2016 +0100
Revision:
112:53ace74b190c
Parent:
59:28712e303960
Child:
114:031a41d65add
Synchronized with git revision 860fdd282b0dc3631a6c46b39442d4ab5343e534

Full URL: https://github.com/mbedmicro/mbed/commit/860fdd282b0dc3631a6c46b39442d4ab5343e534/

rtx update to v4.79

Who changed what in which revision?

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