RTOS lib used for Eurobot 2012

Dependents:   09_BC2_encoder

Committer:
eembed
Date:
Thu Aug 01 07:49:38 2019 +0000
Revision:
1:b270f864114f
Parent:
0:e477ba491a3b
First commit

Who changed what in which revision?

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