Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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