cmsis_os2.h 35 KB

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