RTOS configured for use with Networking libraries

Dependents:   EthernetHTTPClientTest

Committer:
donatien
Date:
Thu May 24 08:56:51 2012 +0000
Revision:
0:07f30e7c9897
[mbed] converted /VodafoneK3770Lib/rtos

Who changed what in which revision?

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