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