Alan Ffrench / Mbed 2 deprecated Experiment_2_5

Dependencies:   mbed

Committer:
alanffrench
Date:
Wed Jul 29 18:51:38 2020 +0000
Revision:
0:52468b19aa21
Threads

Who changed what in which revision?

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