updated

Dependents:   NSDL_HelloWorld_WiFi_K64_test

Fork of mbed-rtos by ARM Shanghai IoT Team (Internal)

Committer:
lvwei1990
Date:
Fri Jan 16 06:35:14 2015 +0000
Revision:
56:703a0ea0ca4d
Parent:
55:7ae48e99d3f3
Demo for the problem with nsdl_lib and rtos on FRDM- K64F

Who changed what in which revision?

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