Dave Lu / Mbed 2 deprecated FYDP

Dependencies:   mbed

Fork of FYDP_Final2 by Dave Lu

Committer:
tntmarket
Date:
Wed Mar 25 11:44:05 2015 +0000
Revision:
8:3d5a84b897be
Parent:
mbed/mbed-rtos/rtx/cmsis_os.h@0:21019d94ad33
lift folders

Who changed what in which revision?

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