]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/rtos/rtx/TARGET_CORTEX_A/cmsis_os.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / rtos / rtx / TARGET_CORTEX_A / cmsis_os.h
1 /* ----------------------------------------------------------------------
2 * $Date: 5. June 2012
3 * $Revision: V1.01
4 *
5 * Project: CMSIS-RTOS API
6 * Title: cmsis_os.h RTX header file
7 *
8 * Version 0.02
9 * Initial Proposal Phase
10 * Version 0.03
11 * osKernelStart added, optional feature: main started as thread
12 * osSemaphores have standard behavior
13 * osTimerCreate does not start the timer, added osTimerStart
14 * osThreadPass is renamed to osThreadYield
15 * Version 1.01
16 * Support for C++ interface
17 * - const attribute removed from the osXxxxDef_t typedef's
18 * - const attribute added to the osXxxxDef macros
19 * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
20 * Added: osKernelInitialize
21 *----------------------------------------------------------------------------
22 *
23 * Copyright (c) 2012 ARM LIMITED
24 * All rights reserved.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions are met:
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * - Neither the name of ARM nor the names of its contributors may be used
33 * to endorse or promote products derived from this software without
34 * specific prior written permission.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
37 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
40 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 * POSSIBILITY OF SUCH DAMAGE.
47 *---------------------------------------------------------------------------*/
48
49 /**
50 \page cmsis_os_h Header File Template: cmsis_os.h
51
52 The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS).
53 Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents
54 its implementation.
55
56 The file cmsis_os.h contains:
57 - CMSIS-RTOS API function definitions
58 - struct definitions for parameters and return types
59 - status and priority values used by CMSIS-RTOS API functions
60 - macros for defining threads and other kernel objects
61
62
63 <b>Name conventions and header file modifications</b>
64
65 All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions.
66 Definitions that are prefixed \b os_ are not used in the application code but local to this header file.
67 All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread.
68
69 Definitions that are marked with <b>CAN BE CHANGED</b> can be adapted towards the needs of the actual CMSIS-RTOS implementation.
70 These definitions can be specific to the underlying RTOS kernel.
71
72 Definitions that are marked with <b>MUST REMAIN UNCHANGED</b> cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer
73 compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation.
74
75
76 <b>Function calls from interrupt service routines</b>
77
78 The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR):
79 - \ref osSignalSet
80 - \ref osSemaphoreRelease
81 - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree
82 - \ref osMessagePut, \ref osMessageGet
83 - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree
84
85 Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called
86 from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector.
87
88 Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time.
89 If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive.
90
91
92 <b>Define and reference object definitions</b>
93
94 With <b>\#define osObjectsExternal</b> objects are defined as external symbols. This allows to create a consistent header file
95 that is used throughout a project as shown below:
96
97 <i>Header File</i>
98 \code
99 #include <cmsis_os.h> // CMSIS RTOS header file
100
101 // Thread definition
102 extern void thread_sample (void const *argument); // function prototype
103 osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100);
104
105 // Pool definition
106 osPoolDef(MyPool, 10, long);
107 \endcode
108
109
110 This header file defines all objects when included in a C/C++ source file. When <b>\#define osObjectsExternal</b> is
111 present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be
112 used throughout the whole project.
113
114 <i>Example</i>
115 \code
116 #include "osObjects.h" // Definition of the CMSIS-RTOS objects
117 \endcode
118
119 \code
120 #define osObjectExternal // Objects will be defined as external symbols
121 #include "osObjects.h" // Reference to the CMSIS-RTOS objects
122 \endcode
123
124 */
125
126 #ifndef _CMSIS_OS_H
127 #define _CMSIS_OS_H
128
129 /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version.
130 #define osCMSIS 0x10001 ///< API version (main [31:16] .sub [15:0])
131
132 /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
133 #define osCMSIS_RTX ((4<<16)|61) ///< RTOS identification and version (main [31:16] .sub [15:0])
134
135 /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
136 #define osKernelSystemId "RTX V4.61" ///< RTOS identification string
137
138 #define CMSIS_OS_RTX
139 #define CMSIS_OS_RTX_CA /* new define for Coretex-A */
140
141 // The stack space occupied is mainly dependent on the underling C standard library
142 #if defined(TOOLCHAIN_GCC) || defined(TOOLCHAIN_ARM_STD)
143 # define WORDS_STACK_SIZE 512
144 #elif defined(TOOLCHAIN_ARM_MICRO)
145 # define WORDS_STACK_SIZE 128
146 #endif
147
148 #define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
149
150 /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
151 #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
152 #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available
153 #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available
154 #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
155 #define osFeature_Signals 16 ///< maximum number of Signal Flags available per thread
156 #define osFeature_Semaphore 65535 ///< maximum count for \ref osSemaphoreCreate function
157 #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available
158
159 #if defined (__CC_ARM)
160 #define os_InRegs __value_in_regs // Compiler specific: force struct in registers
161 #else
162 #define os_InRegs
163 #endif
164
165 #include <stdint.h>
166 #include <stddef.h>
167
168 #ifdef __cplusplus
169 extern "C"
170 {
171 #endif
172
173
174 // ==== Enumeration, structures, defines ====
175
176 /// Priority used for thread control.
177 /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
178 typedef enum {
179 osPriorityIdle = -3, ///< priority: idle (lowest)
180 osPriorityLow = -2, ///< priority: low
181 osPriorityBelowNormal = -1, ///< priority: below normal
182 osPriorityNormal = 0, ///< priority: normal (default)
183 osPriorityAboveNormal = +1, ///< priority: above normal
184 osPriorityHigh = +2, ///< priority: high
185 osPriorityRealtime = +3, ///< priority: realtime (highest)
186 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
187 } osPriority;
188
189 /// Timeout value.
190 /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
191 #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
192
193 /// Status code values returned by CMSIS-RTOS functions.
194 /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
195 typedef enum {
196 osOK = 0, ///< function completed; no error or event occurred.
197 osEventSignal = 0x08, ///< function completed; signal event occurred.
198 osEventMessage = 0x10, ///< function completed; message event occurred.
199 osEventMail = 0x20, ///< function completed; mail event occurred.
200 osEventTimeout = 0x40, ///< function completed; timeout occurred.
201 osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
202 osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
203 osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
204 osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
205 osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
206 osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
207 osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
208 osErrorValue = 0x86, ///< value of a parameter is out of range.
209 osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
210 os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
211 } osStatus;
212
213
214 /// Timer type value for the timer definition.
215 /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
216 typedef enum {
217 osTimerOnce = 0, ///< one-shot timer
218 osTimerPeriodic = 1 ///< repeating timer
219 } os_timer_type;
220
221 /// Entry point of a thread.
222 /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
223 typedef void (*os_pthread) (void const *argument);
224
225 /// Entry point of a timer call back function.
226 /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
227 typedef void (*os_ptimer) (void const *argument);
228
229 // >>> the following data type definitions may shall adapted towards a specific RTOS
230
231 /// Thread ID identifies the thread (pointer to a thread control block).
232 /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
233 typedef struct os_thread_cb *osThreadId;
234
235 /// Timer ID identifies the timer (pointer to a timer control block).
236 /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
237 typedef struct os_timer_cb *osTimerId;
238
239 /// Mutex ID identifies the mutex (pointer to a mutex control block).
240 /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
241 typedef struct os_mutex_cb *osMutexId;
242
243 /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
244 /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
245 typedef struct os_semaphore_cb *osSemaphoreId;
246
247 /// Pool ID identifies the memory pool (pointer to a memory pool control block).
248 /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
249 typedef struct os_pool_cb *osPoolId;
250
251 /// Message ID identifies the message queue (pointer to a message queue control block).
252 /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
253 typedef struct os_messageQ_cb *osMessageQId;
254
255 /// Mail ID identifies the mail queue (pointer to a mail queue control block).
256 /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
257 typedef struct os_mailQ_cb *osMailQId;
258
259
260 /// Thread Definition structure contains startup information of a thread.
261 /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
262 typedef struct os_thread_def {
263 os_pthread pthread; ///< start address of thread function
264 osPriority tpriority; ///< initial thread priority
265 uint32_t instances; ///< maximum number of instances of that thread function
266 uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
267 } osThreadDef_t;
268
269 /// Timer Definition structure contains timer parameters.
270 /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
271 typedef struct os_timer_def {
272 os_ptimer ptimer; ///< start address of a timer function
273 void *timer; ///< pointer to internal data
274 } osTimerDef_t;
275
276 /// Mutex Definition structure contains setup information for a mutex.
277 /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
278 typedef struct os_mutex_def {
279 void *mutex; ///< pointer to internal data
280 } osMutexDef_t;
281
282 /// Semaphore Definition structure contains setup information for a semaphore.
283 /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
284 typedef struct os_semaphore_def {
285 void *semaphore; ///< pointer to internal data
286 } osSemaphoreDef_t;
287
288 /// Definition structure for memory block allocation.
289 /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
290 typedef struct os_pool_def {
291 uint32_t pool_sz; ///< number of items (elements) in the pool
292 uint32_t item_sz; ///< size of an item
293 void *pool; ///< pointer to memory for pool
294 } osPoolDef_t;
295
296 /// Definition structure for message queue.
297 /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
298 typedef struct os_messageQ_def {
299 uint32_t queue_sz; ///< number of elements in the queue
300 void *pool; ///< memory array for messages
301 } osMessageQDef_t;
302
303 /// Definition structure for mail queue.
304 /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
305 typedef struct os_mailQ_def {
306 uint32_t queue_sz; ///< number of elements in the queue
307 uint32_t item_sz; ///< size of an item
308 void *pool; ///< memory array for mail
309 } osMailQDef_t;
310
311 /// Event structure contains detailed information about an event.
312 /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
313 /// However the struct may be extended at the end.
314 typedef struct {
315 osStatus status; ///< status code: event or error information
316 union {
317 uint32_t v; ///< message as 32-bit value
318 void *p; ///< message or mail as void pointer
319 int32_t signals; ///< signal flags
320 } value; ///< event value
321 union {
322 osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
323 osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
324 } def; ///< event definition
325 } osEvent;
326
327
328 // ==== Kernel Control Functions ====
329
330 /// Initialize the RTOS Kernel for creating objects.
331 /// \return status code that indicates the execution status of the function.
332 /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
333 osStatus osKernelInitialize (void);
334
335 /// Start the RTOS Kernel.
336 /// \return status code that indicates the execution status of the function.
337 /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
338 osStatus osKernelStart (void);
339
340 /// Check if the RTOS kernel is already started.
341 /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
342 /// \return 0 RTOS is not started, 1 RTOS is started.
343 int32_t osKernelRunning(void);
344
345
346 // ==== Thread Management ====
347
348 /// Create a Thread Definition with function, priority, and stack requirements.
349 /// \param name name of the thread function.
350 /// \param priority initial priority of the thread function.
351 /// \param instances number of possible thread instances.
352 /// \param stacksz stack size (in bytes) requirements for the thread function.
353 /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
354 /// macro body is implementation specific in every CMSIS-RTOS.
355 #if defined (osObjectsExternal) // object is external
356 #define osThreadDef(name, priority, instances, stacksz) \
357 extern const osThreadDef_t os_thread_def_##name
358 #else // define the object
359 #if defined (__MBED_CMSIS_RTOS_CA9)
360 #define osThreadDef(name, priority, stacksz) \
361 const osThreadDef_t os_thread_def_##name = \
362 { (name), (priority), 1, (stacksz) }
363 #else
364 #define osThreadDef(name, priority, instances, stacksz) \
365 const osThreadDef_t os_thread_def_##name = \
366 { (name), (priority), (instances), (stacksz) }
367 #endif
368 #endif
369
370 /// Access a Thread definition.
371 /// \param name name of the thread definition object.
372 /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
373 /// macro body is implementation specific in every CMSIS-RTOS.
374 #define osThread(name) \
375 &os_thread_def_##name
376
377 /// Create a thread and add it to Active Threads and set it to state READY.
378 /// \param[in] thread_def thread definition referenced with \ref osThread.
379 /// \param[in] argument pointer that is passed to the thread function as start argument.
380 /// \return thread ID for reference by other functions or NULL in case of error.
381 /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
382 osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
383
384 /// Return the thread ID of the current running thread.
385 /// \return thread ID for reference by other functions or NULL in case of error.
386 /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
387 osThreadId osThreadGetId (void);
388
389 /// Terminate execution of a thread and remove it from Active Threads.
390 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
391 /// \return status code that indicates the execution status of the function.
392 /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
393 osStatus osThreadTerminate (osThreadId thread_id);
394
395 /// Pass control to next thread that is in state \b READY.
396 /// \return status code that indicates the execution status of the function.
397 /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
398 osStatus osThreadYield (void);
399
400 /// Change priority of an active thread.
401 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
402 /// \param[in] priority new priority value for the thread function.
403 /// \return status code that indicates the execution status of the function.
404 /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
405 osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
406
407 /// Get current priority of an active thread.
408 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
409 /// \return current priority value of the thread function.
410 /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
411 osPriority osThreadGetPriority (osThreadId thread_id);
412
413 #ifdef __MBED_CMSIS_RTOS_CA9
414 /// Get current thread state.
415 uint8_t osThreadGetState (osThreadId thread_id);
416 #endif
417
418 // ==== Generic Wait Functions ====
419
420 /// Wait for Timeout (Time Delay).
421 /// \param[in] millisec time delay value
422 /// \return status code that indicates the execution status of the function.
423 osStatus osDelay (uint32_t millisec);
424
425 #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
426
427 /// Wait for Signal, Message, Mail, or Timeout.
428 /// \param[in] millisec timeout value or 0 in case of no time-out
429 /// \return event that contains signal, message, or mail information or error code.
430 /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
431 os_InRegs osEvent osWait (uint32_t millisec);
432
433 #endif // Generic Wait available
434
435
436 // ==== Timer Management Functions ====
437 /// Define a Timer object.
438 /// \param name name of the timer object.
439 /// \param function name of the timer call back function.
440 /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
441 /// macro body is implementation specific in every CMSIS-RTOS.
442 #if defined (osObjectsExternal) // object is external
443 #define osTimerDef(name, function) \
444 extern const osTimerDef_t os_timer_def_##name
445 #else // define the object
446 #define osTimerDef(name, function) \
447 uint32_t os_timer_cb_##name[5]; \
448 const osTimerDef_t os_timer_def_##name = \
449 { (function), (os_timer_cb_##name) }
450 #endif
451
452 /// Access a Timer definition.
453 /// \param name name of the timer object.
454 /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
455 /// macro body is implementation specific in every CMSIS-RTOS.
456 #define osTimer(name) \
457 &os_timer_def_##name
458
459 /// Create a timer.
460 /// \param[in] timer_def timer object referenced with \ref osTimer.
461 /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
462 /// \param[in] argument argument to the timer call back function.
463 /// \return timer ID for reference by other functions or NULL in case of error.
464 /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
465 osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
466
467 /// Start or restart a timer.
468 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
469 /// \param[in] millisec time delay value of the timer.
470 /// \return status code that indicates the execution status of the function.
471 /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
472 osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
473
474 /// Stop the timer.
475 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
476 /// \return status code that indicates the execution status of the function.
477 /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
478 osStatus osTimerStop (osTimerId timer_id);
479
480 /// Delete a timer that was created by \ref osTimerCreate.
481 /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
482 /// \return status code that indicates the execution status of the function.
483 /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
484 osStatus osTimerDelete (osTimerId timer_id);
485
486
487 // ==== Signal Management ====
488
489 /// Set the specified Signal Flags of an active thread.
490 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
491 /// \param[in] signals specifies the signal flags of the thread that should be set.
492 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
493 /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
494 int32_t osSignalSet (osThreadId thread_id, int32_t signals);
495
496 /// Clear the specified Signal Flags of an active thread.
497 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
498 /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
499 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
500 /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
501 int32_t osSignalClear (osThreadId thread_id, int32_t signals);
502
503 /// Get Signal Flags status of an active thread.
504 /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
505 /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
506 /// \note MUST REMAIN UNCHANGED: \b osSignalGet shall be consistent in every CMSIS-RTOS.
507 int32_t osSignalGet (osThreadId thread_id);
508
509 /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
510 /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
511 /// \param[in] millisec timeout value or 0 in case of no time-out.
512 /// \return event flag information or error code.
513 /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
514 os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec);
515
516
517 // ==== Mutex Management ====
518
519 /// Define a Mutex.
520 /// \param name name of the mutex object.
521 /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
522 /// macro body is implementation specific in every CMSIS-RTOS.
523 #if defined (osObjectsExternal) // object is external
524 #define osMutexDef(name) \
525 extern const osMutexDef_t os_mutex_def_##name
526 #else // define the object
527 #define osMutexDef(name) \
528 uint32_t os_mutex_cb_##name[3]; \
529 const osMutexDef_t os_mutex_def_##name = { (os_mutex_cb_##name) }
530 #endif
531
532 /// Access a Mutex definition.
533 /// \param name name of the mutex object.
534 /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
535 /// macro body is implementation specific in every CMSIS-RTOS.
536 #define osMutex(name) \
537 &os_mutex_def_##name
538
539 /// Create and Initialize a Mutex object.
540 /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
541 /// \return mutex ID for reference by other functions or NULL in case of error.
542 /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
543 osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
544
545 /// Wait until a Mutex becomes available.
546 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
547 /// \param[in] millisec timeout value or 0 in case of no time-out.
548 /// \return status code that indicates the execution status of the function.
549 /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
550 osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
551
552 /// Release a Mutex that was obtained by \ref osMutexWait.
553 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
554 /// \return status code that indicates the execution status of the function.
555 /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
556 osStatus osMutexRelease (osMutexId mutex_id);
557
558 /// Delete a Mutex that was created by \ref osMutexCreate.
559 /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
560 /// \return status code that indicates the execution status of the function.
561 /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
562 osStatus osMutexDelete (osMutexId mutex_id);
563
564
565 // ==== Semaphore Management Functions ====
566
567 #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
568
569 /// Define a Semaphore object.
570 /// \param name name of the semaphore object.
571 /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
572 /// macro body is implementation specific in every CMSIS-RTOS.
573 #if defined (osObjectsExternal) // object is external
574 #define osSemaphoreDef(name) \
575 extern const osSemaphoreDef_t os_semaphore_def_##name
576 #else // define the object
577 #define osSemaphoreDef(name) \
578 uint32_t os_semaphore_cb_##name[2]; \
579 const osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) }
580 #endif
581
582 /// Access a Semaphore definition.
583 /// \param name name of the semaphore object.
584 /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
585 /// macro body is implementation specific in every CMSIS-RTOS.
586 #define osSemaphore(name) \
587 &os_semaphore_def_##name
588
589 /// Create and Initialize a Semaphore object used for managing resources.
590 /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
591 /// \param[in] count number of available resources.
592 /// \return semaphore ID for reference by other functions or NULL in case of error.
593 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
594 osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
595
596 /// Wait until a Semaphore token becomes available.
597 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
598 /// \param[in] millisec timeout value or 0 in case of no time-out.
599 /// \return number of available tokens, or -1 in case of incorrect parameters.
600 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
601 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
602
603 /// Release a Semaphore token.
604 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
605 /// \return status code that indicates the execution status of the function.
606 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
607 osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
608
609 /// Delete a Semaphore that was created by \ref osSemaphoreCreate.
610 /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
611 /// \return status code that indicates the execution status of the function.
612 /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
613 osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
614
615 #endif // Semaphore available
616
617
618 // ==== Memory Pool Management Functions ====
619
620 #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
621
622 /// \brief Define a Memory Pool.
623 /// \param name name of the memory pool.
624 /// \param no maximum number of blocks (objects) in the memory pool.
625 /// \param type data type of a single block (object).
626 /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
627 /// macro body is implementation specific in every CMSIS-RTOS.
628 #if defined (osObjectsExternal) // object is external
629 #define osPoolDef(name, no, type) \
630 extern const osPoolDef_t os_pool_def_##name
631 #else // define the object
632 #define osPoolDef(name, no, type) \
633 uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \
634 const osPoolDef_t os_pool_def_##name = \
635 { (no), sizeof(type), (os_pool_m_##name) }
636 #endif
637
638 /// \brief Access a Memory Pool definition.
639 /// \param name name of the memory pool
640 /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
641 /// macro body is implementation specific in every CMSIS-RTOS.
642 #define osPool(name) \
643 &os_pool_def_##name
644
645 /// Create and Initialize a memory pool.
646 /// \param[in] pool_def memory pool definition referenced with \ref osPool.
647 /// \return memory pool ID for reference by other functions or NULL in case of error.
648 /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
649 osPoolId osPoolCreate (const osPoolDef_t *pool_def);
650
651 /// Allocate a memory block from a memory pool.
652 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
653 /// \return address of the allocated memory block or NULL in case of no memory available.
654 /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
655 void *osPoolAlloc (osPoolId pool_id);
656
657 /// Allocate a memory block from a memory pool and set memory block to zero.
658 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
659 /// \return address of the allocated memory block or NULL in case of no memory available.
660 /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
661 void *osPoolCAlloc (osPoolId pool_id);
662
663 /// Return an allocated memory block back to a specific memory pool.
664 /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
665 /// \param[in] block address of the allocated memory block that is returned to the memory pool.
666 /// \return status code that indicates the execution status of the function.
667 /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
668 osStatus osPoolFree (osPoolId pool_id, void *block);
669
670 #endif // Memory Pool Management available
671
672
673 // ==== Message Queue Management Functions ====
674
675 #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
676
677 /// \brief Create a Message Queue Definition.
678 /// \param name name of the queue.
679 /// \param queue_sz maximum number of messages in the queue.
680 /// \param type data type of a single message element (for debugger).
681 /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
682 /// macro body is implementation specific in every CMSIS-RTOS.
683 #if defined (osObjectsExternal) // object is external
684 #define osMessageQDef(name, queue_sz, type) \
685 extern const osMessageQDef_t os_messageQ_def_##name
686 #else // define the object
687 #define osMessageQDef(name, queue_sz, type) \
688 uint32_t os_messageQ_q_##name[4+(queue_sz)]; \
689 const osMessageQDef_t os_messageQ_def_##name = \
690 { (queue_sz), (os_messageQ_q_##name) }
691 #endif
692
693 /// \brief Access a Message Queue Definition.
694 /// \param name name of the queue
695 /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
696 /// macro body is implementation specific in every CMSIS-RTOS.
697 #define osMessageQ(name) \
698 &os_messageQ_def_##name
699
700 /// Create and Initialize a Message Queue.
701 /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
702 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
703 /// \return message queue ID for reference by other functions or NULL in case of error.
704 /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
705 osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
706
707 /// Put a Message to a Queue.
708 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
709 /// \param[in] info message information.
710 /// \param[in] millisec timeout value or 0 in case of no time-out.
711 /// \return status code that indicates the execution status of the function.
712 /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
713 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
714
715 /// Get a Message or Wait for a Message from a Queue.
716 /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
717 /// \param[in] millisec timeout value or 0 in case of no time-out.
718 /// \return event information that includes status code.
719 /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
720 os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
721
722 #endif // Message Queues available
723
724
725 // ==== Mail Queue Management Functions ====
726
727 #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
728
729 /// \brief Create a Mail Queue Definition.
730 /// \param name name of the queue
731 /// \param queue_sz maximum number of messages in queue
732 /// \param type data type of a single message element
733 /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
734 /// macro body is implementation specific in every CMSIS-RTOS.
735 #if defined (osObjectsExternal) // object is external
736 #define osMailQDef(name, queue_sz, type) \
737 extern const osMailQDef_t os_mailQ_def_##name
738 #else // define the object
739 #define osMailQDef(name, queue_sz, type) \
740 uint32_t os_mailQ_q_##name[4+(queue_sz)]; \
741 uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \
742 void * os_mailQ_p_##name[2] = { (os_mailQ_q_##name), os_mailQ_m_##name }; \
743 const osMailQDef_t os_mailQ_def_##name = \
744 { (queue_sz), sizeof(type), (os_mailQ_p_##name) }
745 #endif
746
747 /// \brief Access a Mail Queue Definition.
748 /// \param name name of the queue
749 /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
750 /// macro body is implementation specific in every CMSIS-RTOS.
751 #define osMailQ(name) \
752 &os_mailQ_def_##name
753
754 /// Create and Initialize mail queue.
755 /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
756 /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
757 /// \return mail queue ID for reference by other functions or NULL in case of error.
758 /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
759 osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
760
761 /// Allocate a memory block from a mail.
762 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
763 /// \param[in] millisec timeout value or 0 in case of no time-out
764 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
765 /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
766 void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
767
768 /// Allocate a memory block from a mail and set memory block to zero.
769 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
770 /// \param[in] millisec timeout value or 0 in case of no time-out
771 /// \return pointer to memory block that can be filled with mail or NULL in case of error.
772 /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
773 void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
774
775 /// Put a mail to a queue.
776 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
777 /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
778 /// \return status code that indicates the execution status of the function.
779 /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
780 osStatus osMailPut (osMailQId queue_id, void *mail);
781
782 /// Get a mail from a queue.
783 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
784 /// \param[in] millisec timeout value or 0 in case of no time-out
785 /// \return event that contains mail information or error code.
786 /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
787 os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
788
789 /// Free a memory block from a mail.
790 /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
791 /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
792 /// \return status code that indicates the execution status of the function.
793 /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
794 osStatus osMailFree (osMailQId queue_id, void *mail);
795
796 #endif // Mail Queues available
797
798
799 #ifdef __cplusplus
800 }
801 #endif
802
803 #endif // _CMSIS_OS_H
Imprint / Impressum