cmsis_os.h 36 KB

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