ProjetoBB

Dependencies:   F7_Ethernet WebSocketClient mbed mcp3008

Fork of Nucleo_F746ZG_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sat Jun 18 10:49:12 2016 +0000
Revision:
0:f9b6112278fe
Ethernet for the NUCLEO STM32F746 Board Testprogram uses DHCP and NTP to set the clock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:f9b6112278fe 1 /* ----------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 2 * $Date: 5. February 2013
DieterGraef 0:f9b6112278fe 3 * $Revision: V1.02
DieterGraef 0:f9b6112278fe 4 *
DieterGraef 0:f9b6112278fe 5 * Project: CMSIS-RTOS API
DieterGraef 0:f9b6112278fe 6 * Title: cmsis_os.h RTX header file
DieterGraef 0:f9b6112278fe 7 *
DieterGraef 0:f9b6112278fe 8 * Version 0.02
DieterGraef 0:f9b6112278fe 9 * Initial Proposal Phase
DieterGraef 0:f9b6112278fe 10 * Version 0.03
DieterGraef 0:f9b6112278fe 11 * osKernelStart added, optional feature: main started as thread
DieterGraef 0:f9b6112278fe 12 * osSemaphores have standard behavior
DieterGraef 0:f9b6112278fe 13 * osTimerCreate does not start the timer, added osTimerStart
DieterGraef 0:f9b6112278fe 14 * osThreadPass is renamed to osThreadYield
DieterGraef 0:f9b6112278fe 15 * Version 1.01
DieterGraef 0:f9b6112278fe 16 * Support for C++ interface
DieterGraef 0:f9b6112278fe 17 * - const attribute removed from the osXxxxDef_t typedef's
DieterGraef 0:f9b6112278fe 18 * - const attribute added to the osXxxxDef macros
DieterGraef 0:f9b6112278fe 19 * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
DieterGraef 0:f9b6112278fe 20 * Added: osKernelInitialize
DieterGraef 0:f9b6112278fe 21 * Version 1.02
DieterGraef 0:f9b6112278fe 22 * Control functions for short timeouts in microsecond resolution:
DieterGraef 0:f9b6112278fe 23 * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
DieterGraef 0:f9b6112278fe 24 * Removed: osSignalGet
DieterGraef 0:f9b6112278fe 25 *----------------------------------------------------------------------------
DieterGraef 0:f9b6112278fe 26 *
DieterGraef 0:f9b6112278fe 27 * Copyright (c) 2013 ARM LIMITED
DieterGraef 0:f9b6112278fe 28 * All rights reserved.
DieterGraef 0:f9b6112278fe 29 * Redistribution and use in source and binary forms, with or without
DieterGraef 0:f9b6112278fe 30 * modification, are permitted provided that the following conditions are met:
DieterGraef 0:f9b6112278fe 31 * - Redistributions of source code must retain the above copyright
DieterGraef 0:f9b6112278fe 32 * notice, this list of conditions and the following disclaimer.
DieterGraef 0:f9b6112278fe 33 * - Redistributions in binary form must reproduce the above copyright
DieterGraef 0:f9b6112278fe 34 * notice, this list of conditions and the following disclaimer in the
DieterGraef 0:f9b6112278fe 35 * documentation and/or other materials provided with the distribution.
DieterGraef 0:f9b6112278fe 36 * - Neither the name of ARM nor the names of its contributors may be used
DieterGraef 0:f9b6112278fe 37 * to endorse or promote products derived from this software without
DieterGraef 0:f9b6112278fe 38 * specific prior written permission.
DieterGraef 0:f9b6112278fe 39 *
DieterGraef 0:f9b6112278fe 40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
DieterGraef 0:f9b6112278fe 41 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
DieterGraef 0:f9b6112278fe 42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
DieterGraef 0:f9b6112278fe 43 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
DieterGraef 0:f9b6112278fe 44 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
DieterGraef 0:f9b6112278fe 45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
DieterGraef 0:f9b6112278fe 46 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:f9b6112278fe 47 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:f9b6112278fe 48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
DieterGraef 0:f9b6112278fe 49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
DieterGraef 0:f9b6112278fe 50 * POSSIBILITY OF SUCH DAMAGE.
DieterGraef 0:f9b6112278fe 51 *---------------------------------------------------------------------------*/
DieterGraef 0:f9b6112278fe 52
DieterGraef 0:f9b6112278fe 53
DieterGraef 0:f9b6112278fe 54 #ifndef _CMSIS_OS_H
DieterGraef 0:f9b6112278fe 55 #define _CMSIS_OS_H
DieterGraef 0:f9b6112278fe 56
DieterGraef 0:f9b6112278fe 57 #define CMSIS_OS_RTX
DieterGraef 0:f9b6112278fe 58
DieterGraef 0:f9b6112278fe 59 // __MBED_CMSIS_RTOS_CM captures our changes to the RTX kernel
DieterGraef 0:f9b6112278fe 60 #define __MBED_CMSIS_RTOS_CM
DieterGraef 0:f9b6112278fe 61 // we use __CMSIS_RTOS version, which changes some API in the kernel
DieterGraef 0:f9b6112278fe 62 #define __CMSIS_RTOS
DieterGraef 0:f9b6112278fe 63
DieterGraef 0:f9b6112278fe 64 // The stack space occupied is mainly dependent on the underling C standard library
DieterGraef 0:f9b6112278fe 65 #if defined(TOOLCHAIN_GCC) || defined(TOOLCHAIN_ARM_STD) || defined(TOOLCHAIN_IAR)
DieterGraef 0:f9b6112278fe 66 # define WORDS_STACK_SIZE 512
DieterGraef 0:f9b6112278fe 67 #elif defined(TOOLCHAIN_ARM_MICRO)
DieterGraef 0:f9b6112278fe 68 # define WORDS_STACK_SIZE 128
DieterGraef 0:f9b6112278fe 69 #endif
DieterGraef 0:f9b6112278fe 70
DieterGraef 0:f9b6112278fe 71 #define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
DieterGraef 0:f9b6112278fe 72
DieterGraef 0:f9b6112278fe 73 #define osCMSIS 0x10002U ///< CMSIS-RTOS API version (main [31:16] .sub [15:0])
DieterGraef 0:f9b6112278fe 74
DieterGraef 0:f9b6112278fe 75 #define osCMSIS_RTX ((4<<16)|80) ///< RTOS identification and version (main [31:16] .sub [15:0])
DieterGraef 0:f9b6112278fe 76
DieterGraef 0:f9b6112278fe 77 #define osKernelSystemId "RTX V4.80" ///< RTOS identification string
DieterGraef 0:f9b6112278fe 78
DieterGraef 0:f9b6112278fe 79
DieterGraef 0:f9b6112278fe 80 #define osFeature_MainThread 1 ///< main can be thread
DieterGraef 0:f9b6112278fe 81 #define osFeature_Pool 1 ///< Memory Pools available
DieterGraef 0:f9b6112278fe 82 #define osFeature_MailQ 1 ///< Mail Queues available
DieterGraef 0:f9b6112278fe 83 #define osFeature_MessageQ 1 ///< Message Queues available
DieterGraef 0:f9b6112278fe 84 #define osFeature_Signals 16 ///< 16 Signal Flags available per thread
DieterGraef 0:f9b6112278fe 85 #define osFeature_Semaphore 65535 ///< Maximum count for \ref osSemaphoreCreate function
DieterGraef 0:f9b6112278fe 86 #define osFeature_Wait 0 ///< osWait not available
DieterGraef 0:f9b6112278fe 87 #define osFeature_SysTick 1 ///< osKernelSysTick functions available
DieterGraef 0:f9b6112278fe 88
DieterGraef 0:f9b6112278fe 89 #if defined (__CC_ARM)
DieterGraef 0:f9b6112278fe 90 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers
DieterGraef 0:f9b6112278fe 91 #elif defined (__ICCARM__)
DieterGraef 0:f9b6112278fe 92 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers
DieterGraef 0:f9b6112278fe 93 #else
DieterGraef 0:f9b6112278fe 94 #define os_InRegs
DieterGraef 0:f9b6112278fe 95 #endif
DieterGraef 0:f9b6112278fe 96
DieterGraef 0:f9b6112278fe 97 #include <stdint.h>
DieterGraef 0:f9b6112278fe 98 #include <stddef.h>
DieterGraef 0:f9b6112278fe 99
DieterGraef 0:f9b6112278fe 100 #ifdef __cplusplus
DieterGraef 0:f9b6112278fe 101 extern "C"
DieterGraef 0:f9b6112278fe 102 {
DieterGraef 0:f9b6112278fe 103 #endif
DieterGraef 0:f9b6112278fe 104
DieterGraef 0:f9b6112278fe 105 // ==== Enumeration, structures, defines ====
DieterGraef 0:f9b6112278fe 106
DieterGraef 0:f9b6112278fe 107 /// Priority used for thread control.
DieterGraef 0:f9b6112278fe 108 typedef enum {
DieterGraef 0:f9b6112278fe 109 osPriorityIdle = -3, ///< priority: idle (lowest)
DieterGraef 0:f9b6112278fe 110 osPriorityLow = -2, ///< priority: low
DieterGraef 0:f9b6112278fe 111 osPriorityBelowNormal = -1, ///< priority: below normal
DieterGraef 0:f9b6112278fe 112 osPriorityNormal = 0, ///< priority: normal (default)
DieterGraef 0:f9b6112278fe 113 osPriorityAboveNormal = +1, ///< priority: above normal
DieterGraef 0:f9b6112278fe 114 osPriorityHigh = +2, ///< priority: high
DieterGraef 0:f9b6112278fe 115 osPriorityRealtime = +3, ///< priority: realtime (highest)
DieterGraef 0:f9b6112278fe 116 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
DieterGraef 0:f9b6112278fe 117 } osPriority;
DieterGraef 0:f9b6112278fe 118
DieterGraef 0:f9b6112278fe 119 /// Timeout value.
DieterGraef 0:f9b6112278fe 120 #define osWaitForever 0xFFFFFFFFU ///< wait forever timeout value
DieterGraef 0:f9b6112278fe 121
DieterGraef 0:f9b6112278fe 122 /// Status code values returned by CMSIS-RTOS functions.
DieterGraef 0:f9b6112278fe 123 typedef enum {
DieterGraef 0:f9b6112278fe 124 osOK = 0, ///< function completed; no error or event occurred.
DieterGraef 0:f9b6112278fe 125 osEventSignal = 0x08, ///< function completed; signal event occurred.
DieterGraef 0:f9b6112278fe 126 osEventMessage = 0x10, ///< function completed; message event occurred.
DieterGraef 0:f9b6112278fe 127 osEventMail = 0x20, ///< function completed; mail event occurred.
DieterGraef 0:f9b6112278fe 128 osEventTimeout = 0x40, ///< function completed; timeout occurred.
DieterGraef 0:f9b6112278fe 129 osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
DieterGraef 0:f9b6112278fe 130 osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
DieterGraef 0:f9b6112278fe 131 osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
DieterGraef 0:f9b6112278fe 132 osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
DieterGraef 0:f9b6112278fe 133 osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
DieterGraef 0:f9b6112278fe 134 osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
DieterGraef 0:f9b6112278fe 135 osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
DieterGraef 0:f9b6112278fe 136 osErrorValue = 0x86, ///< value of a parameter is out of range.
DieterGraef 0:f9b6112278fe 137 osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
DieterGraef 0:f9b6112278fe 138 os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
DieterGraef 0:f9b6112278fe 139 } osStatus;
DieterGraef 0:f9b6112278fe 140
DieterGraef 0:f9b6112278fe 141
DieterGraef 0:f9b6112278fe 142 /// Timer type value for the timer definition.
DieterGraef 0:f9b6112278fe 143 typedef enum {
DieterGraef 0:f9b6112278fe 144 osTimerOnce = 0, ///< one-shot timer
DieterGraef 0:f9b6112278fe 145 osTimerPeriodic = 1 ///< repeating timer
DieterGraef 0:f9b6112278fe 146 } os_timer_type;
DieterGraef 0:f9b6112278fe 147
DieterGraef 0:f9b6112278fe 148 /// Entry point of a thread.
DieterGraef 0:f9b6112278fe 149 typedef void (*os_pthread) (void const *argument);
DieterGraef 0:f9b6112278fe 150
DieterGraef 0:f9b6112278fe 151 /// Entry point of a timer call back function.
DieterGraef 0:f9b6112278fe 152 typedef void (*os_ptimer) (void const *argument);
DieterGraef 0:f9b6112278fe 153
DieterGraef 0:f9b6112278fe 154 // >>> the following data type definitions may shall adapted towards a specific RTOS
DieterGraef 0:f9b6112278fe 155
DieterGraef 0:f9b6112278fe 156 /// Thread ID identifies the thread (pointer to a thread control block).
DieterGraef 0:f9b6112278fe 157 typedef struct os_thread_cb *osThreadId;
DieterGraef 0:f9b6112278fe 158
DieterGraef 0:f9b6112278fe 159 /// Timer ID identifies the timer (pointer to a timer control block).
DieterGraef 0:f9b6112278fe 160 typedef struct os_timer_cb *osTimerId;
DieterGraef 0:f9b6112278fe 161
DieterGraef 0:f9b6112278fe 162 /// Mutex ID identifies the mutex (pointer to a mutex control block).
DieterGraef 0:f9b6112278fe 163 typedef struct os_mutex_cb *osMutexId;
DieterGraef 0:f9b6112278fe 164
DieterGraef 0:f9b6112278fe 165 /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
DieterGraef 0:f9b6112278fe 166 typedef struct os_semaphore_cb *osSemaphoreId;
DieterGraef 0:f9b6112278fe 167
DieterGraef 0:f9b6112278fe 168 /// Pool ID identifies the memory pool (pointer to a memory pool control block).
DieterGraef 0:f9b6112278fe 169 typedef struct os_pool_cb *osPoolId;
DieterGraef 0:f9b6112278fe 170
DieterGraef 0:f9b6112278fe 171 /// Message ID identifies the message queue (pointer to a message queue control block).
DieterGraef 0:f9b6112278fe 172 typedef struct os_messageQ_cb *osMessageQId;
DieterGraef 0:f9b6112278fe 173
DieterGraef 0:f9b6112278fe 174 /// Mail ID identifies the mail queue (pointer to a mail queue control block).
DieterGraef 0:f9b6112278fe 175 typedef struct os_mailQ_cb *osMailQId;
DieterGraef 0:f9b6112278fe 176
DieterGraef 0:f9b6112278fe 177
DieterGraef 0:f9b6112278fe 178 /// Thread Definition structure contains startup information of a thread.
DieterGraef 0:f9b6112278fe 179 typedef struct os_thread_def {
DieterGraef 0:f9b6112278fe 180 os_pthread pthread; ///< start address of thread function
DieterGraef 0:f9b6112278fe 181 osPriority tpriority; ///< initial thread priority
DieterGraef 0:f9b6112278fe 182 uint32_t instances; ///< maximum number of instances of that thread function
DieterGraef 0:f9b6112278fe 183 uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
DieterGraef 0:f9b6112278fe 184 #ifdef __MBED_CMSIS_RTOS_CM
DieterGraef 0:f9b6112278fe 185 uint32_t *stack_pointer; ///< pointer to the stack memory block
DieterGraef 0:f9b6112278fe 186 #endif
DieterGraef 0:f9b6112278fe 187 } osThreadDef_t;
DieterGraef 0:f9b6112278fe 188
DieterGraef 0:f9b6112278fe 189 /// Timer Definition structure contains timer parameters.
DieterGraef 0:f9b6112278fe 190 typedef struct os_timer_def {
DieterGraef 0:f9b6112278fe 191 os_ptimer ptimer; ///< start address of a timer function
DieterGraef 0:f9b6112278fe 192 void *timer; ///< pointer to internal data
DieterGraef 0:f9b6112278fe 193 } osTimerDef_t;
DieterGraef 0:f9b6112278fe 194
DieterGraef 0:f9b6112278fe 195 /// Mutex Definition structure contains setup information for a mutex.
DieterGraef 0:f9b6112278fe 196 typedef struct os_mutex_def {
DieterGraef 0:f9b6112278fe 197 void *mutex; ///< pointer to internal data
DieterGraef 0:f9b6112278fe 198 } osMutexDef_t;
DieterGraef 0:f9b6112278fe 199
DieterGraef 0:f9b6112278fe 200 /// Semaphore Definition structure contains setup information for a semaphore.
DieterGraef 0:f9b6112278fe 201 typedef struct os_semaphore_def {
DieterGraef 0:f9b6112278fe 202 void *semaphore; ///< pointer to internal data
DieterGraef 0:f9b6112278fe 203 } osSemaphoreDef_t;
DieterGraef 0:f9b6112278fe 204
DieterGraef 0:f9b6112278fe 205 /// Definition structure for memory block allocation.
DieterGraef 0:f9b6112278fe 206 typedef struct os_pool_def {
DieterGraef 0:f9b6112278fe 207 uint32_t pool_sz; ///< number of items (elements) in the pool
DieterGraef 0:f9b6112278fe 208 uint32_t item_sz; ///< size of an item
DieterGraef 0:f9b6112278fe 209 void *pool; ///< pointer to memory for pool
DieterGraef 0:f9b6112278fe 210 } osPoolDef_t;
DieterGraef 0:f9b6112278fe 211
DieterGraef 0:f9b6112278fe 212 /// Definition structure for message queue.
DieterGraef 0:f9b6112278fe 213 typedef struct os_messageQ_def {
DieterGraef 0:f9b6112278fe 214 uint32_t queue_sz; ///< number of elements in the queue
DieterGraef 0:f9b6112278fe 215 void *pool; ///< memory array for messages
DieterGraef 0:f9b6112278fe 216 } osMessageQDef_t;
DieterGraef 0:f9b6112278fe 217
DieterGraef 0:f9b6112278fe 218 /// Definition structure for mail queue.
DieterGraef 0:f9b6112278fe 219 typedef struct os_mailQ_def {
DieterGraef 0:f9b6112278fe 220 uint32_t queue_sz; ///< number of elements in the queue
DieterGraef 0:f9b6112278fe 221 uint32_t item_sz; ///< size of an item
DieterGraef 0:f9b6112278fe 222 void *pool; ///< memory array for mail
DieterGraef 0:f9b6112278fe 223 } osMailQDef_t;
DieterGraef 0:f9b6112278fe 224
DieterGraef 0:f9b6112278fe 225 /// Event structure contains detailed information about an event.
DieterGraef 0:f9b6112278fe 226 typedef struct {
DieterGraef 0:f9b6112278fe 227 osStatus status; ///< status code: event or error information
DieterGraef 0:f9b6112278fe 228 union {
DieterGraef 0:f9b6112278fe 229 uint32_t v; ///< message as 32-bit value
DieterGraef 0:f9b6112278fe 230 void *p; ///< message or mail as void pointer
DieterGraef 0:f9b6112278fe 231 int32_t signals; ///< signal flags
DieterGraef 0:f9b6112278fe 232 } value; ///< event value
DieterGraef 0:f9b6112278fe 233 union {
DieterGraef 0:f9b6112278fe 234 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
DieterGraef 0:f9b6112278fe 235 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
DieterGraef 0:f9b6112278fe 236 } def; ///< event definition
DieterGraef 0:f9b6112278fe 237 } osEvent;
DieterGraef 0:f9b6112278fe 238
DieterGraef 0:f9b6112278fe 239
DieterGraef 0:f9b6112278fe 240 // ==== Kernel Control Functions ====
DieterGraef 0:f9b6112278fe 241
DieterGraef 0:f9b6112278fe 242 /// Initialize the RTOS Kernel for creating objects.
DieterGraef 0:f9b6112278fe 243 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 244 osStatus osKernelInitialize (void);
DieterGraef 0:f9b6112278fe 245
DieterGraef 0:f9b6112278fe 246 /// Start the RTOS Kernel.
DieterGraef 0:f9b6112278fe 247 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 248 osStatus osKernelStart (void);
DieterGraef 0:f9b6112278fe 249
DieterGraef 0:f9b6112278fe 250 /// Check if the RTOS kernel is already started.
DieterGraef 0:f9b6112278fe 251 /// \return 0 RTOS is not started, 1 RTOS is started.
DieterGraef 0:f9b6112278fe 252 int32_t osKernelRunning(void);
DieterGraef 0:f9b6112278fe 253
DieterGraef 0:f9b6112278fe 254 #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
DieterGraef 0:f9b6112278fe 255
DieterGraef 0:f9b6112278fe 256 /// \cond INTERNAL_VARIABLES
DieterGraef 0:f9b6112278fe 257 extern uint32_t const os_tickfreq;
DieterGraef 0:f9b6112278fe 258 extern uint16_t const os_tickus_i;
DieterGraef 0:f9b6112278fe 259 extern uint16_t const os_tickus_f;
DieterGraef 0:f9b6112278fe 260 /// \endcond
DieterGraef 0:f9b6112278fe 261
DieterGraef 0:f9b6112278fe 262 /// Get the RTOS kernel system timer counter.
DieterGraef 0:f9b6112278fe 263 /// \return RTOS kernel system timer as 32-bit value
DieterGraef 0:f9b6112278fe 264 uint32_t osKernelSysTick (void);
DieterGraef 0:f9b6112278fe 265
DieterGraef 0:f9b6112278fe 266 /// The RTOS kernel system timer frequency in Hz.
DieterGraef 0:f9b6112278fe 267 /// \note Reflects the system timer setting and is typically defined in a configuration file.
DieterGraef 0:f9b6112278fe 268 #define osKernelSysTickFrequency os_tickfreq
DieterGraef 0:f9b6112278fe 269
DieterGraef 0:f9b6112278fe 270 /// Convert a microseconds value to a RTOS kernel system timer value.
DieterGraef 0:f9b6112278fe 271 /// \param microsec time value in microseconds.
DieterGraef 0:f9b6112278fe 272 /// \return time value normalized to the \ref osKernelSysTickFrequency
DieterGraef 0:f9b6112278fe 273 /*
DieterGraef 0:f9b6112278fe 274 #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
DieterGraef 0:f9b6112278fe 275 */
DieterGraef 0:f9b6112278fe 276 #define osKernelSysTickMicroSec(microsec) ((microsec * os_tickus_i) + ((microsec * os_tickus_f) >> 16))
DieterGraef 0:f9b6112278fe 277
DieterGraef 0:f9b6112278fe 278 #endif // System Timer available
DieterGraef 0:f9b6112278fe 279
DieterGraef 0:f9b6112278fe 280 // ==== Thread Management ====
DieterGraef 0:f9b6112278fe 281
DieterGraef 0:f9b6112278fe 282 /// Create a Thread Definition with function, priority, and stack requirements.
DieterGraef 0:f9b6112278fe 283 /// \param name name of the thread function.
DieterGraef 0:f9b6112278fe 284 /// \param priority initial priority of the thread function.
DieterGraef 0:f9b6112278fe 285 /// \param instances number of possible thread instances.
DieterGraef 0:f9b6112278fe 286 /// \param stacksz stack size (in bytes) requirements for the thread function.
DieterGraef 0:f9b6112278fe 287 /// macro body is implementation specific in every CMSIS-RTOS.
DieterGraef 0:f9b6112278fe 288 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 289 #define osThreadDef(name, priority, instances, stacksz) \
DieterGraef 0:f9b6112278fe 290 extern const osThreadDef_t os_thread_def_##name
DieterGraef 0:f9b6112278fe 291 #else // define the object
DieterGraef 0:f9b6112278fe 292 #ifdef __MBED_CMSIS_RTOS_CM
DieterGraef 0:f9b6112278fe 293 #define osThreadDef(name, priority, stacksz) \
DieterGraef 0:f9b6112278fe 294 uint32_t os_thread_def_stack_##name [stacksz / sizeof(uint32_t)]; \
DieterGraef 0:f9b6112278fe 295 const osThreadDef_t os_thread_def_##name = \
DieterGraef 0:f9b6112278fe 296 { (name), (priority), 1, (stacksz), (os_thread_def_stack_##name) }
DieterGraef 0:f9b6112278fe 297 #else
DieterGraef 0:f9b6112278fe 298 #define osThreadDef(name, priority, instances, stacksz) \
DieterGraef 0:f9b6112278fe 299 const osThreadDef_t os_thread_def_##name = \
DieterGraef 0:f9b6112278fe 300 { (name), (priority), (instances), (stacksz) }
DieterGraef 0:f9b6112278fe 301 #endif
DieterGraef 0:f9b6112278fe 302 #endif
DieterGraef 0:f9b6112278fe 303
DieterGraef 0:f9b6112278fe 304 /// Access a Thread definition.
DieterGraef 0:f9b6112278fe 305 /// \param name name of the thread definition object.
DieterGraef 0:f9b6112278fe 306 /// macro body is implementation specific in every CMSIS-RTOS.
DieterGraef 0:f9b6112278fe 307 #define osThread(name) \
DieterGraef 0:f9b6112278fe 308 &os_thread_def_##name
DieterGraef 0:f9b6112278fe 309
DieterGraef 0:f9b6112278fe 310 /// Create a thread and add it to Active Threads and set it to state READY.
DieterGraef 0:f9b6112278fe 311 /// \param[in] thread_def thread definition referenced with \ref osThread.
DieterGraef 0:f9b6112278fe 312 /// \param[in] argument pointer that is passed to the thread function as start argument.
DieterGraef 0:f9b6112278fe 313 /// \return thread ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 314 osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
DieterGraef 0:f9b6112278fe 315
DieterGraef 0:f9b6112278fe 316 /// Return the thread ID of the current running thread.
DieterGraef 0:f9b6112278fe 317 /// \return thread ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 318 osThreadId osThreadGetId (void);
DieterGraef 0:f9b6112278fe 319
DieterGraef 0:f9b6112278fe 320 /// Terminate execution of a thread and remove it from Active Threads.
DieterGraef 0:f9b6112278fe 321 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
DieterGraef 0:f9b6112278fe 322 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 323 osStatus osThreadTerminate (osThreadId thread_id);
DieterGraef 0:f9b6112278fe 324
DieterGraef 0:f9b6112278fe 325 /// Pass control to next thread that is in state \b READY.
DieterGraef 0:f9b6112278fe 326 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 327 osStatus osThreadYield (void);
DieterGraef 0:f9b6112278fe 328
DieterGraef 0:f9b6112278fe 329 /// Change priority of an active thread.
DieterGraef 0:f9b6112278fe 330 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
DieterGraef 0:f9b6112278fe 331 /// \param[in] priority new priority value for the thread function.
DieterGraef 0:f9b6112278fe 332 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 333 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
DieterGraef 0:f9b6112278fe 334
DieterGraef 0:f9b6112278fe 335 /// Get current priority of an active thread.
DieterGraef 0:f9b6112278fe 336 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
DieterGraef 0:f9b6112278fe 337 /// \return current priority value of the thread function.
DieterGraef 0:f9b6112278fe 338 osPriority osThreadGetPriority (osThreadId thread_id);
DieterGraef 0:f9b6112278fe 339
DieterGraef 0:f9b6112278fe 340 #ifdef __MBED_CMSIS_RTOS_CM
DieterGraef 0:f9b6112278fe 341 /// Get current thread state.
DieterGraef 0:f9b6112278fe 342 uint8_t osThreadGetState (osThreadId thread_id);
DieterGraef 0:f9b6112278fe 343 #endif
DieterGraef 0:f9b6112278fe 344
DieterGraef 0:f9b6112278fe 345 // ==== Generic Wait Functions ====
DieterGraef 0:f9b6112278fe 346
DieterGraef 0:f9b6112278fe 347 /// Wait for Timeout (Time Delay).
DieterGraef 0:f9b6112278fe 348 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "Time delay" value
DieterGraef 0:f9b6112278fe 349 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 350 osStatus osDelay (uint32_t millisec);
DieterGraef 0:f9b6112278fe 351
DieterGraef 0:f9b6112278fe 352 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
DieterGraef 0:f9b6112278fe 353
DieterGraef 0:f9b6112278fe 354 /// Wait for Signal, Message, Mail, or Timeout.
DieterGraef 0:f9b6112278fe 355 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
DieterGraef 0:f9b6112278fe 356 /// \return event that contains signal, message, or mail information or error code.
DieterGraef 0:f9b6112278fe 357 os_InRegs osEvent osWait (uint32_t millisec);
DieterGraef 0:f9b6112278fe 358
DieterGraef 0:f9b6112278fe 359 #endif // Generic Wait available
DieterGraef 0:f9b6112278fe 360
DieterGraef 0:f9b6112278fe 361
DieterGraef 0:f9b6112278fe 362 // ==== Timer Management Functions ====
DieterGraef 0:f9b6112278fe 363 /// Define a Timer object.
DieterGraef 0:f9b6112278fe 364 /// \param name name of the timer object.
DieterGraef 0:f9b6112278fe 365 /// \param function name of the timer call back function.
DieterGraef 0:f9b6112278fe 366 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 367 #define osTimerDef(name, function) \
DieterGraef 0:f9b6112278fe 368 extern const osTimerDef_t os_timer_def_##name
DieterGraef 0:f9b6112278fe 369 #else // define the object
DieterGraef 0:f9b6112278fe 370 #define osTimerDef(name, function) \
DieterGraef 0:f9b6112278fe 371 uint32_t os_timer_cb_##name[6]; \
DieterGraef 0:f9b6112278fe 372 const osTimerDef_t os_timer_def_##name = \
DieterGraef 0:f9b6112278fe 373 { (function), (os_timer_cb_##name) }
DieterGraef 0:f9b6112278fe 374 #endif
DieterGraef 0:f9b6112278fe 375
DieterGraef 0:f9b6112278fe 376 /// Access a Timer definition.
DieterGraef 0:f9b6112278fe 377 /// \param name name of the timer object.
DieterGraef 0:f9b6112278fe 378 #define osTimer(name) \
DieterGraef 0:f9b6112278fe 379 &os_timer_def_##name
DieterGraef 0:f9b6112278fe 380
DieterGraef 0:f9b6112278fe 381 /// Create a timer.
DieterGraef 0:f9b6112278fe 382 /// \param[in] timer_def timer object referenced with \ref osTimer.
DieterGraef 0:f9b6112278fe 383 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
DieterGraef 0:f9b6112278fe 384 /// \param[in] argument argument to the timer call back function.
DieterGraef 0:f9b6112278fe 385 /// \return timer ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 386 osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
DieterGraef 0:f9b6112278fe 387
DieterGraef 0:f9b6112278fe 388 /// Start or restart a timer.
DieterGraef 0:f9b6112278fe 389 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
DieterGraef 0:f9b6112278fe 390 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "Time delay" value of the timer.
DieterGraef 0:f9b6112278fe 391 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 392 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 393
DieterGraef 0:f9b6112278fe 394 /// Stop the timer.
DieterGraef 0:f9b6112278fe 395 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
DieterGraef 0:f9b6112278fe 396 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 397 osStatus osTimerStop (osTimerId timer_id);
DieterGraef 0:f9b6112278fe 398
DieterGraef 0:f9b6112278fe 399 /// Delete a timer that was created by \ref osTimerCreate.
DieterGraef 0:f9b6112278fe 400 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
DieterGraef 0:f9b6112278fe 401 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 402 osStatus osTimerDelete (osTimerId timer_id);
DieterGraef 0:f9b6112278fe 403
DieterGraef 0:f9b6112278fe 404
DieterGraef 0:f9b6112278fe 405 // ==== Signal Management ====
DieterGraef 0:f9b6112278fe 406
DieterGraef 0:f9b6112278fe 407 /// Set the specified Signal Flags of an active thread.
DieterGraef 0:f9b6112278fe 408 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
DieterGraef 0:f9b6112278fe 409 /// \param[in] signals specifies the signal flags of the thread that should be set.
DieterGraef 0:f9b6112278fe 410 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
DieterGraef 0:f9b6112278fe 411 int32_t osSignalSet (osThreadId thread_id, int32_t signals);
DieterGraef 0:f9b6112278fe 412
DieterGraef 0:f9b6112278fe 413 /// Clear the specified Signal Flags of an active thread.
DieterGraef 0:f9b6112278fe 414 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
DieterGraef 0:f9b6112278fe 415 /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
DieterGraef 0:f9b6112278fe 416 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
DieterGraef 0:f9b6112278fe 417 int32_t osSignalClear (osThreadId thread_id, int32_t signals);
DieterGraef 0:f9b6112278fe 418
DieterGraef 0:f9b6112278fe 419 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
DieterGraef 0:f9b6112278fe 420 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
DieterGraef 0:f9b6112278fe 421 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
DieterGraef 0:f9b6112278fe 422 /// \return event flag information or error code.
DieterGraef 0:f9b6112278fe 423 os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec);
DieterGraef 0:f9b6112278fe 424
DieterGraef 0:f9b6112278fe 425
DieterGraef 0:f9b6112278fe 426 // ==== Mutex Management ====
DieterGraef 0:f9b6112278fe 427
DieterGraef 0:f9b6112278fe 428 /// Define a Mutex.
DieterGraef 0:f9b6112278fe 429 /// \param name name of the mutex object.
DieterGraef 0:f9b6112278fe 430 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 431 #define osMutexDef(name) \
DieterGraef 0:f9b6112278fe 432 extern const osMutexDef_t os_mutex_def_##name
DieterGraef 0:f9b6112278fe 433 #else // define the object
DieterGraef 0:f9b6112278fe 434 #define osMutexDef(name) \
DieterGraef 0:f9b6112278fe 435 uint32_t os_mutex_cb_##name[4] = { 0 }; \
DieterGraef 0:f9b6112278fe 436 const osMutexDef_t os_mutex_def_##name = { (os_mutex_cb_##name) }
DieterGraef 0:f9b6112278fe 437 #endif
DieterGraef 0:f9b6112278fe 438
DieterGraef 0:f9b6112278fe 439 /// Access a Mutex definition.
DieterGraef 0:f9b6112278fe 440 /// \param name name of the mutex object.
DieterGraef 0:f9b6112278fe 441 #define osMutex(name) \
DieterGraef 0:f9b6112278fe 442 &os_mutex_def_##name
DieterGraef 0:f9b6112278fe 443
DieterGraef 0:f9b6112278fe 444 /// Create and Initialize a Mutex object.
DieterGraef 0:f9b6112278fe 445 /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
DieterGraef 0:f9b6112278fe 446 /// \return mutex ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 447 osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
DieterGraef 0:f9b6112278fe 448
DieterGraef 0:f9b6112278fe 449 /// Wait until a Mutex becomes available.
DieterGraef 0:f9b6112278fe 450 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
DieterGraef 0:f9b6112278fe 451 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
DieterGraef 0:f9b6112278fe 452 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 453 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 454
DieterGraef 0:f9b6112278fe 455 /// Release a Mutex that was obtained by \ref osMutexWait.
DieterGraef 0:f9b6112278fe 456 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
DieterGraef 0:f9b6112278fe 457 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 458 osStatus osMutexRelease (osMutexId mutex_id);
DieterGraef 0:f9b6112278fe 459
DieterGraef 0:f9b6112278fe 460 /// Delete a Mutex that was created by \ref osMutexCreate.
DieterGraef 0:f9b6112278fe 461 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
DieterGraef 0:f9b6112278fe 462 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 463 osStatus osMutexDelete (osMutexId mutex_id);
DieterGraef 0:f9b6112278fe 464
DieterGraef 0:f9b6112278fe 465
DieterGraef 0:f9b6112278fe 466 // ==== Semaphore Management Functions ====
DieterGraef 0:f9b6112278fe 467
DieterGraef 0:f9b6112278fe 468 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
DieterGraef 0:f9b6112278fe 469
DieterGraef 0:f9b6112278fe 470 /// Define a Semaphore object.
DieterGraef 0:f9b6112278fe 471 /// \param name name of the semaphore object.
DieterGraef 0:f9b6112278fe 472 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 473 #define osSemaphoreDef(name) \
DieterGraef 0:f9b6112278fe 474 extern const osSemaphoreDef_t os_semaphore_def_##name
DieterGraef 0:f9b6112278fe 475 #else // define the object
DieterGraef 0:f9b6112278fe 476 #define osSemaphoreDef(name) \
DieterGraef 0:f9b6112278fe 477 uint32_t os_semaphore_cb_##name[2] = { 0 }; \
DieterGraef 0:f9b6112278fe 478 const osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) }
DieterGraef 0:f9b6112278fe 479 #endif
DieterGraef 0:f9b6112278fe 480
DieterGraef 0:f9b6112278fe 481 /// Access a Semaphore definition.
DieterGraef 0:f9b6112278fe 482 /// \param name name of the semaphore object.
DieterGraef 0:f9b6112278fe 483 #define osSemaphore(name) \
DieterGraef 0:f9b6112278fe 484 &os_semaphore_def_##name
DieterGraef 0:f9b6112278fe 485
DieterGraef 0:f9b6112278fe 486 /// Create and Initialize a Semaphore object used for managing resources.
DieterGraef 0:f9b6112278fe 487 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
DieterGraef 0:f9b6112278fe 488 /// \param[in] count number of available resources.
DieterGraef 0:f9b6112278fe 489 /// \return semaphore ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 490 osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
DieterGraef 0:f9b6112278fe 491
DieterGraef 0:f9b6112278fe 492 /// Wait until a Semaphore token becomes available.
DieterGraef 0:f9b6112278fe 493 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
DieterGraef 0:f9b6112278fe 494 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
DieterGraef 0:f9b6112278fe 495 /// \return number of available tokens, or -1 in case of incorrect parameters.
DieterGraef 0:f9b6112278fe 496 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 497
DieterGraef 0:f9b6112278fe 498 /// Release a Semaphore token.
DieterGraef 0:f9b6112278fe 499 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
DieterGraef 0:f9b6112278fe 500 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 501 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
DieterGraef 0:f9b6112278fe 502
DieterGraef 0:f9b6112278fe 503 /// Delete a Semaphore that was created by \ref osSemaphoreCreate.
DieterGraef 0:f9b6112278fe 504 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
DieterGraef 0:f9b6112278fe 505 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 506 osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
DieterGraef 0:f9b6112278fe 507
DieterGraef 0:f9b6112278fe 508 #endif // Semaphore available
DieterGraef 0:f9b6112278fe 509
DieterGraef 0:f9b6112278fe 510
DieterGraef 0:f9b6112278fe 511 // ==== Memory Pool Management Functions ====
DieterGraef 0:f9b6112278fe 512
DieterGraef 0:f9b6112278fe 513 #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
DieterGraef 0:f9b6112278fe 514
DieterGraef 0:f9b6112278fe 515 /// \brief Define a Memory Pool.
DieterGraef 0:f9b6112278fe 516 /// \param name name of the memory pool.
DieterGraef 0:f9b6112278fe 517 /// \param no maximum number of blocks (objects) in the memory pool.
DieterGraef 0:f9b6112278fe 518 /// \param type data type of a single block (object).
DieterGraef 0:f9b6112278fe 519 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 520 #define osPoolDef(name, no, type) \
DieterGraef 0:f9b6112278fe 521 extern const osPoolDef_t os_pool_def_##name
DieterGraef 0:f9b6112278fe 522 #else // define the object
DieterGraef 0:f9b6112278fe 523 #define osPoolDef(name, no, type) \
DieterGraef 0:f9b6112278fe 524 uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \
DieterGraef 0:f9b6112278fe 525 const osPoolDef_t os_pool_def_##name = \
DieterGraef 0:f9b6112278fe 526 { (no), sizeof(type), (os_pool_m_##name) }
DieterGraef 0:f9b6112278fe 527 #endif
DieterGraef 0:f9b6112278fe 528
DieterGraef 0:f9b6112278fe 529 /// \brief Access a Memory Pool definition.
DieterGraef 0:f9b6112278fe 530 /// \param name name of the memory pool
DieterGraef 0:f9b6112278fe 531 #define osPool(name) \
DieterGraef 0:f9b6112278fe 532 &os_pool_def_##name
DieterGraef 0:f9b6112278fe 533
DieterGraef 0:f9b6112278fe 534 /// Create and Initialize a memory pool.
DieterGraef 0:f9b6112278fe 535 /// \param[in] pool_def memory pool definition referenced with \ref osPool.
DieterGraef 0:f9b6112278fe 536 /// \return memory pool ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 537 osPoolId osPoolCreate (const osPoolDef_t *pool_def);
DieterGraef 0:f9b6112278fe 538
DieterGraef 0:f9b6112278fe 539 /// Allocate a memory block from a memory pool.
DieterGraef 0:f9b6112278fe 540 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
DieterGraef 0:f9b6112278fe 541 /// \return address of the allocated memory block or NULL in case of no memory available.
DieterGraef 0:f9b6112278fe 542 void *osPoolAlloc (osPoolId pool_id);
DieterGraef 0:f9b6112278fe 543
DieterGraef 0:f9b6112278fe 544 /// Allocate a memory block from a memory pool and set memory block to zero.
DieterGraef 0:f9b6112278fe 545 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
DieterGraef 0:f9b6112278fe 546 /// \return address of the allocated memory block or NULL in case of no memory available.
DieterGraef 0:f9b6112278fe 547 void *osPoolCAlloc (osPoolId pool_id);
DieterGraef 0:f9b6112278fe 548
DieterGraef 0:f9b6112278fe 549 /// Return an allocated memory block back to a specific memory pool.
DieterGraef 0:f9b6112278fe 550 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
DieterGraef 0:f9b6112278fe 551 /// \param[in] block address of the allocated memory block that is returned to the memory pool.
DieterGraef 0:f9b6112278fe 552 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 553 osStatus osPoolFree (osPoolId pool_id, void *block);
DieterGraef 0:f9b6112278fe 554
DieterGraef 0:f9b6112278fe 555 #endif // Memory Pool Management available
DieterGraef 0:f9b6112278fe 556
DieterGraef 0:f9b6112278fe 557
DieterGraef 0:f9b6112278fe 558 // ==== Message Queue Management Functions ====
DieterGraef 0:f9b6112278fe 559
DieterGraef 0:f9b6112278fe 560 #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
DieterGraef 0:f9b6112278fe 561
DieterGraef 0:f9b6112278fe 562 /// \brief Create a Message Queue Definition.
DieterGraef 0:f9b6112278fe 563 /// \param name name of the queue.
DieterGraef 0:f9b6112278fe 564 /// \param queue_sz maximum number of messages in the queue.
DieterGraef 0:f9b6112278fe 565 /// \param type data type of a single message element (for debugger).
DieterGraef 0:f9b6112278fe 566 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 567 #define osMessageQDef(name, queue_sz, type) \
DieterGraef 0:f9b6112278fe 568 extern const osMessageQDef_t os_messageQ_def_##name
DieterGraef 0:f9b6112278fe 569 #else // define the object
DieterGraef 0:f9b6112278fe 570 #define osMessageQDef(name, queue_sz, type) \
DieterGraef 0:f9b6112278fe 571 uint32_t os_messageQ_q_##name[4+(queue_sz)] = { 0 }; \
DieterGraef 0:f9b6112278fe 572 const osMessageQDef_t os_messageQ_def_##name = \
DieterGraef 0:f9b6112278fe 573 { (queue_sz), (os_messageQ_q_##name) }
DieterGraef 0:f9b6112278fe 574 #endif
DieterGraef 0:f9b6112278fe 575
DieterGraef 0:f9b6112278fe 576 /// \brief Access a Message Queue Definition.
DieterGraef 0:f9b6112278fe 577 /// \param name name of the queue
DieterGraef 0:f9b6112278fe 578 #define osMessageQ(name) \
DieterGraef 0:f9b6112278fe 579 &os_messageQ_def_##name
DieterGraef 0:f9b6112278fe 580
DieterGraef 0:f9b6112278fe 581 /// Create and Initialize a Message Queue.
DieterGraef 0:f9b6112278fe 582 /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
DieterGraef 0:f9b6112278fe 583 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
DieterGraef 0:f9b6112278fe 584 /// \return message queue ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 585 osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
DieterGraef 0:f9b6112278fe 586
DieterGraef 0:f9b6112278fe 587 /// Put a Message to a Queue.
DieterGraef 0:f9b6112278fe 588 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
DieterGraef 0:f9b6112278fe 589 /// \param[in] info message information.
DieterGraef 0:f9b6112278fe 590 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
DieterGraef 0:f9b6112278fe 591 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 592 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
DieterGraef 0:f9b6112278fe 593
DieterGraef 0:f9b6112278fe 594 /// Get a Message or Wait for a Message from a Queue.
DieterGraef 0:f9b6112278fe 595 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
DieterGraef 0:f9b6112278fe 596 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
DieterGraef 0:f9b6112278fe 597 /// \return event information that includes status code.
DieterGraef 0:f9b6112278fe 598 os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 599
DieterGraef 0:f9b6112278fe 600 #endif // Message Queues available
DieterGraef 0:f9b6112278fe 601
DieterGraef 0:f9b6112278fe 602
DieterGraef 0:f9b6112278fe 603 // ==== Mail Queue Management Functions ====
DieterGraef 0:f9b6112278fe 604
DieterGraef 0:f9b6112278fe 605 #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
DieterGraef 0:f9b6112278fe 606
DieterGraef 0:f9b6112278fe 607 /// \brief Create a Mail Queue Definition.
DieterGraef 0:f9b6112278fe 608 /// \param name name of the queue
DieterGraef 0:f9b6112278fe 609 /// \param queue_sz maximum number of messages in queue
DieterGraef 0:f9b6112278fe 610 /// \param type data type of a single message element
DieterGraef 0:f9b6112278fe 611 #if defined (osObjectsExternal) // object is external
DieterGraef 0:f9b6112278fe 612 #define osMailQDef(name, queue_sz, type) \
DieterGraef 0:f9b6112278fe 613 extern const osMailQDef_t os_mailQ_def_##name
DieterGraef 0:f9b6112278fe 614 #else // define the object
DieterGraef 0:f9b6112278fe 615 #define osMailQDef(name, queue_sz, type) \
DieterGraef 0:f9b6112278fe 616 uint32_t os_mailQ_q_##name[4+(queue_sz)] = { 0 }; \
DieterGraef 0:f9b6112278fe 617 uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \
DieterGraef 0:f9b6112278fe 618 void * os_mailQ_p_##name[2] = { (os_mailQ_q_##name), os_mailQ_m_##name }; \
DieterGraef 0:f9b6112278fe 619 const osMailQDef_t os_mailQ_def_##name = \
DieterGraef 0:f9b6112278fe 620 { (queue_sz), sizeof(type), (os_mailQ_p_##name) }
DieterGraef 0:f9b6112278fe 621 #endif
DieterGraef 0:f9b6112278fe 622
DieterGraef 0:f9b6112278fe 623 /// \brief Access a Mail Queue Definition.
DieterGraef 0:f9b6112278fe 624 /// \param name name of the queue
DieterGraef 0:f9b6112278fe 625 #define osMailQ(name) \
DieterGraef 0:f9b6112278fe 626 &os_mailQ_def_##name
DieterGraef 0:f9b6112278fe 627
DieterGraef 0:f9b6112278fe 628 /// Create and Initialize mail queue.
DieterGraef 0:f9b6112278fe 629 /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
DieterGraef 0:f9b6112278fe 630 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
DieterGraef 0:f9b6112278fe 631 /// \return mail queue ID for reference by other functions or NULL in case of error.
DieterGraef 0:f9b6112278fe 632 osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
DieterGraef 0:f9b6112278fe 633
DieterGraef 0:f9b6112278fe 634 /// Allocate a memory block from a mail.
DieterGraef 0:f9b6112278fe 635 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
DieterGraef 0:f9b6112278fe 636 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
DieterGraef 0:f9b6112278fe 637 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
DieterGraef 0:f9b6112278fe 638 void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 639
DieterGraef 0:f9b6112278fe 640 /// Allocate a memory block from a mail and set memory block to zero.
DieterGraef 0:f9b6112278fe 641 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
DieterGraef 0:f9b6112278fe 642 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
DieterGraef 0:f9b6112278fe 643 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
DieterGraef 0:f9b6112278fe 644 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 645
DieterGraef 0:f9b6112278fe 646 /// Put a mail to a queue.
DieterGraef 0:f9b6112278fe 647 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
DieterGraef 0:f9b6112278fe 648 /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
DieterGraef 0:f9b6112278fe 649 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 650 osStatus osMailPut (osMailQId queue_id, void *mail);
DieterGraef 0:f9b6112278fe 651
DieterGraef 0:f9b6112278fe 652 /// Get a mail from a queue.
DieterGraef 0:f9b6112278fe 653 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
DieterGraef 0:f9b6112278fe 654 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
DieterGraef 0:f9b6112278fe 655 /// \return event that contains mail information or error code.
DieterGraef 0:f9b6112278fe 656 os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
DieterGraef 0:f9b6112278fe 657
DieterGraef 0:f9b6112278fe 658 /// Free a memory block from a mail.
DieterGraef 0:f9b6112278fe 659 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
DieterGraef 0:f9b6112278fe 660 /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
DieterGraef 0:f9b6112278fe 661 /// \return status code that indicates the execution status of the function.
DieterGraef 0:f9b6112278fe 662 osStatus osMailFree (osMailQId queue_id, void *mail);
DieterGraef 0:f9b6112278fe 663
DieterGraef 0:f9b6112278fe 664 #endif // Mail Queues available
DieterGraef 0:f9b6112278fe 665
DieterGraef 0:f9b6112278fe 666
DieterGraef 0:f9b6112278fe 667 // ==== RTX Extensions ====
DieterGraef 0:f9b6112278fe 668
DieterGraef 0:f9b6112278fe 669 /// Suspend the RTX task scheduler.
DieterGraef 0:f9b6112278fe 670 /// \return number of ticks, for how long the system can sleep or power-down.
DieterGraef 0:f9b6112278fe 671 uint32_t os_suspend (void);
DieterGraef 0:f9b6112278fe 672
DieterGraef 0:f9b6112278fe 673 /// Resume the RTX task scheduler
DieterGraef 0:f9b6112278fe 674 /// \param[in] sleep_time specifies how long the system was in sleep or power-down mode.
DieterGraef 0:f9b6112278fe 675 void os_resume (uint32_t sleep_time);
DieterGraef 0:f9b6112278fe 676
DieterGraef 0:f9b6112278fe 677
DieterGraef 0:f9b6112278fe 678 #ifdef __cplusplus
DieterGraef 0:f9b6112278fe 679 }
DieterGraef 0:f9b6112278fe 680 #endif
DieterGraef 0:f9b6112278fe 681
DieterGraef 0:f9b6112278fe 682 #endif // _CMSIS_OS_H