]> begriffs open source - cmsis/blob - CMSIS/RTOS2/Include/cmsis_os2.h
CoreValidation: Fixed example projects.
[cmsis] / CMSIS / RTOS2 / Include / cmsis_os2.h
1 /*
2  * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
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
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * ----------------------------------------------------------------------
19  *
20  * $Date:        9. June 2017
21  * $Revision:    V2.1.1
22  *
23  * Project:      CMSIS-RTOS2 API
24  * Title:        cmsis_os2.h header file
25  *
26  * Version 2.1.1
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
31  * Version 2.1.0
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
37  * Version 2.0.0
38  *    Initial Release
39  *---------------------------------------------------------------------------*/
40  
41 #ifndef CMSIS_OS2_H_
42 #define CMSIS_OS2_H_
43  
44 #ifndef __NO_RETURN
45 #if   defined(__CC_ARM)
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
53 #else
54 #define __NO_RETURN
55 #endif
56 #endif
57  
58 #include <stdint.h>
59 #include <stddef.h>
60  
61 #ifdef  __cplusplus
62 extern "C"
63 {
64 #endif
65  
66  
67 //  ==== Enumerations, structures, defines ====
68  
69 /// Version information.
70 typedef struct {
71   uint32_t                       api;   ///< API version (major.minor.rev: mmnnnrrrr dec).
72   uint32_t                    kernel;   ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
73 } osVersion_t;
74  
75 /// Kernel state.
76 typedef enum {
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.
84 } osKernelState_t;
85  
86 /// Thread state.
87 typedef enum {
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.
95 } osThreadState_t;
96  
97 /// Priority values.
98 typedef enum {
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.
152 } osPriority_t;
153  
154 /// Entry point of a thread.
155 typedef void (*osThreadFunc_t) (void *argument);
156  
157 /// Timer callback function.
158 typedef void (*osTimerFunc_t) (void *argument);
159  
160 /// Timer type.
161 typedef enum {
162   osTimerOnce               = 0,          ///< One-shot timer.
163   osTimerPeriodic           = 1           ///< Repeating timer.
164 } osTimerType_t;
165  
166 // Timeout value.
167 #define osWaitForever         0xFFFFFFFFU ///< Wait forever timeout value.
168  
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.
173  
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).
181  
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
185  
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.
190  
191 /// Status code values returned by CMSIS-RTOS functions.
192 typedef enum {
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.
201 } osStatus_t;
202  
203  
204 /// \details Thread ID identifies the thread.
205 typedef void *osThreadId_t;
206  
207 /// \details Timer ID identifies the timer.
208 typedef void *osTimerId_t;
209  
210 /// \details Event Flags ID identifies the event flags.
211 typedef void *osEventFlagsId_t;
212  
213 /// \details Mutex ID identifies the mutex.
214 typedef void *osMutexId_t;
215  
216 /// \details Semaphore ID identifies the semaphore.
217 typedef void *osSemaphoreId_t;
218  
219 /// \details Memory Pool ID identifies the memory pool.
220 typedef void *osMemoryPoolId_t;
221  
222 /// \details Message Queue ID identifies the message queue.
223 typedef void *osMessageQueueId_t;
224  
225  
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;
230 #endif
231  
232  
233 /// Attributes structure for thread.
234 typedef struct {
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)
244 } osThreadAttr_t;
245  
246 /// Attributes structure for timer.
247 typedef struct {
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
252 } osTimerAttr_t;
253  
254 /// Attributes structure for event flags.
255 typedef struct {
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;
261  
262 /// Attributes structure for mutex.
263 typedef struct {
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
268 } osMutexAttr_t;
269  
270 /// Attributes structure for semaphore.
271 typedef struct {
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
276 } osSemaphoreAttr_t;
277  
278 /// Attributes structure for memory pool.
279 typedef struct {
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;
287  
288 /// Attributes structure for message queue.
289 typedef struct {
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;
297  
298  
299 //  ==== Kernel Management Functions ====
300  
301 /// Initialize the RTOS Kernel.
302 /// \return status code that indicates the execution status of the function.
303 osStatus_t osKernelInitialize (void);
304  
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);
311  
312 /// Get the current RTOS Kernel state.
313 /// \return current RTOS Kernel state.
314 osKernelState_t osKernelGetState (void);
315  
316 /// Start the RTOS Kernel scheduler.
317 /// \return status code that indicates the execution status of the function.
318 osStatus_t osKernelStart (void);
319  
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);
323  
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);
327  
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);
332  
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);
336  
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);
340  
341 /// Get the RTOS kernel tick count.
342 /// \return RTOS kernel current tick count.
343 uint32_t osKernelGetTickCount (void);
344  
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);
348  
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);
352  
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);
356  
357  
358 //  ==== Thread Management Functions ====
359  
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);
366  
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);
371  
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);
375  
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);
380  
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);
385  
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);
390  
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);
396  
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);
401  
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);
405  
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);
410  
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);
415  
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);
420  
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);
425  
426 /// Terminate execution of current running thread.
427 __NO_RETURN void osThreadExit (void);
428  
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);
433  
434 /// Get number of active threads.
435 /// \return number of active threads.
436 uint32_t osThreadGetCount (void);
437  
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);
443  
444  
445 //  ==== Thread Flags Functions ====
446  
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);
452  
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);
457  
458 /// Get the current Thread Flags of current running thread.
459 /// \return current thread flags.
460 uint32_t osThreadFlagsGet (void);
461  
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);
468  
469  
470 //  ==== Generic Wait Functions ====
471  
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);
476  
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);
481  
482  
483 //  ==== Timer Management Functions ====
484  
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);
492  
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);
497  
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);
503  
504 /// Stop a timer.
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);
508  
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);
513  
514 /// Delete a timer.
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);
518  
519  
520 //  ==== Event Flags Management Functions ====
521  
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);
526  
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);
531  
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);
537  
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);
543  
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);
548  
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);
556  
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);
561  
562  
563 //  ==== Mutex Management Functions ====
564  
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);
569  
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);
574  
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);
580  
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);
585  
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);
590  
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);
595  
596  
597 //  ==== Semaphore Management Functions ====
598  
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);
605  
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);
610  
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);
616  
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);
621  
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);
626  
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);
631  
632  
633 //  ==== Memory Pool Management Functions ====
634  
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);
641  
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);
646  
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);
652  
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);
658  
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);
663  
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);
668  
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);
673  
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);
678  
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);
683  
684  
685 //  ==== Message Queue Management Functions ====
686  
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);
693  
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);
698  
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);
706  
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);
714  
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);
719  
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);
724  
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);
729  
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);
734  
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);
739  
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);
744  
745  
746 #ifdef  __cplusplus
747 }
748 #endif
749  
750 #endif  // CMSIS_OS2_H_