IC Eurobot 2012 Program published from Shuto's account

Dependents:   Eurobot2012_Primary

Committer:
narshu
Date:
Tue Aug 07 10:25:51 2012 +0000
Revision:
0:62626fd22b30
[mbed] converted /Eurobot_2012_Primary/rtos

Who changed what in which revision?

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