cmsis_os.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /* ----------------------------------------------------------------------
  2. * $Date: 5. February 2013
  3. * $Revision: V1.02
  4. *
  5. * Project: CMSIS-RTOS API
  6. * Title: cmsis_os.h template header file
  7. *
  8. * Version 0.02
  9. * Initial Proposal Phase
  10. * Version 0.03
  11. * osKernelStart added, optional feature: main started as thread
  12. * osSemaphores have standard behavior
  13. * osTimerCreate does not start the timer, added osTimerStart
  14. * osThreadPass is renamed to osThreadYield
  15. * Version 1.01
  16. * Support for C++ interface
  17. * - const attribute removed from the osXxxxDef_t typedef's
  18. * - const attribute added to the osXxxxDef macros
  19. * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
  20. * Added: osKernelInitialize
  21. * Version 1.02
  22. * Control functions for short timeouts in microsecond resolution:
  23. * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
  24. * Removed: osSignalGet
  25. *----------------------------------------------------------------------------
  26. *
  27. * Copyright (c) 2013-2017 ARM LIMITED
  28. *
  29. * SPDX-License-Identifier: Apache-2.0
  30. *
  31. * Licensed under the Apache License, Version 2.0 (the License); you may
  32. * not use this file except in compliance with the License.
  33. * You may obtain a copy of the License at
  34. *
  35. * www.apache.org/licenses/LICENSE-2.0
  36. *
  37. * Unless required by applicable law or agreed to in writing, software
  38. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  39. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  40. * See the License for the specific language governing permissions and
  41. * limitations under the License.
  42. *---------------------------------------------------------------------------*/
  43. #ifndef _CMSIS_OS_H
  44. #define _CMSIS_OS_H
  45. /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version.
  46. #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0])
  47. /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
  48. #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0])
  49. /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
  50. #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string
  51. /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
  52. #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
  53. #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available
  54. #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available
  55. #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
  56. #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread
  57. #define osFeature_Semaphore 30 ///< maximum count for \ref osSemaphoreCreate function
  58. #define osFeature_Wait 1 ///< osWait function: 1=available, 0=not available
  59. #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available
  60. #include <stdint.h>
  61. #include <stddef.h>
  62. #ifdef __cplusplus
  63. extern "C"
  64. {
  65. #endif
  66. // ==== Enumeration, structures, defines ====
  67. /// Priority used for thread control.
  68. /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
  69. typedef enum {
  70. osPriorityIdle = -3, ///< priority: idle (lowest)
  71. osPriorityLow = -2, ///< priority: low
  72. osPriorityBelowNormal = -1, ///< priority: below normal
  73. osPriorityNormal = 0, ///< priority: normal (default)
  74. osPriorityAboveNormal = +1, ///< priority: above normal
  75. osPriorityHigh = +2, ///< priority: high
  76. osPriorityRealtime = +3, ///< priority: realtime (highest)
  77. osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
  78. } osPriority;
  79. /// Timeout value.
  80. /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
  81. #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
  82. /// Status code values returned by CMSIS-RTOS functions.
  83. /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
  84. typedef enum {
  85. osOK = 0, ///< function completed; no error or event occurred.
  86. osEventSignal = 0x08, ///< function completed; signal event occurred.
  87. osEventMessage = 0x10, ///< function completed; message event occurred.
  88. osEventMail = 0x20, ///< function completed; mail event occurred.
  89. osEventTimeout = 0x40, ///< function completed; timeout occurred.
  90. osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
  91. osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
  92. osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
  93. osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
  94. osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
  95. osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
  96. osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
  97. osErrorValue = 0x86, ///< value of a parameter is out of range.
  98. osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
  99. os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
  100. } osStatus;
  101. /// Timer type value for the timer definition.
  102. /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
  103. typedef enum {
  104. osTimerOnce = 0, ///< one-shot timer
  105. osTimerPeriodic = 1 ///< repeating timer
  106. } os_timer_type;
  107. /// Entry point of a thread.
  108. /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
  109. typedef void (*os_pthread) (void const *argument);
  110. /// Entry point of a timer call back function.
  111. /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
  112. typedef void (*os_ptimer) (void const *argument);
  113. // >>> the following data type definitions may shall adapted towards a specific RTOS
  114. /// Thread ID identifies the thread (pointer to a thread control block).
  115. /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
  116. typedef struct os_thread_cb *osThreadId;
  117. /// Timer ID identifies the timer (pointer to a timer control block).
  118. /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
  119. typedef struct os_timer_cb *osTimerId;
  120. /// Mutex ID identifies the mutex (pointer to a mutex control block).
  121. /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
  122. typedef struct os_mutex_cb *osMutexId;
  123. /// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
  124. /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
  125. typedef struct os_semaphore_cb *osSemaphoreId;
  126. /// Pool ID identifies the memory pool (pointer to a memory pool control block).
  127. /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
  128. typedef struct os_pool_cb *osPoolId;
  129. /// Message ID identifies the message queue (pointer to a message queue control block).
  130. /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
  131. typedef struct os_messageQ_cb *osMessageQId;
  132. /// Mail ID identifies the mail queue (pointer to a mail queue control block).
  133. /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
  134. typedef struct os_mailQ_cb *osMailQId;
  135. /// Thread Definition structure contains startup information of a thread.
  136. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
  137. typedef struct os_thread_def {
  138. os_pthread pthread; ///< start address of thread function
  139. osPriority tpriority; ///< initial thread priority
  140. uint32_t instances; ///< maximum number of instances of that thread function
  141. uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
  142. } osThreadDef_t;
  143. /// Timer Definition structure contains timer parameters.
  144. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
  145. typedef struct os_timer_def {
  146. os_ptimer ptimer; ///< start address of a timer function
  147. } osTimerDef_t;
  148. /// Mutex Definition structure contains setup information for a mutex.
  149. /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
  150. typedef struct os_mutex_def {
  151. uint32_t dummy; ///< dummy value.
  152. } osMutexDef_t;
  153. /// Semaphore Definition structure contains setup information for a semaphore.
  154. /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
  155. typedef struct os_semaphore_def {
  156. uint32_t dummy; ///< dummy value.
  157. } osSemaphoreDef_t;
  158. /// Definition structure for memory block allocation.
  159. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
  160. typedef struct os_pool_def {
  161. uint32_t pool_sz; ///< number of items (elements) in the pool
  162. uint32_t item_sz; ///< size of an item
  163. void *pool; ///< pointer to memory for pool
  164. } osPoolDef_t;
  165. /// Definition structure for message queue.
  166. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
  167. typedef struct os_messageQ_def {
  168. uint32_t queue_sz; ///< number of elements in the queue
  169. uint32_t item_sz; ///< size of an item
  170. void *pool; ///< memory array for messages
  171. } osMessageQDef_t;
  172. /// Definition structure for mail queue.
  173. /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
  174. typedef struct os_mailQ_def {
  175. uint32_t queue_sz; ///< number of elements in the queue
  176. uint32_t item_sz; ///< size of an item
  177. void *pool; ///< memory array for mail
  178. } osMailQDef_t;
  179. /// Event structure contains detailed information about an event.
  180. /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
  181. /// However the struct may be extended at the end.
  182. typedef struct {
  183. osStatus status; ///< status code: event or error information
  184. union {
  185. uint32_t v; ///< message as 32-bit value
  186. void *p; ///< message or mail as void pointer
  187. int32_t signals; ///< signal flags
  188. } value; ///< event value
  189. union {
  190. osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
  191. osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
  192. } def; ///< event definition
  193. } osEvent;
  194. // ==== Kernel Control Functions ====
  195. /// Initialize the RTOS Kernel for creating objects.
  196. /// \return status code that indicates the execution status of the function.
  197. /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
  198. osStatus osKernelInitialize (void);
  199. /// Start the RTOS Kernel.
  200. /// \return status code that indicates the execution status of the function.
  201. /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
  202. osStatus osKernelStart (void);
  203. /// Check if the RTOS kernel is already started.
  204. /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
  205. /// \return 0 RTOS is not started, 1 RTOS is started.
  206. int32_t osKernelRunning(void);
  207. #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
  208. /// Get the RTOS kernel system timer counter
  209. /// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.
  210. /// \return RTOS kernel system timer as 32-bit value
  211. uint32_t osKernelSysTick (void);
  212. /// The RTOS kernel system timer frequency in Hz
  213. /// \note Reflects the system timer setting and is typically defined in a configuration file.
  214. #define osKernelSysTickFrequency 100000000
  215. /// Convert a microseconds value to a RTOS kernel system timer value.
  216. /// \param microsec time value in microseconds.
  217. /// \return time value normalized to the \ref osKernelSysTickFrequency
  218. #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
  219. #endif // System Timer available
  220. // ==== Thread Management ====
  221. /// Create a Thread Definition with function, priority, and stack requirements.
  222. /// \param name name of the thread function.
  223. /// \param priority initial priority of the thread function.
  224. /// \param instances number of possible thread instances.
  225. /// \param stacksz stack size (in bytes) requirements for the thread function.
  226. /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
  227. /// macro body is implementation specific in every CMSIS-RTOS.
  228. #if defined (osObjectsExternal) // object is external
  229. #define osThreadDef(name, priority, instances, stacksz) \
  230. extern const osThreadDef_t os_thread_def_##name
  231. #else // define the object
  232. #define osThreadDef(name, priority, instances, stacksz) \
  233. const osThreadDef_t os_thread_def_##name = \
  234. { (name), (priority), (instances), (stacksz) }
  235. #endif
  236. /// Access a Thread definition.
  237. /// \param name name of the thread definition object.
  238. /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
  239. /// macro body is implementation specific in every CMSIS-RTOS.
  240. #define osThread(name) \
  241. &os_thread_def_##name
  242. /// Create a thread and add it to Active Threads and set it to state READY.
  243. /// \param[in] thread_def thread definition referenced with \ref osThread.
  244. /// \param[in] argument pointer that is passed to the thread function as start argument.
  245. /// \return thread ID for reference by other functions or NULL in case of error.
  246. /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
  247. osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
  248. /// Return the thread ID of the current running thread.
  249. /// \return thread ID for reference by other functions or NULL in case of error.
  250. /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
  251. osThreadId osThreadGetId (void);
  252. /// Terminate execution of a thread and remove it from Active Threads.
  253. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  254. /// \return status code that indicates the execution status of the function.
  255. /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
  256. osStatus osThreadTerminate (osThreadId thread_id);
  257. /// Pass control to next thread that is in state \b READY.
  258. /// \return status code that indicates the execution status of the function.
  259. /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
  260. osStatus osThreadYield (void);
  261. /// Change priority of an active thread.
  262. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  263. /// \param[in] priority new priority value for the thread function.
  264. /// \return status code that indicates the execution status of the function.
  265. /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
  266. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
  267. /// Get current priority of an active thread.
  268. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  269. /// \return current priority value of the thread function.
  270. /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
  271. osPriority osThreadGetPriority (osThreadId thread_id);
  272. // ==== Generic Wait Functions ====
  273. /// Wait for Timeout (Time Delay).
  274. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
  275. /// \return status code that indicates the execution status of the function.
  276. osStatus osDelay (uint32_t millisec);
  277. #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
  278. /// Wait for Signal, Message, Mail, or Timeout.
  279. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  280. /// \return event that contains signal, message, or mail information or error code.
  281. /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
  282. osEvent osWait (uint32_t millisec);
  283. #endif // Generic Wait available
  284. // ==== Timer Management Functions ====
  285. /// Define a Timer object.
  286. /// \param name name of the timer object.
  287. /// \param function name of the timer call back function.
  288. /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
  289. /// macro body is implementation specific in every CMSIS-RTOS.
  290. #if defined (osObjectsExternal) // object is external
  291. #define osTimerDef(name, function) \
  292. extern const osTimerDef_t os_timer_def_##name
  293. #else // define the object
  294. #define osTimerDef(name, function) \
  295. const osTimerDef_t os_timer_def_##name = \
  296. { (function) }
  297. #endif
  298. /// Access a Timer definition.
  299. /// \param name name of the timer object.
  300. /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
  301. /// macro body is implementation specific in every CMSIS-RTOS.
  302. #define osTimer(name) \
  303. &os_timer_def_##name
  304. /// Create a timer.
  305. /// \param[in] timer_def timer object referenced with \ref osTimer.
  306. /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
  307. /// \param[in] argument argument to the timer call back function.
  308. /// \return timer ID for reference by other functions or NULL in case of error.
  309. /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
  310. osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
  311. /// Start or restart a timer.
  312. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  313. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
  314. /// \return status code that indicates the execution status of the function.
  315. /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
  316. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
  317. /// Stop the timer.
  318. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  319. /// \return status code that indicates the execution status of the function.
  320. /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
  321. osStatus osTimerStop (osTimerId timer_id);
  322. /// Delete a timer that was created by \ref osTimerCreate.
  323. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
  324. /// \return status code that indicates the execution status of the function.
  325. /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
  326. osStatus osTimerDelete (osTimerId timer_id);
  327. // ==== Signal Management ====
  328. /// Set the specified Signal Flags of an active thread.
  329. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  330. /// \param[in] signals specifies the signal flags of the thread that should be set.
  331. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  332. /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
  333. int32_t osSignalSet (osThreadId thread_id, int32_t signals);
  334. /// Clear the specified Signal Flags of an active thread.
  335. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  336. /// \param[in] signals specifies the signal flags of the thread that shall be cleared.
  337. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
  338. /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
  339. int32_t osSignalClear (osThreadId thread_id, int32_t signals);
  340. /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
  341. /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
  342. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  343. /// \return event flag information or error code.
  344. /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
  345. osEvent osSignalWait (int32_t signals, uint32_t millisec);
  346. // ==== Mutex Management ====
  347. /// Define a Mutex.
  348. /// \param name name of the mutex object.
  349. /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
  350. /// macro body is implementation specific in every CMSIS-RTOS.
  351. #if defined (osObjectsExternal) // object is external
  352. #define osMutexDef(name) \
  353. extern const osMutexDef_t os_mutex_def_##name
  354. #else // define the object
  355. #define osMutexDef(name) \
  356. const osMutexDef_t os_mutex_def_##name = { 0 }
  357. #endif
  358. /// Access a Mutex definition.
  359. /// \param name name of the mutex object.
  360. /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
  361. /// macro body is implementation specific in every CMSIS-RTOS.
  362. #define osMutex(name) \
  363. &os_mutex_def_##name
  364. /// Create and Initialize a Mutex object.
  365. /// \param[in] mutex_def mutex definition referenced with \ref osMutex.
  366. /// \return mutex ID for reference by other functions or NULL in case of error.
  367. /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
  368. osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
  369. /// Wait until a Mutex becomes available.
  370. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  371. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  372. /// \return status code that indicates the execution status of the function.
  373. /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
  374. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
  375. /// Release a Mutex that was obtained by \ref osMutexWait.
  376. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  377. /// \return status code that indicates the execution status of the function.
  378. /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
  379. osStatus osMutexRelease (osMutexId mutex_id);
  380. /// Delete a Mutex that was created by \ref osMutexCreate.
  381. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
  382. /// \return status code that indicates the execution status of the function.
  383. /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
  384. osStatus osMutexDelete (osMutexId mutex_id);
  385. // ==== Semaphore Management Functions ====
  386. #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
  387. /// Define a Semaphore object.
  388. /// \param name name of the semaphore object.
  389. /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
  390. /// macro body is implementation specific in every CMSIS-RTOS.
  391. #if defined (osObjectsExternal) // object is external
  392. #define osSemaphoreDef(name) \
  393. extern const osSemaphoreDef_t os_semaphore_def_##name
  394. #else // define the object
  395. #define osSemaphoreDef(name) \
  396. const osSemaphoreDef_t os_semaphore_def_##name = { 0 }
  397. #endif
  398. /// Access a Semaphore definition.
  399. /// \param name name of the semaphore object.
  400. /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
  401. /// macro body is implementation specific in every CMSIS-RTOS.
  402. #define osSemaphore(name) \
  403. &os_semaphore_def_##name
  404. /// Create and Initialize a Semaphore object used for managing resources.
  405. /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
  406. /// \param[in] count number of available resources.
  407. /// \return semaphore ID for reference by other functions or NULL in case of error.
  408. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
  409. osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
  410. /// Wait until a Semaphore token becomes available.
  411. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  412. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  413. /// \return number of available tokens, or -1 in case of incorrect parameters.
  414. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
  415. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
  416. /// Release a Semaphore token.
  417. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  418. /// \return status code that indicates the execution status of the function.
  419. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
  420. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
  421. /// Delete a Semaphore that was created by \ref osSemaphoreCreate.
  422. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
  423. /// \return status code that indicates the execution status of the function.
  424. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
  425. osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
  426. #endif // Semaphore available
  427. // ==== Memory Pool Management Functions ====
  428. #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
  429. /// \brief Define a Memory Pool.
  430. /// \param name name of the memory pool.
  431. /// \param no maximum number of blocks (objects) in the memory pool.
  432. /// \param type data type of a single block (object).
  433. /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
  434. /// macro body is implementation specific in every CMSIS-RTOS.
  435. #if defined (osObjectsExternal) // object is external
  436. #define osPoolDef(name, no, type) \
  437. extern const osPoolDef_t os_pool_def_##name
  438. #else // define the object
  439. #define osPoolDef(name, no, type) \
  440. const osPoolDef_t os_pool_def_##name = \
  441. { (no), sizeof(type), NULL }
  442. #endif
  443. /// \brief Access a Memory Pool definition.
  444. /// \param name name of the memory pool
  445. /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
  446. /// macro body is implementation specific in every CMSIS-RTOS.
  447. #define osPool(name) \
  448. &os_pool_def_##name
  449. /// Create and Initialize a memory pool.
  450. /// \param[in] pool_def memory pool definition referenced with \ref osPool.
  451. /// \return memory pool ID for reference by other functions or NULL in case of error.
  452. /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
  453. osPoolId osPoolCreate (const osPoolDef_t *pool_def);
  454. /// Allocate a memory block from a memory pool.
  455. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  456. /// \return address of the allocated memory block or NULL in case of no memory available.
  457. /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
  458. void *osPoolAlloc (osPoolId pool_id);
  459. /// Allocate a memory block from a memory pool and set memory block to zero.
  460. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  461. /// \return address of the allocated memory block or NULL in case of no memory available.
  462. /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
  463. void *osPoolCAlloc (osPoolId pool_id);
  464. /// Return an allocated memory block back to a specific memory pool.
  465. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
  466. /// \param[in] block address of the allocated memory block that is returned to the memory pool.
  467. /// \return status code that indicates the execution status of the function.
  468. /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
  469. osStatus osPoolFree (osPoolId pool_id, void *block);
  470. #endif // Memory Pool Management available
  471. // ==== Message Queue Management Functions ====
  472. #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
  473. /// \brief Create a Message Queue Definition.
  474. /// \param name name of the queue.
  475. /// \param queue_sz maximum number of messages in the queue.
  476. /// \param type data type of a single message element (for debugger).
  477. /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
  478. /// macro body is implementation specific in every CMSIS-RTOS.
  479. #if defined (osObjectsExternal) // object is external
  480. #define osMessageQDef(name, queue_sz, type) \
  481. extern const osMessageQDef_t os_messageQ_def_##name
  482. #else // define the object
  483. #define osMessageQDef(name, queue_sz, type) \
  484. const osMessageQDef_t os_messageQ_def_##name = \
  485. { (queue_sz), sizeof (type) }
  486. #endif
  487. /// \brief Access a Message Queue Definition.
  488. /// \param name name of the queue
  489. /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
  490. /// macro body is implementation specific in every CMSIS-RTOS.
  491. #define osMessageQ(name) \
  492. &os_messageQ_def_##name
  493. /// Create and Initialize a Message Queue.
  494. /// \param[in] queue_def queue definition referenced with \ref osMessageQ.
  495. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  496. /// \return message queue ID for reference by other functions or NULL in case of error.
  497. /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
  498. osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
  499. /// Put a Message to a Queue.
  500. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  501. /// \param[in] info message information.
  502. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  503. /// \return status code that indicates the execution status of the function.
  504. /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
  505. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
  506. /// Get a Message or Wait for a Message from a Queue.
  507. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
  508. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  509. /// \return event information that includes status code.
  510. /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
  511. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
  512. #endif // Message Queues available
  513. // ==== Mail Queue Management Functions ====
  514. #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
  515. /// \brief Create a Mail Queue Definition.
  516. /// \param name name of the queue
  517. /// \param queue_sz maximum number of messages in queue
  518. /// \param type data type of a single message element
  519. /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
  520. /// macro body is implementation specific in every CMSIS-RTOS.
  521. #if defined (osObjectsExternal) // object is external
  522. #define osMailQDef(name, queue_sz, type) \
  523. extern const osMailQDef_t os_mailQ_def_##name
  524. #else // define the object
  525. #define osMailQDef(name, queue_sz, type) \
  526. const osMailQDef_t os_mailQ_def_##name = \
  527. { (queue_sz), sizeof (type) }
  528. #endif
  529. /// \brief Access a Mail Queue Definition.
  530. /// \param name name of the queue
  531. /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
  532. /// macro body is implementation specific in every CMSIS-RTOS.
  533. #define osMailQ(name) \
  534. &os_mailQ_def_##name
  535. /// Create and Initialize mail queue.
  536. /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
  537. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  538. /// \return mail queue ID for reference by other functions or NULL in case of error.
  539. /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
  540. osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
  541. /// Allocate a memory block from a mail.
  542. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  543. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  544. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  545. /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
  546. void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
  547. /// Allocate a memory block from a mail and set memory block to zero.
  548. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  549. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  550. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  551. /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
  552. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
  553. /// Put a mail to a queue.
  554. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  555. /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
  556. /// \return status code that indicates the execution status of the function.
  557. /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
  558. osStatus osMailPut (osMailQId queue_id, void *mail);
  559. /// Get a mail from a queue.
  560. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  561. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  562. /// \return event that contains mail information or error code.
  563. /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
  564. osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
  565. /// Free a memory block from a mail.
  566. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
  567. /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
  568. /// \return status code that indicates the execution status of the function.
  569. /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
  570. osStatus osMailFree (osMailQId queue_id, void *mail);
  571. #endif // Mail Queues available
  572. #ifdef __cplusplus
  573. }
  574. #endif
  575. #endif // _CMSIS_OS_H