queue.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * FreeRTOS Kernel V10.5.1
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. */
  8. #ifndef QUEUE_H
  9. #define QUEUE_H
  10. #ifndef INC_FREERTOS_H
  11. #error "include FreeRTOS.h" must appear in source files before "include queue.h"
  12. #endif
  13. #include "task.h"
  14. /**
  15. * Type by which queues are referenced. For example, a call to xQueueCreate()
  16. * returns an QueueHandle_t variable that can then be used as a parameter to
  17. * xQueueSend(), xQueueReceive(), etc.
  18. */
  19. struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
  20. typedef struct QueueDefinition *QueueHandle_t;
  21. /**
  22. * Type by which queue sets are referenced. For example, a call to
  23. * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
  24. * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
  25. */
  26. typedef struct QueueDefinition *QueueSetHandle_t;
  27. /**
  28. * Queue sets can contain both queues and semaphores, so the
  29. * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
  30. * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
  31. */
  32. typedef struct QueueDefinition *QueueSetMemberHandle_t;
  33. /* For internal use only. */
  34. #define queueSEND_TO_BACK ((BaseType_t)0)
  35. #define queueSEND_TO_FRONT ((BaseType_t)1)
  36. #define queueOVERWRITE ((BaseType_t)2)
  37. /**
  38. * For internal use only. These definitions *must* match those in queue.c.
  39. * 队列的类型
  40. */
  41. #define queueQUEUE_TYPE_BASE ((uint8_t) 0U) /* 基本队列 */
  42. #define queueQUEUE_TYPE_SET ((uint8_t) 0U) /* 队列集合 */
  43. #define queueQUEUE_TYPE_MUTEX ((uint8_t) 1U) /* 互斥锁 */
  44. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ((uint8_t) 2U) /* 计数型信号量 */
  45. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ((uint8_t) 3U) /* 二值信号量 */
  46. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ((uint8_t) 4U)
  47. /**
  48. * 动态创建队列
  49. * @uxQueueLength: 队列中存放消息个数
  50. * @uxItemSize: 队列消息的长度
  51. */
  52. #define xQueueCreate(uxQueueLength, uxItemSize) xQueueGenericCreate((uxQueueLength), (uxItemSize), (queueQUEUE_TYPE_BASE))
  53. /*
  54. * 向队列的头部发送消息
  55. * @pvItemToQueue: 消息
  56. * @xTicksToWait: 等待发送超时tick
  57. */
  58. #define xQueueSendToFront(xQueue, pvItemToQueue, xTicksToWait) \
  59. xQueueGenericSend((xQueue), (pvItemToQueue), (xTicksToWait), queueSEND_TO_FRONT)
  60. /*
  61. * 向队列的尾部发送消息
  62. * @pvItemToQueue: 消息
  63. * @xTicksToWait: 等待发送超时tick
  64. */
  65. #define xQueueSendToBack(xQueue, pvItemToQueue, xTicksToWait) \
  66. xQueueGenericSend((xQueue), (pvItemToQueue), (xTicksToWait), queueSEND_TO_BACK)
  67. /**
  68. *
  69. * 向队列发送消息
  70. * @pvItemToQueue: 消息
  71. * @xTicksToWait: 等待发送超时tick
  72. */
  73. #define xQueueSend(xQueue, pvItemToQueue, xTicksToWait) \
  74. xQueueGenericSend((xQueue), (pvItemToQueue), (xTicksToWait), queueSEND_TO_BACK)
  75. /**
  76. *
  77. * 向队列发送消息,覆盖消息的方式
  78. * @pvItemToQueue: 消息
  79. * @xTicksToWait: 等待发送超时tick
  80. */
  81. #define xQueueOverwrite(xQueue, pvItemToQueue) \
  82. xQueueGenericSend((xQueue), (pvItemToQueue), 0, queueOVERWRITE)
  83. /**
  84. * 向队列发送消息
  85. * @pvItemToQueue: 消息
  86. * @xTicksToWait: 等待发送超时tick
  87. * @xCopyPosition: 消息添加到队列的方式
  88. * queueSEND_TO_FRONT: 添加到队列头
  89. * queueSEND_TO_BACK: 添加到队列的尾部
  90. * queueOVERWRITE: 覆盖消息
  91. */
  92. BaseType_t xQueueGenericSend(QueueHandle_t xQueue,
  93. const void * const pvItemToQueue,
  94. TickType_t xTicksToWait,
  95. const BaseType_t xCopyPosition) PRIVILEGED_FUNCTION;
  96. /**
  97. * Receive an item from a queue without removing the item from the queue.
  98. * The item is received by copy so a buffer of adequate size must be
  99. * provided. The number of bytes copied into the buffer was defined when
  100. * the queue was created.
  101. *
  102. * Successfully received items remain on the queue so will be returned again
  103. * by the next call, or a call to xQueueReceive().
  104. *
  105. * This macro must not be used in an interrupt service routine. See
  106. * xQueuePeekFromISR() for an alternative that can be called from an interrupt
  107. * service routine.
  108. *
  109. * @param xQueue The handle to the queue from which the item is to be
  110. * received.
  111. *
  112. * @param pvBuffer Pointer to the buffer into which the received item will
  113. * be copied.
  114. *
  115. * @param xTicksToWait The maximum amount of time the task should block
  116. * waiting for an item to receive should the queue be empty at the time
  117. * of the call. The time is defined in tick periods so the constant
  118. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  119. * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
  120. * is empty.
  121. *
  122. * @return pdTRUE if an item was successfully received from the queue,
  123. * otherwise pdFALSE.
  124. *
  125. */
  126. BaseType_t xQueuePeek(QueueHandle_t xQueue,
  127. void * const pvBuffer,
  128. TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  129. /**
  130. * Receive an item from a queue without removing the item from the queue.
  131. * The item is received by copy so a buffer of adequate size must be
  132. * provided. The number of bytes copied into the buffer was defined when
  133. * the queue was created.
  134. *
  135. * Successfully received items remain on the queue so will be returned again
  136. * by the next call, or a call to xQueueReceive().
  137. *
  138. * @param xQueue The handle to the queue from which the item is to be
  139. * received.
  140. *
  141. * @param pvBuffer Pointer to the buffer into which the received item will
  142. * be copied.
  143. *
  144. * @return pdTRUE if an item was successfully received from the queue,
  145. * otherwise pdFALSE.
  146. *
  147. * \defgroup xQueuePeekFromISR xQueuePeekFromISR
  148. * \ingroup QueueManagement
  149. */
  150. BaseType_t xQueuePeekFromISR(QueueHandle_t xQueue,
  151. void * const pvBuffer) PRIVILEGED_FUNCTION;
  152. /**
  153. * Receive an item from a queue. The item is received by copy so a buffer of
  154. * adequate size must be provided. The number of bytes copied into the buffer
  155. * was defined when the queue was created.
  156. *
  157. * Successfully received items are removed from the queue.
  158. *
  159. * This function must not be used in an interrupt service routine. See
  160. * xQueueReceiveFromISR for an alternative that can.
  161. *
  162. * @param xQueue The handle to the queue from which the item is to be
  163. * received.
  164. *
  165. * @param pvBuffer Pointer to the buffer into which the received item will
  166. * be copied.
  167. *
  168. * @param xTicksToWait The maximum amount of time the task should block
  169. * waiting for an item to receive should the queue be empty at the time
  170. * of the call. xQueueReceive() will return immediately if xTicksToWait
  171. * is zero and the queue is empty. The time is defined in tick periods so the
  172. * constant portTICK_PERIOD_MS should be used to convert to real time if this is
  173. * required.
  174. *
  175. * @return pdTRUE if an item was successfully received from the queue,
  176. * otherwise pdFALSE.
  177. *
  178. */
  179. BaseType_t xQueueReceive(QueueHandle_t xQueue,
  180. void * const pvBuffer,
  181. TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  182. /**
  183. *
  184. * Return the number of messages stored in a queue.
  185. *
  186. * @param xQueue A handle to the queue being queried.
  187. *
  188. * @return The number of messages available in the queue.
  189. *
  190. * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  191. * \ingroup QueueManagement
  192. */
  193. UBaseType_t uxQueueMessagesWaiting(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  194. /**
  195. *
  196. * Return the number of free spaces available in a queue. This is equal to the
  197. * number of items that can be sent to the queue before the queue becomes full
  198. * if no items are removed.
  199. *
  200. * @param xQueue A handle to the queue being queried.
  201. *
  202. * @return The number of spaces available in the queue.
  203. *
  204. * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  205. * \ingroup QueueManagement
  206. */
  207. UBaseType_t uxQueueSpacesAvailable(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  208. /**
  209. * Delete a queue - freeing all the memory allocated for storing of items
  210. * placed on the queue.
  211. *
  212. * @param xQueue A handle to the queue to be deleted.
  213. *
  214. * \defgroup vQueueDelete vQueueDelete
  215. * \ingroup QueueManagement
  216. */
  217. void vQueueDelete(QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  218. /**
  219. * This is a macro that calls xQueueGenericSendFromISR().
  220. *
  221. * Post an item to the front of a queue. It is safe to use this macro from
  222. * within an interrupt service routine.
  223. *
  224. * Items are queued by copy not reference so it is preferable to only
  225. * queue small items, especially when called from an ISR. In most cases
  226. * it would be preferable to store a pointer to the item being queued.
  227. *
  228. * @param xQueue The handle to the queue on which the item is to be posted.
  229. *
  230. * @param pvItemToQueue A pointer to the item that is to be placed on the
  231. * queue. The size of the items the queue will hold was defined when the
  232. * queue was created, so this many bytes will be copied from pvItemToQueue
  233. * into the queue storage area.
  234. *
  235. * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
  236. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  237. * to unblock, and the unblocked task has a priority higher than the currently
  238. * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
  239. * a context switch should be requested before the interrupt is exited.
  240. *
  241. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  242. * errQUEUE_FULL.
  243. *
  244. */
  245. #define xQueueSendToFrontFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken) \
  246. xQueueGenericSendFromISR((xQueue), (pvItemToQueue), (pxHigherPriorityTaskWoken), queueSEND_TO_FRONT )
  247. /**
  248. * This is a macro that calls xQueueGenericSendFromISR().
  249. *
  250. * Post an item to the back of a queue. It is safe to use this macro from
  251. * within an interrupt service routine.
  252. *
  253. * Items are queued by copy not reference so it is preferable to only
  254. * queue small items, especially when called from an ISR. In most cases
  255. * it would be preferable to store a pointer to the item being queued.
  256. *
  257. * @param xQueue The handle to the queue on which the item is to be posted.
  258. *
  259. * @param pvItemToQueue A pointer to the item that is to be placed on the
  260. * queue. The size of the items the queue will hold was defined when the
  261. * queue was created, so this many bytes will be copied from pvItemToQueue
  262. * into the queue storage area.
  263. *
  264. * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
  265. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  266. * to unblock, and the unblocked task has a priority higher than the currently
  267. * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
  268. * a context switch should be requested before the interrupt is exited.
  269. *
  270. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  271. * errQUEUE_FULL.
  272. *
  273. */
  274. #define xQueueSendToBackFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken) \
  275. xQueueGenericSendFromISR((xQueue), (pvItemToQueue), (pxHigherPriorityTaskWoken), queueSEND_TO_BACK)
  276. /**
  277. * A version of xQueueOverwrite() that can be used in an interrupt service
  278. * routine (ISR).
  279. *
  280. * Only for use with queues that can hold a single item - so the queue is either
  281. * empty or full.
  282. *
  283. * Post an item on a queue. If the queue is already full then overwrite the
  284. * value held in the queue. The item is queued by copy, not by reference.
  285. *
  286. * @param xQueue The handle to the queue on which the item is to be posted.
  287. *
  288. * @param pvItemToQueue A pointer to the item that is to be placed on the
  289. * queue. The size of the items the queue will hold was defined when the
  290. * queue was created, so this many bytes will be copied from pvItemToQueue
  291. * into the queue storage area.
  292. *
  293. * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
  294. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  295. * to unblock, and the unblocked task has a priority higher than the currently
  296. * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
  297. * a context switch should be requested before the interrupt is exited.
  298. *
  299. * @return xQueueOverwriteFromISR() is a macro that calls
  300. * xQueueGenericSendFromISR(), and therefore has the same return values as
  301. * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
  302. * returned because xQueueOverwriteFromISR() will write to the queue even when
  303. * the queue is already full.
  304. *
  305. */
  306. #define xQueueOverwriteFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken) \
  307. xQueueGenericSendFromISR((xQueue), (pvItemToQueue), (pxHigherPriorityTaskWoken), queueOVERWRITE)
  308. /**
  309. * This is a macro that calls xQueueGenericSendFromISR(). It is included
  310. * for backward compatibility with versions of FreeRTOS.org that did not
  311. * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
  312. * macros.
  313. *
  314. * Post an item to the back of a queue. It is safe to use this function from
  315. * within an interrupt service routine.
  316. *
  317. * Items are queued by copy not reference so it is preferable to only
  318. * queue small items, especially when called from an ISR. In most cases
  319. * it would be preferable to store a pointer to the item being queued.
  320. *
  321. * @param xQueue The handle to the queue on which the item is to be posted.
  322. *
  323. * @param pvItemToQueue A pointer to the item that is to be placed on the
  324. * queue. The size of the items the queue will hold was defined when the
  325. * queue was created, so this many bytes will be copied from pvItemToQueue
  326. * into the queue storage area.
  327. *
  328. * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
  329. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  330. * to unblock, and the unblocked task has a priority higher than the currently
  331. * running task. If xQueueSendFromISR() sets this value to pdTRUE then
  332. * a context switch should be requested before the interrupt is exited.
  333. *
  334. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  335. * errQUEUE_FULL.
  336. *
  337. */
  338. #define xQueueSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken) \
  339. xQueueGenericSendFromISR((xQueue), (pvItemToQueue), (pxHigherPriorityTaskWoken), queueSEND_TO_BACK)
  340. /**
  341. * It is preferred that the macros xQueueSendFromISR(),
  342. * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
  343. * of calling this function directly. xQueueGiveFromISR() is an
  344. * equivalent for use by semaphores that don't actually copy any data.
  345. *
  346. * Post an item on a queue. It is safe to use this function from within an
  347. * interrupt service routine.
  348. *
  349. * Items are queued by copy not reference so it is preferable to only
  350. * queue small items, especially when called from an ISR. In most cases
  351. * it would be preferable to store a pointer to the item being queued.
  352. *
  353. * @param xQueue The handle to the queue on which the item is to be posted.
  354. *
  355. * @param pvItemToQueue A pointer to the item that is to be placed on the
  356. * queue. The size of the items the queue will hold was defined when the
  357. * queue was created, so this many bytes will be copied from pvItemToQueue
  358. * into the queue storage area.
  359. *
  360. * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
  361. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  362. * to unblock, and the unblocked task has a priority higher than the currently
  363. * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
  364. * a context switch should be requested before the interrupt is exited.
  365. *
  366. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  367. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  368. * at the front of the queue (for high priority messages).
  369. *
  370. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  371. * errQUEUE_FULL.
  372. *
  373. */
  374. BaseType_t xQueueGenericSendFromISR(QueueHandle_t xQueue,
  375. const void * const pvItemToQueue,
  376. BaseType_t * const pxHigherPriorityTaskWoken,
  377. const BaseType_t xCopyPosition) PRIVILEGED_FUNCTION;
  378. BaseType_t xQueueGiveFromISR(QueueHandle_t xQueue,
  379. BaseType_t * const pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION;
  380. /**
  381. * Receive an item from a queue. It is safe to use this function from within an
  382. * interrupt service routine.
  383. *
  384. * @param xQueue The handle to the queue from which the item is to be
  385. * received.
  386. *
  387. * @param pvBuffer Pointer to the buffer into which the received item will
  388. * be copied.
  389. *
  390. * @param pxTaskWoken A task may be blocked waiting for space to become
  391. * available on the queue. If xQueueReceiveFromISR causes such a task to
  392. * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  393. * remain unchanged.
  394. *
  395. * @return pdTRUE if an item was successfully received from the queue,
  396. * otherwise pdFALSE.
  397. *
  398. */
  399. BaseType_t xQueueReceiveFromISR(QueueHandle_t xQueue,
  400. void * const pvBuffer,
  401. BaseType_t * const pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION;
  402. /*
  403. * Utilities to query queues that are safe to use from an ISR. These utilities
  404. * should be used only from within an ISR, or within a critical section.
  405. */
  406. BaseType_t xQueueIsQueueEmptyFromISR(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  407. BaseType_t xQueueIsQueueFullFromISR(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  408. UBaseType_t uxQueueMessagesWaitingFromISR(const QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  409. /*
  410. * The functions defined above are for passing data to and from tasks. The
  411. * functions below are the equivalents for passing data to and from
  412. * co-routines.
  413. *
  414. * These functions are called from the co-routine macro implementation and
  415. * should not be called directly from application code. Instead use the macro
  416. * wrappers defined within croutine.h.
  417. */
  418. BaseType_t xQueueCRSendFromISR(QueueHandle_t xQueue,
  419. const void * pvItemToQueue,
  420. BaseType_t xCoRoutinePreviouslyWoken);
  421. BaseType_t xQueueCRReceiveFromISR(QueueHandle_t xQueue,
  422. void * pvBuffer,
  423. BaseType_t * pxTaskWoken);
  424. BaseType_t xQueueCRSend(QueueHandle_t xQueue,
  425. const void * pvItemToQueue,
  426. TickType_t xTicksToWait);
  427. BaseType_t xQueueCRReceive(QueueHandle_t xQueue,
  428. void * pvBuffer,
  429. TickType_t xTicksToWait);
  430. /*
  431. * For internal use only. Use xSemaphoreCreateMutex(),
  432. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  433. * these functions directly.
  434. */
  435. QueueHandle_t xQueueCreateMutex(const uint8_t ucQueueType) PRIVILEGED_FUNCTION;
  436. QueueHandle_t xQueueCreateMutexStatic(const uint8_t ucQueueType,
  437. StaticQueue_t * pxStaticQueue) PRIVILEGED_FUNCTION;
  438. QueueHandle_t xQueueCreateCountingSemaphore(const UBaseType_t uxMaxCount,
  439. const UBaseType_t uxInitialCount) PRIVILEGED_FUNCTION;
  440. QueueHandle_t xQueueCreateCountingSemaphoreStatic(const UBaseType_t uxMaxCount,
  441. const UBaseType_t uxInitialCount,
  442. StaticQueue_t * pxStaticQueue) PRIVILEGED_FUNCTION;
  443. BaseType_t xQueueSemaphoreTake(QueueHandle_t xQueue,
  444. TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  445. TaskHandle_t xQueueGetMutexHolder(QueueHandle_t xSemaphore) PRIVILEGED_FUNCTION;
  446. TaskHandle_t xQueueGetMutexHolderFromISR(QueueHandle_t xSemaphore) PRIVILEGED_FUNCTION;
  447. /*
  448. * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  449. * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  450. */
  451. BaseType_t xQueueTakeMutexRecursive(QueueHandle_t xMutex,
  452. TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  453. BaseType_t xQueueGiveMutexRecursive(QueueHandle_t xMutex) PRIVILEGED_FUNCTION;
  454. /*
  455. * Reset a queue back to its original empty state. The return value is now
  456. * obsolete and is always set to pdPASS.
  457. */
  458. #define xQueueReset(xQueue) xQueueGenericReset((xQueue), pdFALSE)
  459. /*
  460. * The registry is provided as a means for kernel aware debuggers to
  461. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  462. * a queue, semaphore or mutex handle to the registry if you want the handle
  463. * to be available to a kernel aware debugger. If you are not using a kernel
  464. * aware debugger then this function can be ignored.
  465. *
  466. * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
  467. * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
  468. * within FreeRTOSConfig.h for the registry to be available. Its value
  469. * does not affect the number of queues, semaphores and mutexes that can be
  470. * created - just the number that the registry can hold.
  471. *
  472. * If vQueueAddToRegistry is called more than once with the same xQueue
  473. * parameter, the registry will store the pcQueueName parameter from the
  474. * most recent call to vQueueAddToRegistry.
  475. *
  476. * @param xQueue The handle of the queue being added to the registry. This
  477. * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
  478. * handles can also be passed in here.
  479. *
  480. * @param pcQueueName The name to be associated with the handle. This is the
  481. * name that the kernel aware debugger will display. The queue registry only
  482. * stores a pointer to the string - so the string must be persistent (global or
  483. * preferably in ROM/Flash), not on the stack.
  484. */
  485. #if (configQUEUE_REGISTRY_SIZE > 0)
  486. void vQueueAddToRegistry(QueueHandle_t xQueue,
  487. const char * pcQueueName) PRIVILEGED_FUNCTION;
  488. #endif
  489. /*
  490. * The registry is provided as a means for kernel aware debuggers to
  491. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  492. * a queue, semaphore or mutex handle to the registry if you want the handle
  493. * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
  494. * remove the queue, semaphore or mutex from the register. If you are not using
  495. * a kernel aware debugger then this function can be ignored.
  496. *
  497. * @param xQueue The handle of the queue being removed from the registry.
  498. */
  499. #if (configQUEUE_REGISTRY_SIZE > 0 )
  500. void vQueueUnregisterQueue(QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  501. #endif
  502. /*
  503. * The queue registry is provided as a means for kernel aware debuggers to
  504. * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
  505. * up and return the name of a queue in the queue registry from the queue's
  506. * handle.
  507. *
  508. * @param xQueue The handle of the queue the name of which will be returned.
  509. * @return If the queue is in the registry then a pointer to the name of the
  510. * queue is returned. If the queue is not in the registry then NULL is
  511. * returned.
  512. */
  513. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  514. const char * pcQueueGetName(QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  515. #endif
  516. /*
  517. * Generic version of the function used to create a queue using dynamic memory
  518. * allocation. This is called by other functions and macros that create other
  519. * RTOS objects that use the queue structure as their base.
  520. */
  521. QueueHandle_t xQueueGenericCreate(const UBaseType_t uxQueueLength,
  522. const UBaseType_t uxItemSize,
  523. const uint8_t ucQueueType) PRIVILEGED_FUNCTION;
  524. /*
  525. * Queue sets provide a mechanism to allow a task to block (pend) on a read
  526. * operation from multiple queues or semaphores simultaneously.
  527. *
  528. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  529. * function.
  530. *
  531. * A queue set must be explicitly created using a call to xQueueCreateSet()
  532. * before it can be used. Once created, standard FreeRTOS queues and semaphores
  533. * can be added to the set using calls to xQueueAddToSet().
  534. * xQueueSelectFromSet() is then used to determine which, if any, of the queues
  535. * or semaphores contained in the set is in a state where a queue read or
  536. * semaphore take operation would be successful.
  537. *
  538. * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
  539. * for reasons why queue sets are very rarely needed in practice as there are
  540. * simpler methods of blocking on multiple objects.
  541. *
  542. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  543. * mutex holder to inherit the priority of the blocked task.
  544. *
  545. * Note 3: An additional 4 bytes of RAM is required for each space in a every
  546. * queue added to a queue set. Therefore counting semaphores that have a high
  547. * maximum count value should not be added to a queue set.
  548. *
  549. * Note 4: A receive (in the case of a queue) or take (in the case of a
  550. * semaphore) operation must not be performed on a member of a queue set unless
  551. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  552. *
  553. * @param uxEventQueueLength Queue sets store events that occur on
  554. * the queues and semaphores contained in the set. uxEventQueueLength specifies
  555. * the maximum number of events that can be queued at once. To be absolutely
  556. * certain that events are not lost uxEventQueueLength should be set to the
  557. * total sum of the length of the queues added to the set, where binary
  558. * semaphores and mutexes have a length of 1, and counting semaphores have a
  559. * length set by their maximum count value. Examples:
  560. * + If a queue set is to hold a queue of length 5, another queue of length 12,
  561. * and a binary semaphore, then uxEventQueueLength should be set to
  562. * (5 + 12 + 1), or 18.
  563. * + If a queue set is to hold three binary semaphores then uxEventQueueLength
  564. * should be set to (1 + 1 + 1 ), or 3.
  565. * + If a queue set is to hold a counting semaphore that has a maximum count of
  566. * 5, and a counting semaphore that has a maximum count of 3, then
  567. * uxEventQueueLength should be set to (5 + 3), or 8.
  568. *
  569. * @return If the queue set is created successfully then a handle to the created
  570. * queue set is returned. Otherwise NULL is returned.
  571. */
  572. QueueSetHandle_t xQueueCreateSet(const UBaseType_t uxEventQueueLength) PRIVILEGED_FUNCTION;
  573. /*
  574. * Adds a queue or semaphore to a queue set that was previously created by a
  575. * call to xQueueCreateSet().
  576. *
  577. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  578. * function.
  579. *
  580. * Note 1: A receive (in the case of a queue) or take (in the case of a
  581. * semaphore) operation must not be performed on a member of a queue set unless
  582. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  583. *
  584. * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
  585. * the queue set (cast to an QueueSetMemberHandle_t type).
  586. *
  587. * @param xQueueSet The handle of the queue set to which the queue or semaphore
  588. * is being added.
  589. *
  590. * @return If the queue or semaphore was successfully added to the queue set
  591. * then pdPASS is returned. If the queue could not be successfully added to the
  592. * queue set because it is already a member of a different queue set then pdFAIL
  593. * is returned.
  594. */
  595. BaseType_t xQueueAddToSet(QueueSetMemberHandle_t xQueueOrSemaphore,
  596. QueueSetHandle_t xQueueSet) PRIVILEGED_FUNCTION;
  597. /*
  598. * Removes a queue or semaphore from a queue set. A queue or semaphore can only
  599. * be removed from a set if the queue or semaphore is empty.
  600. *
  601. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  602. * function.
  603. *
  604. * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
  605. * from the queue set (cast to an QueueSetMemberHandle_t type).
  606. *
  607. * @param xQueueSet The handle of the queue set in which the queue or semaphore
  608. * is included.
  609. *
  610. * @return If the queue or semaphore was successfully removed from the queue set
  611. * then pdPASS is returned. If the queue was not in the queue set, or the
  612. * queue (or semaphore) was not empty, then pdFAIL is returned.
  613. */
  614. BaseType_t xQueueRemoveFromSet(QueueSetMemberHandle_t xQueueOrSemaphore,
  615. QueueSetHandle_t xQueueSet) PRIVILEGED_FUNCTION;
  616. /*
  617. * xQueueSelectFromSet() selects from the members of a queue set a queue or
  618. * semaphore that either contains data (in the case of a queue) or is available
  619. * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
  620. * allows a task to block (pend) on a read operation on all the queues and
  621. * semaphores in a queue set simultaneously.
  622. *
  623. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  624. * function.
  625. *
  626. * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
  627. * for reasons why queue sets are very rarely needed in practice as there are
  628. * simpler methods of blocking on multiple objects.
  629. *
  630. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  631. * mutex holder to inherit the priority of the blocked task.
  632. *
  633. * Note 3: A receive (in the case of a queue) or take (in the case of a
  634. * semaphore) operation must not be performed on a member of a queue set unless
  635. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  636. *
  637. * @param xQueueSet The queue set on which the task will (potentially) block.
  638. *
  639. * @param xTicksToWait The maximum time, in ticks, that the calling task will
  640. * remain in the Blocked state (with other tasks executing) to wait for a member
  641. * of the queue set to be ready for a successful queue read or semaphore take
  642. * operation.
  643. *
  644. * @return xQueueSelectFromSet() will return the handle of a queue (cast to
  645. * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
  646. * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
  647. * in the queue set that is available, or NULL if no such queue or semaphore
  648. * exists before before the specified block time expires.
  649. */
  650. QueueSetMemberHandle_t xQueueSelectFromSet(QueueSetHandle_t xQueueSet,
  651. const TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
  652. /*
  653. * A version of xQueueSelectFromSet() that can be used from an ISR.
  654. */
  655. QueueSetMemberHandle_t xQueueSelectFromSetFromISR(QueueSetHandle_t xQueueSet) PRIVILEGED_FUNCTION;
  656. /* Not public API functions. */
  657. void vQueueWaitForMessageRestricted(QueueHandle_t xQueue,
  658. TickType_t xTicksToWait,
  659. const BaseType_t xWaitIndefinitely) PRIVILEGED_FUNCTION;
  660. BaseType_t xQueueGenericReset(QueueHandle_t xQueue,
  661. BaseType_t xNewQueue) PRIVILEGED_FUNCTION;
  662. void vQueueSetQueueNumber(QueueHandle_t xQueue,
  663. UBaseType_t uxQueueNumber) PRIVILEGED_FUNCTION;
  664. UBaseType_t uxQueueGetQueueNumber(QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  665. uint8_t ucQueueGetQueueType(QueueHandle_t xQueue) PRIVILEGED_FUNCTION;
  666. #endif /* QUEUE_H */