2 * Copyright (c) 2013-2019 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * ----------------------------------------------------------------------
20 * $Date: 10. January 2017
23 * Project: CMSIS-RTOS API
24 * Title: cmsis_os.h FreeRTOS header file
27 * Initial Proposal Phase
29 * osKernelStart added, optional feature: main started as thread
30 * osSemaphores have standard behavior
31 * osTimerCreate does not start the timer, added osTimerStart
32 * osThreadPass is renamed to osThreadYield
34 * Support for C++ interface
35 * - const attribute removed from the osXxxxDef_t typedefs
36 * - const attribute added to the osXxxxDef macros
37 * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
38 * Added: osKernelInitialize
40 * Control functions for short timeouts in microsecond resolution:
41 * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
42 * Removed: osSignalGet
44 * OS objects creation without macros (dynamic creation and resource allocation):
45 * - added: osXxxxNew functions which replace osXxxxCreate
46 * - added: osXxxxAttr_t structures
47 * - deprecated: osXxxxCreate functions, osXxxxDef_t structures
48 * - deprecated: osXxxxDef and osXxxx macros
49 * osStatus codes simplified and renamed to osStatus_t
50 * osEvent return structure deprecated
52 * - added: osKernelInfo_t and osKernelGetInfo
53 * - added: osKernelState_t and osKernelGetState (replaces osKernelRunning)
54 * - added: osKernelLock, osKernelUnlock
55 * - added: osKernelSuspend, osKernelResume
56 * - added: osKernelGetTickCount, osKernelGetTickFreq
57 * - renamed osKernelSysTick to osKernelGetSysTimerCount
58 * - replaced osKernelSysTickFrequency with osKernelGetSysTimerFreq
59 * - deprecated osKernelSysTickMicroSec
61 * - extended number of thread priorities
62 * - renamed osPrioriry to osPrioriry_t
63 * - replaced osThreadCreate with osThreadNew
64 * - added: osThreadGetName
65 * - added: osThreadState_t and osThreadGetState
66 * - added: osThreadGetStackSize, osThreadGetStackSpace
67 * - added: osThreadSuspend, osThreadResume
68 * - added: osThreadJoin, osThreadDetach, osThreadExit
69 * - added: osThreadGetCount, osThreadEnumerate
70 * - added: Thread Flags (moved from Signals)
72 * - renamed osSignals to osThreadFlags (moved to Thread Flags)
73 * - changed return value of Set/Clear/Wait functions
74 * - Clear function limited to current running thread
75 * - extended Wait function (options)
76 * - added: osThreadFlagsGet
78 * - added new independent object for handling Event Flags
79 * Delay and Wait functions:
80 * - added: osDelayUntil
81 * - deprecated: osWait
83 * - replaced osTimerCreate with osTimerNew
84 * - added: osTimerGetName, osTimerIsRunning
86 * - extended: attributes (Recursive, Priority Inherit, Robust)
87 * - replaced osMutexCreate with osMutexNew
88 * - renamed osMutexWait to osMutexAcquire
89 * - added: osMutexGetName, osMutexGetOwner
91 * - extended: maximum and initial token count
92 * - replaced osSemaphoreCreate with osSemaphoreNew
93 * - renamed osSemaphoreWait to osSemaphoreAcquire (changed return value)
94 * - added: osSemaphoreGetName, osSemaphoreGetCount
96 * - using osMemoryPool prefix instead of osPool
97 * - replaced osPoolCreate with osMemoryPoolNew
98 * - extended osMemoryPoolAlloc (timeout)
99 * - added: osMemoryPoolGetName
100 * - added: osMemoryPoolGetCapacity, osMemoryPoolGetBlockSize
101 * - added: osMemoryPoolGetCount, osMemoryPoolGetSpace
102 * - added: osMemoryPoolDelete
103 * - deprecated: osPoolCAlloc
105 * - extended: fixed size message instead of a single 32-bit value
106 * - using osMessageQueue prefix instead of osMessage
107 * - replaced osMessageCreate with osMessageQueueNew
108 * - updated: osMessageQueuePut, osMessageQueueGet
109 * - added: osMessageQueueGetName
110 * - added: osMessageQueueGetCapacity, osMessageQueueGetMsgSize
111 * - added: osMessageQueueGetCount, osMessageQueueGetSpace
112 * - added: osMessageQueueReset, osMessageQueueDelete
114 * - deprecated (superseded by extended Message Queue functionality)
116 * Support for critical and uncritical sections (nesting safe):
117 * - updated: osKernelLock, osKernelUnlock
118 * - added: osKernelRestoreLock
119 * Updated Thread and Event Flags:
120 * - changed flags parameter and return type from int32_t to uint32_t
121 *---------------------------------------------------------------------------*/
126 #include "FreeRTOS.h"
129 #define RTOS_ID_n ((tskKERNEL_VERSION_MAJOR << 16) | (tskKERNEL_VERSION_MINOR))
130 #define RTOS_ID_s ("FreeRTOS " tskKERNEL_VERSION_NUMBER)
132 #define osCMSIS 0x20001U ///< API version (main[31:16].sub[15:0])
134 #define osCMSIS_FreeRTOS RTOS_ID_n ///< RTOS identification and version (main[31:16].sub[15:0])
136 #define osKernelSystemId RTOS_ID_s ///< RTOS identification string
138 #define osFeature_MainThread 0 ///< main thread 1=main can be thread, 0=not available
139 #define osFeature_Signals 24U ///< maximum number of Signal Flags available per thread
140 #define osFeature_Semaphore 65535U ///< maximum count for \ref osSemaphoreCreate function
141 #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available
142 #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available
143 #define osFeature_Pool 0 ///< Memory Pools: 1=available, 0=not available
144 #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
145 #define osFeature_MailQ 0 ///< Mail Queues: 1=available, 0=not available
147 #if defined(__CC_ARM)
148 #define os_InRegs __value_in_regs
149 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
150 #define os_InRegs __attribute__((value_in_regs))
155 #include "cmsis_os2.h"
163 // ==== Enumerations, structures, defines ====
166 #if (osCMSIS < 0x20000U)
168 osPriorityIdle = -3, ///< Priority: idle (lowest)
169 osPriorityLow = -2, ///< Priority: low
170 osPriorityBelowNormal = -1, ///< Priority: below normal
171 osPriorityNormal = 0, ///< Priority: normal (default)
172 osPriorityAboveNormal = +1, ///< Priority: above normal
173 osPriorityHigh = +2, ///< Priority: high
174 osPriorityRealtime = +3, ///< Priority: realtime (highest)
175 osPriorityError = 0x84, ///< System cannot determine priority or illegal priority.
176 osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
179 #define osPriority osPriority_t
182 /// Entry point of a thread.
183 typedef void (*os_pthread) (void const *argument);
185 /// Entry point of a timer call back function.
186 typedef void (*os_ptimer) (void const *argument);
189 #if (osCMSIS < 0x20000U)
191 osTimerOnce = 0, ///< One-shot timer.
192 osTimerPeriodic = 1 ///< Repeating timer.
195 #define os_timer_type osTimerType_t
199 #define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
201 /// Status code values returned by CMSIS-RTOS functions.
202 #if (osCMSIS < 0x20000U)
204 osOK = 0, ///< Function completed; no error or event occurred.
205 osEventSignal = 0x08, ///< Function completed; signal event occurred.
206 osEventMessage = 0x10, ///< Function completed; message event occurred.
207 osEventMail = 0x20, ///< Function completed; mail event occurred.
208 osEventTimeout = 0x40, ///< Function completed; timeout occurred.
209 osErrorParameter = 0x80, ///< Parameter error: a mandatory parameter was missing or specified an incorrect object.
210 osErrorResource = 0x81, ///< Resource not available: a specified resource was not available.
211 osErrorTimeoutResource = 0xC1, ///< Resource not available within given time: a specified resource was not available within the timeout period.
212 osErrorISR = 0x82, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
213 osErrorISRRecursive = 0x83, ///< Function called multiple times from ISR with same object.
214 osErrorPriority = 0x84, ///< System cannot determine priority or thread has illegal priority.
215 osErrorNoMemory = 0x85, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
216 osErrorValue = 0x86, ///< Value of a parameter is out of range.
217 osErrorOS = 0xFF, ///< Unspecified RTOS error: run-time error but no other error message fits.
218 osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
221 typedef int32_t osStatus;
222 #define osEventSignal (0x08)
223 #define osEventMessage (0x10)
224 #define osEventMail (0x20)
225 #define osEventTimeout (0x40)
226 #define osErrorOS osError
227 #define osErrorTimeoutResource osErrorTimeout
228 #define osErrorISRRecursive (-126)
229 #define osErrorValue (-127)
230 #define osErrorPriority (-128)
234 // >>> the following data type definitions may be adapted towards a specific RTOS
236 /// Thread ID identifies the thread.
237 #if (osCMSIS < 0x20000U)
238 typedef void *osThreadId;
240 #define osThreadId osThreadId_t
243 /// Timer ID identifies the timer.
244 #if (osCMSIS < 0x20000U)
245 typedef void *osTimerId;
247 #define osTimerId osTimerId_t
250 /// Mutex ID identifies the mutex.
251 #if (osCMSIS < 0x20000U)
252 typedef void *osMutexId;
254 #define osMutexId osMutexId_t
257 /// Semaphore ID identifies the semaphore.
258 #if (osCMSIS < 0x20000U)
259 typedef void *osSemaphoreId;
261 #define osSemaphoreId osSemaphoreId_t
264 /// Pool ID identifies the memory pool.
265 typedef void *osPoolId;
267 /// Message ID identifies the message queue.
268 typedef void *osMessageQId;
270 /// Mail ID identifies the mail queue.
271 typedef void *osMailQId;
274 /// Thread Definition structure contains startup information of a thread.
275 #if (osCMSIS < 0x20000U)
276 typedef struct os_thread_def {
277 os_pthread pthread; ///< start address of thread function
278 osPriority tpriority; ///< initial thread priority
279 uint32_t instances; ///< maximum number of instances of that thread function
280 uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
283 typedef struct os_thread_def {
284 os_pthread pthread; ///< start address of thread function
285 osThreadAttr_t attr; ///< thread attributes
289 /// Timer Definition structure contains timer parameters.
290 #if (osCMSIS < 0x20000U)
291 typedef struct os_timer_def {
292 os_ptimer ptimer; ///< start address of a timer function
295 typedef struct os_timer_def {
296 os_ptimer ptimer; ///< start address of a timer function
297 osTimerAttr_t attr; ///< timer attributes
301 /// Mutex Definition structure contains setup information for a mutex.
302 #if (osCMSIS < 0x20000U)
303 typedef struct os_mutex_def {
304 uint32_t dummy; ///< dummy value
307 #define osMutexDef_t osMutexAttr_t
310 /// Semaphore Definition structure contains setup information for a semaphore.
311 #if (osCMSIS < 0x20000U)
312 typedef struct os_semaphore_def {
313 uint32_t dummy; ///< dummy value
316 #define osSemaphoreDef_t osSemaphoreAttr_t
319 /// Definition structure for memory block allocation.
320 #if (osCMSIS < 0x20000U)
321 typedef struct os_pool_def {
322 uint32_t pool_sz; ///< number of items (elements) in the pool
323 uint32_t item_sz; ///< size of an item
324 void *pool; ///< pointer to memory for pool
327 typedef struct os_pool_def {
328 uint32_t pool_sz; ///< number of items (elements) in the pool
329 uint32_t item_sz; ///< size of an item
330 osMemoryPoolAttr_t attr; ///< memory pool attributes
334 /// Definition structure for message queue.
335 #if (osCMSIS < 0x20000U)
336 typedef struct os_messageQ_def {
337 uint32_t queue_sz; ///< number of elements in the queue
338 void *pool; ///< memory array for messages
341 typedef struct os_messageQ_def {
342 uint32_t queue_sz; ///< number of elements in the queue
343 osMessageQueueAttr_t attr; ///< message queue attributes
347 /// Definition structure for mail queue.
348 #if (osCMSIS < 0x20000U)
349 typedef struct os_mailQ_def {
350 uint32_t queue_sz; ///< number of elements in the queue
351 uint32_t item_sz; ///< size of an item
352 void *pool; ///< memory array for mail
355 typedef struct os_mailQ_def {
356 uint32_t queue_sz; ///< number of elements in the queue
357 uint32_t item_sz; ///< size of an item
358 void *mail; ///< pointer to mail
359 osMemoryPoolAttr_t mp_attr; ///< memory pool attributes
360 osMessageQueueAttr_t mq_attr; ///< message queue attributes
365 /// Event structure contains detailed information about an event.
367 osStatus status; ///< status code: event or error information
369 uint32_t v; ///< message as 32-bit value
370 void *p; ///< message or mail as void pointer
371 int32_t signals; ///< signal flags
372 } value; ///< event value
374 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
375 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
376 } def; ///< event definition
380 // ==== Kernel Management Functions ====
382 /// Initialize the RTOS Kernel for creating objects.
383 /// \return status code that indicates the execution status of the function.
384 #if (osCMSIS < 0x20000U)
385 osStatus osKernelInitialize (void);
388 /// Start the RTOS Kernel scheduler.
389 /// \return status code that indicates the execution status of the function.
390 #if (osCMSIS < 0x20000U)
391 osStatus osKernelStart (void);
394 /// Check if the RTOS kernel is already started.
395 /// \return 0 RTOS is not started, 1 RTOS is started.
396 #if (osCMSIS < 0x20000U)
397 int32_t osKernelRunning(void);
400 #if (defined(osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
402 /// Get the RTOS kernel system timer counter.
403 /// \return RTOS kernel system timer as 32-bit value
404 #if (osCMSIS < 0x20000U)
405 uint32_t osKernelSysTick (void);
407 #define osKernelSysTick osKernelGetSysTimerCount
410 /// The RTOS kernel system timer frequency in Hz.
411 /// \note Reflects the system timer setting and is typically defined in a configuration file.
412 #if (osCMSIS < 0x20000U)
413 #define osKernelSysTickFrequency 100000000
416 /// Convert a microseconds value to a RTOS kernel system timer value.
417 /// \param microsec time value in microseconds.
418 /// \return time value normalized to the \ref osKernelSysTickFrequency
419 #if (osCMSIS < 0x20000U)
420 #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
422 #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * osKernelGetSysTimerFreq()) / 1000000)
425 #endif // System Timer available
428 // ==== Thread Management Functions ====
430 /// Create a Thread Definition with function, priority, and stack requirements.
431 /// \param name name of the thread function.
432 /// \param priority initial priority of the thread function.
433 /// \param instances number of possible thread instances.
434 /// \param stacksz stack size (in bytes) requirements for the thread function.
435 #if defined (osObjectsExternal) // object is external
436 #define osThreadDef(name, priority, instances, stacksz) \
437 extern const osThreadDef_t os_thread_def_##name
438 #else // define the object
439 #define osThreadDef(name, priority, instances, stacksz) \
440 static uint64_t os_thread_stack##name[(stacksz)?(((stacksz+7)/8)):1]; \
441 static StaticTask_t os_thread_cb_##name; \
442 const osThreadDef_t os_thread_def_##name = \
444 { NULL, osThreadDetached, \
445 (instances == 1) ? (&os_thread_cb_##name) : NULL,\
446 (instances == 1) ? sizeof(StaticTask_t) : 0U, \
447 ((stacksz) && (instances == 1)) ? (&os_thread_stack##name) : NULL, \
449 (priority), 0U, 0U } }
452 /// Access a Thread definition.
453 /// \param name name of the thread definition object.
454 #define osThread(name) \
455 &os_thread_def_##name
457 /// Create a thread and add it to Active Threads and set it to state READY.
458 /// \param[in] thread_def thread definition referenced with \ref osThread.
459 /// \param[in] argument pointer that is passed to the thread function as start argument.
460 /// \return thread ID for reference by other functions or NULL in case of error.
461 osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
463 /// Return the thread ID of the current running thread.
464 /// \return thread ID for reference by other functions or NULL in case of error.
465 #if (osCMSIS < 0x20000U)
466 osThreadId osThreadGetId (void);
469 /// Change priority of a thread.
470 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
471 /// \param[in] priority new priority value for the thread function.
472 /// \return status code that indicates the execution status of the function.
473 #if (osCMSIS < 0x20000U)
474 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
477 /// Get current priority of a thread.
478 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
479 /// \return current priority value of the specified thread.
480 #if (osCMSIS < 0x20000U)
481 osPriority osThreadGetPriority (osThreadId thread_id);
484 /// Pass control to next thread that is in state \b READY.
485 /// \return status code that indicates the execution status of the function.
486 #if (osCMSIS < 0x20000U)
487 osStatus osThreadYield (void);
490 /// Terminate execution of a thread.
491 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
492 /// \return status code that indicates the execution status of the function.
493 #if (osCMSIS < 0x20000U)
494 osStatus osThreadTerminate (osThreadId thread_id);
498 // ==== Signal Management ====
500 /// Set the specified Signal Flags of an active thread.
501 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
502 /// \param[in] signals specifies the signal flags of the thread that should be set.
503 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
504 int32_t osSignalSet (osThreadId thread_id, int32_t signals);
506 /// Clear the specified Signal Flags of an active thread.
507 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
508 /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
509 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
510 int32_t osSignalClear (osThreadId thread_id, int32_t signals);
512 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
513 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
514 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
515 /// \return event flag information or error code.
516 os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec);
519 // ==== Generic Wait Functions ====
521 /// Wait for Timeout (Time Delay).
522 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
523 /// \return status code that indicates the execution status of the function.
524 #if (osCMSIS < 0x20000U)
525 osStatus osDelay (uint32_t millisec);
528 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
530 /// Wait for Signal, Message, Mail, or Timeout.
531 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
532 /// \return event that contains signal, message, or mail information or error code.
533 os_InRegs osEvent osWait (uint32_t millisec);
535 #endif // Generic Wait available
538 // ==== Timer Management Functions ====
540 /// Define a Timer object.
541 /// \param name name of the timer object.
542 /// \param function name of the timer call back function.
543 #if defined (osObjectsExternal) // object is external
544 #define osTimerDef(name, function) \
545 extern const osTimerDef_t os_timer_def_##name
546 #else // define the object
547 #define osTimerDef(name, function) \
548 static StaticTimer_t os_timer_cb_##name; \
549 const osTimerDef_t os_timer_def_##name = \
550 { (function), { NULL, 0U, (&os_timer_cb_##name), sizeof(StaticTimer_t) } }
553 /// Access a Timer definition.
554 /// \param name name of the timer object.
555 #define osTimer(name) \
558 /// Create and Initialize a timer.
559 /// \param[in] timer_def timer object referenced with \ref osTimer.
560 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
561 /// \param[in] argument argument to the timer call back function.
562 /// \return timer ID for reference by other functions or NULL in case of error.
563 osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
565 /// Start or restart a timer.
566 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
567 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
568 /// \return status code that indicates the execution status of the function.
569 #if (osCMSIS < 0x20000U)
570 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
574 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
575 /// \return status code that indicates the execution status of the function.
576 #if (osCMSIS < 0x20000U)
577 osStatus osTimerStop (osTimerId timer_id);
581 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
582 /// \return status code that indicates the execution status of the function.
583 #if (osCMSIS < 0x20000U)
584 osStatus osTimerDelete (osTimerId timer_id);
588 // ==== Mutex Management Functions ====
591 /// \param name name of the mutex object.
592 #if defined (osObjectsExternal) // object is external
593 #define osMutexDef(name) \
594 extern const osMutexDef_t os_mutex_def_##name
595 #else // define the object
596 #define osMutexDef(name) \
597 static StaticSemaphore_t os_mutex_cb_##name; \
598 const osMutexDef_t os_mutex_def_##name = \
599 { NULL, osMutexRecursive | osMutexPrioInherit, (&os_mutex_cb_##name), sizeof(StaticSemaphore_t) }
602 /// Access a Mutex definition.
603 /// \param name name of the mutex object.
604 #define osMutex(name) \
607 /// Create and Initialize a Mutex object.
608 /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
609 /// \return mutex ID for reference by other functions or NULL in case of error.
610 osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
612 /// Wait until a Mutex becomes available.
613 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
614 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
615 /// \return status code that indicates the execution status of the function.
616 #if (osCMSIS < 0x20000U)
617 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
619 #define osMutexWait osMutexAcquire
622 /// Release a Mutex that was obtained by \ref osMutexWait.
623 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
624 /// \return status code that indicates the execution status of the function.
625 #if (osCMSIS < 0x20000U)
626 osStatus osMutexRelease (osMutexId mutex_id);
629 /// Delete a Mutex object.
630 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
631 /// \return status code that indicates the execution status of the function.
632 #if (osCMSIS < 0x20000U)
633 osStatus osMutexDelete (osMutexId mutex_id);
637 // ==== Semaphore Management Functions ====
639 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) // Semaphore available
641 /// Define a Semaphore object.
642 /// \param name name of the semaphore object.
643 #if defined (osObjectsExternal) // object is external
644 #define osSemaphoreDef(name) \
645 extern const osSemaphoreDef_t os_semaphore_def_##name
646 #else // define the object
647 #define osSemaphoreDef(name) \
648 static StaticSemaphore_t os_semaphore_cb_##name; \
649 const osSemaphoreDef_t os_semaphore_def_##name = \
650 { NULL, 0U, (&os_semaphore_cb_##name), sizeof(StaticSemaphore_t) }
653 /// Access a Semaphore definition.
654 /// \param name name of the semaphore object.
655 #define osSemaphore(name) \
656 &os_semaphore_def_##name
658 /// Create and Initialize a Semaphore object.
659 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
660 /// \param[in] count maximum and initial number of available tokens.
661 /// \return semaphore ID for reference by other functions or NULL in case of error.
662 osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
664 /// Wait until a Semaphore token becomes available.
665 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
666 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
667 /// \return number of available tokens, or -1 in case of incorrect parameters.
668 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
670 /// Release a Semaphore token.
671 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
672 /// \return status code that indicates the execution status of the function.
673 #if (osCMSIS < 0x20000U)
674 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
677 /// Delete a Semaphore object.
678 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
679 /// \return status code that indicates the execution status of the function.
680 #if (osCMSIS < 0x20000U)
681 osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
684 #endif // Semaphore available
687 // ==== Memory Pool Management Functions ====
689 #if (defined(osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool available
691 /// \brief Define a Memory Pool.
692 /// \param name name of the memory pool.
693 /// \param no maximum number of blocks (objects) in the memory pool.
694 /// \param type data type of a single block (object).
695 #if defined (osObjectsExternal) // object is external
696 #define osPoolDef(name, no, type) \
697 extern const osPoolDef_t os_pool_def_##name
698 #else // define the object
699 #define osPoolDef(name, no, type) \
700 const osPoolDef_t os_pool_def_##name = \
701 { (no), sizeof(type), {NULL} }
704 /// \brief Access a Memory Pool definition.
705 /// \param name name of the memory pool
706 #define osPool(name) \
709 /// Create and Initialize a Memory Pool object.
710 /// \param[in] pool_def memory pool definition referenced with \ref osPool.
711 /// \return memory pool ID for reference by other functions or NULL in case of error.
712 osPoolId osPoolCreate (const osPoolDef_t *pool_def);
714 /// Allocate a memory block from a Memory Pool.
715 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
716 /// \return address of the allocated memory block or NULL in case of no memory available.
717 void *osPoolAlloc (osPoolId pool_id);
719 /// Allocate a memory block from a Memory Pool and set memory block to zero.
720 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
721 /// \return address of the allocated memory block or NULL in case of no memory available.
722 void *osPoolCAlloc (osPoolId pool_id);
724 /// Return an allocated memory block back to a Memory Pool.
725 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
726 /// \param[in] block address of the allocated memory block to be returned to the memory pool.
727 /// \return status code that indicates the execution status of the function.
728 osStatus osPoolFree (osPoolId pool_id, void *block);
730 #endif // Memory Pool available
733 // ==== Message Queue Management Functions ====
735 #if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queue available
737 /// \brief Create a Message Queue Definition.
738 /// \param name name of the queue.
739 /// \param queue_sz maximum number of messages in the queue.
740 /// \param type data type of a single message element (for debugger).
741 #if defined (osObjectsExternal) // object is external
742 #define osMessageQDef(name, queue_sz, type) \
743 extern const osMessageQDef_t os_messageQ_def_##name
744 #else // define the object
745 #define osMessageQDef(name, queue_sz, type) \
746 static StaticQueue_t os_mq_cb_##name; \
747 static uint32_t os_mq_data_##name[(queue_sz) * sizeof(type)]; \
748 const osMessageQDef_t os_messageQ_def_##name = \
750 { NULL, 0U, (&os_mq_cb_##name), sizeof(StaticQueue_t), \
751 (&os_mq_data_##name), sizeof(os_mq_data_##name) } }
754 /// \brief Access a Message Queue Definition.
755 /// \param name name of the queue
756 #define osMessageQ(name) \
757 &os_messageQ_def_##name
759 /// Create and Initialize a Message Queue object.
760 /// \param[in] queue_def message queue definition referenced with \ref osMessageQ.
761 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
762 /// \return message queue ID for reference by other functions or NULL in case of error.
763 osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
765 /// Put a Message to a Queue.
766 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
767 /// \param[in] info message information.
768 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
769 /// \return status code that indicates the execution status of the function.
770 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
772 /// Get a Message from a Queue or timeout if Queue is empty.
773 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
774 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
775 /// \return event information that includes status code.
776 os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
778 #endif // Message Queue available
781 // ==== Mail Queue Management Functions ====
783 #if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queue available
785 /// \brief Create a Mail Queue Definition.
786 /// \param name name of the queue.
787 /// \param queue_sz maximum number of mails in the queue.
788 /// \param type data type of a single mail element.
789 #if defined (osObjectsExternal) // object is external
790 #define osMailQDef(name, queue_sz, type) \
791 extern const osMailQDef_t os_mailQ_def_##name
792 #else // define the object
793 #define osMailQDef(name, queue_sz, type) \
794 const osMailQDef_t os_mailQ_def_##name = \
795 { (queue_sz), sizeof(type), NULL }
798 /// \brief Access a Mail Queue Definition.
799 /// \param name name of the queue
800 #define osMailQ(name) \
803 /// Create and Initialize a Mail Queue object.
804 /// \param[in] queue_def mail queue definition referenced with \ref osMailQ.
805 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
806 /// \return mail queue ID for reference by other functions or NULL in case of error.
807 osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
809 /// Allocate a memory block for mail from a mail memory pool.
810 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
811 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
812 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
813 void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
815 /// Allocate a memory block for mail from a mail memory pool and set memory block to zero.
816 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
817 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
818 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
819 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
821 /// Put a Mail into a Queue.
822 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
823 /// \param[in] mail pointer to memory with mail to put into a queue.
824 /// \return status code that indicates the execution status of the function.
825 osStatus osMailPut (osMailQId queue_id, const void *mail);
827 /// Get a Mail from a Queue or timeout if Queue is empty.
828 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
829 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
830 /// \return event information that includes status code.
831 os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
833 /// Free a memory block by returning it to a mail memory pool.
834 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
835 /// \param[in] mail pointer to memory block that was obtained with \ref osMailGet.
836 /// \return status code that indicates the execution status of the function.
837 osStatus osMailFree (osMailQId queue_id, void *mail);
839 #endif // Mail Queue available
846 #endif // CMSIS_OS_H_