RTOS lib used for Eurobot 2012
Dependents: Eurobot2012_Secondary Team_Sprint2 Team_Sprint2 Rafi_Final ... more
cmsis_os.h
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2012 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 5. March 2012 00005 * $Revision: V0.03 00006 * 00007 * Project: CMSIS-RTOS API 00008 * Title: cmsis_os.h RTX header file 00009 * 00010 * Version 0.02 00011 * Initial Proposal Phase 00012 * Version 0.03 00013 * osKernelStart added, optional feature: main started as thread 00014 * osSemaphores have standard behaviour 00015 * osTimerCreate does not start the timer, added osTimerStart 00016 * osThreadPass is renamed to osThreadYield 00017 * -------------------------------------------------------------------- */ 00018 00019 /** 00020 \page cmsis_os_h Header File Template: cmsis_os.h 00021 00022 The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS). 00023 Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents 00024 its implementation. 00025 00026 The file cmsis_os.h contains: 00027 - CMSIS-RTOS API function definitions 00028 - struct definitions for parameters and return types 00029 - status and priority values used by CMSIS-RTOS API functions 00030 - macros for defining threads and other kernel objects 00031 00032 00033 <b>Name conventions and header file modifications</b> 00034 00035 All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions. 00036 Definitions that are prefixed \b os_ are not used in the application code but local to this header file. 00037 All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread. 00038 00039 Definitions that are marked with <b>CAN BE CHANGED</b> can be adapted towards the needs of the actual CMSIS-RTOS implementation. 00040 These definitions can be specific to the underlying RTOS kernel. 00041 00042 Definitions that are marked with <b>MUST REMAIN UNCHANGED</b> cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer 00043 compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation. 00044 00045 00046 <b>Function calls from interrupt service routines</b> 00047 00048 The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR): 00049 - \ref osSignalSet 00050 - \ref osSemaphoreRelease 00051 - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree 00052 - \ref osMessagePut, \ref osMessageGet 00053 - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree 00054 00055 Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called 00056 from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector. 00057 00058 Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time. 00059 If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive. 00060 00061 00062 <b>Define and reference object definitions</b> 00063 00064 With <b>\#define osObjectsExternal</b> objects are defined as external symbols. This allows to create a consistent header file 00065 that is used troughtout a project as shown below: 00066 00067 <i>Header File</i> 00068 \code 00069 #include <cmsis_os.h> // CMSIS RTOS header file 00070 00071 // Thread definition 00072 extern void thread_sample (void const *argument); // function prototype 00073 osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100); 00074 00075 // Pool definition 00076 osPoolDef(MyPool, 10, long); 00077 \endcode 00078 00079 00080 This header file defines all objects when included in a C/C++ source file. When <b>\#define osObjectsExternal</b> is 00081 present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be 00082 used throughout the whole project. 00083 00084 <i>Example</i> 00085 \code 00086 #include "osObjects.h" // Definition of the CMSIS-RTOS objects 00087 \endcode 00088 00089 \code 00090 #define osObjectExternal // Objects will be defined as external symbols 00091 #include "osObjects.h" // Reference to the CMSIS-RTOS objects 00092 \endcode 00093 00094 */ 00095 00096 #ifndef _CMSIS_OS_H 00097 #define _CMSIS_OS_H 00098 00099 /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version 00100 #define osCMSIS 0x10000 ///< API version (main [31:16] .sub [15:0]) 00101 00102 /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlaying RTOS kernel and version number. 00103 #define osCMSIS_RTX 0x0003 ///< RTOS identification and version (main [31:16] .sub [15:0]) 00104 00105 /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS. 00106 #define osKernelSystemId "RTX V0.03" ///< RTOS identification string 00107 00108 00109 #define CMSIS_OS_RTX 00110 00111 #ifdef TOOLCHAIN_GCC_ARM 00112 # define WORDS_STACK_SIZE 512 00113 #else 00114 # if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00115 # define WORDS_STACK_SIZE 256 00116 # elif defined(TARGET_LPC11U24) 00117 # define WORDS_STACK_SIZE 128 00118 # endif 00119 #endif 00120 00121 #define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4) 00122 00123 00124 /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. 00125 #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available 00126 #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available 00127 #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available 00128 #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available 00129 #define osFeature_Signals 16 ///< maximum number of Signal Flags available per thread 00130 #define osFeature_Semaphore 8 ///< maximum count for SemaphoreInit function 00131 #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available 00132 00133 #if defined (__CC_ARM) 00134 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers 00135 #else 00136 #define os_InRegs 00137 #endif 00138 00139 #include <stdint.h> 00140 #include <stddef.h> 00141 00142 #ifdef __cplusplus 00143 extern "C" 00144 { 00145 #endif 00146 00147 00148 // ==== Enumeration, structures, defines ==== 00149 00150 /// Priority used for thread control. 00151 /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS. 00152 typedef enum { 00153 osPriorityIdle = -3, ///< priority: idle (lowest) 00154 osPriorityLow = -2, ///< priority: low 00155 osPriorityBelowNormal = -1, ///< priority: below normal 00156 osPriorityNormal = 0, ///< priority: normal (default) 00157 osPriorityAboveNormal = +1, ///< priority: above normal 00158 osPriorityHigh = +2, ///< priority: high 00159 osPriorityRealtime = +3, ///< priority: realtime (highest) 00160 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority 00161 } osPriority; 00162 00163 /// Timeout value 00164 /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS. 00165 #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value 00166 00167 /// Status code values returned by CMSIS-RTOS functions 00168 /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS. 00169 typedef enum { 00170 osOK = 0, ///< function completed; no event occurred. 00171 osEventSignal = 0x08, ///< function completed; signal event occurred. 00172 osEventMessage = 0x10, ///< function completed; message event occurred. 00173 osEventMail = 0x20, ///< function completed; mail event occurred. 00174 osEventTimeout = 0x40, ///< function completed; timeout occurred. 00175 osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. 00176 osErrorResource = 0x81, ///< resource not available: a specified resource was not available. 00177 osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. 00178 osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. 00179 osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. 00180 osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. 00181 osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. 00182 osErrorValue = 0x86, ///< value of a parameter is out of range. 00183 osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. 00184 os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. 00185 } osStatus; 00186 00187 00188 /// Timer type value for the timer definition 00189 /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS. 00190 typedef enum { 00191 osTimerOnce = 0, ///< one-shot timer 00192 osTimerPeriodic = 1 ///< repeating timer 00193 } os_timer_type; 00194 00195 /// Entry point of a thread. 00196 /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS. 00197 typedef void (*os_pthread) (void const *argument); 00198 00199 /// Entry point of a timer call back function. 00200 /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS. 00201 typedef void (*os_ptimer) (void const *argument); 00202 00203 // >>> the following data type definitions may shall adapted towards a specific RTOS 00204 00205 /// Thread ID identifies the thread (pointer to a thread control block). 00206 /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS. 00207 typedef struct os_thread_cb *osThreadId; 00208 00209 /// Timer ID identifies the timer (pointer to a timer control block). 00210 /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS. 00211 typedef struct os_timer_cb *osTimerId; 00212 00213 /// Mutex ID identifies the mutex (pointer to a mutex control block). 00214 /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS. 00215 typedef struct os_mutex_cb *osMutexId; 00216 00217 /// Semaphore ID identifies the semaphore (pointer to a semaphore control block). 00218 /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS. 00219 typedef struct os_semaphore_cb *osSemaphoreId; 00220 00221 /// Pool ID identifies the memory pool (pointer to a memory pool control block). 00222 /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. 00223 typedef struct os_pool_cb *osPoolId; 00224 00225 /// Message ID identifies the message queue (pointer to a message queue control block). 00226 /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. 00227 typedef struct os_messageQ_cb *osMessageQId; 00228 00229 /// Mail ID identifies the mail queue (pointer to a mail queue control block). 00230 /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS. 00231 typedef struct os_mailQ_cb *osMailQId; 00232 00233 00234 /// Thread Definition structure contains startup information of a thread. 00235 /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. 00236 typedef struct os_thread_def { 00237 os_pthread pthread; ///< start address of thread function 00238 osPriority tpriority; ///< initial thread priority 00239 uint32_t instances; ///< maximum number of instances of that thread function 00240 uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size 00241 } osThreadDef_t; 00242 00243 /// Timer Definition structure contains timer parameters. 00244 /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. 00245 typedef struct os_timer_def { 00246 os_ptimer ptimer; ///< start address of a timer function 00247 void *timer; ///< pointer to internal data 00248 } osTimerDef_t; 00249 00250 /// Mutex Definition structure contains setup information for a mutex. 00251 /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. 00252 typedef struct os_mutex_def { 00253 void *mutex; ///< pointer to internal data 00254 } osMutexDef_t; 00255 00256 /// Semaphore Definition structure contains setup information for a semaphore. 00257 /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. 00258 typedef struct os_semaphore_def { 00259 void *semaphore; ///< pointer to internal data 00260 } osSemaphoreDef_t; 00261 00262 /// Definition structure for memory block allocation 00263 /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. 00264 typedef struct os_pool_def { 00265 uint32_t pool_sz; ///< number of items (elements) in the pool 00266 uint32_t item_sz; ///< size of an item 00267 void *pool; ///< pointer to memory for pool 00268 } osPoolDef_t; 00269 00270 /// Definition structure for message queue 00271 /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. 00272 typedef struct os_messageQ_def { 00273 uint32_t queue_sz; ///< number of elements in the queue 00274 void *pool; ///< memory array for messages 00275 } osMessageQDef_t; 00276 00277 /// Definition structure for mail queue 00278 /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. 00279 typedef struct os_mailQ_def { 00280 uint32_t queue_sz; ///< number of elements in the queue 00281 uint32_t item_sz; ///< size of an item 00282 void *pool; ///< memory array for mail 00283 } osMailQDef_t; 00284 00285 /// Event structure contains detailed information about an event. 00286 /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS. 00287 /// However the struct may be extended at the end. 00288 typedef struct { 00289 osStatus status; ///< status code: event or error information 00290 union { 00291 uint32_t v; ///< message as 32-bit value 00292 void *p; ///< message or mail as void pointer 00293 int32_t signals; ///< signal flags 00294 } value; ///< event value 00295 union { 00296 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate 00297 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate 00298 } def; ///< event definition 00299 } osEvent; 00300 00301 00302 // ==== Kernel Control Functions ==== 00303 00304 /// Start the RTOS Kernel with executing the specified thread. 00305 /// \param[in] thread_def thread definition referenced with \ref osThread. 00306 /// \param[in] argument pointer that is passed to the thread function as start argument. 00307 /// \return status code that indicates the execution status of the function. 00308 /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. 00309 osStatus osKernelStart (osThreadDef_t *thread_def, void *argument); 00310 00311 /// Check if the RTOS kernel is already started. 00312 /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. 00313 /// \return 0 RTOS is not started, 1 RTOS is started. 00314 int32_t osKernelRunning(void); 00315 00316 00317 // ==== Thread Management ==== 00318 00319 /// Create a Thread Definition with function, priority, and stack requirements. 00320 /// \param name name of the thread function. 00321 /// \param priority initial priority of the thread function. 00322 /// \param instances number of possible thread instances. 00323 /// \param stacksz stack size (in bytes) requirements for the thread function. 00324 /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the 00325 /// macro body is implementation specific in every CMSIS-RTOS. 00326 #if defined (osObjectsExternal) // object is external 00327 #define osThreadDef(name, priority, instances, stacksz) \ 00328 extern osThreadDef_t os_thread_def_##name 00329 #else // define the object 00330 #define osThreadDef(name, priority, instances, stacksz) \ 00331 osThreadDef_t os_thread_def_##name = \ 00332 { (name), (priority), (instances), (stacksz) } 00333 #endif 00334 00335 /// Access a Thread defintion. 00336 /// \param name name of the thread definition object. 00337 /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the 00338 /// macro body is implementation specific in every CMSIS-RTOS. 00339 #define osThread(name) \ 00340 &os_thread_def_##name 00341 00342 00343 /// Create a thread and add it to Active Threads and set it to state READY. 00344 /// \param[in] thread_def thread definition referenced with \ref osThread. 00345 /// \param[in] argument pointer that is passed to the thread function as start argument. 00346 /// \return thread ID for reference by other functions or NULL in case of error. 00347 /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. 00348 osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument); 00349 00350 /// Return the thread ID of the current running thread. 00351 /// \return thread ID for reference by other functions or NULL in case of error. 00352 /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. 00353 osThreadId osThreadGetId (void); 00354 00355 /// Terminate execution of a thread and remove it from Active Threads. 00356 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00357 /// \return status code that indicates the execution status of the function. 00358 /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. 00359 osStatus osThreadTerminate (osThreadId thread_id); 00360 00361 /// Pass control to next thread that is in state \b READY. 00362 /// \return status code that indicates the execution status of the function. 00363 /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. 00364 osStatus osThreadYield (void); 00365 00366 /// Change priority of an active thread. 00367 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00368 /// \param[in] priority new priority value for the thread function. 00369 /// \return status code that indicates the execution status of the function. 00370 /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. 00371 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); 00372 00373 /// Get current priority of an active thread. 00374 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00375 /// \return current priority value of the thread function. 00376 /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. 00377 osPriority osThreadGetPriority (osThreadId thread_id); 00378 00379 00380 00381 // ==== Generic Wait Functions ==== 00382 00383 /// Wait for Timeout (Time Delay) 00384 /// \param[in] millisec time delay value 00385 /// \return status code that indicates the execution status of the function. 00386 osStatus osDelay (uint32_t millisec); 00387 00388 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available 00389 00390 /// Wait for Signal, Message, Mail, or Timeout 00391 /// \param[in] millisec timeout value or 0 in case of no time-out 00392 /// \return event that contains signal, message, or mail information or error code. 00393 /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. 00394 os_InRegs osEvent osWait (uint32_t millisec); 00395 00396 #endif // Generic Wait available 00397 00398 00399 // ==== Timer Management Functions ==== 00400 /// Define a Timer object. 00401 /// \param name name of the timer object. 00402 /// \param function name of the timer call back function. 00403 /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the 00404 /// macro body is implementation specific in every CMSIS-RTOS. 00405 #if defined (osObjectsExternal) // object is external 00406 #define osTimerDef(name, function) \ 00407 extern osTimerDef_t os_timer_def_##name 00408 #else // define the object 00409 #define osTimerDef(name, function) \ 00410 uint32_t os_timer_cb_##name[5]; \ 00411 osTimerDef_t os_timer_def_##name = \ 00412 { (function), (os_timer_cb_##name) } 00413 #endif 00414 00415 /// Access a Timer definition. 00416 /// \param name name of the timer object. 00417 /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the 00418 /// macro body is implementation specific in every CMSIS-RTOS. 00419 #define osTimer(name) \ 00420 &os_timer_def_##name 00421 00422 /// Create a timer. 00423 /// \param[in] timer_def timer object referenced with \ref osTimer. 00424 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. 00425 /// \param[in] argument argument to the timer call back function. 00426 /// \return timer ID for reference by other functions or NULL in case of error. 00427 /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. 00428 osTimerId osTimerCreate (osTimerDef_t *timer_def, os_timer_type type, void *argument); 00429 00430 /// Start or restart a timer. 00431 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 00432 /// \param[in] millisec time delay value of the timer. 00433 /// \return status code that indicates the execution status of the function. 00434 /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. 00435 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); 00436 00437 /// Stop the timer. 00438 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. 00439 /// \return status code that indicates the execution status of the function. 00440 /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. 00441 osStatus osTimerStop (osTimerId timer_id); 00442 00443 00444 // ==== Signal Management ==== 00445 00446 /// Set the specified Signal Flags of an active thread. 00447 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00448 /// \param[in] signals specifies the signal flags of the thread that should be set. 00449 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 00450 /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. 00451 int32_t osSignalSet (osThreadId thread_id, int32_t signal); 00452 00453 /// Clear the specified Signal Flags of an active thread. 00454 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00455 /// \param[in] signals specifies the signal flags of the thread that shall be cleared. 00456 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 00457 /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. 00458 int32_t osSignalClear (osThreadId thread_id, int32_t signal); 00459 00460 /// Get Signal Flags status of an active thread. 00461 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. 00462 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. 00463 /// \note MUST REMAIN UNCHANGED: \b osSignalGet shall be consistent in every CMSIS-RTOS. 00464 int32_t osSignalGet (osThreadId thread_id); 00465 00466 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. 00467 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. 00468 /// \param[in] millisec timeout value or 0 in case of no time-out. 00469 /// \return event flag information or error code. 00470 /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. 00471 os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec); 00472 00473 00474 // ==== Mutex Management ==== 00475 00476 /// Define a Mutex. 00477 /// \param name name of the mutex object. 00478 /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the 00479 /// macro body is implementation specific in every CMSIS-RTOS. 00480 #if defined (osObjectsExternal) // object is external 00481 #define osMutexDef(name) \ 00482 extern osMutexDef_t os_mutex_def_##name 00483 #else // define the object 00484 #define osMutexDef(name) \ 00485 uint32_t os_mutex_cb_##name[3]; \ 00486 osMutexDef_t os_mutex_def_##name = { (os_mutex_cb_##name) } 00487 #endif 00488 00489 /// Access a Mutex defintion. 00490 /// \param name name of the mutex object. 00491 /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the 00492 /// macro body is implementation specific in every CMSIS-RTOS. 00493 #define osMutex(name) \ 00494 &os_mutex_def_##name 00495 00496 /// Create and Initialize a Mutex object 00497 /// \param[in] mutex_def mutex definition referenced with \ref osMutex. 00498 /// \return mutex ID for reference by other functions or NULL in case of error. 00499 /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. 00500 osMutexId osMutexCreate (osMutexDef_t *mutex_def); 00501 00502 /// Wait until a Mutex becomes available 00503 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 00504 /// \param[in] millisec timeout value or 0 in case of no time-out. 00505 /// \return status code that indicates the execution status of the function. 00506 /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. 00507 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); 00508 00509 /// Release a Mutex that was obtained by \ref osMutexWait 00510 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. 00511 /// \return status code that indicates the execution status of the function. 00512 /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. 00513 osStatus osMutexRelease (osMutexId mutex_id); 00514 00515 00516 // ==== Semaphore Management Functions ==== 00517 00518 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available 00519 00520 /// Define a Semaphore object. 00521 /// \param name name of the semaphore object. 00522 /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the 00523 /// macro body is implementation specific in every CMSIS-RTOS. 00524 #if defined (osObjectsExternal) // object is external 00525 #define osSemaphoreDef(name) \ 00526 extern osSemaphoreDef_t os_semaphore_def_##name 00527 #else // define the object 00528 #define osSemaphoreDef(name) \ 00529 uint32_t os_semaphore_cb_##name[2]; \ 00530 osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) } 00531 #endif 00532 00533 /// Access a Semaphore definition. 00534 /// \param name name of the semaphore object. 00535 /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the 00536 /// macro body is implementation specific in every CMSIS-RTOS. 00537 #define osSemaphore(name) \ 00538 &os_semaphore_def_##name 00539 00540 /// Create and Initialize a Semaphore object used for managing resources 00541 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. 00542 /// \param[in] count number of available resources. 00543 /// \return semaphore ID for reference by other functions or NULL in case of error. 00544 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. 00545 osSemaphoreId osSemaphoreCreate (osSemaphoreDef_t *semaphore_def, int32_t count); 00546 00547 /// Wait until a Semaphore token becomes available 00548 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphore. 00549 /// \param[in] millisec timeout value or 0 in case of no time-out. 00550 /// \return number of available tokens, or -1 in case of incorrect parameters. 00551 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. 00552 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); 00553 00554 /// Release a Semaphore token 00555 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphore. 00556 /// \return status code that indicates the execution status of the function. 00557 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. 00558 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); 00559 00560 #endif // Semaphore available 00561 00562 // ==== Memory Pool Management Functions ==== 00563 00564 #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available 00565 00566 /// \brief Define a Memory Pool. 00567 /// \param name name of the memory pool. 00568 /// \param no maximum number of objects (elements) in the memory pool. 00569 /// \param type data type of a single object (element). 00570 /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the 00571 /// macro body is implementation specific in every CMSIS-RTOS. 00572 #if defined (osObjectsExternal) // object is external 00573 #define osPoolDef(name, no, type) \ 00574 extern osPoolDef_t os_pool_def_##name 00575 #else // define the object 00576 #define osPoolDef(name, no, type) \ 00577 uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \ 00578 osPoolDef_t os_pool_def_##name = \ 00579 { (no), sizeof(type), (os_pool_m_##name) } 00580 #endif 00581 00582 /// \brief Access a Memory Pool definition. 00583 /// \param name name of the memory pool 00584 /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the 00585 /// macro body is implementation specific in every CMSIS-RTOS. 00586 #define osPool(name) \ 00587 &os_pool_def_##name 00588 00589 /// Create and Initialize a memory pool 00590 /// \param[in] pool_def memory pool definition referenced with \ref osPool. 00591 /// \return memory pool ID for reference by other functions or NULL in case of error. 00592 /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. 00593 osPoolId osPoolCreate (osPoolDef_t *pool_def); 00594 00595 /// Allocate a memory block from a memory pool 00596 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 00597 /// \return address of the allocated memory block or NULL in case of no memory available. 00598 /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. 00599 void *osPoolAlloc (osPoolId pool_id); 00600 00601 /// Allocate a memory block from a memory pool and set memory block to zero 00602 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 00603 /// \return address of the allocated memory block or NULL in case of no memory available. 00604 /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. 00605 void *osPoolCAlloc (osPoolId pool_id); 00606 00607 /// Return an allocated memory block back to a specific memory pool 00608 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. 00609 /// \param[in] block address of the allocated memory block that is returned to the memory pool. 00610 /// \return status code that indicates the execution status of the function. 00611 /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. 00612 osStatus osPoolFree (osPoolId pool_id, void *block); 00613 00614 #endif // Memory Pool Management available 00615 00616 00617 // ==== Message Queue Management Functions ==== 00618 00619 #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available 00620 00621 /// \brief Create a Message Queue Definition. 00622 /// \param name name of the queue. 00623 /// \param queue_sz maximum number of messages in the queue. 00624 /// \param type data type of a single message element (for debugger). 00625 /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the 00626 /// macro body is implementation specific in every CMSIS-RTOS. 00627 #if defined (osObjectsExternal) // object is external 00628 #define osMessageQDef(name, queue_sz, type) \ 00629 extern osMessageQDef_t os_messageQ_def_##name 00630 #else // define the object 00631 #define osMessageQDef(name, queue_sz, type) \ 00632 uint32_t os_messageQ_q_##name[4+(queue_sz)]; \ 00633 osMessageQDef_t os_messageQ_def_##name = \ 00634 { (queue_sz), (os_messageQ_q_##name) } 00635 #endif 00636 00637 /// \brief Access a Message Queue Definition. 00638 /// \param name name of the queue 00639 /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the 00640 /// macro body is implementation specific in every CMSIS-RTOS. 00641 #define osMessageQ(name) \ 00642 &os_messageQ_def_##name 00643 00644 /// Create and Initialize a Message Queue. 00645 /// \param[in] queue_def queue definition referenced with \ref osMessageQ. 00646 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 00647 /// \return message queue ID for reference by other functions or NULL in case of error. 00648 /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. 00649 osMessageQId osMessageCreate (osMessageQDef_t *queue_def, osThreadId thread_id); 00650 00651 /// Put a Message to a Queue. 00652 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 00653 /// \param[in] info message information. 00654 /// \param[in] millisec timeout value or 0 in case of no time-out. 00655 /// \return status code that indicates the execution status of the function. 00656 /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. 00657 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); 00658 00659 /// Get a Message or Wait for a Message from a Queue. 00660 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. 00661 /// \param[in] millisec timeout value or 0 in case of no time-out. 00662 /// \return event information that includes status code. 00663 /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. 00664 os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); 00665 00666 #endif // Message Queues available 00667 00668 00669 // ==== Mail Queue Management Functions ==== 00670 00671 #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available 00672 00673 /// \brief Create a Mail Queue Definition 00674 /// \param name name of the queue 00675 /// \param queue_sz maximum number of messages in queue 00676 /// \param type data type of a single message element 00677 /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the 00678 /// macro body is implementation specific in every CMSIS-RTOS. 00679 #if defined (osObjectsExternal) // object is external 00680 #define osMailQDef(name, queue_sz, type) \ 00681 extern osMailQDef_t os_mailQ_def_##name 00682 #else // define the object 00683 #define osMailQDef(name, queue_sz, type) \ 00684 uint32_t os_mailQ_q_##name[4+(queue_sz)]; \ 00685 uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \ 00686 void * os_mailQ_p_##name[2] = { (os_mailQ_q_##name), os_mailQ_m_##name }; \ 00687 osMailQDef_t os_mailQ_def_##name = \ 00688 { (queue_sz), sizeof(type), (os_mailQ_p_##name) } 00689 #endif 00690 00691 /// \brief Access a Mail Queue Definition 00692 /// \param name name of the queue 00693 /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the 00694 /// macro body is implementation specific in every CMSIS-RTOS. 00695 #define osMailQ(name) \ 00696 &os_mailQ_def_##name 00697 00698 /// Create and Initialize mail queue 00699 /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ 00700 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. 00701 /// \return mail queue ID for reference by other functions or NULL in case of error. 00702 /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. 00703 osMailQId osMailCreate (osMailQDef_t *queue_def, osThreadId thread_id); 00704 00705 /// Allocate a memory block from a mail 00706 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 00707 /// \param[in] millisec timeout value or 0 in case of no time-out 00708 /// \return pointer to memory block that can be filled with mail or NULL in case error. 00709 /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. 00710 void *osMailAlloc (osMailQId queue_id, uint32_t millisec); 00711 00712 /// Allocate a memory block from a mail and set memory block to zero 00713 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 00714 /// \param[in] millisec timeout value or 0 in case of no time-out 00715 /// \return pointer to memory block that can shall filled with mail or NULL in case error. 00716 /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. 00717 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); 00718 00719 /// Put a mail to a queue 00720 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 00721 /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. 00722 /// \return status code that indicates the execution status of the function. 00723 /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. 00724 osStatus osMailPut (osMailQId queue_id, void *mail); 00725 00726 /// Get a mail from a queue 00727 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 00728 /// \param[in] millisec timeout value or 0 in case of no time-out 00729 /// \return event that contains mail information or error code. 00730 /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. 00731 os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec); 00732 00733 /// Free a memory block from a mail 00734 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. 00735 /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet. 00736 /// \return status code that indicates the execution status of the function. 00737 /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. 00738 osStatus osMailFree (osMailQId queue_id, void *mail); 00739 00740 #endif // Mail Queues available 00741 00742 /// Set Thread Error (for Create funcions which return IDs) 00743 extern void sysThreadError(osStatus status); 00744 00745 #ifdef __cplusplus 00746 } 00747 #endif 00748 00749 #endif // _CMSIS_OS_H
Generated on Wed Jul 13 2022 19:50:35 by 1.7.2