cmsis_os2.h 33 KB

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