cmsis_os2.h 35 KB

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