cmsis_os.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2012 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 5. March 2012
  5. * $Revision: V0.03
  6. *
  7. * Project: CMSIS-RTOS API
  8. * Title: cmsis_os.h RT-Thread header file
  9. *
  10. * Version 0.02
  11. * Initial Proposal Phase
  12. * Version 0.03
  13. * osKernelStart added, optional feature: main started as thread
  14. * osSemaphores have standard behaviour
  15. * osTimerCreate does not start the timer, added osTimerStart
  16. * osThreadPass is renamed to osThreadYield
  17. * -------------------------------------------------------------------- */
  18. /**
  19. \page cmsis_os_h Header File Template: cmsis_os.h
  20. The file \b cmsis_os.h is a template header file for a CMSIS-RTOS compliant Real-Time Operating System (RTOS).
  21. Each RTOS that is compliant with CMSIS-RTOS shall provide a specific \b cmsis_os.h header file that represents
  22. its implementation.
  23. The file cmsis_os.h contains:
  24. - CMSIS-RTOS API function definitions
  25. - struct definitions for parameters and return types
  26. - status and priority values used by CMSIS-RTOS API functions
  27. - macros for defining threads and other kernel objects
  28. <b>Name conventions and header file modifications</b>
  29. All definitions are prefixed with \b os to give an unique name space for CMSIS-RTOS functions.
  30. Definitions that are prefixed \b os_ are not used in the application code but local to this header file.
  31. All definitions and functions that belong to a module are grouped and have a common prefix, i.e. \b osThread.
  32. Definitions that are marked with <b>CAN BE CHANGED</b> can be adapted towards the needs of the actual CMSIS-RTOS implementation.
  33. These definitions can be specific to the underlying RTOS kernel.
  34. Definitions that are marked with <b>MUST REMAIN UNCHANGED</b> cannot be altered. Otherwise the CMSIS-RTOS implementation is no longer
  35. compliant to the standard. Note that some functions are optional and need not to be provided by every CMSIS-RTOS implementation.
  36. <b>Function calls from interrupt service routines</b>
  37. The following CMSIS-RTOS functions can be called from threads and interrupt service routines (ISR):
  38. - \ref osSignalSet
  39. - \ref osSemaphoreRelease
  40. - \ref osPoolAlloc, \ref osPoolCAlloc, \ref osPoolFree
  41. - \ref osMessagePut, \ref osMessageGet
  42. - \ref osMailAlloc, \ref osMailCAlloc, \ref osMailGet, \ref osMailPut, \ref osMailFree
  43. Functions that cannot be called from an ISR are verifying the interrupt status and return in case that they are called
  44. from an ISR context the status code \b osErrorISR. In some implementations this condition might be caught using the HARD FAULT vector.
  45. Some CMSIS-RTOS implementations support CMSIS-RTOS function calls from multiple ISR at the same time.
  46. If this is impossible, the CMSIS-RTOS rejects calls by nested ISR functions with the status code \b osErrorISRRecursive.
  47. <b>Define and reference object definitions</b>
  48. With <b>\#define osObjectsExternal</b> objects are defined as external symbols. This allows to create a consistent header file
  49. that is used troughtout a project as shown below:
  50. <i>Header File</i>
  51. \code
  52. #include <cmsis_os.h> // CMSIS RTOS header file
  53. // Thread definition
  54. extern void thread_sample (void const *argument); // function prototype
  55. osThreadDef (thread_sample, osPriorityBelowNormal, 1, 100);
  56. // Pool definition
  57. osPoolDef(MyPool, 10, long);
  58. \endcode
  59. This header file defines all objects when included in a C/C++ source file. When <b>\#define osObjectsExternal</b> is
  60. present before the header file, the objects are defined as external symbols. A single consistent header file can therefore be
  61. used throughout the whole project.
  62. <i>Example</i>
  63. \code
  64. #include "osObjects.h" // Definition of the CMSIS-RTOS objects
  65. \endcode
  66. \code
  67. #define osObjectExternal // Objects will be defined as external symbols
  68. #include "osObjects.h" // Reference to the CMSIS-RTOS objects
  69. \endcode
  70. */
  71. #ifndef _CMSIS_OS_H
  72. #define _CMSIS_OS_H
  73. #include <rtthread.h>
  74. /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version
  75. #define osCMSIS 0x00003 ///< API version (main [31:16] .sub [15:0])
  76. /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlaying RTOS kernel and version number.
  77. #define osCMSIS_RTT 0x10001 ///< RTOS identification and version (main [31:16] .sub [15:0])
  78. /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
  79. #define osKernelSystemId "RT-Thread V1.1.0" ///< RTOS identification string
  80. /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
  81. #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
  82. #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available
  83. #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available
  84. #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
  85. #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread
  86. #define osFeature_Semaphore 30 ///< maximum count for SemaphoreInit function
  87. #define osFeature_Wait 1 ///< osWait function: 1=available, 0=not available
  88. #include <stdint.h>
  89. #include <stddef.h>
  90. #ifdef __cplusplus
  91. extern "C"
  92. {
  93. #endif
  94. // ==== Enumeration, structures, defines ====
  95. /// Priority used for thread control.
  96. /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
  97. typedef enum {
  98. osPriorityIdle = -3, ///< priority: idle (lowest)
  99. osPriorityLow = -2, ///< priority: low
  100. osPriorityBelowNormal = -1, ///< priority: below normal
  101. osPriorityNormal = 0, ///< priority: normal (default)
  102. osPriorityAboveNormal = +1, ///< priority: above normal
  103. osPriorityHigh = +2, ///< priority: high
  104. osPriorityRealtime = +3, ///< priority: realtime (highest)
  105. osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
  106. } osPriority;
  107. /// Timeout value
  108. /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
  109. #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
  110. /// Status code values returned by CMSIS-RTOS functions
  111. /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
  112. typedef enum {
  113. osOK = 0, ///< function completed; no event occurred.
  114. osEventSignal = 0x08, ///< function completed; signal event occurred.
  115. osEventMessage = 0x10, ///< function completed; message event occurred.
  116. osEventMail = 0x20, ///< function completed; mail event occurred.
  117. osEventTimeout = 0x40, ///< function completed; timeout occurred.
  118. osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
  119. osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
  120. osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
  121. osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
  122. osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
  123. osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
  124. osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
  125. osErrorValue = 0x86, ///< value of a parameter is out of range.
  126. osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
  127. os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
  128. } osStatus;
  129. /// Timer type value for the timer definition
  130. /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
  131. typedef enum {
  132. osTimerOnce = 0, ///< one-shot timer
  133. osTimerPeriodic = 1 ///< repeating timer
  134. } os_timer_type;
  135. /// Entry point of a thread.
  136. /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
  137. typedef void (*os_pthread) (void const *argument);
  138. /// Entry point of a timer call back function.
  139. /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
  140. typedef void (*os_ptimer) (void const *argument);
  141. // >>> the following data type definitions may shall adapted towards a specific RTOS
  142. /// Thread ID identifies the thread (pointer to a thread control block).
  143. /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
  144. typedef struct rt_thread *osThreadId;
  145. /// Timer ID identifies the timer (pointer to a timer control block).
  146. /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
  147. typedef struct rt_timer *osTimerId;
  148. /// Mutex ID identifies the mutex (pointer to a mutex control block).
  149. /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
  150. typedef struct rt_mutex *osMutexId;
  151. /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
  152. /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
  153. typedef struct rt_semaphore *osSemaphoreId;
  154. /// Pool ID identifies the memory pool (pointer to a memory pool control block).
  155. /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
  156. typedef struct rt_mempool *osPoolId;
  157. /// Message ID identifies the message queue (pointer to a message queue control block).
  158. /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
  159. typedef struct rt_messagequeue *osMessageQId;
  160. /// Mail ID identifies the mail queue (pointer to a mail queue control block).
  161. /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
  162. typedef struct rt_mailbox *osMailQId;
  163. /// Thread Definition structure contains startup information of a thread.
  164. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
  165. typedef const struct os_thread_def {
  166. const char *name;
  167. void (*entry)(void *parameter);
  168. rt_uint32_t stack_size;
  169. rt_uint8_t priority;
  170. rt_uint32_t tick;
  171. } osThreadDef_t;
  172. /// Timer Definition structure contains timer parameters.
  173. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
  174. typedef const struct os_timer_def {
  175. const char *name;
  176. void (*timeout)(void *parameter);
  177. void *parameter;
  178. rt_tick_t time;
  179. rt_uint8_t flag;
  180. } osTimerDef_t;
  181. /// Mutex Definition structure contains setup information for a mutex.
  182. /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
  183. typedef const struct os_mutex_def {
  184. const char *name;
  185. rt_uint8_t flag;
  186. } osMutexDef_t;
  187. /// Semaphore Definition structure contains setup information for a semaphore.
  188. /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
  189. typedef const struct os_semaphore_def {
  190. const char *name;
  191. rt_uint8_t flag;
  192. } osSemaphoreDef_t;
  193. /// Definition structure for memory block allocation
  194. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
  195. typedef const struct os_pool_def {
  196. const char *name;
  197. rt_size_t block_count;
  198. rt_size_t block_size;
  199. } osPoolDef_t;
  200. /// Definition structure for message queue
  201. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
  202. typedef const struct os_messageQ_def {
  203. const char *name;
  204. rt_size_t msg_size;
  205. rt_size_t max_msgs;
  206. rt_uint8_t flag;
  207. } osMessageQDef_t;
  208. /// Definition structure for mail queue
  209. /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
  210. typedef const struct os_mailQ_def {
  211. const char *name;
  212. rt_size_t size;
  213. rt_uint8_t flag;
  214. } osMailQDef_t;
  215. /// Event structure contains detailed information about an event.
  216. /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
  217. /// However the struct may be extended at the end.
  218. typedef struct {
  219. osStatus status; ///< status code: event or error information
  220. union {
  221. uint32_t v; ///< message as 32-bit value
  222. void *p; ///< message or mail as void pointer
  223. int32_t signals; ///< signal flags
  224. } value; ///< event value
  225. union {
  226. osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
  227. osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
  228. } def; ///< event definition
  229. } osEvent;
  230. // ==== Kernel Control Functions ====
  231. /// Start the RTOS Kernel with executing the specified thread.
  232. /// \param[in] thread_def thread definition referenced with \ref osThread.
  233. /// \param[in] argument pointer that is passed to the thread function as start argument.
  234. /// \return status code that indicates the execution status of the function.
  235. /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
  236. osStatus osKernelStart (osThreadDef_t *thread_def, void *argument);
  237. /// Check if the RTOS kernel is already started.
  238. /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
  239. /// \return 0 RTOS is not started, 1 RTOS is started.
  240. int32_t osKernelRunning(void);
  241. // ==== Thread Management ====
  242. /// Create a Thread Definition with function, priority, and stack requirements.
  243. /// \param name name of the thread function.
  244. /// \param priority initial priority of the thread function.
  245. /// \param instances number of possible thread instances.
  246. /// \param stacksz stack size (in bytes) requirements for the thread function.
  247. /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
  248. /// macro body is implementation specific in every CMSIS-RTOS.
  249. #if defined (osObjectsExternal) // object is external
  250. #define osThreadDef(name, priority, instances, stacksz) \
  251. extern osThreadDef_t os_thread_def_##name
  252. #else // define the object
  253. #define osThreadDef(name, priority, instances, stacksz) \
  254. osThreadDef_t os_thread_def_##name = \
  255. {("cmsis"), (name), (stacksz), ((rt_uint8_t)(priority - osPriorityIdle) + 1), 50}
  256. #endif
  257. /// Access a Thread defintion.
  258. /// \param name name of the thread definition object.
  259. /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
  260. /// macro body is implementation specific in every CMSIS-RTOS.
  261. #define osThread(name) \
  262. &os_thread_def_##name
  263. /// Create a thread and add it to Active Threads and set it to state READY.
  264. /// \param[in] thread_def thread definition referenced with \ref osThread.
  265. /// \param[in] argument pointer that is passed to the thread function as start argument.
  266. /// \return thread ID for reference by other functions or NULL in case of error.
  267. /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
  268. osThreadId osThreadCreate (osThreadDef_t *thread_def, void *argument);
  269. /// Return the thread ID of the current running thread.
  270. /// \return thread ID for reference by other functions or NULL in case of error.
  271. /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
  272. osThreadId osThreadGetId (void);
  273. /// Terminate execution of a thread and remove it from Active Threads.
  274. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  275. /// \return status code that indicates the execution status of the function.
  276. /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
  277. osStatus osThreadTerminate (osThreadId thread_id);
  278. /// Pass control to next thread that is in state \b READY.
  279. /// \return status code that indicates the execution status of the function.
  280. /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
  281. osStatus osThreadYield (void);
  282. /// Change priority of an active thread.
  283. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  284. /// \param[in] priority new priority value for the thread function.
  285. /// \return status code that indicates the execution status of the function.
  286. /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
  287. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
  288. /// Get current priority of an active thread.
  289. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  290. /// \return current priority value of the thread function.
  291. /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
  292. osPriority osThreadGetPriority (osThreadId thread_id);
  293. // ==== Generic Wait Functions ====
  294. /// Wait for Timeout (Time Delay)
  295. /// \param[in] millisec time delay value
  296. /// \return status code that indicates the execution status of the function.
  297. osStatus osDelay (uint32_t millisec);
  298. #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
  299. /// Wait for Signal, Message, Mail, or Timeout
  300. /// \param[in] millisec timeout value or 0 in case of no time-out
  301. /// \return event that contains signal, message, or mail information or error code.
  302. /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
  303. osEvent osWait (uint32_t millisec);
  304. #endif // Generic Wait available
  305. // ==== Timer Management Functions ====
  306. /// Define a Timer object.
  307. /// \param name name of the timer object.
  308. /// \param function name of the timer call back function.
  309. /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
  310. /// macro body is implementation specific in every CMSIS-RTOS.
  311. #if defined (osObjectsExternal) // object is external
  312. #define osTimerDef(name, function) \
  313. extern osTimerDef_t os_timer_def_##name
  314. #else // define the object
  315. #define osTimerDef(name, function) \
  316. osTimerDef_t os_timer_def_##name = \
  317. {("timer"), (function), (RT_NULL) }
  318. #endif
  319. /// Access a Timer definition.
  320. /// \param name name of the timer object.
  321. /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
  322. /// macro body is implementation specific in every CMSIS-RTOS.
  323. #define osTimer(name) \
  324. &os_timer_def_##name
  325. /// Create a timer.
  326. /// \param[in] timer_def timer object referenced with \ref osTimer.
  327. /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
  328. /// \param[in] argument argument to the timer call back function.
  329. /// \return timer ID for reference by other functions or NULL in case of error.
  330. /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
  331. osTimerId osTimerCreate (osTimerDef_t *timer_def, os_timer_type type, void *argument);
  332. /// Start or restart a timer.
  333. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  334. /// \param[in] millisec time delay value of the timer.
  335. /// \return status code that indicates the execution status of the function.
  336. /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
  337. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
  338. /// Stop the timer.
  339. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  340. /// \return status code that indicates the execution status of the function.
  341. /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
  342. osStatus osTimerStop (osTimerId timer_id);
  343. // ==== Signal Management ====
  344. /// Set the specified Signal Flags of an active thread.
  345. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  346. /// \param[in] signals specifies the signal flags of the thread that should be set.
  347. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  348. /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
  349. int32_t osSignalSet (osThreadId thread_id, int32_t signal);
  350. /// Clear the specified Signal Flags of an active thread.
  351. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  352. /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
  353. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  354. /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
  355. int32_t osSignalClear (osThreadId thread_id, int32_t signal);
  356. /// Get Signal Flags status of an active thread.
  357. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  358. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  359. /// \note MUST REMAIN UNCHANGED: \b osSignalGet shall be consistent in every CMSIS-RTOS.
  360. int32_t osSignalGet (osThreadId thread_id);
  361. /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
  362. /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
  363. /// \param[in] millisec timeout value or 0 in case of no time-out.
  364. /// \return event flag information or error code.
  365. /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
  366. osEvent osSignalWait (int32_t signals, uint32_t millisec);
  367. // ==== Mutex Management ====
  368. /// Define a Mutex.
  369. /// \param name name of the mutex object.
  370. /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
  371. /// macro body is implementation specific in every CMSIS-RTOS.
  372. #if defined (osObjectsExternal) // object is external
  373. #define osMutexDef(name) \
  374. extern osMutexDef_t os_mutex_def_##name
  375. #else // define the object
  376. #define osMutexDef(name) \
  377. osMutexDef_t os_mutex_def_##name = { 0 }
  378. #endif
  379. /// Access a Mutex defintion.
  380. /// \param name name of the mutex object.
  381. /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
  382. /// macro body is implementation specific in every CMSIS-RTOS.
  383. #define osMutex(name) \
  384. &os_mutex_def_##name
  385. /// Create and Initialize a Mutex object
  386. /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
  387. /// \return mutex ID for reference by other functions or NULL in case of error.
  388. /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
  389. osMutexId osMutexCreate (osMutexDef_t *mutex_def);
  390. /// Wait until a Mutex becomes available
  391. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  392. /// \param[in] millisec timeout value or 0 in case of no time-out.
  393. /// \return status code that indicates the execution status of the function.
  394. /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
  395. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
  396. /// Release a Mutex that was obtained by \ref osMutexWait
  397. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  398. /// \return status code that indicates the execution status of the function.
  399. /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
  400. osStatus osMutexRelease (osMutexId mutex_id);
  401. // ==== Semaphore Management Functions ====
  402. #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
  403. /// Define a Semaphore object.
  404. /// \param name name of the semaphore object.
  405. /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
  406. /// macro body is implementation specific in every CMSIS-RTOS.
  407. #if defined (osObjectsExternal) // object is external
  408. #define osSemaphoreDef(name) \
  409. extern osSemaphoreDef_t os_semaphore_def_##name
  410. #else // define the object
  411. #define osSemaphoreDef(name) \
  412. osSemaphoreDef_t os_semaphore_def_##name = { 0 }
  413. #endif
  414. /// Access a Semaphore definition.
  415. /// \param name name of the semaphore object.
  416. /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
  417. /// macro body is implementation specific in every CMSIS-RTOS.
  418. #define osSemaphore(name) \
  419. &os_semaphore_def_##name
  420. /// Create and Initialize a Semaphore object used for managing resources
  421. /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
  422. /// \param[in] count number of available resources.
  423. /// \return semaphore ID for reference by other functions or NULL in case of error.
  424. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
  425. osSemaphoreId osSemaphoreCreate (osSemaphoreDef_t *semaphore_def, int32_t count);
  426. /// Wait until a Semaphore token becomes available
  427. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphore.
  428. /// \param[in] millisec timeout value or 0 in case of no time-out.
  429. /// \return number of available tokens, or -1 in case of incorrect parameters.
  430. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
  431. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
  432. /// Release a Semaphore token
  433. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphore.
  434. /// \return status code that indicates the execution status of the function.
  435. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
  436. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
  437. #endif // Semaphore available
  438. // ==== Memory Pool Management Functions ====
  439. #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
  440. /// \brief Define a Memory Pool.
  441. /// \param name name of the memory pool.
  442. /// \param no maximum number of objects (elements) in the memory pool.
  443. /// \param type data type of a single object (element).
  444. /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
  445. /// macro body is implementation specific in every CMSIS-RTOS.
  446. #if defined (osObjectsExternal) // object is external
  447. #define osPoolDef(name, no, type) \
  448. extern osPoolDef_t os_pool_def_##name
  449. #else // define the object
  450. #define osPoolDef(name, no, type) \
  451. osPoolDef_t os_pool_def_##name = \
  452. { (no), sizeof(type), NULL }
  453. #endif
  454. /// \brief Access a Memory Pool definition.
  455. /// \param name name of the memory pool
  456. /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
  457. /// macro body is implementation specific in every CMSIS-RTOS.
  458. #define osPool(name) \
  459. &os_pool_def_##name
  460. /// Create and Initialize a memory pool
  461. /// \param[in] pool_def memory pool definition referenced with \ref osPool.
  462. /// \return memory pool ID for reference by other functions or NULL in case of error.
  463. /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
  464. osPoolId osPoolCreate (osPoolDef_t *pool_def);
  465. /// Allocate a memory block from a memory pool
  466. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  467. /// \return address of the allocated memory block or NULL in case of no memory available.
  468. /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
  469. void *osPoolAlloc (osPoolId pool_id);
  470. /// Allocate a memory block from a memory pool and set memory block to zero
  471. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  472. /// \return address of the allocated memory block or NULL in case of no memory available.
  473. /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
  474. void *osPoolCAlloc (osPoolId pool_id);
  475. /// Return an allocated memory block back to a specific memory pool
  476. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  477. /// \param[in] block address of the allocated memory block that is returned to the memory pool.
  478. /// \return status code that indicates the execution status of the function.
  479. /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
  480. osStatus osPoolFree (osPoolId pool_id, void *block);
  481. #endif // Memory Pool Management available
  482. // ==== Message Queue Management Functions ====
  483. #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
  484. /// \brief Create a Message Queue Definition.
  485. /// \param name name of the queue.
  486. /// \param queue_sz maximum number of messages in the queue.
  487. /// \param type data type of a single message element (for debugger).
  488. /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
  489. /// macro body is implementation specific in every CMSIS-RTOS.
  490. #if defined (osObjectsExternal) // object is external
  491. #define osMessageQDef(name, queue_sz, type) \
  492. extern osMessageQDef_t os_messageQ_def_##name
  493. #else // define the object
  494. #define osMessageQDef(name, queue_sz, type) \
  495. osMessageQDef_t os_messageQ_def_##name = \
  496. { (queue_sz), sizeof (type) }
  497. #endif
  498. /// \brief Access a Message Queue Definition.
  499. /// \param name name of the queue
  500. /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
  501. /// macro body is implementation specific in every CMSIS-RTOS.
  502. #define osMessageQ(name) \
  503. &os_messageQ_def_##name
  504. /// Create and Initialize a Message Queue.
  505. /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
  506. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  507. /// \return message queue ID for reference by other functions or NULL in case of error.
  508. /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
  509. osMessageQId osMessageCreate (osMessageQDef_t *queue_def, osThreadId thread_id);
  510. /// Put a Message to a Queue.
  511. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  512. /// \param[in] info message information.
  513. /// \param[in] millisec timeout value or 0 in case of no time-out.
  514. /// \return status code that indicates the execution status of the function.
  515. /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
  516. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
  517. /// Get a Message or Wait for a Message from a Queue.
  518. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  519. /// \param[in] millisec timeout value or 0 in case of no time-out.
  520. /// \return event information that includes status code.
  521. /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
  522. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
  523. #endif // Message Queues available
  524. // ==== Mail Queue Management Functions ====
  525. #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
  526. /// \brief Create a Mail Queue Definition
  527. /// \param name name of the queue
  528. /// \param queue_sz maximum number of messages in queue
  529. /// \param type data type of a single message element
  530. /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
  531. /// macro body is implementation specific in every CMSIS-RTOS.
  532. #if defined (osObjectsExternal) // object is external
  533. #define osMailQDef(name, queue_sz, type) \
  534. extern osMailQDef_t os_mailQ_def_##name
  535. #else // define the object
  536. #define osMailQDef(name, queue_sz, type) \
  537. osMailQDef_t os_mailQ_def_##name = \
  538. { (queue_sz), sizeof (type) }
  539. #endif
  540. /// \brief Access a Mail Queue Definition
  541. /// \param name name of the queue
  542. /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
  543. /// macro body is implementation specific in every CMSIS-RTOS.
  544. #define osMailQ(name) \
  545. &os_mailQ_def_##name
  546. /// Create and Initialize mail queue
  547. /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
  548. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  549. /// \return mail queue ID for reference by other functions or NULL in case of error.
  550. /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
  551. osMailQId osMailCreate (osMailQDef_t *queue_def, osThreadId thread_id);
  552. /// Allocate a memory block from a mail
  553. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  554. /// \param[in] millisec timeout value or 0 in case of no time-out
  555. /// \return pointer to memory block that can be filled with mail or NULL in case error.
  556. /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
  557. void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
  558. /// Allocate a memory block from a mail and set memory block to zero
  559. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  560. /// \param[in] millisec timeout value or 0 in case of no time-out
  561. /// \return pointer to memory block that can shall filled with mail or NULL in case error.
  562. /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
  563. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
  564. /// Put a mail to a queue
  565. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  566. /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
  567. /// \return status code that indicates the execution status of the function.
  568. /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
  569. osStatus osMailPut (osMailQId queue_id, void *mail);
  570. /// Get a mail from a queue
  571. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  572. /// \param[in] millisec timeout value or 0 in case of no time-out
  573. /// \return event that contains mail information or error code.
  574. /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
  575. osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
  576. /// Free a memory block from a mail
  577. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  578. /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
  579. /// \return status code that indicates the execution status of the function.
  580. /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
  581. osStatus osMailFree (osMailQId queue_id, void *mail);
  582. #endif // Mail Queues available
  583. #ifdef __cplusplus
  584. }
  585. #endif
  586. #endif // _CMSIS_OS_H