cmsis_os2.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Copyright (c) 2013-2016 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. * http://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: 30. June 2016
  21. * $Revision: V2.0
  22. *
  23. * Project: CMSIS-RTOS2 API
  24. * Title: cmsis_os2.h header file
  25. *
  26. * Version 2.0
  27. * Initial Release
  28. *---------------------------------------------------------------------------*/
  29. #ifndef __CMSIS_OS2_H
  30. #define __CMSIS_OS2_H
  31. #if defined(__CC_ARM)
  32. #define __NO_RETURN __declspec(noreturn)
  33. #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  34. #define __NO_RETURN __attribute__((noreturn))
  35. #elif defined(__GNUC__)
  36. #define __NO_RETURN __attribute__((noreturn))
  37. #elif defined(__ICCARM__)
  38. #define __NO_RETURN __noreturn
  39. #else
  40. #define __NO_RETURN
  41. #endif
  42. #include <stdint.h>
  43. #include <stddef.h>
  44. #ifdef __cplusplus
  45. extern "C"
  46. {
  47. #endif
  48. // ==== Enumerations, structures, defines ====
  49. /// Version information.
  50. typedef struct osVersion_s {
  51. uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec).
  52. uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
  53. } osVersion_t;
  54. /// Kernel state.
  55. typedef enum {
  56. osKernelInactive = 0, ///< Inactive.
  57. osKernelReady = 1, ///< Ready.
  58. osKernelRunning = 2, ///< Running.
  59. osKernelLocked = 3, ///< Locked.
  60. osKernelSuspended = 4, ///< Suspended.
  61. osKernelError = -1, ///< Error.
  62. osKernelReserved = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization.
  63. } osKernelState_t;
  64. /// Thread state.
  65. typedef enum {
  66. osThreadInactive = 0, ///< Inactive.
  67. osThreadReady = 1, ///< Ready.
  68. osThreadRunning = 2, ///< Running.
  69. osThreadWaiting = 3, ///< Waiting.
  70. osThreadSuspended = 4, ///< Suspended.
  71. osThreadTerminated = 5, ///< Terminated.
  72. osThreadError = -1, ///< Error.
  73. osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  74. } osThreadState_t;
  75. /// Priority values.
  76. typedef enum {
  77. osPriorityNone = 0, ///< No priority (not initialized).
  78. osPriorityIdle = 1, ///< Reserved for Idle thread.
  79. osPriorityLow = 8, ///< Priority: low
  80. osPriorityLow1 = 8+1, ///< Priority: low + 1
  81. osPriorityLow2 = 8+2, ///< Priority: low + 2
  82. osPriorityLow3 = 8+3, ///< Priority: low + 3
  83. osPriorityLow4 = 8+4, ///< Priority: low + 4
  84. osPriorityLow5 = 8+5, ///< Priority: low + 5
  85. osPriorityLow6 = 8+6, ///< Priority: low + 6
  86. osPriorityLow7 = 8+7, ///< Priority: low + 7
  87. osPriorityBelowNormal = 16, ///< Priority: below normal
  88. osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1
  89. osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2
  90. osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3
  91. osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4
  92. osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5
  93. osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6
  94. osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7
  95. osPriorityNormal = 24, ///< Priority: normal
  96. osPriorityNormal1 = 24+1, ///< Priority: normal + 1
  97. osPriorityNormal2 = 24+2, ///< Priority: normal + 2
  98. osPriorityNormal3 = 24+3, ///< Priority: normal + 3
  99. osPriorityNormal4 = 24+4, ///< Priority: normal + 4
  100. osPriorityNormal5 = 24+5, ///< Priority: normal + 5
  101. osPriorityNormal6 = 24+6, ///< Priority: normal + 6
  102. osPriorityNormal7 = 24+7, ///< Priority: normal + 7
  103. osPriorityAboveNormal = 32, ///< Priority: above normal
  104. osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1
  105. osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2
  106. osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3
  107. osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4
  108. osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5
  109. osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6
  110. osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7
  111. osPriorityHigh = 40, ///< Priority: high
  112. osPriorityHigh1 = 40+1, ///< Priority: high + 1
  113. osPriorityHigh2 = 40+2, ///< Priority: high + 2
  114. osPriorityHigh3 = 40+3, ///< Priority: high + 3
  115. osPriorityHigh4 = 40+4, ///< Priority: high + 4
  116. osPriorityHigh5 = 40+5, ///< Priority: high + 5
  117. osPriorityHigh6 = 40+6, ///< Priority: high + 6
  118. osPriorityHigh7 = 40+7, ///< Priority: high + 7
  119. osPriorityRealtime = 48, ///< Priority: realtime
  120. osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1
  121. osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2
  122. osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3
  123. osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4
  124. osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5
  125. osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6
  126. osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7
  127. osPriorityISR = 56, ///< Reserved for ISR deferred thread.
  128. osPriorityError = -1, ///< System cannot determine priority or illegal priority.
  129. osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  130. } osPriority_t;
  131. /// Entry point of a thread.
  132. typedef void *(*os_thread_func_t) (void *argument);
  133. /// Entry point of a timer call back function.
  134. typedef void (*os_timer_func_t) (void *argument);
  135. /// Timer type.
  136. typedef enum {
  137. osTimerOnce = 0, ///< One-shot timer.
  138. osTimerPeriodic = 1 ///< Repeating timer.
  139. } osTimerType_t;
  140. /// Timeout value.
  141. #define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
  142. /// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
  143. #define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
  144. #define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
  145. #define osFlagsAutoClear 0x00000002U ///< Clear flags which have been specified to wait for.
  146. /// Thread attributes (attr_bits in \ref osThreadAttr_t).
  147. #define osThreadJoinable 0x00000000U ///< Thread created in joinable state (default)
  148. #define osThreadDetached 0x00000001U ///< Thread created in detached state
  149. /// Mutex attributes (attr_bits in \ref osMutexAttr_t).
  150. #define osMutexRecursive 0x00000001U ///< Recursive mutex.
  151. #define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
  152. #define osMutexRobust 0x00000008U ///< Robust mutex.
  153. /// Status code values returned by CMSIS-RTOS functions.
  154. typedef enum {
  155. osOK = 0, ///< Operation completed successfully.
  156. osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
  157. osErrorTimeout = -2, ///< Operation not completed within the timeout period.
  158. osErrorResource = -3, ///< Resource not available.
  159. osErrorParameter = -4, ///< Parameter error.
  160. osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
  161. osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
  162. osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
  163. } osStatus_t;
  164. /// \details Thread ID identifies the thread.
  165. typedef uint32_t osThreadId_t;
  166. /// \details Timer ID identifies the timer.
  167. typedef uint32_t osTimerId_t;
  168. /// \details Event Flags ID identifies the event flags.
  169. typedef uint32_t osEventFlagsId_t;
  170. /// \details Mutex ID identifies the mutex.
  171. typedef uint32_t osMutexId_t;
  172. /// \details Semaphore ID identifies the semaphore.
  173. typedef uint32_t osSemaphoreId_t;
  174. /// \details Memory Pool ID identifies the memory pool.
  175. typedef uint32_t osMemoryPoolId_t;
  176. /// \details Message Queue ID identifies the message queue.
  177. typedef uint32_t osMessageQueueId_t;
  178. /// Attributes structure for thread.
  179. typedef struct osThreadAttr_s {
  180. const char *name; ///< name of the thread
  181. uint32_t attr_bits; ///< attribute bits
  182. void *cb_mem; ///< memory for control block
  183. uint32_t cb_size; ///< size of provided memory for control block
  184. void *stack_mem; ///< memory for stack
  185. uint32_t stack_size; ///< size of stack
  186. osPriority_t priority; ///< initial thread priority (default: osPriorityNormal)
  187. uint32_t reserved[2]; ///< reserved (must be 0)
  188. } osThreadAttr_t;
  189. /// Attributes structure for timer.
  190. typedef struct osTimerAttr_s {
  191. const char *name; ///< name of the timer
  192. uint32_t attr_bits; ///< attribute bits
  193. void *cb_mem; ///< memory for control block
  194. uint32_t cb_size; ///< size of provided memory for control block
  195. } osTimerAttr_t;
  196. /// Attributes structure for event flags.
  197. typedef struct osEventFlagsAttr_s {
  198. const char *name; ///< name of the event flags
  199. uint32_t attr_bits; ///< attribute bits
  200. void *cb_mem; ///< memory for control block
  201. uint32_t cb_size; ///< size of provided memory for control block
  202. } osEventFlagsAttr_t;
  203. /// Attributes structure for mutex.
  204. typedef struct osMutexAttr_s {
  205. const char *name; ///< name of the mutex
  206. uint32_t attr_bits; ///< attribute bits
  207. void *cb_mem; ///< memory for control block
  208. uint32_t cb_size; ///< size of provided memory for control block
  209. } osMutexAttr_t;
  210. /// Attributes structure for semaphore.
  211. typedef struct osSemaphoreAttr_s {
  212. const char *name; ///< name of the semaphore
  213. uint32_t attr_bits; ///< attribute bits
  214. void *cb_mem; ///< memory for control block
  215. uint32_t cb_size; ///< size of provided memory for control block
  216. } osSemaphoreAttr_t;
  217. /// Attributes structure for memory pool.
  218. typedef struct osMemoryPoolAttr_s {
  219. const char *name; ///< name of the memory pool
  220. uint32_t attr_bits; ///< attribute bits
  221. void *cb_mem; ///< memory for control block
  222. uint32_t cb_size; ///< size of provided memory for control block
  223. void *mp_mem; ///< memory for data storage
  224. uint32_t mp_size; ///< size of provided memory for data storage
  225. } osMemoryPoolAttr_t;
  226. /// Attributes structure for message queue.
  227. typedef struct osMessageQueueAttr_s {
  228. const char *name; ///< name of the message queue
  229. uint32_t attr_bits; ///< attribute bits
  230. void *cb_mem; ///< memory for control block
  231. uint32_t cb_size; ///< size of provided memory for control block
  232. void *mq_mem; ///< memory for data storage
  233. uint32_t mq_size; ///< size of provided memory for data storage
  234. } osMessageQueueAttr_t;
  235. // ==== Kernel Management Functions ====
  236. /// Initialize the RTOS Kernel.
  237. /// \return status code that indicates the execution status of the function.
  238. osStatus_t osKernelInitialize (void);
  239. /// Get RTOS Kernel Information.
  240. /// \param[out] version pointer to buffer for retrieving version information.
  241. /// \param[out] id_buf pointer to buffer for retrieving kernel identification string.
  242. /// \param[in] id_size maximum size of buffer for kernel identification string.
  243. /// \return status code that indicates the execution status of the function.
  244. osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
  245. /// Get the current RTOS Kernel state.
  246. /// \return current RTOS Kernel state.
  247. osKernelState_t osKernelGetState (void);
  248. /// Start the RTOS Kernel scheduler.
  249. /// \return status code that indicates the execution status of the function.
  250. osStatus_t osKernelStart (void);
  251. /// Lock the RTOS Kernel scheduler.
  252. /// \return 0 already locked, 1 locked.
  253. uint32_t osKernelLock (void);
  254. /// Unlock the RTOS Kernel scheduler.
  255. void osKernelUnlock (void);
  256. /// Suspend the RTOS Kernel scheduler.
  257. /// \return time in millisec, for how long the system can sleep or power-down.
  258. uint32_t osKernelSuspend (void);
  259. /// Resume the RTOS Kernel scheduler.
  260. /// \param[in] sleep_time time in millisec for how long the system was in sleep or power-down mode.
  261. void osKernelResume (uint32_t sleep_time);
  262. /// Get the RTOS kernel time.
  263. /// \return RTOS kernel current time in millisec.
  264. uint64_t osKernelGetTime (void);
  265. /// Get the RTOS kernel system timer counter.
  266. /// \return RTOS kernel system timer as 32-bit value.
  267. uint32_t osKernelGetTick (void);
  268. /// Convert a microseconds value to a RTOS kernel system timer value.
  269. /// \param microsec time value in microseconds.
  270. /// \return time value normalized to the system timer ticks.
  271. uint32_t osKernelTickMicroSec (uint32_t microsec);
  272. // ==== Thread Management Functions ====
  273. /// Create a thread and add it to Active Threads.
  274. /// \param[in] func thread function.
  275. /// \param[in] argument pointer that is passed to the thread function as start argument.
  276. /// \param[in] attr thread attributes; NULL: default values.
  277. /// \return thread ID for reference by other functions or NULL in case of error.
  278. osThreadId_t osThreadNew (os_thread_func_t func, void *argument, const osThreadAttr_t *attr);
  279. /// Return the thread ID of the current running thread.
  280. /// \return thread ID for reference by other functions or NULL in case of error.
  281. osThreadId_t osThreadGetId (void);
  282. /// Get current thread state of a thread.
  283. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  284. /// \return current thread state of the specified thread.
  285. osThreadState_t osThreadGetState (osThreadId_t thread_id);
  286. /// Change priority of a thread.
  287. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  288. /// \param[in] priority new priority value for the thread function.
  289. /// \return status code that indicates the execution status of the function.
  290. osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
  291. /// Get current priority of a thread.
  292. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  293. /// \return current priority value of the specified thread.
  294. osPriority_t osThreadGetPriority (osThreadId_t thread_id);
  295. /// Pass control to next thread that is in state \b READY.
  296. /// \return status code that indicates the execution status of the function.
  297. osStatus_t osThreadYield (void);
  298. /// Abort waiting operation of a thread.
  299. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  300. /// \return status code that indicates the execution status of the function.
  301. osStatus_t osThreadAbortWait (osThreadId_t thread_id);
  302. /// Suspend execution of a thread.
  303. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  304. /// \return status code that indicates the execution status of the function.
  305. osStatus_t osThreadSuspend (osThreadId_t thread_id);
  306. /// Resume execution of a thread.
  307. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  308. /// \return status code that indicates the execution status of the function.
  309. osStatus_t osThreadResume (osThreadId_t thread_id);
  310. /// Detach a thread (thread storage can be reclaimed when thread terminates).
  311. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  312. /// \return status code that indicates the execution status of the function.
  313. osStatus_t osThreadDetach (osThreadId_t thread_id);
  314. /// Wait for specified thread to terminate.
  315. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  316. /// \param[out] exit_ptr pointer to thread exit pointer value.
  317. /// \return status code that indicates the execution status of the function.
  318. osStatus_t osThreadJoin (osThreadId_t thread_id, void **exit_ptr);
  319. /// Terminate execution of current running thread.
  320. /// \param[in] exit_ptr thread exit pointer value.
  321. __NO_RETURN void osThreadExit (void *exit_ptr);
  322. /// Terminate execution of a thread.
  323. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  324. /// \return status code that indicates the execution status of the function.
  325. osStatus_t osThreadTerminate (osThreadId_t thread_id);
  326. // ==== Thread Flags Functions ====
  327. /// Set the specified Thread Flags of a thread.
  328. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  329. /// \param[in] flags specifies the flags of the thread that shall be set.
  330. /// \return thread flags after setting or error code if negative.
  331. int32_t osThreadFlagsSet (osThreadId_t thread_id, int32_t flags);
  332. /// Clear the specified Thread Flags of a thread.
  333. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  334. /// \param[in] flags specifies the flags of the thread that shall be cleared.
  335. /// \return thread flags before clearing or error code if negative.
  336. int32_t osThreadFlagsClear (osThreadId_t thread_id, int32_t flags);
  337. /// Get the current Thread Flags of a thread.
  338. /// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
  339. /// \return current thread flags.
  340. int32_t osThreadFlagsGet (osThreadId_t thread_id);
  341. /// Wait for one or more Thread Flags of the current running thread to become signaled.
  342. /// \param[in] flags specifies the flags to wait for.
  343. /// \param[in] options specifies flags options (osFlagsXxxx).
  344. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  345. /// \return thread flags before clearing or error code if negative.
  346. int32_t osThreadFlagsWait (int32_t flags, uint32_t options, uint32_t millisec);
  347. // ==== Generic Wait Functions ====
  348. /// Wait for Timeout (Time Delay).
  349. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
  350. /// \return status code that indicates the execution status of the function.
  351. osStatus_t osDelay (uint32_t millisec);
  352. /// Wait until specified time.
  353. /// \param[in] millisec absolute time in millisec
  354. /// \return status code that indicates the execution status of the function.
  355. osStatus_t osDelayUntil (uint64_t millisec);
  356. // ==== Timer Management Functions ====
  357. /// Create and Initialize a timer.
  358. /// \param[in] func start address of a timer call back function.
  359. /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
  360. /// \param[in] argument argument to the timer call back function.
  361. /// \param[in] attr timer attributes; NULL: default values.
  362. /// \return timer ID for reference by other functions or NULL in case of error.
  363. osTimerId_t osTimerNew (os_timer_func_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
  364. /// Start or restart a timer.
  365. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  366. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
  367. /// \return status code that indicates the execution status of the function.
  368. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t millisec);
  369. /// Stop a timer.
  370. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  371. /// \return status code that indicates the execution status of the function.
  372. osStatus_t osTimerStop (osTimerId_t timer_id);
  373. /// Check if a timer is running.
  374. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  375. /// \return 0 not running, 1 running.
  376. uint32_t osTimerIsRunning (osTimerId_t timer_id);
  377. /// Delete a timer.
  378. /// \param[in] timer_id timer ID obtained by \ref osTimerNew.
  379. /// \return status code that indicates the execution status of the function.
  380. osStatus_t osTimerDelete (osTimerId_t timer_id);
  381. // ==== Event Flags Management Functions ====
  382. /// Create and Initialize an Event Flags object.
  383. /// \param[in] attr event flags attributes; NULL: default values.
  384. /// \return event flags ID for reference by other functions or NULL in case of error.
  385. osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
  386. /// Set the specified Event Flags.
  387. /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
  388. /// \param[in] flags specifies the flags that shall be set.
  389. /// \return event flags after setting or error code if negative.
  390. int32_t osEventFlagsSet (osEventFlagsId_t ef_id, int32_t flags);
  391. /// Clear the specified Event Flags.
  392. /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
  393. /// \param[in] flags specifies the flags that shall be cleared.
  394. /// \return event flags before clearing or error code if negative.
  395. int32_t osEventFlagsClear (osEventFlagsId_t ef_id, int32_t flags);
  396. /// Get the current Event Flags.
  397. /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
  398. /// \return current event flags.
  399. int32_t osEventFlagsGet (osEventFlagsId_t ef_id);
  400. /// Wait for one or more Event Flags to become signaled.
  401. /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
  402. /// \param[in] flags specifies the flags to wait for.
  403. /// \param[in] options specifies flags options (osFlagsXxxx).
  404. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  405. /// \return event flags before clearing or error code if negative.
  406. int32_t osEventFlagsWait (osEventFlagsId_t ef_id, int32_t flags, uint32_t options, uint32_t millisec);
  407. /// Delete an Event Flags object.
  408. /// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
  409. /// \return status code that indicates the execution status of the function.
  410. osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
  411. // ==== Mutex Management Functions ====
  412. /// Create and Initialize a Mutex object.
  413. /// \param[in] attr mutex attributes; NULL: default values.
  414. /// \return mutex ID for reference by other functions or NULL in case of error.
  415. osMutexId_t osMutexNew (const osMutexAttr_t *attr);
  416. /// Acquire a Mutex or timeout if it is locked.
  417. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  418. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  419. /// \return status code that indicates the execution status of the function.
  420. osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t millisec);
  421. /// Release a Mutex that was acquired by \ref osMutexAcquire.
  422. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  423. /// \return status code that indicates the execution status of the function.
  424. osStatus_t osMutexRelease (osMutexId_t mutex_id);
  425. /// Get Thread which owns a Mutex object.
  426. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  427. /// \return thread ID of owner thread or NULL when mutex was not acquired.
  428. osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
  429. /// Delete a Mutex object.
  430. /// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
  431. /// \return status code that indicates the execution status of the function.
  432. osStatus_t osMutexDelete (osMutexId_t mutex_id);
  433. // ==== Semaphore Management Functions ====
  434. /// Create and Initialize a Semaphore object.
  435. /// \param[in] max_count maximum number of available tokens.
  436. /// \param[in] initial_count initial number of available tokens.
  437. /// \param[in] attr semaphore attributes; NULL: default values.
  438. /// \return semaphore ID for reference by other functions or NULL in case of error.
  439. osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
  440. /// Acquire a Semaphore token or timeout if no tokens are available.
  441. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  442. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  443. /// \return status code that indicates the execution status of the function.
  444. osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t millisec);
  445. /// Release a Semaphore token that was acquired by \ref osSemaphoreAcquire.
  446. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  447. /// \return status code that indicates the execution status of the function.
  448. osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
  449. /// Get current Semaphore token count.
  450. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  451. /// \return number of tokens available.
  452. uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
  453. /// Delete a Semaphore object.
  454. /// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
  455. /// \return status code that indicates the execution status of the function.
  456. osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
  457. // ==== Memory Pool Management Functions ====
  458. /// Create and Initialize a Memory Pool object.
  459. /// \param[in] block_count maximum number of memory blocks in memory pool.
  460. /// \param[in] block_size memory block size in bytes.
  461. /// \param[in] attr memory pool attributes; NULL: default values.
  462. /// \return memory pool ID for reference by other functions or NULL in case of error.
  463. osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
  464. /// Allocate a memory block from a Memory Pool.
  465. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  466. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  467. /// \return address of the allocated memory block or NULL in case of no memory is available.
  468. void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t millisec);
  469. /// Return an allocated memory block back to a Memory Pool.
  470. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  471. /// \param[in] block address of the allocated memory block to be returned to the memory pool.
  472. /// \return status code that indicates the execution status of the function.
  473. osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
  474. /// Get maximum number of memory blocks in a Memory Pool.
  475. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  476. /// \return maximum number of memory blocks.
  477. uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
  478. /// Get memory block size in a Memory Pool.
  479. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  480. /// \return memory block size in bytes.
  481. uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
  482. /// Get number of memory blocks used in a Memory Pool.
  483. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  484. /// \return number of memory blocks used.
  485. uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
  486. /// Get number of memory blocks available in a Memory Pool.
  487. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  488. /// \return number of memory blocks available.
  489. uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
  490. /// Delete a Memory Pool object.
  491. /// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
  492. /// \return status code that indicates the execution status of the function.
  493. osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
  494. // ==== Message Queue Management Functions ====
  495. /// Create and Initialize a Message Queue object.
  496. /// \param[in] msg_count maximum number of messages in queue.
  497. /// \param[in] msg_size maximum message size in bytes.
  498. /// \param[in] attr message queue attributes; NULL: default values.
  499. /// \return message queue ID for reference by other functions or NULL in case of error.
  500. osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
  501. /// Put a Message into a Queue or timeout if Queue is full.
  502. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  503. /// \param[in] msg_ptr pointer to buffer with message to put into a queue.
  504. /// \param[in] msg_prio message priority.
  505. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  506. /// \return status code that indicates the execution status of the function.
  507. osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t millisec);
  508. /// Get a Message from a Queue or timeout if Queue is empty.
  509. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  510. /// \param[out] msg_ptr pointer to buffer for message to get from a queue.
  511. /// \param[out] msg_prio pointer to buffer for message priority or NULL.
  512. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  513. /// \return status code that indicates the execution status of the function.
  514. osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t millisec);
  515. /// Get maximum number of messages in a Message Queue.
  516. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  517. /// \return maximum number of messages.
  518. uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
  519. /// Get maximum message size in a Memory Pool.
  520. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  521. /// \return maximum message size in bytes.
  522. uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
  523. /// Get number of queued messages in a Message Queue.
  524. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  525. /// \return number of queued messages.
  526. uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
  527. /// Get number of available slots for messages in a Message Queue.
  528. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  529. /// \return number of available slots for messages.
  530. uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
  531. /// Reset a Message Queue to initial empty state.
  532. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  533. /// \return status code that indicates the execution status of the function.
  534. osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
  535. /// Delete a Message Queue object.
  536. /// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
  537. /// \return status code that indicates the execution status of the function.
  538. osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
  539. #ifdef __cplusplus
  540. }
  541. #endif
  542. #endif // __CMSIS_OS2_H