cmsis_os2.h 35 KB

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