cmsis_os.h 36 KB

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