2 * Copyright (c) 2013-2017 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 * ----------------------------------------------------------------------
23 * Project: CMSIS-RTOS2 API
24 * Title: cmsis_os2.h header file
27 * Additional functions allowed to be called from Interrupt Service Routines:
28 * - osKernelGetTickCount, osKernelGetTickFreq
29 * Changed Kernel Tick type to uint32_t:
30 * - updated: osKernelGetTickCount, osDelayUntil
32 * Support for critical and uncritical sections (nesting safe):
33 * - updated: osKernelLock, osKernelUnlock
34 * - added: osKernelRestoreLock
35 * Updated Thread and Event Flags:
36 * - changed flags parameter and return type from int32_t to uint32_t
39 *---------------------------------------------------------------------------*/
46 #define __NO_RETURN __declspec(noreturn)
47 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
48 #define __NO_RETURN __attribute__((noreturn))
49 #elif defined(__GNUC__)
50 #define __NO_RETURN __attribute__((noreturn))
51 #elif defined(__ICCARM__)
52 #define __NO_RETURN __noreturn
67 // ==== Enumerations, structures, defines ====
69 /// Version information.
71 uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec).
72 uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
77 osKernelInactive = 0, ///< Inactive.
78 osKernelReady = 1, ///< Ready.
79 osKernelRunning = 2, ///< Running.
80 osKernelLocked = 3, ///< Locked.
81 osKernelSuspended = 4, ///< Suspended.
82 osKernelError = -1, ///< Error.
83 osKernelReserved = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization.
88 osThreadInactive = 0, ///< Inactive.
89 osThreadReady = 1, ///< Ready.
90 osThreadRunning = 2, ///< Running.
91 osThreadBlocked = 3, ///< Blocked.
92 osThreadTerminated = 4, ///< Terminated.
93 osThreadError = -1, ///< Error.
94 osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
99 osPriorityNone = 0, ///< No priority (not initialized).
100 osPriorityIdle = 1, ///< Reserved for Idle thread.
101 osPriorityLow = 8, ///< Priority: low
102 osPriorityLow1 = 8+1, ///< Priority: low + 1
103 osPriorityLow2 = 8+2, ///< Priority: low + 2
104 osPriorityLow3 = 8+3, ///< Priority: low + 3
105 osPriorityLow4 = 8+4, ///< Priority: low + 4
106 osPriorityLow5 = 8+5, ///< Priority: low + 5
107 osPriorityLow6 = 8+6, ///< Priority: low + 6
108 osPriorityLow7 = 8+7, ///< Priority: low + 7
109 osPriorityBelowNormal = 16, ///< Priority: below normal
110 osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1
111 osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2
112 osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3
113 osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4
114 osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5
115 osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6
116 osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7
117 osPriorityNormal = 24, ///< Priority: normal
118 osPriorityNormal1 = 24+1, ///< Priority: normal + 1
119 osPriorityNormal2 = 24+2, ///< Priority: normal + 2
120 osPriorityNormal3 = 24+3, ///< Priority: normal + 3
121 osPriorityNormal4 = 24+4, ///< Priority: normal + 4
122 osPriorityNormal5 = 24+5, ///< Priority: normal + 5
123 osPriorityNormal6 = 24+6, ///< Priority: normal + 6
124 osPriorityNormal7 = 24+7, ///< Priority: normal + 7
125 osPriorityAboveNormal = 32, ///< Priority: above normal
126 osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1
127 osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2
128 osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3
129 osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4
130 osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5
131 osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6
132 osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7
133 osPriorityHigh = 40, ///< Priority: high
134 osPriorityHigh1 = 40+1, ///< Priority: high + 1
135 osPriorityHigh2 = 40+2, ///< Priority: high + 2
136 osPriorityHigh3 = 40+3, ///< Priority: high + 3
137 osPriorityHigh4 = 40+4, ///< Priority: high + 4
138 osPriorityHigh5 = 40+5, ///< Priority: high + 5
139 osPriorityHigh6 = 40+6, ///< Priority: high + 6
140 osPriorityHigh7 = 40+7, ///< Priority: high + 7
141 osPriorityRealtime = 48, ///< Priority: realtime
142 osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1
143 osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2
144 osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3
145 osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4
146 osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5
147 osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6
148 osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7
149 osPriorityISR = 56, ///< Reserved for ISR deferred thread.
150 osPriorityError = -1, ///< System cannot determine priority or illegal priority.
151 osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
154 /// Entry point of a thread.
155 typedef void (*osThreadFunc_t) (void *argument);
157 /// Timer callback function.
158 typedef void (*osTimerFunc_t) (void *argument);
162 osTimerOnce = 0, ///< One-shot timer.
163 osTimerPeriodic = 1 ///< Repeating timer.
167 #define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
169 // Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
170 #define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
171 #define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
172 #define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
174 // Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
175 #define osFlagsError 0x80000000U ///< Error indicator.
176 #define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1).
177 #define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2).
178 #define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3).
179 #define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).
180 #define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6).
182 // Thread attributes (attr_bits in \ref osThreadAttr_t).
183 #define osThreadDetached 0x00000000U ///< Thread created in detached mode (default)
184 #define osThreadJoinable 0x00000001U ///< Thread created in joinable mode
186 // Mutex attributes (attr_bits in \ref osMutexAttr_t).
187 #define osMutexRecursive 0x00000001U ///< Recursive mutex.
188 #define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
189 #define osMutexRobust 0x00000008U ///< Robust mutex.
191 /// Status code values returned by CMSIS-RTOS functions.
193 osOK = 0, ///< Operation completed successfully.
194 osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
195 osErrorTimeout = -2, ///< Operation not completed within the timeout period.
196 osErrorResource = -3, ///< Resource not available.
197 osErrorParameter = -4, ///< Parameter error.
198 osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
199 osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
200 osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
204 /// \details Thread ID identifies the thread.
205 typedef void *osThreadId_t;
207 /// \details Timer ID identifies the timer.
208 typedef void *osTimerId_t;
210 /// \details Event Flags ID identifies the event flags.
211 typedef void *osEventFlagsId_t;
213 /// \details Mutex ID identifies the mutex.
214 typedef void *osMutexId_t;
216 /// \details Semaphore ID identifies the semaphore.
217 typedef void *osSemaphoreId_t;
219 /// \details Memory Pool ID identifies the memory pool.
220 typedef void *osMemoryPoolId_t;
222 /// \details Message Queue ID identifies the message queue.
223 typedef void *osMessageQueueId_t;
226 #ifndef TZ_MODULEID_T
227 #define TZ_MODULEID_T
228 /// \details Data type that identifies secure software modules called by a process.
229 typedef uint32_t TZ_ModuleId_t;
233 /// Attributes structure for thread.
235 const char *name; ///< name of the thread
236 uint32_t attr_bits; ///< attribute bits
237 void *cb_mem; ///< memory for control block
238 uint32_t cb_size; ///< size of provided memory for control block
239 void *stack_mem; ///< memory for stack
240 uint32_t stack_size; ///< size of stack
241 osPriority_t priority; ///< initial thread priority (default: osPriorityNormal)
242 TZ_ModuleId_t tz_module; ///< TrustZone module identifier
243 uint32_t reserved; ///< reserved (must be 0)
246 /// Attributes structure for timer.
248 const char *name; ///< name of the timer
249 uint32_t attr_bits; ///< attribute bits
250 void *cb_mem; ///< memory for control block
251 uint32_t cb_size; ///< size of provided memory for control block
254 /// Attributes structure for event flags.
256 const char *name; ///< name of the event flags
257 uint32_t attr_bits; ///< attribute bits
258 void *cb_mem; ///< memory for control block
259 uint32_t cb_size; ///< size of provided memory for control block
260 } osEventFlagsAttr_t;
262 /// Attributes structure for mutex.
264 const char *name; ///< name of the mutex
265 uint32_t attr_bits; ///< attribute bits
266 void *cb_mem; ///< memory for control block
267 uint32_t cb_size; ///< size of provided memory for control block
270 /// Attributes structure for semaphore.
272 const char *name; ///< name of the semaphore
273 uint32_t attr_bits; ///< attribute bits
274 void *cb_mem; ///< memory for control block
275 uint32_t cb_size; ///< size of provided memory for control block
278 /// Attributes structure for memory pool.
280 const char *name; ///< name of the memory pool
281 uint32_t attr_bits; ///< attribute bits
282 void *cb_mem; ///< memory for control block
283 uint32_t cb_size; ///< size of provided memory for control block
284 void *mp_mem; ///< memory for data storage
285 uint32_t mp_size; ///< size of provided memory for data storage
286 } osMemoryPoolAttr_t;
288 /// Attributes structure for message queue.
290 const char *name; ///< name of the message queue
291 uint32_t attr_bits; ///< attribute bits
292 void *cb_mem; ///< memory for control block
293 uint32_t cb_size; ///< size of provided memory for control block
294 void *mq_mem; ///< memory for data storage
295 uint32_t mq_size; ///< size of provided memory for data storage
296 } osMessageQueueAttr_t;
299 // ==== Kernel Management Functions ====
301 /// Initialize the RTOS Kernel.
302 /// \return status code that indicates the execution status of the function.
303 osStatus_t osKernelInitialize (void);
305 /// Get RTOS Kernel Information.
306 /// \param[out] version pointer to buffer for retrieving version information.
307 /// \param[out] id_buf pointer to buffer for retrieving kernel identification string.
308 /// \param[in] id_size size of buffer for kernel identification string.
309 /// \return status code that indicates the execution status of the function.
310 osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
312 /// Get the current RTOS Kernel state.
313 /// \return current RTOS Kernel state.
314 osKernelState_t osKernelGetState (void);
316 /// Start the RTOS Kernel scheduler.
317 /// \return status code that indicates the execution status of the function.
318 osStatus_t osKernelStart (void);
320 /// Lock the RTOS Kernel scheduler.
321 /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
322 int32_t osKernelLock (void);
324 /// Unlock the RTOS Kernel scheduler.
325 /// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
326 int32_t osKernelUnlock (void);
328 /// Restore the RTOS Kernel scheduler lock state.
329 /// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock.
330 /// \return new lock state (1 - locked, 0 - not locked, error code if negative).
331 int32_t osKernelRestoreLock (int32_t lock);
333 /// Suspend the RTOS Kernel scheduler.
334 /// \return time in ticks, for how long the system can sleep or power-down.
335 uint32_t osKernelSuspend (void);
337 /// Resume the RTOS Kernel scheduler.
338 /// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode.
339 void osKernelResume (uint32_t sleep_ticks);
341 /// Get the RTOS kernel tick count.
342 /// \return RTOS kernel current tick count.
343 uint32_t osKernelGetTickCount (void);
345 /// Get the RTOS kernel tick frequency.
346 /// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second.
347 uint32_t osKernelGetTickFreq (void);
349 /// Get the RTOS kernel system timer count.
350 /// \return RTOS kernel current system timer count as 32-bit value.
351 uint32_t osKernelGetSysTimerCount (void);
353 /// Get the RTOS kernel system timer frequency.
354 /// \return frequency of the system timer in hertz, i.e. timer ticks per second.
355 uint32_t osKernelGetSysTimerFreq (void);
358 // ==== Thread Management Functions ====
360 /// Create a thread and add it to Active Threads.
361 /// \param[in] func thread function.
362 /// \param[in] argument pointer that is passed to the thread function as start argument.
363 /// \param[in] attr thread attributes; NULL: default values.
364 /// \return thread ID for reference by other functions or NULL in case of error.
365 osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
367 /// Get name of a thread.
368 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
369 /// \return name as NULL terminated string.
370 const char *osThreadGetName (osThreadId_t thread_id);
372 /// Return the thread ID of the current running thread.
373 /// \return thread ID for reference by other functions or NULL in case of error.
374 osThreadId_t osThreadGetId (void);
376 /// Get current thread state of a thread.
377 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
378 /// \return current thread state of the specified thread.
379 osThreadState_t osThreadGetState (osThreadId_t thread_id);
381 /// Get stack size of a thread.
382 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
383 /// \return stack size in bytes.
384 uint32_t osThreadGetStackSize (osThreadId_t thread_id);
386 /// Get available stack space of a thread based on stack watermark recording during execution.
387 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
388 /// \return remaining stack space in bytes.
389 uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
391 /// Change priority of a thread.
392 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
393 /// \param[in] priority new priority value for the thread function.
394 /// \return status code that indicates the execution status of the function.
395 osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
397 /// Get current priority of a thread.
398 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
399 /// \return current priority value of the specified thread.
400 osPriority_t osThreadGetPriority (osThreadId_t thread_id);
402 /// Pass control to next thread that is in state \b READY.
403 /// \return status code that indicates the execution status of the function.
404 osStatus_t osThreadYield (void);
406 /// Suspend execution of a thread.
407 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
408 /// \return status code that indicates the execution status of the function.
409 osStatus_t osThreadSuspend (osThreadId_t thread_id);
411 /// Resume execution of a thread.
412 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
413 /// \return status code that indicates the execution status of the function.
414 osStatus_t osThreadResume (osThreadId_t thread_id);
416 /// Detach a thread (thread storage can be reclaimed when thread terminates).
417 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
418 /// \return status code that indicates the execution status of the function.
419 osStatus_t osThreadDetach (osThreadId_t thread_id);
421 /// Wait for specified thread to terminate.
422 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
423 /// \return status code that indicates the execution status of the function.
424 osStatus_t osThreadJoin (osThreadId_t thread_id);
426 /// Terminate execution of current running thread.
427 __NO_RETURN void osThreadExit (void);
429 /// Terminate execution of a thread.
430 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
431 /// \return status code that indicates the execution status of the function.
432 osStatus_t osThreadTerminate (osThreadId_t thread_id);
434 /// Get number of active threads.
435 /// \return number of active threads.
436 uint32_t osThreadGetCount (void);
438 /// Enumerate active threads.
439 /// \param[out] thread_array pointer to array for retrieving thread IDs.
440 /// \param[in] array_items maximum number of items in array for retrieving thread IDs.
441 /// \return number of enumerated threads.
442 uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
445 // ==== Thread Flags Functions ====
447 /// Set the specified Thread Flags of a thread.
448 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
449 /// \param[in] flags specifies the flags of the thread that shall be set.
450 /// \return thread flags after setting or error code if highest bit set.
451 uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
453 /// Clear the specified Thread Flags of current running thread.
454 /// \param[in] flags specifies the flags of the thread that shall be cleared.
455 /// \return thread flags before clearing or error code if highest bit set.
456 uint32_t osThreadFlagsClear (uint32_t flags);
458 /// Get the current Thread Flags of current running thread.
459 /// \return current thread flags.
460 uint32_t osThreadFlagsGet (void);
462 /// Wait for one or more Thread Flags of the current running thread to become signaled.
463 /// \param[in] flags specifies the flags to wait for.
464 /// \param[in] options specifies flags options (osFlagsXxxx).
465 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
466 /// \return thread flags before clearing or error code if highest bit set.
467 uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
470 // ==== Generic Wait Functions ====
472 /// Wait for Timeout (Time Delay).
473 /// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value
474 /// \return status code that indicates the execution status of the function.
475 osStatus_t osDelay (uint32_t ticks);
477 /// Wait until specified time.
478 /// \param[in] ticks absolute time in ticks
479 /// \return status code that indicates the execution status of the function.
480 osStatus_t osDelayUntil (uint32_t ticks);
483 // ==== Timer Management Functions ====
485 /// Create and Initialize a timer.
486 /// \param[in] func function pointer to callback function.
487 /// \param[in] type \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior.
488 /// \param[in] argument argument to the timer callback function.
489 /// \param[in] attr timer attributes; NULL: default values.
490 /// \return timer ID for reference by other functions or NULL in case of error.
491 osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
493 /// Get name of a timer.
494 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
495 /// \return name as NULL terminated string.
496 const char *osTimerGetName (osTimerId_t timer_id);
498 /// Start or restart a timer.
499 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
500 /// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer.
501 /// \return status code that indicates the execution status of the function.
502 osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
505 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
506 /// \return status code that indicates the execution status of the function.
507 osStatus_t osTimerStop (osTimerId_t timer_id);
509 /// Check if a timer is running.
510 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
511 /// \return 0 not running, 1 running.
512 uint32_t osTimerIsRunning (osTimerId_t timer_id);
515 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
516 /// \return status code that indicates the execution status of the function.
517 osStatus_t osTimerDelete (osTimerId_t timer_id);
520 // ==== Event Flags Management Functions ====
522 /// Create and Initialize an Event Flags object.
523 /// \param[in] attr event flags attributes; NULL: default values.
524 /// \return event flags ID for reference by other functions or NULL in case of error.
525 osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
527 /// Get name of an Event Flags object.
528 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
529 /// \return name as NULL terminated string.
530 const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
532 /// Set the specified Event Flags.
533 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
534 /// \param[in] flags specifies the flags that shall be set.
535 /// \return event flags after setting or error code if highest bit set.
536 uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);
538 /// Clear the specified Event Flags.
539 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
540 /// \param[in] flags specifies the flags that shall be cleared.
541 /// \return event flags before clearing or error code if highest bit set.
542 uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
544 /// Get the current Event Flags.
545 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
546 /// \return current event flags.
547 uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
549 /// Wait for one or more Event Flags to become signaled.
550 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
551 /// \param[in] flags specifies the flags to wait for.
552 /// \param[in] options specifies flags options (osFlagsXxxx).
553 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
554 /// \return event flags before clearing or error code if highest bit set.
555 uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
557 /// Delete an Event Flags object.
558 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
559 /// \return status code that indicates the execution status of the function.
560 osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
563 // ==== Mutex Management Functions ====
565 /// Create and Initialize a Mutex object.
566 /// \param[in] attr mutex attributes; NULL: default values.
567 /// \return mutex ID for reference by other functions or NULL in case of error.
568 osMutexId_t osMutexNew (const osMutexAttr_t *attr);
570 /// Get name of a Mutex object.
571 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
572 /// \return name as NULL terminated string.
573 const char *osMutexGetName (osMutexId_t mutex_id);
575 /// Acquire a Mutex or timeout if it is locked.
576 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
577 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
578 /// \return status code that indicates the execution status of the function.
579 osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
581 /// Release a Mutex that was acquired by \ref osMutexAcquire.
582 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
583 /// \return status code that indicates the execution status of the function.
584 osStatus_t osMutexRelease (osMutexId_t mutex_id);
586 /// Get Thread which owns a Mutex object.
587 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
588 /// \return thread ID of owner thread or NULL when mutex was not acquired.
589 osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
591 /// Delete a Mutex object.
592 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
593 /// \return status code that indicates the execution status of the function.
594 osStatus_t osMutexDelete (osMutexId_t mutex_id);
597 // ==== Semaphore Management Functions ====
599 /// Create and Initialize a Semaphore object.
600 /// \param[in] max_count maximum number of available tokens.
601 /// \param[in] initial_count initial number of available tokens.
602 /// \param[in] attr semaphore attributes; NULL: default values.
603 /// \return semaphore ID for reference by other functions or NULL in case of error.
604 osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
606 /// Get name of a Semaphore object.
607 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
608 /// \return name as NULL terminated string.
609 const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
611 /// Acquire a Semaphore token or timeout if no tokens are available.
612 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
613 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
614 /// \return status code that indicates the execution status of the function.
615 osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
617 /// Release a Semaphore token up to the initial maximum count.
618 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
619 /// \return status code that indicates the execution status of the function.
620 osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
622 /// Get current Semaphore token count.
623 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
624 /// \return number of tokens available.
625 uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
627 /// Delete a Semaphore object.
628 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
629 /// \return status code that indicates the execution status of the function.
630 osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
633 // ==== Memory Pool Management Functions ====
635 /// Create and Initialize a Memory Pool object.
636 /// \param[in] block_count maximum number of memory blocks in memory pool.
637 /// \param[in] block_size memory block size in bytes.
638 /// \param[in] attr memory pool attributes; NULL: default values.
639 /// \return memory pool ID for reference by other functions or NULL in case of error.
640 osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
642 /// Get name of a Memory Pool object.
643 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
644 /// \return name as NULL terminated string.
645 const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
647 /// Allocate a memory block from a Memory Pool.
648 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
649 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
650 /// \return address of the allocated memory block or NULL in case of no memory is available.
651 void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
653 /// Return an allocated memory block back to a Memory Pool.
654 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
655 /// \param[in] block address of the allocated memory block to be returned to the memory pool.
656 /// \return status code that indicates the execution status of the function.
657 osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
659 /// Get maximum number of memory blocks in a Memory Pool.
660 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
661 /// \return maximum number of memory blocks.
662 uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
664 /// Get memory block size in a Memory Pool.
665 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
666 /// \return memory block size in bytes.
667 uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
669 /// Get number of memory blocks used in a Memory Pool.
670 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
671 /// \return number of memory blocks used.
672 uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
674 /// Get number of memory blocks available in a Memory Pool.
675 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
676 /// \return number of memory blocks available.
677 uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
679 /// Delete a Memory Pool object.
680 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
681 /// \return status code that indicates the execution status of the function.
682 osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
685 // ==== Message Queue Management Functions ====
687 /// Create and Initialize a Message Queue object.
688 /// \param[in] msg_count maximum number of messages in queue.
689 /// \param[in] msg_size maximum message size in bytes.
690 /// \param[in] attr message queue attributes; NULL: default values.
691 /// \return message queue ID for reference by other functions or NULL in case of error.
692 osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
694 /// Get name of a Message Queue object.
695 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
696 /// \return name as NULL terminated string.
697 const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
699 /// Put a Message into a Queue or timeout if Queue is full.
700 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
701 /// \param[in] msg_ptr pointer to buffer with message to put into a queue.
702 /// \param[in] msg_prio message priority.
703 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
704 /// \return status code that indicates the execution status of the function.
705 osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
707 /// Get a Message from a Queue or timeout if Queue is empty.
708 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
709 /// \param[out] msg_ptr pointer to buffer for message to get from a queue.
710 /// \param[out] msg_prio pointer to buffer for message priority or NULL.
711 /// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
712 /// \return status code that indicates the execution status of the function.
713 osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
715 /// Get maximum number of messages in a Message Queue.
716 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
717 /// \return maximum number of messages.
718 uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
720 /// Get maximum message size in a Memory Pool.
721 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
722 /// \return maximum message size in bytes.
723 uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
725 /// Get number of queued messages in a Message Queue.
726 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
727 /// \return number of queued messages.
728 uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
730 /// Get number of available slots for messages in a Message Queue.
731 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
732 /// \return number of available slots for messages.
733 uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
735 /// Reset a Message Queue to initial empty state.
736 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
737 /// \return status code that indicates the execution status of the function.
738 osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
740 /// Delete a Message Queue object.
741 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
742 /// \return status code that indicates the execution status of the function.
743 osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
750 #endif // CMSIS_OS2_H_