cmsis_os2.h 35 KB

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