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:
Thu Aug 18 14:38:56 2016 +0100
Revision:
120:4dc938e301cc
Parent:
119:19af2d39a542
Child:
123:58563e6cba1e
RTOS rev120

Compatible with the mbed library v124

Changes:
- Fix heap limit checking
- Fix set initial stack pointer K64F + stack pointer size
- Fix stack size for NRF51
- Turn on main thread stack check
- Use new deprecate macros

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