mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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