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:
Kojto
Date:
Tue Jul 04 13:32:20 2017 +0100
Revision:
125:5713cbbdb706
Parent:
123:58563e6cba1e
replace mbed_rtx by mbed_rtx4

Not causing a conflict with mbed_rtx that is for newer rtos

Who changed what in which revision?

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