mutex++

Dependents:   header_main_publish

Fork of mbed-rtos by mbed official

Committer:
mbed_official
Date:
Tue Jun 03 11:30:14 2014 +0100
Revision:
31:015df9e602b6
Parent:
13:869ef732a8a2
Synchronized with git revision bcacbb9fbf3432829227430830cca4315b57c1b9

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

Who changed what in which revision?

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