Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmsis_os.h 40KB

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