硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1551|回复: 0
收起左侧

[CMSIS-RTOS] RTX5的cmsis_os2.h头文件

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106959
QQ
发表于 2018-3-13 11:03:33 | 显示全部楼层 |阅读模式
把头文件cmsis_os2.h贴出来,方便以后直接查阅:

  1. /*
  2. * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * ----------------------------------------------------------------------
  19. *
  20. * $Date:        30. October 2017
  21. * $Revision:    V2.1.2
  22. *
  23. * Project:      CMSIS-RTOS API
  24. * Title:        cmsis_os.h template header file
  25. *
  26. * Version 0.02
  27. *    Initial Proposal Phase
  28. * Version 0.03
  29. *    osKernelStart added, optional feature: main started as thread
  30. *    osSemaphores have standard behavior
  31. *    osTimerCreate does not start the timer, added osTimerStart
  32. *    osThreadPass is renamed to osThreadYield
  33. * Version 1.01
  34. *    Support for C++ interface
  35. *     - const attribute removed from the osXxxxDef_t typedefs
  36. *     - const attribute added to the osXxxxDef macros
  37. *    Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
  38. *    Added: osKernelInitialize
  39. * Version 1.02
  40. *    Control functions for short timeouts in microsecond resolution:
  41. *    Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
  42. *    Removed: osSignalGet
  43. * Version 2.0.0
  44. *    OS objects creation without macros (dynamic creation and resource allocation):
  45. *     - added: osXxxxNew functions which replace osXxxxCreate
  46. *     - added: osXxxxAttr_t structures
  47. *     - deprecated: osXxxxCreate functions, osXxxxDef_t structures
  48. *     - deprecated: osXxxxDef and osXxxx macros
  49. *    osStatus codes simplified and renamed to osStatus_t
  50. *    osEvent return structure deprecated
  51. *    Kernel:
  52. *     - added: osKernelInfo_t and osKernelGetInfo
  53. *     - added: osKernelState_t and osKernelGetState (replaces osKernelRunning)
  54. *     - added: osKernelLock, osKernelUnlock
  55. *     - added: osKernelSuspend, osKernelResume
  56. *     - added: osKernelGetTickCount, osKernelGetTickFreq
  57. *     - renamed osKernelSysTick to osKernelGetSysTimerCount
  58. *     - replaced osKernelSysTickFrequency with osKernelGetSysTimerFreq
  59. *     - deprecated osKernelSysTickMicroSec
  60. *    Thread:
  61. *     - extended number of thread priorities
  62. *     - renamed osPrioriry to osPrioriry_t
  63. *     - replaced osThreadCreate with osThreadNew
  64. *     - added: osThreadGetName
  65. *     - added: osThreadState_t and osThreadGetState
  66. *     - added: osThreadGetStackSize, osThreadGetStackSpace
  67. *     - added: osThreadSuspend, osThreadResume
  68. *     - added: osThreadJoin, osThreadDetach, osThreadExit
  69. *     - added: osThreadGetCount, osThreadEnumerate
  70. *     - added: Thread Flags (moved from Signals)
  71. *    Signals:
  72. *     - renamed osSignals to osThreadFlags (moved to Thread Flags)
  73. *     - changed return value of Set/Clear/Wait functions
  74. *     - Clear function limited to current running thread
  75. *     - extended Wait function (options)
  76. *     - added: osThreadFlagsGet
  77. *    Event Flags:
  78. *     - added new independent object for handling Event Flags
  79. *    Delay and Wait functions:
  80. *     - added: osDelayUntil
  81. *     - deprecated: osWait
  82. *    Timer:
  83. *     - replaced osTimerCreate with osTimerNew
  84. *     - added: osTimerGetName, osTimerIsRunning
  85. *    Mutex:
  86. *     - extended: attributes (Recursive, Priority Inherit, Robust)
  87. *     - replaced osMutexCreate with osMutexNew
  88. *     - renamed osMutexWait to osMutexAcquire
  89. *     - added: osMutexGetName, osMutexGetOwner
  90. *    Semaphore:
  91. *     - extended: maximum and initial token count
  92. *     - replaced osSemaphoreCreate with osSemaphoreNew
  93. *     - renamed osSemaphoreWait to osSemaphoreAcquire (changed return value)
  94. *     - added: osSemaphoreGetName, osSemaphoreGetCount
  95. *    Memory Pool:
  96. *     - using osMemoryPool prefix instead of osPool
  97. *     - replaced osPoolCreate with osMemoryPoolNew
  98. *     - extended osMemoryPoolAlloc (timeout)
  99. *     - added: osMemoryPoolGetName
  100. *     - added: osMemoryPoolGetCapacity, osMemoryPoolGetBlockSize
  101. *     - added: osMemoryPoolGetCount, osMemoryPoolGetSpace
  102. *     - added: osMemoryPoolDelete
  103. *     - deprecated: osPoolCAlloc
  104. *    Message Queue:
  105. *     - extended: fixed size message instead of a single 32-bit value
  106. *     - using osMessageQueue prefix instead of osMessage
  107. *     - replaced osMessageCreate with osMessageQueueNew
  108. *     - updated: osMessageQueuePut, osMessageQueueGet
  109. *     - added: osMessageQueueGetName
  110. *     - added: osMessageQueueGetCapacity, osMessageQueueGetMsgSize
  111. *     - added: osMessageQueueGetCount, osMessageQueueGetSpace
  112. *     - added: osMessageQueueReset, osMessageQueueDelete
  113. *    Mail Queue:
  114. *     - deprecated (superseded by extended Message Queue functionality)
  115. * Version 2.1.0
  116. *    Support for critical and uncritical sections (nesting safe):
  117. *    - updated: osKernelLock, osKernelUnlock
  118. *    - added: osKernelRestoreLock
  119. *    Updated Thread and Event Flags:
  120. *    - changed flags parameter and return type from int32_t to uint32_t
  121. * Version 2.1.1
  122. *    Additional functions allowed to be called from Interrupt Service Routines:
  123. *    - osKernelGetTickCount, osKernelGetTickFreq
  124. *    Changed Kernel Tick type to uint32_t:
  125. *    - updated: osKernelGetTickCount, osDelayUntil
  126. * Version 2.1.2
  127. *    Additional functions allowed to be called from Interrupt Service Routines:
  128. *    - osKernelGetInfo, osKernelGetState
  129. *---------------------------------------------------------------------------*/

  130. #ifndef CMSIS_OS_H_
  131. #define CMSIS_OS_H_

  132. /// \b osCMSIS identifies the CMSIS-RTOS API version.
  133. #define osCMSIS             0x20001U    ///< API version (main[31:16].sub[15:0])

  134. /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
  135. #define osCMSIS_KERNEL      0x10000U    ///< RTOS identification and version (main[31:16].sub[15:0])

  136. /// \note CAN BE CHANGED: \b osKernelSystemId identifies the underlying RTOS kernel.
  137. #define osKernelSystemId "KERNEL V1.0"  ///< RTOS identification string

  138. /// \note CAN BE CHANGED: \b osFeature_xxx identifies RTOS features.
  139. #define osFeature_MainThread  0         ///< main thread      1=main can be thread, 0=not available
  140. #define osFeature_Signals     16U       ///< maximum number of Signal Flags available per thread
  141. #define osFeature_Semaphore   65535U    ///< maximum count for \ref osSemaphoreCreate function
  142. #define osFeature_Wait        0         ///< osWait function: 1=available, 0=not available
  143. #define osFeature_SysTick     1         ///< osKernelSysTick functions: 1=available, 0=not available
  144. #define osFeature_Pool        1         ///< Memory Pools:    1=available, 0=not available
  145. #define osFeature_MessageQ    1         ///< Message Queues:  1=available, 0=not available
  146. #define osFeature_MailQ       1         ///< Mail Queues:     1=available, 0=not available

  147. #if (osCMSIS >= 0x20000U)
  148. #include "cmsis_os2.h"
  149. #else
  150. #include <stdint.h>
  151. #include <stddef.h>
  152. #endif

  153. #ifdef  __cplusplus
  154. extern "C"
  155. {
  156. #endif


  157. // ==== Enumerations, structures, defines ====

  158. /// Priority values.
  159. #if (osCMSIS < 0x20000U)
  160. typedef enum {
  161.   osPriorityIdle          = -3,         ///< Priority: idle (lowest)
  162.   osPriorityLow           = -2,         ///< Priority: low
  163.   osPriorityBelowNormal   = -1,         ///< Priority: below normal
  164.   osPriorityNormal        =  0,         ///< Priority: normal (default)
  165.   osPriorityAboveNormal   = +1,         ///< Priority: above normal
  166.   osPriorityHigh          = +2,         ///< Priority: high
  167.   osPriorityRealtime      = +3,         ///< Priority: realtime (highest)
  168.   osPriorityError         = 0x84,       ///< System cannot determine priority or illegal priority.
  169.   osPriorityReserved      = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
  170. } osPriority;
  171. #else
  172. #define osPriority osPriority_t
  173. #endif

  174. /// Entry point of a thread.
  175. typedef void (*os_pthread) (void const *argument);

  176. /// Entry point of a timer call back function.
  177. typedef void (*os_ptimer) (void const *argument);

  178. /// Timer type.
  179. #if (osCMSIS < 0x20000U)
  180. typedef enum {
  181.   osTimerOnce             = 0,          ///< One-shot timer.
  182.   osTimerPeriodic         = 1           ///< Repeating timer.
  183. } os_timer_type;
  184. #else
  185. #define os_timer_type osTimerType_t
  186. #endif

  187. /// Timeout value.
  188. #define osWaitForever       0xFFFFFFFFU ///< Wait forever timeout value.

  189. /// Status code values returned by CMSIS-RTOS functions.
  190. #if (osCMSIS < 0x20000U)
  191. typedef enum {
  192.   osOK                    =    0,       ///< Function completed; no error or event occurred.
  193.   osEventSignal           = 0x08,       ///< Function completed; signal event occurred.
  194.   osEventMessage          = 0x10,       ///< Function completed; message event occurred.
  195.   osEventMail             = 0x20,       ///< Function completed; mail event occurred.
  196.   osEventTimeout          = 0x40,       ///< Function completed; timeout occurred.
  197.   osErrorParameter        = 0x80,       ///< Parameter error: a mandatory parameter was missing or specified an incorrect object.
  198.   osErrorResource         = 0x81,       ///< Resource not available: a specified resource was not available.
  199.   osErrorTimeoutResource  = 0xC1,       ///< Resource not available within given time: a specified resource was not available within the timeout period.
  200.   osErrorISR              = 0x82,       ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
  201.   osErrorISRRecursive     = 0x83,       ///< Function called multiple times from ISR with same object.
  202.   osErrorPriority         = 0x84,       ///< System cannot determine priority or thread has illegal priority.
  203.   osErrorNoMemory         = 0x85,       ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
  204.   osErrorValue            = 0x86,       ///< Value of a parameter is out of range.
  205.   osErrorOS               = 0xFF,       ///< Unspecified RTOS error: run-time error but no other error message fits.
  206.   osStatusReserved        = 0x7FFFFFFF  ///< Prevents enum down-size compiler optimization.
  207. } osStatus;
  208. #else
  209. typedef int32_t                  osStatus;
  210. #define osEventSignal           (0x08)
  211. #define osEventMessage          (0x10)
  212. #define osEventMail             (0x20)
  213. #define osEventTimeout          (0x40)
  214. #define osErrorOS               osError
  215. #define osErrorTimeoutResource  osErrorTimeout
  216. #define osErrorISRRecursive     (-126)
  217. #define osErrorValue            (-127)
  218. #define osErrorPriority         (-128)
  219. #endif


  220. // >>> the following data type definitions may be adapted towards a specific RTOS

  221. /// Thread ID identifies the thread.
  222. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  223. #if (osCMSIS < 0x20000U)
  224. typedef void *osThreadId;
  225. #else
  226. #define osThreadId osThreadId_t
  227. #endif

  228. /// Timer ID identifies the timer.
  229. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  230. #if (osCMSIS < 0x20000U)
  231. typedef void *osTimerId;
  232. #else
  233. #define osTimerId osTimerId_t
  234. #endif

  235. /// Mutex ID identifies the mutex.
  236. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  237. #if (osCMSIS < 0x20000U)
  238. typedef void *osMutexId;
  239. #else
  240. #define osMutexId osMutexId_t
  241. #endif

  242. /// Semaphore ID identifies the semaphore.
  243. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  244. #if (osCMSIS < 0x20000U)
  245. typedef void *osSemaphoreId;
  246. #else
  247. #define osSemaphoreId osSemaphoreId_t
  248. #endif

  249. /// Pool ID identifies the memory pool.
  250. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  251. typedef void *osPoolId;

  252. /// Message ID identifies the message queue.
  253. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  254. typedef void *osMessageQId;

  255. /// Mail ID identifies the mail queue.
  256. /// \note CAN BE CHANGED: \b implementation specific in every CMSIS-RTOS.
  257. typedef void *osMailQId;


  258. /// Thread Definition structure contains startup information of a thread.
  259. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
  260. #if (osCMSIS < 0x20000U)
  261. typedef struct os_thread_def {
  262.   os_pthread                 pthread;   ///< start address of thread function
  263.   osPriority               tpriority;   ///< initial thread priority
  264.   uint32_t                 instances;   ///< maximum number of instances of that thread function
  265.   uint32_t                 stacksize;   ///< stack size requirements in bytes; 0 is default stack size
  266. } osThreadDef_t;
  267. #else
  268. typedef struct os_thread_def {
  269.   os_pthread                 pthread;   ///< start address of thread function
  270.   osThreadAttr_t                attr;   ///< thread attributes
  271. } osThreadDef_t;
  272. #endif

  273. /// Timer Definition structure contains timer parameters.
  274. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
  275. #if (osCMSIS < 0x20000U)
  276. typedef struct os_timer_def {
  277.   os_ptimer                   ptimer;   ///< start address of a timer function
  278. } osTimerDef_t;
  279. #else
  280. typedef struct os_timer_def {
  281.   os_ptimer                   ptimer;   ///< start address of a timer function
  282.   osTimerAttr_t                 attr;   ///< timer attributes
  283. } osTimerDef_t;
  284. #endif

  285. /// Mutex Definition structure contains setup information for a mutex.
  286. /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
  287. #if (osCMSIS < 0x20000U)
  288. typedef struct os_mutex_def {
  289.   uint32_t                     dummy;   ///< dummy value
  290. } osMutexDef_t;
  291. #else
  292. #define osMutexDef_t osMutexAttr_t
  293. #endif

  294. /// Semaphore Definition structure contains setup information for a semaphore.
  295. /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
  296. #if (osCMSIS < 0x20000U)
  297. typedef struct os_semaphore_def {
  298.   uint32_t                     dummy;   ///< dummy value
  299. } osSemaphoreDef_t;
  300. #else
  301. #define osSemaphoreDef_t osSemaphoreAttr_t
  302. #endif

  303. /// Definition structure for memory block allocation.
  304. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
  305. #if (osCMSIS < 0x20000U)
  306. typedef struct os_pool_def {
  307.   uint32_t                   pool_sz;   ///< number of items (elements) in the pool
  308.   uint32_t                   item_sz;   ///< size of an item
  309.   void                         *pool;   ///< pointer to memory for pool
  310. } osPoolDef_t;
  311. #else
  312. typedef struct os_pool_def {
  313.   uint32_t                   pool_sz;   ///< number of items (elements) in the pool
  314.   uint32_t                   item_sz;   ///< size of an item
  315.   osMemoryPoolAttr_t            attr;   ///< memory pool attributes
  316. } osPoolDef_t;
  317. #endif

  318. /// Definition structure for message queue.
  319. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
  320. #if (osCMSIS < 0x20000U)
  321. typedef struct os_messageQ_def {
  322.   uint32_t                  queue_sz;   ///< number of elements in the queue
  323.   void                         *pool;   ///< memory array for messages
  324. } osMessageQDef_t;
  325. #else
  326. typedef struct os_messageQ_def {
  327.   uint32_t                  queue_sz;   ///< number of elements in the queue
  328.   osMessageQueueAttr_t          attr;   ///< message queue attributes
  329. } osMessageQDef_t;
  330. #endif

  331. /// Definition structure for mail queue.
  332. /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
  333. #if (osCMSIS < 0x20000U)
  334. typedef struct os_mailQ_def {
  335.   uint32_t                  queue_sz;   ///< number of elements in the queue
  336.   uint32_t                   item_sz;   ///< size of an item
  337.   void                         *pool;   ///< memory array for mail
  338. } osMailQDef_t;
  339. #else
  340. typedef struct os_mailQ_def {
  341.   uint32_t                  queue_sz;   ///< number of elements in the queue
  342.   uint32_t                   item_sz;   ///< size of an item
  343.   void                         *mail;   ///< pointer to mail
  344.   osMemoryPoolAttr_t         mp_attr;   ///< memory pool attributes
  345.   osMessageQueueAttr_t       mq_attr;   ///< message queue attributes
  346. } osMailQDef_t;
  347. #endif


  348. /// Event structure contains detailed information about an event.
  349. typedef struct {
  350.   osStatus                    status;   ///< status code: event or error information
  351.   union {
  352.     uint32_t                       v;   ///< message as 32-bit value
  353.     void                          *p;   ///< message or mail as void pointer
  354.     int32_t                  signals;   ///< signal flags
  355.   } value;                              ///< event value
  356.   union {
  357.     osMailQId                mail_id;   ///< mail id obtained by \ref osMailCreate
  358.     osMessageQId          message_id;   ///< message id obtained by \ref osMessageCreate
  359.   } def;                                ///< event definition
  360. } osEvent;


  361. //  ==== Kernel Management Functions ====

  362. /// Initialize the RTOS Kernel for creating objects.
  363. /// \return status code that indicates the execution status of the function.
  364. #if (osCMSIS < 0x20000U)
  365. osStatus osKernelInitialize (void);
  366. #endif

  367. /// Start the RTOS Kernel scheduler.
  368. /// \return status code that indicates the execution status of the function.
  369. #if (osCMSIS < 0x20000U)
  370. osStatus osKernelStart (void);
  371. #endif

  372. /// Check if the RTOS kernel is already started.
  373. /// \return 0 RTOS is not started, 1 RTOS is started.
  374. #if (osCMSIS < 0x20000U)
  375. int32_t osKernelRunning(void);
  376. #endif

  377. #if (defined(osFeature_SysTick) && (osFeature_SysTick != 0))  // System Timer available

  378. /// Get the RTOS kernel system timer counter.
  379. /// \return RTOS kernel system timer as 32-bit value
  380. #if (osCMSIS < 0x20000U)
  381. uint32_t osKernelSysTick (void);
  382. #else
  383. #define  osKernelSysTick osKernelGetSysTimerCount
  384. #endif

  385. /// The RTOS kernel system timer frequency in Hz.
  386. /// \note Reflects the system timer setting and is typically defined in a configuration file.
  387. #if (osCMSIS < 0x20000U)
  388. #define osKernelSysTickFrequency 100000000
  389. #endif

  390. /// Convert a microseconds value to a RTOS kernel system timer value.
  391. /// \param         microsec     time value in microseconds.
  392. /// \return time value normalized to the \ref osKernelSysTickFrequency
  393. #if (osCMSIS < 0x20000U)
  394. #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
  395. #else
  396. #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec *  osKernelGetSysTimerFreq()) / 1000000)
  397. #endif

  398. #endif  // System Timer available


  399. //  ==== Thread Management Functions ====

  400. /// Create a Thread Definition with function, priority, and stack requirements.
  401. /// \param         name          name of the thread function.
  402. /// \param         priority      initial priority of the thread function.
  403. /// \param         instances     number of possible thread instances.
  404. /// \param         stacksz       stack size (in bytes) requirements for the thread function.
  405. /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
  406. ///       macro body is implementation specific in every CMSIS-RTOS.
  407. #if defined (osObjectsExternal)  // object is external
  408. #define osThreadDef(name, priority, instances, stacksz) \
  409. extern const osThreadDef_t os_thread_def_##name
  410. #else                            // define the object
  411. #if (osCMSIS < 0x20000U)
  412. #define osThreadDef(name, priority, instances, stacksz) \
  413. const osThreadDef_t os_thread_def_##name = \
  414. { (name), (priority), (instances), (stacksz) }
  415. #else
  416. #define osThreadDef(name, priority, instances, stacksz) \
  417. const osThreadDef_t os_thread_def_##name = \
  418. { (name), \
  419.   { NULL, osThreadDetached, NULL, 0U, NULL, 8*((stacksz+7)/8), (priority), 0U, 0U } }
  420. #endif
  421. #endif

  422. /// Access a Thread definition.
  423. /// \param         name          name of the thread definition object.
  424. /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
  425. ///       macro body is implementation specific in every CMSIS-RTOS.
  426. #define osThread(name) \
  427. &os_thread_def_##name

  428. /// Create a thread and add it to Active Threads and set it to state READY.
  429. /// \param[in]     thread_def    thread definition referenced with \ref osThread.
  430. /// \param[in]     argument      pointer that is passed to the thread function as start argument.
  431. /// \return thread ID for reference by other functions or NULL in case of error.
  432. osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);

  433. /// Return the thread ID of the current running thread.
  434. /// \return thread ID for reference by other functions or NULL in case of error.
  435. #if (osCMSIS < 0x20000U)
  436. osThreadId osThreadGetId (void);
  437. #endif

  438. /// Change priority of a thread.
  439. /// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  440. /// \param[in]     priority      new priority value for the thread function.
  441. /// \return status code that indicates the execution status of the function.
  442. #if (osCMSIS < 0x20000U)
  443. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
  444. #endif

  445. /// Get current priority of a thread.
  446. /// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  447. /// \return current priority value of the specified thread.
  448. #if (osCMSIS < 0x20000U)
  449. osPriority osThreadGetPriority (osThreadId thread_id);
  450. #endif

  451. /// Pass control to next thread that is in state \b READY.
  452. /// \return status code that indicates the execution status of the function.
  453. #if (osCMSIS < 0x20000U)
  454. osStatus osThreadYield (void);
  455. #endif

  456. /// Terminate execution of a thread.
  457. /// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  458. /// \return status code that indicates the execution status of the function.
  459. #if (osCMSIS < 0x20000U)
  460. osStatus osThreadTerminate (osThreadId thread_id);
  461. #endif


  462. //  ==== Signal Management ====

  463. /// Set the specified Signal Flags of an active thread.
  464. /// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  465. /// \param[in]     signals       specifies the signal flags of the thread that should be set.
  466. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
  467. int32_t osSignalSet (osThreadId thread_id, int32_t signals);

  468. /// Clear the specified Signal Flags of an active thread.
  469. /// \param[in]     thread_id     thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
  470. /// \param[in]     signals       specifies the signal flags of the thread that shall be cleared.
  471. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
  472. int32_t osSignalClear (osThreadId thread_id, int32_t signals);

  473. /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
  474. /// \param[in]     signals       wait until all specified signal flags set or 0 for any single signal flag.
  475. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  476. /// \return event flag information or error code.
  477. osEvent osSignalWait (int32_t signals, uint32_t millisec);


  478. //  ==== Generic Wait Functions ====

  479. /// Wait for Timeout (Time Delay).
  480. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue "time delay" value
  481. /// \return status code that indicates the execution status of the function.
  482. #if (osCMSIS < 0x20000U)
  483. osStatus osDelay (uint32_t millisec);
  484. #endif

  485. #if (defined (osFeature_Wait) && (osFeature_Wait != 0))  // Generic Wait available

  486. /// Wait for Signal, Message, Mail, or Timeout.
  487. /// \param[in] millisec          \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  488. /// \return event that contains signal, message, or mail information or error code.
  489. osEvent osWait (uint32_t millisec);

  490. #endif  // Generic Wait available


  491. //  ==== Timer Management Functions ====

  492. /// Define a Timer object.
  493. /// \param         name          name of the timer object.
  494. /// \param         function      name of the timer call back function.
  495. /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
  496. ///       macro body is implementation specific in every CMSIS-RTOS.
  497. #if defined (osObjectsExternal)  // object is external
  498. #define osTimerDef(name, function) \
  499. extern const osTimerDef_t os_timer_def_##name
  500. #else                            // define the object
  501. #if (osCMSIS < 0x20000U)
  502. #define osTimerDef(name, function) \
  503. const osTimerDef_t os_timer_def_##name = { (function) }
  504. #else
  505. #define osTimerDef(name, function) \
  506. const osTimerDef_t os_timer_def_##name = \
  507. { (function), { NULL, 0U, NULL, 0U } }
  508. #endif
  509. #endif

  510. /// Access a Timer definition.
  511. /// \param         name          name of the timer object.
  512. /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
  513. ///       macro body is implementation specific in every CMSIS-RTOS.
  514. #define osTimer(name) \
  515. &os_timer_def_##name

  516. /// Create and Initialize a timer.
  517. /// \param[in]     timer_def     timer object referenced with \ref osTimer.
  518. /// \param[in]     type          osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
  519. /// \param[in]     argument      argument to the timer call back function.
  520. /// \return timer ID for reference by other functions or NULL in case of error.
  521. osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);

  522. /// Start or restart a timer.
  523. /// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
  524. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
  525. /// \return status code that indicates the execution status of the function.
  526. #if (osCMSIS < 0x20000U)
  527. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
  528. #endif

  529. /// Stop a timer.
  530. /// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
  531. /// \return status code that indicates the execution status of the function.
  532. #if (osCMSIS < 0x20000U)
  533. osStatus osTimerStop (osTimerId timer_id);
  534. #endif

  535. /// Delete a timer.
  536. /// \param[in]     timer_id      timer ID obtained by \ref osTimerCreate.
  537. /// \return status code that indicates the execution status of the function.
  538. #if (osCMSIS < 0x20000U)
  539. osStatus osTimerDelete (osTimerId timer_id);
  540. #endif


  541. //  ==== Mutex Management Functions ====

  542. /// Define a Mutex.
  543. /// \param         name          name of the mutex object.
  544. /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
  545. ///       macro body is implementation specific in every CMSIS-RTOS.
  546. #if defined (osObjectsExternal)  // object is external
  547. #define osMutexDef(name) \
  548. extern const osMutexDef_t os_mutex_def_##name
  549. #else                            // define the object
  550. #if (osCMSIS < 0x20000U)
  551. #define osMutexDef(name) \
  552. const osMutexDef_t os_mutex_def_##name = { 0 }
  553. #else
  554. #define osMutexDef(name) \
  555. const osMutexDef_t os_mutex_def_##name = \
  556. { NULL, osMutexRecursive | osMutexPrioInherit | osMutexRobust, NULL, 0U }
  557. #endif
  558. #endif

  559. /// Access a Mutex definition.
  560. /// \param         name          name of the mutex object.
  561. /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
  562. ///       macro body is implementation specific in every CMSIS-RTOS.
  563. #define osMutex(name) \
  564. &os_mutex_def_##name

  565. /// Create and Initialize a Mutex object.
  566. /// \param[in]     mutex_def     mutex definition referenced with \ref osMutex.
  567. /// \return mutex ID for reference by other functions or NULL in case of error.
  568. osMutexId osMutexCreate (const osMutexDef_t *mutex_def);

  569. /// Wait until a Mutex becomes available.
  570. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexCreate.
  571. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  572. /// \return status code that indicates the execution status of the function.
  573. #if (osCMSIS < 0x20000U)
  574. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
  575. #else
  576. #define  osMutexWait osMutexAcquire
  577. #endif

  578. /// Release a Mutex that was obtained by \ref osMutexWait.
  579. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexCreate.
  580. /// \return status code that indicates the execution status of the function.
  581. #if (osCMSIS < 0x20000U)
  582. osStatus osMutexRelease (osMutexId mutex_id);
  583. #endif

  584. /// Delete a Mutex object.
  585. /// \param[in]     mutex_id      mutex ID obtained by \ref osMutexCreate.
  586. /// \return status code that indicates the execution status of the function.
  587. #if (osCMSIS < 0x20000U)
  588. osStatus osMutexDelete (osMutexId mutex_id);
  589. #endif


  590. //  ==== Semaphore Management Functions ====

  591. #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U))  // Semaphore available

  592. /// Define a Semaphore object.
  593. /// \param         name          name of the semaphore object.
  594. /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
  595. ///       macro body is implementation specific in every CMSIS-RTOS.
  596. #if defined (osObjectsExternal)  // object is external
  597. #define osSemaphoreDef(name) \
  598. extern const osSemaphoreDef_t os_semaphore_def_##name
  599. #else                            // define the object
  600. #if (osCMSIS < 0x20000U)
  601. #define osSemaphoreDef(name) \
  602. const osSemaphoreDef_t os_semaphore_def_##name = { 0 }
  603. #else
  604. #define osSemaphoreDef(name) \
  605. const osSemaphoreDef_t os_semaphore_def_##name = \
  606. { NULL, 0U, NULL, 0U }
  607. #endif
  608. #endif

  609. /// Access a Semaphore definition.
  610. /// \param         name          name of the semaphore object.
  611. /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
  612. ///       macro body is implementation specific in every CMSIS-RTOS.
  613. #define osSemaphore(name) \
  614. &os_semaphore_def_##name

  615. /// Create and Initialize a Semaphore object.
  616. /// \param[in]     semaphore_def semaphore definition referenced with \ref osSemaphore.
  617. /// \param[in]     count         maximum and initial number of available tokens.
  618. /// \return semaphore ID for reference by other functions or NULL in case of error.
  619. osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);

  620. /// Wait until a Semaphore token becomes available.
  621. /// \param[in]     semaphore_id  semaphore object referenced with \ref osSemaphoreCreate.
  622. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  623. /// \return number of available tokens, or -1 in case of incorrect parameters.
  624. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);

  625. /// Release a Semaphore token.
  626. /// \param[in]     semaphore_id  semaphore object referenced with \ref osSemaphoreCreate.
  627. /// \return status code that indicates the execution status of the function.
  628. #if (osCMSIS < 0x20000U)
  629. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
  630. #endif

  631. /// Delete a Semaphore object.
  632. /// \param[in]     semaphore_id  semaphore object referenced with \ref osSemaphoreCreate.
  633. /// \return status code that indicates the execution status of the function.
  634. #if (osCMSIS < 0x20000U)
  635. osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
  636. #endif

  637. #endif  // Semaphore available


  638. //  ==== Memory Pool Management Functions ====

  639. #if (defined(osFeature_Pool) && (osFeature_Pool != 0))  // Memory Pool available

  640. /// \brief Define a Memory Pool.
  641. /// \param         name          name of the memory pool.
  642. /// \param         no            maximum number of blocks (objects) in the memory pool.
  643. /// \param         type          data type of a single block (object).
  644. /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
  645. ///       macro body is implementation specific in every CMSIS-RTOS.
  646. #if defined (osObjectsExternal)  // object is external
  647. #define osPoolDef(name, no, type) \
  648. extern const osPoolDef_t os_pool_def_##name
  649. #else                            // define the object
  650. #if (osCMSIS < 0x20000U)
  651. #define osPoolDef(name, no, type) \
  652. const osPoolDef_t os_pool_def_##name = \
  653. { (no), sizeof(type), NULL }
  654. #else
  655. #define osPoolDef(name, no, type) \
  656. const osPoolDef_t os_pool_def_##name = \
  657. { (no), sizeof(type), { NULL, 0U, NULL, 0U, NULL, 0U } }
  658. #endif
  659. #endif

  660. /// \brief Access a Memory Pool definition.
  661. /// \param         name          name of the memory pool
  662. /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
  663. ///       macro body is implementation specific in every CMSIS-RTOS.
  664. #define osPool(name) \
  665. &os_pool_def_##name

  666. /// Create and Initialize a Memory Pool object.
  667. /// \param[in]     pool_def      memory pool definition referenced with \ref osPool.
  668. /// \return memory pool ID for reference by other functions or NULL in case of error.
  669. osPoolId osPoolCreate (const osPoolDef_t *pool_def);

  670. /// Allocate a memory block from a Memory Pool.
  671. /// \param[in]     pool_id       memory pool ID obtain referenced with \ref osPoolCreate.
  672. /// \return address of the allocated memory block or NULL in case of no memory available.
  673. void *osPoolAlloc (osPoolId pool_id);

  674. /// Allocate a memory block from a Memory Pool and set memory block to zero.
  675. /// \param[in]     pool_id       memory pool ID obtain referenced with \ref osPoolCreate.
  676. /// \return address of the allocated memory block or NULL in case of no memory available.
  677. void *osPoolCAlloc (osPoolId pool_id);

  678. /// Return an allocated memory block back to a Memory Pool.
  679. /// \param[in]     pool_id       memory pool ID obtain referenced with \ref osPoolCreate.
  680. /// \param[in]     block         address of the allocated memory block to be returned to the memory pool.
  681. /// \return status code that indicates the execution status of the function.
  682. osStatus osPoolFree (osPoolId pool_id, void *block);

  683. #endif  // Memory Pool available


  684. //  ==== Message Queue Management Functions ====

  685. #if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0))  // Message Queue available
  686.   
  687. /// \brief Create a Message Queue Definition.
  688. /// \param         name          name of the queue.
  689. /// \param         queue_sz      maximum number of messages in the queue.
  690. /// \param         type          data type of a single message element (for debugger).
  691. /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
  692. ///       macro body is implementation specific in every CMSIS-RTOS.
  693. #if defined (osObjectsExternal)  // object is external
  694. #define osMessageQDef(name, queue_sz, type) \
  695. extern const osMessageQDef_t os_messageQ_def_##name
  696. #else                            // define the object
  697. #if (osCMSIS < 0x20000U)
  698. #define osMessageQDef(name, queue_sz, type) \
  699. const osMessageQDef_t os_messageQ_def_##name = \
  700. { (queue_sz), NULL }
  701. #else
  702. #define osMessageQDef(name, queue_sz, type) \
  703. const osMessageQDef_t os_messageQ_def_##name = \
  704. { (queue_sz), { NULL, 0U, NULL, 0U, NULL, 0U } }
  705. #endif
  706. #endif

  707. /// \brief Access a Message Queue Definition.
  708. /// \param         name          name of the queue
  709. /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
  710. ///       macro body is implementation specific in every CMSIS-RTOS.
  711. #define osMessageQ(name) \
  712. &os_messageQ_def_##name

  713. /// Create and Initialize a Message Queue object.
  714. /// \param[in]     queue_def     message queue definition referenced with \ref osMessageQ.
  715. /// \param[in]     thread_id     thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  716. /// \return message queue ID for reference by other functions or NULL in case of error.
  717. osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);

  718. /// Put a Message to a Queue.
  719. /// \param[in]     queue_id      message queue ID obtained with \ref osMessageCreate.
  720. /// \param[in]     info          message information.
  721. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  722. /// \return status code that indicates the execution status of the function.
  723. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);

  724. /// Get a Message from a Queue or timeout if Queue is empty.
  725. /// \param[in]     queue_id      message queue ID obtained with \ref osMessageCreate.
  726. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  727. /// \return event information that includes status code.
  728. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);

  729. #endif  // Message Queue available


  730. //  ==== Mail Queue Management Functions ====

  731. #if (defined(osFeature_MailQ) && (osFeature_MailQ != 0))  // Mail Queue available

  732. /// \brief Create a Mail Queue Definition.
  733. /// \param         name          name of the queue.
  734. /// \param         queue_sz      maximum number of mails in the queue.
  735. /// \param         type          data type of a single mail element.
  736. /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
  737. ///       macro body is implementation specific in every CMSIS-RTOS.
  738. #if defined (osObjectsExternal)  // object is external
  739. #define osMailQDef(name, queue_sz, type) \
  740. extern const osMailQDef_t os_mailQ_def_##name
  741. #else                            // define the object
  742. #if (osCMSIS < 0x20000U)
  743. #define osMailQDef(name, queue_sz, type) \
  744. const osMailQDef_t os_mailQ_def_##name = \
  745. { (queue_sz), sizeof(type), NULL }
  746. #else
  747. #define osMailQDef(name, queue_sz, type) \
  748. static void *os_mail_p_##name[2]; \
  749. const osMailQDef_t os_mailQ_def_##name = \
  750. { (queue_sz), sizeof(type), (&os_mail_p_##name), \
  751.   { NULL, 0U, NULL, 0U, NULL, 0U }, \
  752.   { NULL, 0U, NULL, 0U, NULL, 0U } }
  753. #endif
  754. #endif

  755. /// \brief Access a Mail Queue Definition.
  756. /// \param         name          name of the queue
  757. /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
  758. ///       macro body is implementation specific in every CMSIS-RTOS.
  759. #define osMailQ(name) \
  760. &os_mailQ_def_##name

  761. /// Create and Initialize a Mail Queue object.
  762. /// \param[in]     queue_def     mail queue definition referenced with \ref osMailQ.
  763. /// \param[in]     thread_id     thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
  764. /// \return mail queue ID for reference by other functions or NULL in case of error.
  765. osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);

  766. /// Allocate a memory block for mail from a mail memory pool.
  767. /// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
  768. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  769. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  770. void *osMailAlloc (osMailQId queue_id, uint32_t millisec);

  771. /// Allocate a memory block for mail from a mail memory pool and set memory block to zero.
  772. /// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
  773. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
  774. /// \return pointer to memory block that can be filled with mail or NULL in case of error.
  775. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);

  776. /// Put a Mail into a Queue.
  777. /// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
  778. /// \param[in]     mail          pointer to memory with mail to put into a queue.
  779. /// \return status code that indicates the execution status of the function.
  780. osStatus osMailPut (osMailQId queue_id, const void *mail);

  781. /// Get a Mail from a Queue or timeout if Queue is empty.
  782. /// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
  783. /// \param[in]     millisec      \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
  784. /// \return event information that includes status code.
  785. osEvent osMailGet (osMailQId queue_id, uint32_t millisec);

  786. /// Free a memory block by returning it to a mail memory pool.
  787. /// \param[in]     queue_id      mail queue ID obtained with \ref osMailCreate.
  788. /// \param[in]     mail          pointer to memory block that was obtained with \ref osMailGet.
  789. /// \return status code that indicates the execution status of the function.
  790. osStatus osMailFree (osMailQId queue_id, void *mail);

  791. #endif  // Mail Queue available


  792. #ifdef  __cplusplus
  793. }
  794. #endif

  795. #endif  // CMSIS_OS_H_
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-12 03:51 , Processed in 0.212235 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表