florent ollivier / Mbed 2 deprecated Gyro

Dependencies:   mbed

Committer:
flo__
Date:
Mon Mar 28 15:54:19 2022 +0000
Revision:
0:b435eadf76b4
28/03/2022

Who changed what in which revision?

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