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

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

Deprecated

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

Committer:
mbed_official
Date:
Wed Nov 26 08:00:25 2014 +0000
Revision:
53:c35dab33c427
Parent:
49:77c8e4604045
Child:
59:28712e303960
Synchronized with git revision c3208fe6f480055643b5911ca19a9028da3054a9

Full URL: https://github.com/mbedmicro/mbed/commit/c3208fe6f480055643b5911ca19a9028da3054a9/

RTOS: IAR Export for CORTEX M3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 49:77c8e4604045 1 /* ----------------------------------------------------------------------
mbed_official 49:77c8e4604045 2 * Copyright (C) 2012 ARM Limited. All rights reserved.
mbed_official 49:77c8e4604045 3 *
mbed_official 49:77c8e4604045 4 * $Date: 5. June 2012
mbed_official 49:77c8e4604045 5 * $Revision: V1.01
mbed_official 49:77c8e4604045 6 *
mbed_official 49:77c8e4604045 7 * Project: CMSIS-RTOS API
mbed_official 49:77c8e4604045 8 * Title: cmsis_os.h RTX header file
mbed_official 49:77c8e4604045 9 *
mbed_official 49:77c8e4604045 10 * Version 0.02
mbed_official 49:77c8e4604045 11 * Initial Proposal Phase
mbed_official 49:77c8e4604045 12 * Version 0.03
mbed_official 49:77c8e4604045 13 * osKernelStart added, optional feature: main started as thread
mbed_official 49:77c8e4604045 14 * osSemaphores have standard behavior
mbed_official 49:77c8e4604045 15 * osTimerCreate does not start the timer, added osTimerStart
mbed_official 49:77c8e4604045 16 * osThreadPass is renamed to osThreadYield
mbed_official 49:77c8e4604045 17 * Version 1.01
mbed_official 49:77c8e4604045 18 * Support for C++ interface
mbed_official 49:77c8e4604045 19 * - const attribute removed from the osXxxxDef_t typedef's
mbed_official 49:77c8e4604045 20 * - const attribute added to the osXxxxDef macros
mbed_official 49:77c8e4604045 21 * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
mbed_official 49:77c8e4604045 22 * Added: osKernelInitialize
mbed_official 49:77c8e4604045 23 * -------------------------------------------------------------------- */
mbed_official 49:77c8e4604045 24
mbed_official 49:77c8e4604045 25 /**
mbed_official 49:77c8e4604045 26 \page cmsis_os_h Header File Template: cmsis_os.h
mbed_official 49:77c8e4604045 27
mbed_official 49:77c8e4604045 28 The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS).
mbed_official 49:77c8e4604045 29 Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents
mbed_official 49:77c8e4604045 30 its implementation.
mbed_official 49:77c8e4604045 31
mbed_official 49:77c8e4604045 32 The file cmsis_os.h contains:
mbed_official 49:77c8e4604045 33 - CMSIS-RTOS API function definitions
mbed_official 49:77c8e4604045 34 - struct definitions for parameters and return types
mbed_official 49:77c8e4604045 35 - status and priority values used by CMSIS-RTOS API functions
mbed_official 49:77c8e4604045 36 - macros for defining threads and other kernel objects
mbed_official 49:77c8e4604045 37
mbed_official 49:77c8e4604045 38
mbed_official 49:77c8e4604045 39 <b>Name conventions and header file modifications</b>
mbed_official 49:77c8e4604045 40
mbed_official 49:77c8e4604045 41 All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions.
mbed_official 49:77c8e4604045 42 Definitions that are prefixed \b os_ are not used in the application code but local to this header file.
mbed_official 49:77c8e4604045 43 All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread.
mbed_official 49:77c8e4604045 44
mbed_official 49:77c8e4604045 45 Definitions that are marked with <b>CAN BE CHANGED</b> can be adapted towards the needs of the actual CMSIS-RTOS implementation.
mbed_official 49:77c8e4604045 46 These definitions can be specific to the underlying RTOS kernel.
mbed_official 49:77c8e4604045 47
mbed_official 49:77c8e4604045 48 Definitions that are marked with <b>MUST REMAIN UNCHANGED</b> cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer
mbed_official 49:77c8e4604045 49 compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation.
mbed_official 49:77c8e4604045 50
mbed_official 49:77c8e4604045 51
mbed_official 49:77c8e4604045 52 <b>Function calls from interrupt service routines</b>
mbed_official 49:77c8e4604045 53
mbed_official 49:77c8e4604045 54 The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR):
mbed_official 49:77c8e4604045 55 - \ref osSignalSet
mbed_official 49:77c8e4604045 56 - \ref osSemaphoreRelease
mbed_official 49:77c8e4604045 57 - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree
mbed_official 49:77c8e4604045 58 - \ref osMessagePut, \ref osMessageGet
mbed_official 49:77c8e4604045 59 - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree
mbed_official 49:77c8e4604045 60
mbed_official 49:77c8e4604045 61 Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called
mbed_official 49:77c8e4604045 62 from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector.
mbed_official 49:77c8e4604045 63
mbed_official 49:77c8e4604045 64 Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time.
mbed_official 49:77c8e4604045 65 If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive.
mbed_official 49:77c8e4604045 66
mbed_official 49:77c8e4604045 67
mbed_official 49:77c8e4604045 68 <b>Define and reference object definitions</b>
mbed_official 49:77c8e4604045 69
mbed_official 49:77c8e4604045 70 With <b>\#define osObjectsExternal</b> objects are defined as external symbols. This allows to create a consistent header file
mbed_official 49:77c8e4604045 71 that is used throughout a project as shown below:
mbed_official 49:77c8e4604045 72
mbed_official 49:77c8e4604045 73 <i>Header File</i>
mbed_official 49:77c8e4604045 74 \code
mbed_official 49:77c8e4604045 75 #include <cmsis_os.h> // CMSIS RTOS header file
mbed_official 49:77c8e4604045 76
mbed_official 49:77c8e4604045 77 // Thread definition
mbed_official 49:77c8e4604045 78 extern void thread_sample (void const *argument); // function prototype
mbed_official 49:77c8e4604045 79 osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100);
mbed_official 49:77c8e4604045 80
mbed_official 49:77c8e4604045 81 // Pool definition
mbed_official 49:77c8e4604045 82 osPoolDef(MyPool, 10, long);
mbed_official 49:77c8e4604045 83 \endcode
mbed_official 49:77c8e4604045 84
mbed_official 49:77c8e4604045 85
mbed_official 49:77c8e4604045 86 This header file defines all objects when included in a C/C++ source file. When <b>\#define osObjectsExternal</b> is
mbed_official 49:77c8e4604045 87 present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be
mbed_official 49:77c8e4604045 88 used throughout the whole project.
mbed_official 49:77c8e4604045 89
mbed_official 49:77c8e4604045 90 <i>Example</i>
mbed_official 49:77c8e4604045 91 \code
mbed_official 49:77c8e4604045 92 #include "osObjects.h" // Definition of the CMSIS-RTOS objects
mbed_official 49:77c8e4604045 93 \endcode
mbed_official 49:77c8e4604045 94
mbed_official 49:77c8e4604045 95 \code
mbed_official 49:77c8e4604045 96 #define osObjectExternal // Objects will be defined as external symbols
mbed_official 49:77c8e4604045 97 #include "osObjects.h" // Reference to the CMSIS-RTOS objects
mbed_official 49:77c8e4604045 98 \endcode
mbed_official 49:77c8e4604045 99
mbed_official 49:77c8e4604045 100 */
mbed_official 49:77c8e4604045 101
mbed_official 49:77c8e4604045 102 #ifndef _CMSIS_OS_H
mbed_official 49:77c8e4604045 103 #define _CMSIS_OS_H
mbed_official 49:77c8e4604045 104
mbed_official 49:77c8e4604045 105 /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version.
mbed_official 49:77c8e4604045 106 #define osCMSIS 0x10001 ///< API version (main [31:16] .sub [15:0])
mbed_official 49:77c8e4604045 107
mbed_official 49:77c8e4604045 108 /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
mbed_official 49:77c8e4604045 109 #define osCMSIS_RTX ((4<<16)|61) ///< RTOS identification and version (main [31:16] .sub [15:0])
mbed_official 49:77c8e4604045 110
mbed_official 49:77c8e4604045 111 /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 112 #define osKernelSystemId "RTX V4.61" ///< RTOS identification string
mbed_official 49:77c8e4604045 113
mbed_official 49:77c8e4604045 114
mbed_official 49:77c8e4604045 115 #define CMSIS_OS_RTX
mbed_official 49:77c8e4604045 116
mbed_official 49:77c8e4604045 117 // The stack space occupied is mainly dependent on the underling C standard library
mbed_official 53:c35dab33c427 118 #if defined(TOOLCHAIN_GCC) || defined(TOOLCHAIN_ARM_STD) || defined(TOOLCHAIN_IAR)
mbed_official 49:77c8e4604045 119 # define WORDS_STACK_SIZE 512
mbed_official 49:77c8e4604045 120 #elif defined(TOOLCHAIN_ARM_MICRO)
mbed_official 49:77c8e4604045 121 # define WORDS_STACK_SIZE 128
mbed_official 49:77c8e4604045 122 #endif
mbed_official 49:77c8e4604045 123
mbed_official 49:77c8e4604045 124 #define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
mbed_official 49:77c8e4604045 125
mbed_official 49:77c8e4604045 126
mbed_official 49:77c8e4604045 127 /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 128 #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
mbed_official 49:77c8e4604045 129 #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available
mbed_official 49:77c8e4604045 130 #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available
mbed_official 49:77c8e4604045 131 #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
mbed_official 49:77c8e4604045 132 #define osFeature_Signals 16 ///< maximum number of Signal Flags available per thread
mbed_official 49:77c8e4604045 133 #define osFeature_Semaphore 65535 ///< maximum count for \ref osSemaphoreCreate function
mbed_official 49:77c8e4604045 134 #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available
mbed_official 49:77c8e4604045 135
mbed_official 49:77c8e4604045 136 #if defined (__CC_ARM)
mbed_official 49:77c8e4604045 137 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers
mbed_official 53:c35dab33c427 138 #elif defined (__ICCARM__)
mbed_official 53:c35dab33c427 139 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers
mbed_official 49:77c8e4604045 140 #else
mbed_official 49:77c8e4604045 141 #define os_InRegs
mbed_official 49:77c8e4604045 142 #endif
mbed_official 49:77c8e4604045 143
mbed_official 49:77c8e4604045 144 #include <stdint.h>
mbed_official 49:77c8e4604045 145 #include <stddef.h>
mbed_official 49:77c8e4604045 146
mbed_official 49:77c8e4604045 147 #ifdef __cplusplus
mbed_official 49:77c8e4604045 148 extern "C"
mbed_official 49:77c8e4604045 149 {
mbed_official 49:77c8e4604045 150 #endif
mbed_official 49:77c8e4604045 151
mbed_official 49:77c8e4604045 152 #include "os_tcb.h"
mbed_official 49:77c8e4604045 153
mbed_official 49:77c8e4604045 154 // ==== Enumeration, structures, defines ====
mbed_official 49:77c8e4604045 155
mbed_official 49:77c8e4604045 156 /// Priority used for thread control.
mbed_official 49:77c8e4604045 157 /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 158 typedef enum {
mbed_official 49:77c8e4604045 159 osPriorityIdle = -3, ///< priority: idle (lowest)
mbed_official 49:77c8e4604045 160 osPriorityLow = -2, ///< priority: low
mbed_official 49:77c8e4604045 161 osPriorityBelowNormal = -1, ///< priority: below normal
mbed_official 49:77c8e4604045 162 osPriorityNormal = 0, ///< priority: normal (default)
mbed_official 49:77c8e4604045 163 osPriorityAboveNormal = +1, ///< priority: above normal
mbed_official 49:77c8e4604045 164 osPriorityHigh = +2, ///< priority: high
mbed_official 49:77c8e4604045 165 osPriorityRealtime = +3, ///< priority: realtime (highest)
mbed_official 49:77c8e4604045 166 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
mbed_official 49:77c8e4604045 167 } osPriority;
mbed_official 49:77c8e4604045 168
mbed_official 49:77c8e4604045 169 /// Timeout value.
mbed_official 49:77c8e4604045 170 /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 171 #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
mbed_official 49:77c8e4604045 172
mbed_official 49:77c8e4604045 173 /// Status code values returned by CMSIS-RTOS functions.
mbed_official 49:77c8e4604045 174 /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 175 typedef enum {
mbed_official 49:77c8e4604045 176 osOK = 0, ///< function completed; no error or event occurred.
mbed_official 49:77c8e4604045 177 osEventSignal = 0x08, ///< function completed; signal event occurred.
mbed_official 49:77c8e4604045 178 osEventMessage = 0x10, ///< function completed; message event occurred.
mbed_official 49:77c8e4604045 179 osEventMail = 0x20, ///< function completed; mail event occurred.
mbed_official 49:77c8e4604045 180 osEventTimeout = 0x40, ///< function completed; timeout occurred.
mbed_official 49:77c8e4604045 181 osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
mbed_official 49:77c8e4604045 182 osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
mbed_official 49:77c8e4604045 183 osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
mbed_official 49:77c8e4604045 184 osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
mbed_official 49:77c8e4604045 185 osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
mbed_official 49:77c8e4604045 186 osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
mbed_official 49:77c8e4604045 187 osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
mbed_official 49:77c8e4604045 188 osErrorValue = 0x86, ///< value of a parameter is out of range.
mbed_official 49:77c8e4604045 189 osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
mbed_official 49:77c8e4604045 190 os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
mbed_official 49:77c8e4604045 191 } osStatus;
mbed_official 49:77c8e4604045 192
mbed_official 49:77c8e4604045 193
mbed_official 49:77c8e4604045 194 /// Timer type value for the timer definition.
mbed_official 49:77c8e4604045 195 /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 196 typedef enum {
mbed_official 49:77c8e4604045 197 osTimerOnce = 0, ///< one-shot timer
mbed_official 49:77c8e4604045 198 osTimerPeriodic = 1 ///< repeating timer
mbed_official 49:77c8e4604045 199 } os_timer_type;
mbed_official 49:77c8e4604045 200
mbed_official 49:77c8e4604045 201 /// Entry point of a thread.
mbed_official 49:77c8e4604045 202 /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 203 typedef void (*os_pthread) (void const *argument);
mbed_official 49:77c8e4604045 204
mbed_official 49:77c8e4604045 205 /// Entry point of a timer call back function.
mbed_official 49:77c8e4604045 206 /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 207 typedef void (*os_ptimer) (void const *argument);
mbed_official 49:77c8e4604045 208
mbed_official 49:77c8e4604045 209 // >>> the following data type definitions may shall adapted towards a specific RTOS
mbed_official 49:77c8e4604045 210
mbed_official 49:77c8e4604045 211 /// Thread ID identifies the thread (pointer to a thread control block).
mbed_official 49:77c8e4604045 212 /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 213 typedef struct os_thread_cb *osThreadId;
mbed_official 49:77c8e4604045 214
mbed_official 49:77c8e4604045 215 /// Timer ID identifies the timer (pointer to a timer control block).
mbed_official 49:77c8e4604045 216 /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 217 typedef struct os_timer_cb *osTimerId;
mbed_official 49:77c8e4604045 218
mbed_official 49:77c8e4604045 219 /// Mutex ID identifies the mutex (pointer to a mutex control block).
mbed_official 49:77c8e4604045 220 /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 221 typedef struct os_mutex_cb *osMutexId;
mbed_official 49:77c8e4604045 222
mbed_official 49:77c8e4604045 223 /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
mbed_official 49:77c8e4604045 224 /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 225 typedef struct os_semaphore_cb *osSemaphoreId;
mbed_official 49:77c8e4604045 226
mbed_official 49:77c8e4604045 227 /// Pool ID identifies the memory pool (pointer to a memory pool control block).
mbed_official 49:77c8e4604045 228 /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 229 typedef struct os_pool_cb *osPoolId;
mbed_official 49:77c8e4604045 230
mbed_official 49:77c8e4604045 231 /// Message ID identifies the message queue (pointer to a message queue control block).
mbed_official 49:77c8e4604045 232 /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 233 typedef struct os_messageQ_cb *osMessageQId;
mbed_official 49:77c8e4604045 234
mbed_official 49:77c8e4604045 235 /// Mail ID identifies the mail queue (pointer to a mail queue control block).
mbed_official 49:77c8e4604045 236 /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 237 typedef struct os_mailQ_cb *osMailQId;
mbed_official 49:77c8e4604045 238
mbed_official 49:77c8e4604045 239
mbed_official 49:77c8e4604045 240 /// Thread Definition structure contains startup information of a thread.
mbed_official 49:77c8e4604045 241 /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 242 typedef struct os_thread_def {
mbed_official 49:77c8e4604045 243 os_pthread pthread; ///< start address of thread function
mbed_official 49:77c8e4604045 244 osPriority tpriority; ///< initial thread priority
mbed_official 49:77c8e4604045 245 uint32_t stacksize; ///< stack size requirements in bytes
mbed_official 49:77c8e4604045 246 unsigned char *stack_pointer; ///< pointer to the stack memory block
mbed_official 49:77c8e4604045 247 struct OS_TCB tcb;
mbed_official 49:77c8e4604045 248 } osThreadDef_t;
mbed_official 49:77c8e4604045 249
mbed_official 49:77c8e4604045 250 /// Timer Definition structure contains timer parameters.
mbed_official 49:77c8e4604045 251 /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 252 typedef struct os_timer_def {
mbed_official 49:77c8e4604045 253 os_ptimer ptimer; ///< start address of a timer function
mbed_official 49:77c8e4604045 254 void *timer; ///< pointer to internal data
mbed_official 49:77c8e4604045 255 } osTimerDef_t;
mbed_official 49:77c8e4604045 256
mbed_official 49:77c8e4604045 257 /// Mutex Definition structure contains setup information for a mutex.
mbed_official 49:77c8e4604045 258 /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 259 typedef struct os_mutex_def {
mbed_official 49:77c8e4604045 260 void *mutex; ///< pointer to internal data
mbed_official 49:77c8e4604045 261 } osMutexDef_t;
mbed_official 49:77c8e4604045 262
mbed_official 49:77c8e4604045 263 /// Semaphore Definition structure contains setup information for a semaphore.
mbed_official 49:77c8e4604045 264 /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 265 typedef struct os_semaphore_def {
mbed_official 49:77c8e4604045 266 void *semaphore; ///< pointer to internal data
mbed_official 49:77c8e4604045 267 } osSemaphoreDef_t;
mbed_official 49:77c8e4604045 268
mbed_official 49:77c8e4604045 269 /// Definition structure for memory block allocation.
mbed_official 49:77c8e4604045 270 /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 271 typedef struct os_pool_def {
mbed_official 49:77c8e4604045 272 uint32_t pool_sz; ///< number of items (elements) in the pool
mbed_official 49:77c8e4604045 273 uint32_t item_sz; ///< size of an item
mbed_official 49:77c8e4604045 274 void *pool; ///< pointer to memory for pool
mbed_official 49:77c8e4604045 275 } osPoolDef_t;
mbed_official 49:77c8e4604045 276
mbed_official 49:77c8e4604045 277 /// Definition structure for message queue.
mbed_official 49:77c8e4604045 278 /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 279 typedef struct os_messageQ_def {
mbed_official 49:77c8e4604045 280 uint32_t queue_sz; ///< number of elements in the queue
mbed_official 49:77c8e4604045 281 void *pool; ///< memory array for messages
mbed_official 49:77c8e4604045 282 } osMessageQDef_t;
mbed_official 49:77c8e4604045 283
mbed_official 49:77c8e4604045 284 /// Definition structure for mail queue.
mbed_official 49:77c8e4604045 285 /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 286 typedef struct os_mailQ_def {
mbed_official 49:77c8e4604045 287 uint32_t queue_sz; ///< number of elements in the queue
mbed_official 49:77c8e4604045 288 uint32_t item_sz; ///< size of an item
mbed_official 49:77c8e4604045 289 void *pool; ///< memory array for mail
mbed_official 49:77c8e4604045 290 } osMailQDef_t;
mbed_official 49:77c8e4604045 291
mbed_official 49:77c8e4604045 292 /// Event structure contains detailed information about an event.
mbed_official 49:77c8e4604045 293 /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 294 /// However the struct may be extended at the end.
mbed_official 49:77c8e4604045 295 typedef struct {
mbed_official 49:77c8e4604045 296 osStatus status; ///< status code: event or error information
mbed_official 49:77c8e4604045 297 union {
mbed_official 49:77c8e4604045 298 uint32_t v; ///< message as 32-bit value
mbed_official 49:77c8e4604045 299 void *p; ///< message or mail as void pointer
mbed_official 49:77c8e4604045 300 int32_t signals; ///< signal flags
mbed_official 49:77c8e4604045 301 } value; ///< event value
mbed_official 49:77c8e4604045 302 union {
mbed_official 49:77c8e4604045 303 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
mbed_official 49:77c8e4604045 304 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
mbed_official 49:77c8e4604045 305 } def; ///< event definition
mbed_official 49:77c8e4604045 306 } osEvent;
mbed_official 49:77c8e4604045 307
mbed_official 49:77c8e4604045 308
mbed_official 49:77c8e4604045 309 // ==== Kernel Control Functions ====
mbed_official 49:77c8e4604045 310
mbed_official 49:77c8e4604045 311 /// Initialize the RTOS Kernel for creating objects.
mbed_official 49:77c8e4604045 312 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 313 /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 314 osStatus osKernelInitialize (void);
mbed_official 49:77c8e4604045 315
mbed_official 49:77c8e4604045 316 /// Start the RTOS Kernel.
mbed_official 49:77c8e4604045 317 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 318 /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 319 osStatus osKernelStart (void);
mbed_official 49:77c8e4604045 320
mbed_official 49:77c8e4604045 321 /// Check if the RTOS kernel is already started.
mbed_official 49:77c8e4604045 322 /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 323 /// \return 0 RTOS is not started, 1 RTOS is started.
mbed_official 49:77c8e4604045 324 int32_t osKernelRunning(void);
mbed_official 49:77c8e4604045 325
mbed_official 49:77c8e4604045 326
mbed_official 49:77c8e4604045 327 // ==== Thread Management ====
mbed_official 49:77c8e4604045 328
mbed_official 49:77c8e4604045 329 /// Create a Thread Definition with function, priority, and stack requirements.
mbed_official 49:77c8e4604045 330 /// \param name name of the thread function.
mbed_official 49:77c8e4604045 331 /// \param priority initial priority of the thread function.
mbed_official 49:77c8e4604045 332 /// \param stacksz stack size (in bytes) requirements for the thread function.
mbed_official 49:77c8e4604045 333 /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
mbed_official 49:77c8e4604045 334 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 335 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 336 #define osThreadDef(name, priority, stacksz) \
mbed_official 49:77c8e4604045 337 extern osThreadDef_t os_thread_def_##name
mbed_official 49:77c8e4604045 338 #else // define the object
mbed_official 49:77c8e4604045 339 #define osThreadDef(name, priority, stacksz) \
mbed_official 49:77c8e4604045 340 unsigned char os_thread_def_stack_##name [stacksz]; \
mbed_official 49:77c8e4604045 341 osThreadDef_t os_thread_def_##name = \
mbed_official 49:77c8e4604045 342 { (name), (priority), (stacksz), (os_thread_def_stack_##name)}
mbed_official 49:77c8e4604045 343 #endif
mbed_official 49:77c8e4604045 344
mbed_official 49:77c8e4604045 345 /// Access a Thread definition.
mbed_official 49:77c8e4604045 346 /// \param name name of the thread definition object.
mbed_official 49:77c8e4604045 347 /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
mbed_official 49:77c8e4604045 348 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 349 #define osThread(name) \
mbed_official 49:77c8e4604045 350 &os_thread_def_##name
mbed_official 49:77c8e4604045 351
mbed_official 49:77c8e4604045 352 /// Create a thread and add it to Active Threads and set it to state READY.
mbed_official 49:77c8e4604045 353 /// \param[in] thread_def thread definition referenced with \ref osThread.
mbed_official 49:77c8e4604045 354 /// \param[in] argument pointer that is passed to the thread function as start argument.
mbed_official 49:77c8e4604045 355 /// \return thread ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 356 /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 357 osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument);
mbed_official 49:77c8e4604045 358
mbed_official 49:77c8e4604045 359 /// Return the thread ID of the current running thread.
mbed_official 49:77c8e4604045 360 /// \return thread ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 361 /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 362 osThreadId osThreadGetId (void);
mbed_official 49:77c8e4604045 363
mbed_official 49:77c8e4604045 364 /// Terminate execution of a thread and remove it from Active Threads.
mbed_official 49:77c8e4604045 365 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 366 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 367 /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 368 osStatus osThreadTerminate (osThreadId thread_id);
mbed_official 49:77c8e4604045 369
mbed_official 49:77c8e4604045 370 /// Pass control to next thread that is in state \b READY.
mbed_official 49:77c8e4604045 371 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 372 /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 373 osStatus osThreadYield (void);
mbed_official 49:77c8e4604045 374
mbed_official 49:77c8e4604045 375 /// Change priority of an active thread.
mbed_official 49:77c8e4604045 376 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 377 /// \param[in] priority new priority value for the thread function.
mbed_official 49:77c8e4604045 378 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 379 /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 380 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
mbed_official 49:77c8e4604045 381
mbed_official 49:77c8e4604045 382 /// Get current priority of an active thread.
mbed_official 49:77c8e4604045 383 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 384 /// \return current priority value of the thread function.
mbed_official 49:77c8e4604045 385 /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 386 osPriority osThreadGetPriority (osThreadId thread_id);
mbed_official 49:77c8e4604045 387
mbed_official 49:77c8e4604045 388
mbed_official 49:77c8e4604045 389 // ==== Generic Wait Functions ====
mbed_official 49:77c8e4604045 390
mbed_official 49:77c8e4604045 391 /// Wait for Timeout (Time Delay).
mbed_official 49:77c8e4604045 392 /// \param[in] millisec time delay value
mbed_official 49:77c8e4604045 393 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 394 osStatus osDelay (uint32_t millisec);
mbed_official 49:77c8e4604045 395
mbed_official 49:77c8e4604045 396 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
mbed_official 49:77c8e4604045 397
mbed_official 49:77c8e4604045 398 /// Wait for Signal, Message, Mail, or Timeout.
mbed_official 49:77c8e4604045 399 /// \param[in] millisec timeout value or 0 in case of no time-out
mbed_official 49:77c8e4604045 400 /// \return event that contains signal, message, or mail information or error code.
mbed_official 49:77c8e4604045 401 /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 402 os_InRegs osEvent osWait (uint32_t millisec);
mbed_official 49:77c8e4604045 403
mbed_official 49:77c8e4604045 404 #endif // Generic Wait available
mbed_official 49:77c8e4604045 405
mbed_official 49:77c8e4604045 406
mbed_official 49:77c8e4604045 407 // ==== Timer Management Functions ====
mbed_official 49:77c8e4604045 408 /// Define a Timer object.
mbed_official 49:77c8e4604045 409 /// \param name name of the timer object.
mbed_official 49:77c8e4604045 410 /// \param function name of the timer call back function.
mbed_official 49:77c8e4604045 411 /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
mbed_official 49:77c8e4604045 412 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 413 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 414 #define osTimerDef(name, function) \
mbed_official 49:77c8e4604045 415 extern osTimerDef_t os_timer_def_##name
mbed_official 49:77c8e4604045 416 #else // define the object
mbed_official 49:77c8e4604045 417 #define osTimerDef(name, function) \
mbed_official 49:77c8e4604045 418 uint32_t os_timer_cb_##name[5]; \
mbed_official 49:77c8e4604045 419 osTimerDef_t os_timer_def_##name = \
mbed_official 49:77c8e4604045 420 { (function), (os_timer_cb_##name) }
mbed_official 49:77c8e4604045 421 #endif
mbed_official 49:77c8e4604045 422
mbed_official 49:77c8e4604045 423 /// Access a Timer definition.
mbed_official 49:77c8e4604045 424 /// \param name name of the timer object.
mbed_official 49:77c8e4604045 425 /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
mbed_official 49:77c8e4604045 426 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 427 #define osTimer(name) \
mbed_official 49:77c8e4604045 428 &os_timer_def_##name
mbed_official 49:77c8e4604045 429
mbed_official 49:77c8e4604045 430 /// Create a timer.
mbed_official 49:77c8e4604045 431 /// \param[in] timer_def timer object referenced with \ref osTimer.
mbed_official 49:77c8e4604045 432 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
mbed_official 49:77c8e4604045 433 /// \param[in] argument argument to the timer call back function.
mbed_official 49:77c8e4604045 434 /// \return timer ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 435 /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 436 osTimerId osTimerCreate (osTimerDef_t *timer_def, os_timer_type type, void *argument);
mbed_official 49:77c8e4604045 437
mbed_official 49:77c8e4604045 438 /// Start or restart a timer.
mbed_official 49:77c8e4604045 439 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
mbed_official 49:77c8e4604045 440 /// \param[in] millisec time delay value of the timer.
mbed_official 49:77c8e4604045 441 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 442 /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 443 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
mbed_official 49:77c8e4604045 444
mbed_official 49:77c8e4604045 445 /// Stop the timer.
mbed_official 49:77c8e4604045 446 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
mbed_official 49:77c8e4604045 447 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 448 /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 449 osStatus osTimerStop (osTimerId timer_id);
mbed_official 49:77c8e4604045 450
mbed_official 49:77c8e4604045 451 /// Delete a timer that was created by \ref osTimerCreate.
mbed_official 49:77c8e4604045 452 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
mbed_official 49:77c8e4604045 453 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 454 /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 455 osStatus osTimerDelete (osTimerId timer_id);
mbed_official 49:77c8e4604045 456
mbed_official 49:77c8e4604045 457
mbed_official 49:77c8e4604045 458 // ==== Signal Management ====
mbed_official 49:77c8e4604045 459
mbed_official 49:77c8e4604045 460 /// Set the specified Signal Flags of an active thread.
mbed_official 49:77c8e4604045 461 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 462 /// \param[in] signals specifies the signal flags of the thread that should be set.
mbed_official 49:77c8e4604045 463 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
mbed_official 49:77c8e4604045 464 /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 465 int32_t osSignalSet (osThreadId thread_id, int32_t signals);
mbed_official 49:77c8e4604045 466
mbed_official 49:77c8e4604045 467 /// Clear the specified Signal Flags of an active thread.
mbed_official 49:77c8e4604045 468 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 469 /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
mbed_official 49:77c8e4604045 470 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
mbed_official 49:77c8e4604045 471 /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 472 int32_t osSignalClear (osThreadId thread_id, int32_t signals);
mbed_official 49:77c8e4604045 473
mbed_official 49:77c8e4604045 474 /// Get Signal Flags status of an active thread.
mbed_official 49:77c8e4604045 475 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
mbed_official 49:77c8e4604045 476 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
mbed_official 49:77c8e4604045 477 /// \note MUST REMAIN UNCHANGED: \b osSignalGet shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 478 int32_t osSignalGet (osThreadId thread_id);
mbed_official 49:77c8e4604045 479
mbed_official 49:77c8e4604045 480 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
mbed_official 49:77c8e4604045 481 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
mbed_official 49:77c8e4604045 482 /// \param[in] millisec timeout value or 0 in case of no time-out.
mbed_official 49:77c8e4604045 483 /// \return event flag information or error code.
mbed_official 49:77c8e4604045 484 /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 485 os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec);
mbed_official 49:77c8e4604045 486
mbed_official 49:77c8e4604045 487
mbed_official 49:77c8e4604045 488 // ==== Mutex Management ====
mbed_official 49:77c8e4604045 489
mbed_official 49:77c8e4604045 490 /// Define a Mutex.
mbed_official 49:77c8e4604045 491 /// \param name name of the mutex object.
mbed_official 49:77c8e4604045 492 /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
mbed_official 49:77c8e4604045 493 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 494 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 495 #define osMutexDef(name) \
mbed_official 49:77c8e4604045 496 extern osMutexDef_t os_mutex_def_##name
mbed_official 49:77c8e4604045 497 #else // define the object
mbed_official 49:77c8e4604045 498 #define osMutexDef(name) \
mbed_official 49:77c8e4604045 499 uint32_t os_mutex_cb_##name[3]; \
mbed_official 49:77c8e4604045 500 osMutexDef_t os_mutex_def_##name = { (os_mutex_cb_##name) }
mbed_official 49:77c8e4604045 501 #endif
mbed_official 49:77c8e4604045 502
mbed_official 49:77c8e4604045 503 /// Access a Mutex definition.
mbed_official 49:77c8e4604045 504 /// \param name name of the mutex object.
mbed_official 49:77c8e4604045 505 /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
mbed_official 49:77c8e4604045 506 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 507 #define osMutex(name) \
mbed_official 49:77c8e4604045 508 &os_mutex_def_##name
mbed_official 49:77c8e4604045 509
mbed_official 49:77c8e4604045 510 /// Create and Initialize a Mutex object.
mbed_official 49:77c8e4604045 511 /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
mbed_official 49:77c8e4604045 512 /// \return mutex ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 513 /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 514 osMutexId osMutexCreate (osMutexDef_t *mutex_def);
mbed_official 49:77c8e4604045 515
mbed_official 49:77c8e4604045 516 /// Wait until a Mutex becomes available.
mbed_official 49:77c8e4604045 517 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
mbed_official 49:77c8e4604045 518 /// \param[in] millisec timeout value or 0 in case of no time-out.
mbed_official 49:77c8e4604045 519 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 520 /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 521 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
mbed_official 49:77c8e4604045 522
mbed_official 49:77c8e4604045 523 /// Release a Mutex that was obtained by \ref osMutexWait.
mbed_official 49:77c8e4604045 524 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
mbed_official 49:77c8e4604045 525 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 526 /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 527 osStatus osMutexRelease (osMutexId mutex_id);
mbed_official 49:77c8e4604045 528
mbed_official 49:77c8e4604045 529 /// Delete a Mutex that was created by \ref osMutexCreate.
mbed_official 49:77c8e4604045 530 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
mbed_official 49:77c8e4604045 531 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 532 /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 533 osStatus osMutexDelete (osMutexId mutex_id);
mbed_official 49:77c8e4604045 534
mbed_official 49:77c8e4604045 535
mbed_official 49:77c8e4604045 536 // ==== Semaphore Management Functions ====
mbed_official 49:77c8e4604045 537
mbed_official 49:77c8e4604045 538 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
mbed_official 49:77c8e4604045 539
mbed_official 49:77c8e4604045 540 /// Define a Semaphore object.
mbed_official 49:77c8e4604045 541 /// \param name name of the semaphore object.
mbed_official 49:77c8e4604045 542 /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
mbed_official 49:77c8e4604045 543 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 544 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 545 #define osSemaphoreDef(name) \
mbed_official 49:77c8e4604045 546 extern osSemaphoreDef_t os_semaphore_def_##name
mbed_official 49:77c8e4604045 547 #else // define the object
mbed_official 49:77c8e4604045 548 #define osSemaphoreDef(name) \
mbed_official 49:77c8e4604045 549 uint32_t os_semaphore_cb_##name[2]; \
mbed_official 49:77c8e4604045 550 osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) }
mbed_official 49:77c8e4604045 551 #endif
mbed_official 49:77c8e4604045 552
mbed_official 49:77c8e4604045 553 /// Access a Semaphore definition.
mbed_official 49:77c8e4604045 554 /// \param name name of the semaphore object.
mbed_official 49:77c8e4604045 555 /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
mbed_official 49:77c8e4604045 556 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 557 #define osSemaphore(name) \
mbed_official 49:77c8e4604045 558 &os_semaphore_def_##name
mbed_official 49:77c8e4604045 559
mbed_official 49:77c8e4604045 560 /// Create and Initialize a Semaphore object used for managing resources.
mbed_official 49:77c8e4604045 561 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
mbed_official 49:77c8e4604045 562 /// \param[in] count number of available resources.
mbed_official 49:77c8e4604045 563 /// \return semaphore ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 564 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 565 osSemaphoreId osSemaphoreCreate (osSemaphoreDef_t *semaphore_def, int32_t count);
mbed_official 49:77c8e4604045 566
mbed_official 49:77c8e4604045 567 /// Wait until a Semaphore token becomes available.
mbed_official 49:77c8e4604045 568 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
mbed_official 49:77c8e4604045 569 /// \param[in] millisec timeout value or 0 in case of no time-out.
mbed_official 49:77c8e4604045 570 /// \return number of available tokens, or -1 in case of incorrect parameters.
mbed_official 49:77c8e4604045 571 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 572 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
mbed_official 49:77c8e4604045 573
mbed_official 49:77c8e4604045 574 /// Release a Semaphore token.
mbed_official 49:77c8e4604045 575 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
mbed_official 49:77c8e4604045 576 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 577 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 578 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
mbed_official 49:77c8e4604045 579
mbed_official 49:77c8e4604045 580 /// Delete a Semaphore that was created by \ref osSemaphoreCreate.
mbed_official 49:77c8e4604045 581 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
mbed_official 49:77c8e4604045 582 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 583 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 584 osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
mbed_official 49:77c8e4604045 585
mbed_official 49:77c8e4604045 586 #endif // Semaphore available
mbed_official 49:77c8e4604045 587
mbed_official 49:77c8e4604045 588
mbed_official 49:77c8e4604045 589 // ==== Memory Pool Management Functions ====
mbed_official 49:77c8e4604045 590
mbed_official 49:77c8e4604045 591 #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
mbed_official 49:77c8e4604045 592
mbed_official 49:77c8e4604045 593 /// \brief Define a Memory Pool.
mbed_official 49:77c8e4604045 594 /// \param name name of the memory pool.
mbed_official 49:77c8e4604045 595 /// \param no maximum number of blocks (objects) in the memory pool.
mbed_official 49:77c8e4604045 596 /// \param type data type of a single block (object).
mbed_official 49:77c8e4604045 597 /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
mbed_official 49:77c8e4604045 598 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 599 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 600 #define osPoolDef(name, no, type) \
mbed_official 49:77c8e4604045 601 extern osPoolDef_t os_pool_def_##name
mbed_official 49:77c8e4604045 602 #else // define the object
mbed_official 49:77c8e4604045 603 #define osPoolDef(name, no, type) \
mbed_official 49:77c8e4604045 604 uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \
mbed_official 49:77c8e4604045 605 osPoolDef_t os_pool_def_##name = \
mbed_official 49:77c8e4604045 606 { (no), sizeof(type), (os_pool_m_##name) }
mbed_official 49:77c8e4604045 607 #endif
mbed_official 49:77c8e4604045 608
mbed_official 49:77c8e4604045 609 /// \brief Access a Memory Pool definition.
mbed_official 49:77c8e4604045 610 /// \param name name of the memory pool
mbed_official 49:77c8e4604045 611 /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
mbed_official 49:77c8e4604045 612 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 613 #define osPool(name) \
mbed_official 49:77c8e4604045 614 &os_pool_def_##name
mbed_official 49:77c8e4604045 615
mbed_official 49:77c8e4604045 616 /// Create and Initialize a memory pool.
mbed_official 49:77c8e4604045 617 /// \param[in] pool_def memory pool definition referenced with \ref osPool.
mbed_official 49:77c8e4604045 618 /// \return memory pool ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 619 /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 620 osPoolId osPoolCreate (osPoolDef_t *pool_def);
mbed_official 49:77c8e4604045 621
mbed_official 49:77c8e4604045 622 /// Allocate a memory block from a memory pool.
mbed_official 49:77c8e4604045 623 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
mbed_official 49:77c8e4604045 624 /// \return address of the allocated memory block or NULL in case of no memory available.
mbed_official 49:77c8e4604045 625 /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 626 void *osPoolAlloc (osPoolId pool_id);
mbed_official 49:77c8e4604045 627
mbed_official 49:77c8e4604045 628 /// Allocate a memory block from a memory pool and set memory block to zero.
mbed_official 49:77c8e4604045 629 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
mbed_official 49:77c8e4604045 630 /// \return address of the allocated memory block or NULL in case of no memory available.
mbed_official 49:77c8e4604045 631 /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 632 void *osPoolCAlloc (osPoolId pool_id);
mbed_official 49:77c8e4604045 633
mbed_official 49:77c8e4604045 634 /// Return an allocated memory block back to a specific memory pool.
mbed_official 49:77c8e4604045 635 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
mbed_official 49:77c8e4604045 636 /// \param[in] block address of the allocated memory block that is returned to the memory pool.
mbed_official 49:77c8e4604045 637 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 638 /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 639 osStatus osPoolFree (osPoolId pool_id, void *block);
mbed_official 49:77c8e4604045 640
mbed_official 49:77c8e4604045 641 #endif // Memory Pool Management available
mbed_official 49:77c8e4604045 642
mbed_official 49:77c8e4604045 643
mbed_official 49:77c8e4604045 644 // ==== Message Queue Management Functions ====
mbed_official 49:77c8e4604045 645
mbed_official 49:77c8e4604045 646 #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
mbed_official 49:77c8e4604045 647
mbed_official 49:77c8e4604045 648 /// \brief Create a Message Queue Definition.
mbed_official 49:77c8e4604045 649 /// \param name name of the queue.
mbed_official 49:77c8e4604045 650 /// \param queue_sz maximum number of messages in the queue.
mbed_official 49:77c8e4604045 651 /// \param type data type of a single message element (for debugger).
mbed_official 49:77c8e4604045 652 /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
mbed_official 49:77c8e4604045 653 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 654 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 655 #define osMessageQDef(name, queue_sz, type) \
mbed_official 49:77c8e4604045 656 extern osMessageQDef_t os_messageQ_def_##name
mbed_official 49:77c8e4604045 657 #else // define the object
mbed_official 49:77c8e4604045 658 #define osMessageQDef(name, queue_sz, type) \
mbed_official 49:77c8e4604045 659 uint32_t os_messageQ_q_##name[4+(queue_sz)]; \
mbed_official 49:77c8e4604045 660 osMessageQDef_t os_messageQ_def_##name = \
mbed_official 49:77c8e4604045 661 { (queue_sz), (os_messageQ_q_##name) }
mbed_official 49:77c8e4604045 662 #endif
mbed_official 49:77c8e4604045 663
mbed_official 49:77c8e4604045 664 /// \brief Access a Message Queue Definition.
mbed_official 49:77c8e4604045 665 /// \param name name of the queue
mbed_official 49:77c8e4604045 666 /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
mbed_official 49:77c8e4604045 667 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 668 #define osMessageQ(name) \
mbed_official 49:77c8e4604045 669 &os_messageQ_def_##name
mbed_official 49:77c8e4604045 670
mbed_official 49:77c8e4604045 671 /// Create and Initialize a Message Queue.
mbed_official 49:77c8e4604045 672 /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
mbed_official 49:77c8e4604045 673 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
mbed_official 49:77c8e4604045 674 /// \return message queue ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 675 /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 676 osMessageQId osMessageCreate (osMessageQDef_t *queue_def, osThreadId thread_id);
mbed_official 49:77c8e4604045 677
mbed_official 49:77c8e4604045 678 /// Put a Message to a Queue.
mbed_official 49:77c8e4604045 679 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
mbed_official 49:77c8e4604045 680 /// \param[in] info message information.
mbed_official 49:77c8e4604045 681 /// \param[in] millisec timeout value or 0 in case of no time-out.
mbed_official 49:77c8e4604045 682 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 683 /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 684 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
mbed_official 49:77c8e4604045 685
mbed_official 49:77c8e4604045 686 /// Get a Message or Wait for a Message from a Queue.
mbed_official 49:77c8e4604045 687 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
mbed_official 49:77c8e4604045 688 /// \param[in] millisec timeout value or 0 in case of no time-out.
mbed_official 49:77c8e4604045 689 /// \return event information that includes status code.
mbed_official 49:77c8e4604045 690 /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 691 os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
mbed_official 49:77c8e4604045 692
mbed_official 49:77c8e4604045 693 #endif // Message Queues available
mbed_official 49:77c8e4604045 694
mbed_official 49:77c8e4604045 695
mbed_official 49:77c8e4604045 696 // ==== Mail Queue Management Functions ====
mbed_official 49:77c8e4604045 697
mbed_official 49:77c8e4604045 698 #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
mbed_official 49:77c8e4604045 699
mbed_official 49:77c8e4604045 700 /// \brief Create a Mail Queue Definition.
mbed_official 49:77c8e4604045 701 /// \param name name of the queue
mbed_official 49:77c8e4604045 702 /// \param queue_sz maximum number of messages in queue
mbed_official 49:77c8e4604045 703 /// \param type data type of a single message element
mbed_official 49:77c8e4604045 704 /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
mbed_official 49:77c8e4604045 705 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 706 #if defined (osObjectsExternal) // object is external
mbed_official 49:77c8e4604045 707 #define osMailQDef(name, queue_sz, type) \
mbed_official 49:77c8e4604045 708 extern osMailQDef_t os_mailQ_def_##name
mbed_official 49:77c8e4604045 709 #else // define the object
mbed_official 49:77c8e4604045 710 #define osMailQDef(name, queue_sz, type) \
mbed_official 49:77c8e4604045 711 uint32_t os_mailQ_q_##name[4+(queue_sz)]; \
mbed_official 49:77c8e4604045 712 uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \
mbed_official 49:77c8e4604045 713 void * os_mailQ_p_##name[2] = { (os_mailQ_q_##name), os_mailQ_m_##name }; \
mbed_official 49:77c8e4604045 714 osMailQDef_t os_mailQ_def_##name = \
mbed_official 49:77c8e4604045 715 { (queue_sz), sizeof(type), (os_mailQ_p_##name) }
mbed_official 49:77c8e4604045 716 #endif
mbed_official 49:77c8e4604045 717
mbed_official 49:77c8e4604045 718 /// \brief Access a Mail Queue Definition.
mbed_official 49:77c8e4604045 719 /// \param name name of the queue
mbed_official 49:77c8e4604045 720 /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
mbed_official 49:77c8e4604045 721 /// macro body is implementation specific in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 722 #define osMailQ(name) \
mbed_official 49:77c8e4604045 723 &os_mailQ_def_##name
mbed_official 49:77c8e4604045 724
mbed_official 49:77c8e4604045 725 /// Create and Initialize mail queue.
mbed_official 49:77c8e4604045 726 /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
mbed_official 49:77c8e4604045 727 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
mbed_official 49:77c8e4604045 728 /// \return mail queue ID for reference by other functions or NULL in case of error.
mbed_official 49:77c8e4604045 729 /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 730 osMailQId osMailCreate (osMailQDef_t *queue_def, osThreadId thread_id);
mbed_official 49:77c8e4604045 731
mbed_official 49:77c8e4604045 732 /// Allocate a memory block from a mail.
mbed_official 49:77c8e4604045 733 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
mbed_official 49:77c8e4604045 734 /// \param[in] millisec timeout value or 0 in case of no time-out
mbed_official 49:77c8e4604045 735 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
mbed_official 49:77c8e4604045 736 /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 737 void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
mbed_official 49:77c8e4604045 738
mbed_official 49:77c8e4604045 739 /// Allocate a memory block from a mail and set memory block to zero.
mbed_official 49:77c8e4604045 740 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
mbed_official 49:77c8e4604045 741 /// \param[in] millisec timeout value or 0 in case of no time-out
mbed_official 49:77c8e4604045 742 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
mbed_official 49:77c8e4604045 743 /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 744 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
mbed_official 49:77c8e4604045 745
mbed_official 49:77c8e4604045 746 /// Put a mail to a queue.
mbed_official 49:77c8e4604045 747 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
mbed_official 49:77c8e4604045 748 /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
mbed_official 49:77c8e4604045 749 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 750 /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 751 osStatus osMailPut (osMailQId queue_id, void *mail);
mbed_official 49:77c8e4604045 752
mbed_official 49:77c8e4604045 753 /// Get a mail from a queue.
mbed_official 49:77c8e4604045 754 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
mbed_official 49:77c8e4604045 755 /// \param[in] millisec timeout value or 0 in case of no time-out
mbed_official 49:77c8e4604045 756 /// \return event that contains mail information or error code.
mbed_official 49:77c8e4604045 757 /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 758 os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
mbed_official 49:77c8e4604045 759
mbed_official 49:77c8e4604045 760 /// Free a memory block from a mail.
mbed_official 49:77c8e4604045 761 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
mbed_official 49:77c8e4604045 762 /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
mbed_official 49:77c8e4604045 763 /// \return status code that indicates the execution status of the function.
mbed_official 49:77c8e4604045 764 /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
mbed_official 49:77c8e4604045 765 osStatus osMailFree (osMailQId queue_id, void *mail);
mbed_official 49:77c8e4604045 766
mbed_official 49:77c8e4604045 767 #endif // Mail Queues available
mbed_official 49:77c8e4604045 768
mbed_official 49:77c8e4604045 769
mbed_official 49:77c8e4604045 770 #ifdef __cplusplus
mbed_official 49:77c8e4604045 771 }
mbed_official 49:77c8e4604045 772 #endif
mbed_official 49:77c8e4604045 773
mbed_official 49:77c8e4604045 774 #endif // _CMSIS_OS_H