A bundled STM32F10x Std Periph and CMSIS library
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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