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:
Mon Jul 25 14:12:24 2016 +0100
Revision:
118:6635230e06ba
Parent:
114:031a41d65add
Child:
119:19af2d39a542
RTOS rev118

Compatible with the mbed library v122

Changes:
- warnings about duplicated CM symbols fix
- init sequence update - allows init array to be run prior kernel start
- RTOS with OS_TIMERS=0 fix for thread id
- Thread ctor is deprecated, use start() method
- main stack fix for IAR (set via linker script)
- add TCB context pointer
- provide thread safety for toolchains (std lib locks)
- add MBED_RTOS_SINGLE_THREAD macro (sets TSKCNT to 1 and TIMERS to 0)
- nrf51, nucleo l423kc, nucleo f767zi, nucleo f446ze, efm32 support addition
- add OSObserver function

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