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: 12. 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 osThreadJoinable 0x00000000U ///< Thread created in joinable state (default)
165 #define osThreadDetached 0x00000001U ///< Thread created in detached 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 /// \param[out] exit_ptr pointer to thread exit pointer value.
381 /// \return status code that indicates the execution status of the function.
382 osStatus_t osThreadJoin (osThreadId_t thread_id, void **exit_ptr);
384 /// Terminate execution of current running thread.
385 /// \param[in] exit_ptr thread exit pointer value.
386 __NO_RETURN void osThreadExit (void *exit_ptr);
388 /// Terminate execution of a thread.
389 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
390 /// \return status code that indicates the execution status of the function.
391 osStatus_t osThreadTerminate (osThreadId_t thread_id);
394 // ==== Thread Flags Functions ====
396 /// Set the specified Thread Flags of a thread.
397 /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
398 /// \param[in] flags specifies the flags of the thread that shall be set.
399 /// \return thread flags after setting or error code if negative.
400 int32_t osThreadFlagsSet (osThreadId_t thread_id, int32_t flags);
402 /// Clear the specified Thread Flags of current running thread.
403 /// \param[in] flags specifies the flags of the thread that shall be cleared.
404 /// \return thread flags before clearing or error code if negative.
405 int32_t osThreadFlagsClear (int32_t flags);
407 /// Get the current Thread Flags of current running thread.
408 /// \return current thread flags.
409 int32_t osThreadFlagsGet (void);
411 /// Wait for one or more Thread Flags of the current running thread to become signaled.
412 /// \param[in] flags specifies the flags to wait for.
413 /// \param[in] options specifies flags options (osFlagsXxxx).
414 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
415 /// \return thread flags before clearing or error code if negative.
416 int32_t osThreadFlagsWait (int32_t flags, uint32_t options, uint32_t millisec);
419 // ==== Generic Wait Functions ====
421 /// Wait for Timeout (Time Delay).
422 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
423 /// \return status code that indicates the execution status of the function.
424 osStatus_t osDelay (uint32_t millisec);
426 /// Wait until specified time.
427 /// \param[in] millisec absolute time in millisec
428 /// \return status code that indicates the execution status of the function.
429 osStatus_t osDelayUntil (uint64_t millisec);
432 // ==== Timer Management Functions ====
434 /// Create and Initialize a timer.
435 /// \param[in] func start address of a timer call back function.
436 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
437 /// \param[in] argument argument to the timer call back function.
438 /// \param[in] attr timer attributes; NULL: default values.
439 /// \return timer ID for reference by other functions or NULL in case of error.
440 osTimerId_t osTimerNew (os_timer_func_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
442 /// Start or restart a timer.
443 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
444 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
445 /// \return status code that indicates the execution status of the function.
446 osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t millisec);
449 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
450 /// \return status code that indicates the execution status of the function.
451 osStatus_t osTimerStop (osTimerId_t timer_id);
453 /// Check if a timer is running.
454 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
455 /// \return 0 not running, 1 running.
456 uint32_t osTimerIsRunning (osTimerId_t timer_id);
459 /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
460 /// \return status code that indicates the execution status of the function.
461 osStatus_t osTimerDelete (osTimerId_t timer_id);
464 // ==== Event Flags Management Functions ====
466 /// Create and Initialize an Event Flags object.
467 /// \param[in] attr event flags attributes; NULL: default values.
468 /// \return event flags ID for reference by other functions or NULL in case of error.
469 osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
471 /// Set the specified Event Flags.
472 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
473 /// \param[in] flags specifies the flags that shall be set.
474 /// \return event flags after setting or error code if negative.
475 int32_t osEventFlagsSet (osEventFlagsId_t ef_id, int32_t flags);
477 /// Clear the specified Event Flags.
478 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
479 /// \param[in] flags specifies the flags that shall be cleared.
480 /// \return event flags before clearing or error code if negative.
481 int32_t osEventFlagsClear (osEventFlagsId_t ef_id, int32_t flags);
483 /// Get the current Event Flags.
484 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
485 /// \return current event flags.
486 int32_t osEventFlagsGet (osEventFlagsId_t ef_id);
488 /// Wait for one or more Event Flags to become signaled.
489 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
490 /// \param[in] flags specifies the flags to wait for.
491 /// \param[in] options specifies flags options (osFlagsXxxx).
492 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
493 /// \return event flags before clearing or error code if negative.
494 int32_t osEventFlagsWait (osEventFlagsId_t ef_id, int32_t flags, uint32_t options, uint32_t millisec);
496 /// Delete an Event Flags object.
497 /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
498 /// \return status code that indicates the execution status of the function.
499 osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
502 // ==== Mutex Management Functions ====
504 /// Create and Initialize a Mutex object.
505 /// \param[in] attr mutex attributes; NULL: default values.
506 /// \return mutex ID for reference by other functions or NULL in case of error.
507 osMutexId_t osMutexNew (const osMutexAttr_t *attr);
509 /// Acquire a Mutex or timeout if it is locked.
510 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
511 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
512 /// \return status code that indicates the execution status of the function.
513 osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t millisec);
515 /// Release a Mutex that was acquired by \ref osMutexAcquire.
516 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
517 /// \return status code that indicates the execution status of the function.
518 osStatus_t osMutexRelease (osMutexId_t mutex_id);
520 /// Get Thread which owns a Mutex object.
521 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
522 /// \return thread ID of owner thread or NULL when mutex was not acquired.
523 osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
525 /// Delete a Mutex object.
526 /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
527 /// \return status code that indicates the execution status of the function.
528 osStatus_t osMutexDelete (osMutexId_t mutex_id);
531 // ==== Semaphore Management Functions ====
533 /// Create and Initialize a Semaphore object.
534 /// \param[in] max_count maximum number of available tokens.
535 /// \param[in] initial_count initial number of available tokens.
536 /// \param[in] attr semaphore attributes; NULL: default values.
537 /// \return semaphore ID for reference by other functions or NULL in case of error.
538 osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
540 /// Acquire a Semaphore token or timeout if no tokens are available.
541 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
542 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
543 /// \return status code that indicates the execution status of the function.
544 osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t millisec);
546 /// Release a Semaphore token that was acquired by \ref osSemaphoreAcquire.
547 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
548 /// \return status code that indicates the execution status of the function.
549 osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
551 /// Get current Semaphore token count.
552 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
553 /// \return number of tokens available.
554 uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
556 /// Delete a Semaphore object.
557 /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
558 /// \return status code that indicates the execution status of the function.
559 osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
562 // ==== Memory Pool Management Functions ====
564 /// Create and Initialize a Memory Pool object.
565 /// \param[in] block_count maximum number of memory blocks in memory pool.
566 /// \param[in] block_size memory block size in bytes.
567 /// \param[in] attr memory pool attributes; NULL: default values.
568 /// \return memory pool ID for reference by other functions or NULL in case of error.
569 osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
571 /// Allocate a memory block from a Memory Pool.
572 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
573 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
574 /// \return address of the allocated memory block or NULL in case of no memory is available.
575 void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t millisec);
577 /// Return an allocated memory block back to a Memory Pool.
578 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
579 /// \param[in] block address of the allocated memory block to be returned to the memory pool.
580 /// \return status code that indicates the execution status of the function.
581 osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
583 /// Get maximum number of memory blocks in a Memory Pool.
584 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
585 /// \return maximum number of memory blocks.
586 uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
588 /// Get memory block size in a Memory Pool.
589 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
590 /// \return memory block size in bytes.
591 uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
593 /// Get number of memory blocks used in a Memory Pool.
594 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
595 /// \return number of memory blocks used.
596 uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
598 /// Get number of memory blocks available in a Memory Pool.
599 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
600 /// \return number of memory blocks available.
601 uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
603 /// Delete a Memory Pool object.
604 /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
605 /// \return status code that indicates the execution status of the function.
606 osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
609 // ==== Message Queue Management Functions ====
611 /// Create and Initialize a Message Queue object.
612 /// \param[in] msg_count maximum number of messages in queue.
613 /// \param[in] msg_size maximum message size in bytes.
614 /// \param[in] attr message queue attributes; NULL: default values.
615 /// \return message queue ID for reference by other functions or NULL in case of error.
616 osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
618 /// Put a Message into a Queue or timeout if Queue is full.
619 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
620 /// \param[in] msg_ptr pointer to buffer with message to put into a queue.
621 /// \param[in] msg_prio message priority.
622 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
623 /// \return status code that indicates the execution status of the function.
624 osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t millisec);
626 /// Get a Message from a Queue or timeout if Queue is empty.
627 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
628 /// \param[out] msg_ptr pointer to buffer for message to get from a queue.
629 /// \param[out] msg_prio pointer to buffer for message priority or NULL.
630 /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
631 /// \return status code that indicates the execution status of the function.
632 osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t millisec);
634 /// Get maximum number of messages in a Message Queue.
635 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
636 /// \return maximum number of messages.
637 uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
639 /// Get maximum message size in a Memory Pool.
640 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
641 /// \return maximum message size in bytes.
642 uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
644 /// Get number of queued messages in a Message Queue.
645 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
646 /// \return number of queued messages.
647 uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
649 /// Get number of available slots for messages in a Message Queue.
650 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
651 /// \return number of available slots for messages.
652 uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
654 /// Reset a Message Queue to initial empty state.
655 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
656 /// \return status code that indicates the execution status of the function.
657 osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
659 /// Delete a Message Queue object.
660 /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
661 /// \return status code that indicates the execution status of the function.
662 osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
669 #endif // __CMSIS_OS2_H