2 * Copyright (c) 2013-2016 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 * http://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: 17. October 2016
23 * Project: CMSIS-RTOS2 API
24 * Title: cmsis_os2.h header file
28 *---------------------------------------------------------------------------*/
35 #define __NO_RETURN __declspec(noreturn)
36 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
37 #define __NO_RETURN __attribute__((noreturn))
38 #elif defined(__GNUC__)
39 #define __NO_RETURN __attribute__((noreturn))
40 #elif defined(__ICCARM__)
41 #define __NO_RETURN __noreturn
56 // ==== Enumerations, structures, defines ====
58 /// Version information.
60 uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec).
61 uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
66 osKernelInactive = 0, ///< Inactive.
67 osKernelReady = 1, ///< Ready.
68 osKernelRunning = 2, ///< Running.
69 osKernelLocked = 3, ///< Locked.
70 osKernelSuspended = 4, ///< Suspended.
71 osKernelError = -1, ///< Error.
72 osKernelReserved = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization.
77 osThreadInactive = 0, ///< Inactive.
78 osThreadReady = 1, ///< Ready.
79 osThreadRunning = 2, ///< Running.
80 osThreadBlocked = 3, ///< Blocked.
81 osThreadTerminated = 4, ///< Terminated.
82 osThreadError = -1, ///< Error.
83 osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
88 osPriorityNone = 0, ///< No priority (not initialized).
89 osPriorityIdle = 1, ///< Reserved for Idle thread.
90 osPriorityLow = 8, ///< Priority: low
91 osPriorityLow1 = 8+1, ///< Priority: low + 1
92 osPriorityLow2 = 8+2, ///< Priority: low + 2
93 osPriorityLow3 = 8+3, ///< Priority: low + 3
94 osPriorityLow4 = 8+4, ///< Priority: low + 4
95 osPriorityLow5 = 8+5, ///< Priority: low + 5
96 osPriorityLow6 = 8+6, ///< Priority: low + 6
97 osPriorityLow7 = 8+7, ///< Priority: low + 7
98 osPriorityBelowNormal = 16, ///< Priority: below normal
99 osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1
100 osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2
101 osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3
102 osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4
103 osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5
104 osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6
105 osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7
106 osPriorityNormal = 24, ///< Priority: normal
107 osPriorityNormal1 = 24+1, ///< Priority: normal + 1
108 osPriorityNormal2 = 24+2, ///< Priority: normal + 2
109 osPriorityNormal3 = 24+3, ///< Priority: normal + 3
110 osPriorityNormal4 = 24+4, ///< Priority: normal + 4
111 osPriorityNormal5 = 24+5, ///< Priority: normal + 5
112 osPriorityNormal6 = 24+6, ///< Priority: normal + 6
113 osPriorityNormal7 = 24+7, ///< Priority: normal + 7
114 osPriorityAboveNormal = 32, ///< Priority: above normal
115 osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1
116 osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2
117 osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3
118 osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4
119 osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5
120 osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6
121 osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7
122 osPriorityHigh = 40, ///< Priority: high
123 osPriorityHigh1 = 40+1, ///< Priority: high + 1
124 osPriorityHigh2 = 40+2, ///< Priority: high + 2
125 osPriorityHigh3 = 40+3, ///< Priority: high + 3
126 osPriorityHigh4 = 40+4, ///< Priority: high + 4
127 osPriorityHigh5 = 40+5, ///< Priority: high + 5
128 osPriorityHigh6 = 40+6, ///< Priority: high + 6
129 osPriorityHigh7 = 40+7, ///< Priority: high + 7
130 osPriorityRealtime = 48, ///< Priority: realtime
131 osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1
132 osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2
133 osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3
134 osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4
135 osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5
136 osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6
137 osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7
138 osPriorityISR = 56, ///< Reserved for ISR deferred thread.
139 osPriorityError = -1, ///< System cannot determine priority or illegal priority.
140 osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
143 /// Entry point of a thread.
144 typedef void (*os_thread_func_t) (void *argument);
146 /// Entry point of a timer call back function.
147 typedef void (*os_timer_func_t) (void *argument);
151 osTimerOnce = 0, ///< One-shot timer.
152 osTimerPeriodic = 1 ///< Repeating timer.
156 #define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
158 /// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
159 #define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
160 #define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
161 #define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
163 /// Thread attributes (attr_bits in \ref osThreadAttr_t).
164 #define osThreadDetached 0x00000000U ///< Thread created in detached state (default)
165 #define osThreadJoinable 0x00000001U ///< Thread created in joinable state
167 /// Mutex attributes (attr_bits in \ref osMutexAttr_t).
168 #define osMutexRecursive 0x00000001U ///< Recursive mutex.
169 #define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
170 #define osMutexRobust 0x00000008U ///< Robust mutex.
172 /// Status code values returned by CMSIS-RTOS functions.
174 osOK = 0, ///< Operation completed successfully.
175 osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
176 osErrorTimeout = -2, ///< Operation not completed within the timeout period.
177 osErrorResource = -3, ///< Resource not available.
178 osErrorParameter = -4, ///< Parameter error.
179 osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
180 osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
181 osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
185 /// \details Thread ID identifies the thread.
186 typedef void *osThreadId_t;
188 /// \details Timer ID identifies the timer.
189 typedef void *osTimerId_t;
191 /// \details Event Flags ID identifies the event flags.
192 typedef void *osEventFlagsId_t;
194 /// \details Mutex ID identifies the mutex.
195 typedef void *osMutexId_t;
197 /// \details Semaphore ID identifies the semaphore.
198 typedef void *osSemaphoreId_t;
200 /// \details Memory Pool ID identifies the memory pool.
201 typedef void *osMemoryPoolId_t;
203 /// \details Message Queue ID identifies the message queue.
204 typedef void *osMessageQueueId_t;
207 #ifndef TZ_MODULEID_T
208 #define TZ_MODULEID_T
209 /// \details Data type that identifies secure software modules called by a process.
210 typedef uint32_t TZ_ModuleId_t;
214 /// Attributes structure for thread.
215 typedef struct osThreadAttr_s {
216 const char *name; ///< name of the thread
217 uint32_t attr_bits; ///< attribute bits
218 void *cb_mem; ///< memory for control block
219 uint32_t cb_size; ///< size of provided memory for control block
220 void *stack_mem; ///< memory for stack
221 uint32_t stack_size; ///< size of stack
222 osPriority_t priority; ///< initial thread priority (default: osPriorityNormal)
223 TZ_ModuleId_t tz_module; ///< TrustZone module identifier
224 uint32_t reserved; ///< reserved (must be 0)
227 /// Attributes structure for timer.
228 typedef struct osTimerAttr_s {
229 const char *name; ///< name of the timer
230 uint32_t attr_bits; ///< attribute bits
231 void *cb_mem; ///< memory for control block
232 uint32_t cb_size; ///< size of provided memory for control block
235 /// Attributes structure for event flags.
236 typedef struct osEventFlagsAttr_s {
237 const char *name; ///< name of the event flags
238 uint32_t attr_bits; ///< attribute bits
239 void *cb_mem; ///< memory for control block
240 uint32_t cb_size; ///< size of provided memory for control block
241 } osEventFlagsAttr_t;
243 /// Attributes structure for mutex.
244 typedef struct osMutexAttr_s {
245 const char *name; ///< name of the mutex
246 uint32_t attr_bits; ///< attribute bits
247 void *cb_mem; ///< memory for control block
248 uint32_t cb_size; ///< size of provided memory for control block
251 /// Attributes structure for semaphore.
252 typedef struct osSemaphoreAttr_s {
253 const char *name; ///< name of the semaphore
254 uint32_t attr_bits; ///< attribute bits
255 void *cb_mem; ///< memory for control block
256 uint32_t cb_size; ///< size of provided memory for control block
259 /// Attributes structure for memory pool.
260 typedef struct osMemoryPoolAttr_s {
261 const char *name; ///< name of the memory pool
262 uint32_t attr_bits; ///< attribute bits
263 void *cb_mem; ///< memory for control block
264 uint32_t cb_size; ///< size of provided memory for control block
265 void *mp_mem; ///< memory for data storage
266 uint32_t mp_size; ///< size of provided memory for data storage
267 } osMemoryPoolAttr_t;
269 /// Attributes structure for message queue.
270 typedef struct osMessageQueueAttr_s {
271 const char *name; ///< name of the message queue
272 uint32_t attr_bits; ///< attribute bits
273 void *cb_mem; ///< memory for control block
274 uint32_t cb_size; ///< size of provided memory for control block
275 void *mq_mem; ///< memory for data storage
276 uint32_t mq_size; ///< size of provided memory for data storage
277 } osMessageQueueAttr_t;
280 // ==== Kernel Management Functions ====
282 /// Initialize the RTOS Kernel.
283 /// \return status code that indicates the execution status of the function.
284 osStatus_t osKernelInitialize (void);
286 /// Get RTOS Kernel Information.
287 /// \param[out] version pointer to buffer for retrieving version information.
288 /// \param[out] id_buf pointer to buffer for retrieving kernel identification string.
289 /// \param[in] id_size size of buffer for kernel identification string.
290 /// \return status code that indicates the execution status of the function.
291 osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
293 /// Get the current RTOS Kernel state.
294 /// \return current RTOS Kernel state.
295 osKernelState_t osKernelGetState (void);
297 /// Start the RTOS Kernel scheduler.
298 /// \return status code that indicates the execution status of the function.
299 osStatus_t osKernelStart (void);
301 /// Lock the RTOS Kernel scheduler.
302 /// \return 0 already locked, 1 locked.
303 uint32_t osKernelLock (void);
305 /// Unlock the RTOS Kernel scheduler.
306 void osKernelUnlock (void);
308 /// Suspend the RTOS Kernel scheduler.
309 /// \return time in millisec, for how long the system can sleep or power-down.
310 uint32_t osKernelSuspend (void);
312 /// Resume the RTOS Kernel scheduler.
313 /// \param[in] sleep_time time in millisec for how long the system was in sleep or power-down mode.
314 void osKernelResume (uint32_t sleep_time);
316 /// Get the RTOS kernel time.
317 /// \return RTOS kernel current time in millisec.
318 uint64_t osKernelGetTime (void);
320 /// Get the RTOS kernel system timer counter.
321 /// \return RTOS kernel system timer as 32-bit value.
322 uint32_t osKernelGetTick (void);
324 /// Convert a microseconds value to a RTOS kernel system timer value.
325 /// \param microsec time value in microseconds.
326 /// \return time value normalized to the system timer ticks.
327 uint32_t osKernelTickMicroSec (uint32_t microsec);
330 // ==== Thread Management Functions ====
332 /// Create a thread and add it to Active Threads.
333 /// \param[in] func thread function.
334 /// \param[in] argument pointer that is passed to the thread function as start argument.
335 /// \param[in] attr thread attributes; NULL: default values.
336 /// \return thread ID for reference by other functions or NULL in case of error.
337 osThreadId_t osThreadNew (os_thread_func_t func, void *argument, const osThreadAttr_t *attr);
339 /// Return the thread ID of the current running thread.
340 /// \return thread ID for reference by other functions or NULL in case of error.
341 osThreadId_t osThreadGetId (void);
343 /// Get current thread state of a thread.
344 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
345 /// \return current thread state of the specified thread.
346 osThreadState_t osThreadGetState (osThreadId_t thread_id);
348 /// Change priority of a thread.
349 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
350 /// \param[in] priority new priority value for the thread function.
351 /// \return status code that indicates the execution status of the function.
352 osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
354 /// Get current priority of a thread.
355 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
356 /// \return current priority value of the specified thread.
357 osPriority_t osThreadGetPriority (osThreadId_t thread_id);
359 /// Pass control to next thread that is in state \b READY.
360 /// \return status code that indicates the execution status of the function.
361 osStatus_t osThreadYield (void);
363 /// Suspend execution of a thread.
364 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
365 /// \return status code that indicates the execution status of the function.
366 osStatus_t osThreadSuspend (osThreadId_t thread_id);
368 /// Resume execution of a thread.
369 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
370 /// \return status code that indicates the execution status of the function.
371 osStatus_t osThreadResume (osThreadId_t thread_id);
373 /// Detach a thread (thread storage can be reclaimed when thread terminates).
374 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
375 /// \return status code that indicates the execution status of the function.
376 osStatus_t osThreadDetach (osThreadId_t thread_id);
378 /// Wait for specified thread to terminate.
379 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
380 /// \return status code that indicates the execution status of the function.
381 osStatus_t osThreadJoin (osThreadId_t thread_id);
383 /// Terminate execution of current running thread.
384 __NO_RETURN void osThreadExit (void);
386 /// Terminate execution of a thread.
387 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
388 /// \return status code that indicates the execution status of the function.
389 osStatus_t osThreadTerminate (osThreadId_t thread_id);
392 // ==== Thread Flags Functions ====
394 /// Set the specified Thread Flags of a thread.
395 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
396 /// \param[in] flags specifies the flags of the thread that shall be set.
397 /// \return thread flags after setting or error code if negative.
398 int32_t osThreadFlagsSet (osThreadId_t thread_id, int32_t flags);
400 /// Clear the specified Thread Flags of current running thread.
401 /// \param[in] flags specifies the flags of the thread that shall be cleared.
402 /// \return thread flags before clearing or error code if negative.
403 int32_t osThreadFlagsClear (int32_t flags);
405 /// Get the current Thread Flags of current running thread.
406 /// \return current thread flags.
407 int32_t osThreadFlagsGet (void);
409 /// Wait for one or more Thread Flags of the current running thread to become signaled.
410 /// \param[in] flags specifies the flags to wait for.
411 /// \param[in] options specifies flags options (osFlagsXxxx).
412 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
413 /// \return thread flags before clearing or error code if negative.
414 int32_t osThreadFlagsWait (int32_t flags, uint32_t options, uint32_t millisec);
417 // ==== Generic Wait Functions ====
419 /// Wait for Timeout (Time Delay).
420 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
421 /// \return status code that indicates the execution status of the function.
422 osStatus_t osDelay (uint32_t millisec);
424 /// Wait until specified time.
425 /// \param[in] millisec absolute time in millisec
426 /// \return status code that indicates the execution status of the function.
427 osStatus_t osDelayUntil (uint64_t millisec);
430 // ==== Timer Management Functions ====
432 /// Create and Initialize a timer.
433 /// \param[in] func start address of a timer call back function.
434 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
435 /// \param[in] argument argument to the timer call back function.
436 /// \param[in] attr timer attributes; NULL: default values.
437 /// \return timer ID for reference by other functions or NULL in case of error.
438 osTimerId_t osTimerNew (os_timer_func_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
440 /// Start or restart a timer.
441 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
442 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
443 /// \return status code that indicates the execution status of the function.
444 osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t millisec);
447 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
448 /// \return status code that indicates the execution status of the function.
449 osStatus_t osTimerStop (osTimerId_t timer_id);
451 /// Check if a timer is running.
452 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
453 /// \return 0 not running, 1 running.
454 uint32_t osTimerIsRunning (osTimerId_t timer_id);
457 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
458 /// \return status code that indicates the execution status of the function.
459 osStatus_t osTimerDelete (osTimerId_t timer_id);
462 // ==== Event Flags Management Functions ====
464 /// Create and Initialize an Event Flags object.
465 /// \param[in] attr event flags attributes; NULL: default values.
466 /// \return event flags ID for reference by other functions or NULL in case of error.
467 osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
469 /// Set the specified Event Flags.
470 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
471 /// \param[in] flags specifies the flags that shall be set.
472 /// \return event flags after setting or error code if negative.
473 int32_t osEventFlagsSet (osEventFlagsId_t ef_id, int32_t flags);
475 /// Clear the specified Event Flags.
476 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
477 /// \param[in] flags specifies the flags that shall be cleared.
478 /// \return event flags before clearing or error code if negative.
479 int32_t osEventFlagsClear (osEventFlagsId_t ef_id, int32_t flags);
481 /// Get the current Event Flags.
482 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
483 /// \return current event flags.
484 int32_t osEventFlagsGet (osEventFlagsId_t ef_id);
486 /// Wait for one or more Event Flags to become signaled.
487 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
488 /// \param[in] flags specifies the flags to wait for.
489 /// \param[in] options specifies flags options (osFlagsXxxx).
490 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
491 /// \return event flags before clearing or error code if negative.
492 int32_t osEventFlagsWait (osEventFlagsId_t ef_id, int32_t flags, uint32_t options, uint32_t millisec);
494 /// Delete an Event Flags object.
495 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
496 /// \return status code that indicates the execution status of the function.
497 osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
500 // ==== Mutex Management Functions ====
502 /// Create and Initialize a Mutex object.
503 /// \param[in] attr mutex attributes; NULL: default values.
504 /// \return mutex ID for reference by other functions or NULL in case of error.
505 osMutexId_t osMutexNew (const osMutexAttr_t *attr);
507 /// Acquire a Mutex or timeout if it is locked.
508 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
509 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
510 /// \return status code that indicates the execution status of the function.
511 osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t millisec);
513 /// Release a Mutex that was acquired by \ref osMutexAcquire.
514 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
515 /// \return status code that indicates the execution status of the function.
516 osStatus_t osMutexRelease (osMutexId_t mutex_id);
518 /// Get Thread which owns a Mutex object.
519 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
520 /// \return thread ID of owner thread or NULL when mutex was not acquired.
521 osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
523 /// Delete a Mutex object.
524 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
525 /// \return status code that indicates the execution status of the function.
526 osStatus_t osMutexDelete (osMutexId_t mutex_id);
529 // ==== Semaphore Management Functions ====
531 /// Create and Initialize a Semaphore object.
532 /// \param[in] max_count maximum number of available tokens.
533 /// \param[in] initial_count initial number of available tokens.
534 /// \param[in] attr semaphore attributes; NULL: default values.
535 /// \return semaphore ID for reference by other functions or NULL in case of error.
536 osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
538 /// Acquire a Semaphore token or timeout if no tokens are available.
539 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
540 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
541 /// \return status code that indicates the execution status of the function.
542 osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t millisec);
544 /// Release a Semaphore token that was acquired by \ref osSemaphoreAcquire.
545 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
546 /// \return status code that indicates the execution status of the function.
547 osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
549 /// Get current Semaphore token count.
550 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
551 /// \return number of tokens available.
552 uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
554 /// Delete a Semaphore object.
555 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
556 /// \return status code that indicates the execution status of the function.
557 osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
560 // ==== Memory Pool Management Functions ====
562 /// Create and Initialize a Memory Pool object.
563 /// \param[in] block_count maximum number of memory blocks in memory pool.
564 /// \param[in] block_size memory block size in bytes.
565 /// \param[in] attr memory pool attributes; NULL: default values.
566 /// \return memory pool ID for reference by other functions or NULL in case of error.
567 osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
569 /// Allocate a memory block from a Memory Pool.
570 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
571 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
572 /// \return address of the allocated memory block or NULL in case of no memory is available.
573 void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t millisec);
575 /// Return an allocated memory block back to a Memory Pool.
576 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
577 /// \param[in] block address of the allocated memory block to be returned to the memory pool.
578 /// \return status code that indicates the execution status of the function.
579 osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
581 /// Get maximum number of memory blocks in a Memory Pool.
582 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
583 /// \return maximum number of memory blocks.
584 uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
586 /// Get memory block size in a Memory Pool.
587 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
588 /// \return memory block size in bytes.
589 uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
591 /// Get number of memory blocks used in a Memory Pool.
592 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
593 /// \return number of memory blocks used.
594 uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
596 /// Get number of memory blocks available in a Memory Pool.
597 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
598 /// \return number of memory blocks available.
599 uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
601 /// Delete a Memory Pool object.
602 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
603 /// \return status code that indicates the execution status of the function.
604 osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
607 // ==== Message Queue Management Functions ====
609 /// Create and Initialize a Message Queue object.
610 /// \param[in] msg_count maximum number of messages in queue.
611 /// \param[in] msg_size maximum message size in bytes.
612 /// \param[in] attr message queue attributes; NULL: default values.
613 /// \return message queue ID for reference by other functions or NULL in case of error.
614 osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
616 /// Put a Message into a Queue or timeout if Queue is full.
617 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
618 /// \param[in] msg_ptr pointer to buffer with message to put into a queue.
619 /// \param[in] msg_prio message priority.
620 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
621 /// \return status code that indicates the execution status of the function.
622 osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t millisec);
624 /// Get a Message from a Queue or timeout if Queue is empty.
625 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
626 /// \param[out] msg_ptr pointer to buffer for message to get from a queue.
627 /// \param[out] msg_prio pointer to buffer for message priority or NULL.
628 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
629 /// \return status code that indicates the execution status of the function.
630 osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t millisec);
632 /// Get maximum number of messages in a Message Queue.
633 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
634 /// \return maximum number of messages.
635 uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
637 /// Get maximum message size in a Memory Pool.
638 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
639 /// \return maximum message size in bytes.
640 uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
642 /// Get number of queued messages in a Message Queue.
643 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
644 /// \return number of queued messages.
645 uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
647 /// Get number of available slots for messages in a Message Queue.
648 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
649 /// \return number of available slots for messages.
650 uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
652 /// Reset a Message Queue to initial empty state.
653 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
654 /// \return status code that indicates the execution status of the function.
655 osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
657 /// Delete a Message Queue object.
658 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
659 /// \return status code that indicates the execution status of the function.
660 osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
667 #endif // CMSIS_OS2_H_