cmsis_os2.h 35 KB

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