Committer:
PA
Date:
Thu Jun 21 14:04:44 2012 +0000
Revision:
0:7ae810ca8a42

        

Who changed what in which revision?

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