queue.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef QUEUE_H
  29. #define QUEUE_H
  30. /* *INDENT-OFF* */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* *INDENT-ON* */
  35. /**
  36. * Type by which queues are referenced. For example, a call to xQueueCreate()
  37. * returns an QueueHandle_t variable that can then be used as a parameter to
  38. * xQueueSend(), xQueueReceive(), etc.
  39. */
  40. struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
  41. typedef struct QueueDefinition * QueueHandle_t;
  42. /* For internal use only. */
  43. #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
  44. #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
  45. #define queueOVERWRITE ( ( BaseType_t ) 2 )
  46. /* For internal use only. These definitions *must* match those in queue.c. */
  47. #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
  48. #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
  49. #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
  50. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
  51. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
  52. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
  53. /**
  54. * queue. h
  55. * @code{c}
  56. * QueueHandle_t xQueueCreate(
  57. * UBaseType_t uxQueueLength,
  58. * UBaseType_t uxItemSize
  59. * );
  60. * @endcode
  61. *
  62. * Creates a new queue instance, and returns a handle by which the new queue
  63. * can be referenced.
  64. *
  65. * Internally, within the FreeRTOS implementation, queues use two blocks of
  66. * memory. The first block is used to hold the queue's data structures. The
  67. * second block is used to hold items placed into the queue. If a queue is
  68. * created using xQueueCreate() then both blocks of memory are automatically
  69. * dynamically allocated inside the xQueueCreate() function. (see
  70. * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  71. * xQueueCreateStatic() then the application writer must provide the memory that
  72. * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  73. * be created without using any dynamic memory allocation.
  74. *
  75. * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  76. *
  77. * @param uxQueueLength The maximum number of items that the queue can contain.
  78. *
  79. * @param uxItemSize The number of bytes each item in the queue will require.
  80. * Items are queued by copy, not by reference, so this is the number of bytes
  81. * that will be copied for each posted item. Each item on the queue must be
  82. * the same size.
  83. *
  84. * @return If the queue is successfully create then a handle to the newly
  85. * created queue is returned. If the queue cannot be created then 0 is
  86. * returned.
  87. *
  88. * Example usage:
  89. * @code{c}
  90. * struct AMessage
  91. * {
  92. * char ucMessageID;
  93. * char ucData[ 20 ];
  94. * };
  95. *
  96. * void vATask( void *pvParameters )
  97. * {
  98. * QueueHandle_t xQueue1, xQueue2;
  99. *
  100. * // Create a queue capable of containing 10 uint32_t values.
  101. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  102. * if( xQueue1 == 0 )
  103. * {
  104. * // Queue was not created and must not be used.
  105. * }
  106. *
  107. * // Create a queue capable of containing 10 pointers to AMessage structures.
  108. * // These should be passed by pointer as they contain a lot of data.
  109. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  110. * if( xQueue2 == 0 )
  111. * {
  112. * // Queue was not created and must not be used.
  113. * }
  114. *
  115. * // ... Rest of task code.
  116. * }
  117. * @endcode
  118. * \defgroup xQueueCreate xQueueCreate
  119. * \ingroup QueueManagement
  120. */
  121. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  122. #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
  123. #endif
  124. /**
  125. * queue. h
  126. * @code{c}
  127. * QueueHandle_t xQueueCreateStatic(
  128. * UBaseType_t uxQueueLength,
  129. * UBaseType_t uxItemSize,
  130. * uint8_t *pucQueueStorage,
  131. * StaticQueue_t *pxQueueBuffer
  132. * );
  133. * @endcode
  134. *
  135. * Creates a new queue instance, and returns a handle by which the new queue
  136. * can be referenced.
  137. *
  138. * Internally, within the FreeRTOS implementation, queues use two blocks of
  139. * memory. The first block is used to hold the queue's data structures. The
  140. * second block is used to hold items placed into the queue. If a queue is
  141. * created using xQueueCreate() then both blocks of memory are automatically
  142. * dynamically allocated inside the xQueueCreate() function. (see
  143. * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  144. * xQueueCreateStatic() then the application writer must provide the memory that
  145. * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  146. * be created without using any dynamic memory allocation.
  147. *
  148. * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  149. *
  150. * @param uxQueueLength The maximum number of items that the queue can contain.
  151. *
  152. * @param uxItemSize The number of bytes each item in the queue will require.
  153. * Items are queued by copy, not by reference, so this is the number of bytes
  154. * that will be copied for each posted item. Each item on the queue must be
  155. * the same size.
  156. *
  157. * @param pucQueueStorage If uxItemSize is not zero then
  158. * pucQueueStorage must point to a uint8_t array that is at least large
  159. * enough to hold the maximum number of items that can be in the queue at any
  160. * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
  161. * zero then pucQueueStorage can be NULL.
  162. *
  163. * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
  164. * will be used to hold the queue's data structure.
  165. *
  166. * @return If the queue is created then a handle to the created queue is
  167. * returned. If pxQueueBuffer is NULL then NULL is returned.
  168. *
  169. * Example usage:
  170. * @code{c}
  171. * struct AMessage
  172. * {
  173. * char ucMessageID;
  174. * char ucData[ 20 ];
  175. * };
  176. *
  177. #define QUEUE_LENGTH 10
  178. #define ITEM_SIZE sizeof( uint32_t )
  179. *
  180. * // xQueueBuffer will hold the queue structure.
  181. * StaticQueue_t xQueueBuffer;
  182. *
  183. * // ucQueueStorage will hold the items posted to the queue. Must be at least
  184. * // [(queue length) * ( queue item size)] bytes long.
  185. * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
  186. *
  187. * void vATask( void *pvParameters )
  188. * {
  189. * QueueHandle_t xQueue1;
  190. *
  191. * // Create a queue capable of containing 10 uint32_t values.
  192. * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
  193. * ITEM_SIZE // The size of each item in the queue
  194. * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
  195. * &xQueueBuffer ); // The buffer that will hold the queue structure.
  196. *
  197. * // The queue is guaranteed to be created successfully as no dynamic memory
  198. * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
  199. *
  200. * // ... Rest of task code.
  201. * }
  202. * @endcode
  203. * \defgroup xQueueCreateStatic xQueueCreateStatic
  204. * \ingroup QueueManagement
  205. */
  206. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  207. #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
  208. #endif /* configSUPPORT_STATIC_ALLOCATION */
  209. /**
  210. * queue. h
  211. * @code{c}
  212. * BaseType_t xQueueSendToToFront(
  213. * QueueHandle_t xQueue,
  214. * const void *pvItemToQueue,
  215. * TickType_t xTicksToWait
  216. * );
  217. * @endcode
  218. *
  219. * Post an item to the front of a queue. The item is queued by copy, not by
  220. * reference. This function must not be called from an interrupt service
  221. * routine. See xQueueSendFromISR () for an alternative which may be used
  222. * in an ISR.
  223. *
  224. * @param xQueue The handle to the queue on which the item is to be posted.
  225. *
  226. * @param pvItemToQueue A pointer to the item that is to be placed on the
  227. * queue. The size of the items the queue will hold was defined when the
  228. * queue was created, so this many bytes will be copied from pvItemToQueue
  229. * into the queue storage area.
  230. *
  231. * @param xTicksToWait The maximum amount of time the task should block
  232. * waiting for space to become available on the queue, should it already
  233. * be full. The call will return immediately if this is set to 0 and the
  234. * queue is full. The time is defined in tick periods so the constant
  235. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  236. *
  237. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  238. *
  239. * Example usage:
  240. * @code{c}
  241. * struct AMessage
  242. * {
  243. * char ucMessageID;
  244. * char ucData[ 20 ];
  245. * } xMessage;
  246. *
  247. * uint32_t ulVar = 10UL;
  248. *
  249. * void vATask( void *pvParameters )
  250. * {
  251. * QueueHandle_t xQueue1, xQueue2;
  252. * struct AMessage *pxMessage;
  253. *
  254. * // Create a queue capable of containing 10 uint32_t values.
  255. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  256. *
  257. * // Create a queue capable of containing 10 pointers to AMessage structures.
  258. * // These should be passed by pointer as they contain a lot of data.
  259. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  260. *
  261. * // ...
  262. *
  263. * if( xQueue1 != 0 )
  264. * {
  265. * // Send an uint32_t. Wait for 10 ticks for space to become
  266. * // available if necessary.
  267. * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  268. * {
  269. * // Failed to post the message, even after 10 ticks.
  270. * }
  271. * }
  272. *
  273. * if( xQueue2 != 0 )
  274. * {
  275. * // Send a pointer to a struct AMessage object. Don't block if the
  276. * // queue is already full.
  277. * pxMessage = & xMessage;
  278. * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  279. * }
  280. *
  281. * // ... Rest of task code.
  282. * }
  283. * @endcode
  284. * \defgroup xQueueSend xQueueSend
  285. * \ingroup QueueManagement
  286. */
  287. #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
  288. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
  289. /**
  290. * queue. h
  291. * @code{c}
  292. * BaseType_t xQueueSendToBack(
  293. * QueueHandle_t xQueue,
  294. * const void *pvItemToQueue,
  295. * TickType_t xTicksToWait
  296. * );
  297. * @endcode
  298. *
  299. * This is a macro that calls xQueueGenericSend().
  300. *
  301. * Post an item to the back of a queue. The item is queued by copy, not by
  302. * reference. This function must not be called from an interrupt service
  303. * routine. See xQueueSendFromISR () for an alternative which may be used
  304. * in an ISR.
  305. *
  306. * @param xQueue The handle to the queue on which the item is to be posted.
  307. *
  308. * @param pvItemToQueue A pointer to the item that is to be placed on the
  309. * queue. The size of the items the queue will hold was defined when the
  310. * queue was created, so this many bytes will be copied from pvItemToQueue
  311. * into the queue storage area.
  312. *
  313. * @param xTicksToWait The maximum amount of time the task should block
  314. * waiting for space to become available on the queue, should it already
  315. * be full. The call will return immediately if this is set to 0 and the queue
  316. * is full. The time is defined in tick periods so the constant
  317. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  318. *
  319. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  320. *
  321. * Example usage:
  322. * @code{c}
  323. * struct AMessage
  324. * {
  325. * char ucMessageID;
  326. * char ucData[ 20 ];
  327. * } xMessage;
  328. *
  329. * uint32_t ulVar = 10UL;
  330. *
  331. * void vATask( void *pvParameters )
  332. * {
  333. * QueueHandle_t xQueue1, xQueue2;
  334. * struct AMessage *pxMessage;
  335. *
  336. * // Create a queue capable of containing 10 uint32_t values.
  337. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  338. *
  339. * // Create a queue capable of containing 10 pointers to AMessage structures.
  340. * // These should be passed by pointer as they contain a lot of data.
  341. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  342. *
  343. * // ...
  344. *
  345. * if( xQueue1 != 0 )
  346. * {
  347. * // Send an uint32_t. Wait for 10 ticks for space to become
  348. * // available if necessary.
  349. * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  350. * {
  351. * // Failed to post the message, even after 10 ticks.
  352. * }
  353. * }
  354. *
  355. * if( xQueue2 != 0 )
  356. * {
  357. * // Send a pointer to a struct AMessage object. Don't block if the
  358. * // queue is already full.
  359. * pxMessage = & xMessage;
  360. * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  361. * }
  362. *
  363. * // ... Rest of task code.
  364. * }
  365. * @endcode
  366. * \defgroup xQueueSend xQueueSend
  367. * \ingroup QueueManagement
  368. */
  369. #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
  370. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  371. /**
  372. * queue. h
  373. * @code{c}
  374. * BaseType_t xQueueSend(
  375. * QueueHandle_t xQueue,
  376. * const void * pvItemToQueue,
  377. * TickType_t xTicksToWait
  378. * );
  379. * @endcode
  380. *
  381. * This is a macro that calls xQueueGenericSend(). It is included for
  382. * backward compatibility with versions of FreeRTOS.org that did not
  383. * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
  384. * equivalent to xQueueSendToBack().
  385. *
  386. * Post an item on a queue. The item is queued by copy, not by reference.
  387. * This function must not be called from an interrupt service routine.
  388. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  389. *
  390. * @param xQueue The handle to the queue on which the item is to be posted.
  391. *
  392. * @param pvItemToQueue A pointer to the item that is to be placed on the
  393. * queue. The size of the items the queue will hold was defined when the
  394. * queue was created, so this many bytes will be copied from pvItemToQueue
  395. * into the queue storage area.
  396. *
  397. * @param xTicksToWait The maximum amount of time the task should block
  398. * waiting for space to become available on the queue, should it already
  399. * be full. The call will return immediately if this is set to 0 and the
  400. * queue is full. The time is defined in tick periods so the constant
  401. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  402. *
  403. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  404. *
  405. * Example usage:
  406. * @code{c}
  407. * struct AMessage
  408. * {
  409. * char ucMessageID;
  410. * char ucData[ 20 ];
  411. * } xMessage;
  412. *
  413. * uint32_t ulVar = 10UL;
  414. *
  415. * void vATask( void *pvParameters )
  416. * {
  417. * QueueHandle_t xQueue1, xQueue2;
  418. * struct AMessage *pxMessage;
  419. *
  420. * // Create a queue capable of containing 10 uint32_t values.
  421. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  422. *
  423. * // Create a queue capable of containing 10 pointers to AMessage structures.
  424. * // These should be passed by pointer as they contain a lot of data.
  425. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  426. *
  427. * // ...
  428. *
  429. * if( xQueue1 != 0 )
  430. * {
  431. * // Send an uint32_t. Wait for 10 ticks for space to become
  432. * // available if necessary.
  433. * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  434. * {
  435. * // Failed to post the message, even after 10 ticks.
  436. * }
  437. * }
  438. *
  439. * if( xQueue2 != 0 )
  440. * {
  441. * // Send a pointer to a struct AMessage object. Don't block if the
  442. * // queue is already full.
  443. * pxMessage = & xMessage;
  444. * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  445. * }
  446. *
  447. * // ... Rest of task code.
  448. * }
  449. * @endcode
  450. * \defgroup xQueueSend xQueueSend
  451. * \ingroup QueueManagement
  452. */
  453. #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
  454. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  455. /**
  456. * queue. h
  457. * @code{c}
  458. * BaseType_t xQueueGenericSend(
  459. * QueueHandle_t xQueue,
  460. * const void * pvItemToQueue,
  461. * TickType_t xTicksToWait
  462. * BaseType_t xCopyPosition
  463. * );
  464. * @endcode
  465. *
  466. * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
  467. * xQueueSendToBack() are used in place of calling this function directly.
  468. *
  469. * Post an item on a queue. The item is queued by copy, not by reference.
  470. * This function must not be called from an interrupt service routine.
  471. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  472. *
  473. * @param xQueue The handle to the queue on which the item is to be posted.
  474. *
  475. * @param pvItemToQueue A pointer to the item that is to be placed on the
  476. * queue. The size of the items the queue will hold was defined when the
  477. * queue was created, so this many bytes will be copied from pvItemToQueue
  478. * into the queue storage area.
  479. *
  480. * @param xTicksToWait The maximum amount of time the task should block
  481. * waiting for space to become available on the queue, should it already
  482. * be full. The call will return immediately if this is set to 0 and the
  483. * queue is full. The time is defined in tick periods so the constant
  484. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  485. *
  486. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  487. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  488. * at the front of the queue (for high priority messages).
  489. *
  490. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  491. *
  492. * Example usage:
  493. * @code{c}
  494. * struct AMessage
  495. * {
  496. * char ucMessageID;
  497. * char ucData[ 20 ];
  498. * } xMessage;
  499. *
  500. * uint32_t ulVar = 10UL;
  501. *
  502. * void vATask( void *pvParameters )
  503. * {
  504. * QueueHandle_t xQueue1, xQueue2;
  505. * struct AMessage *pxMessage;
  506. *
  507. * // Create a queue capable of containing 10 uint32_t values.
  508. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  509. *
  510. * // Create a queue capable of containing 10 pointers to AMessage structures.
  511. * // These should be passed by pointer as they contain a lot of data.
  512. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  513. *
  514. * // ...
  515. *
  516. * if( xQueue1 != 0 )
  517. * {
  518. * // Send an uint32_t. Wait for 10 ticks for space to become
  519. * // available if necessary.
  520. * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
  521. * {
  522. * // Failed to post the message, even after 10 ticks.
  523. * }
  524. * }
  525. *
  526. * if( xQueue2 != 0 )
  527. * {
  528. * // Send a pointer to a struct AMessage object. Don't block if the
  529. * // queue is already full.
  530. * pxMessage = & xMessage;
  531. * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
  532. * }
  533. *
  534. * // ... Rest of task code.
  535. * }
  536. * @endcode
  537. * \defgroup xQueueSend xQueueSend
  538. * \ingroup QueueManagement
  539. */
  540. BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
  541. const void * const pvItemToQueue,
  542. TickType_t xTicksToWait,
  543. const BaseType_t xCopyPosition );
  544. /**
  545. * queue. h
  546. * @code{c}
  547. * BaseType_t xQueueReceive(
  548. * QueueHandle_t xQueue,
  549. * void *pvBuffer,
  550. * TickType_t xTicksToWait
  551. * );
  552. * @endcode
  553. *
  554. * Receive an item from a queue. The item is received by copy so a buffer of
  555. * adequate size must be provided. The number of bytes copied into the buffer
  556. * was defined when the queue was created.
  557. *
  558. * Successfully received items are removed from the queue.
  559. *
  560. * This function must not be used in an interrupt service routine. See
  561. * xQueueReceiveFromISR for an alternative that can.
  562. *
  563. * @param xQueue The handle to the queue from which the item is to be
  564. * received.
  565. *
  566. * @param pvBuffer Pointer to the buffer into which the received item will
  567. * be copied.
  568. *
  569. * @param xTicksToWait The maximum amount of time the task should block
  570. * waiting for an item to receive should the queue be empty at the time
  571. * of the call. xQueueReceive() will return immediately if xTicksToWait
  572. * is zero and the queue is empty. The time is defined in tick periods so the
  573. * constant portTICK_PERIOD_MS should be used to convert to real time if this is
  574. * required.
  575. *
  576. * @return pdTRUE if an item was successfully received from the queue,
  577. * otherwise pdFALSE.
  578. *
  579. * Example usage:
  580. * @code{c}
  581. * struct AMessage
  582. * {
  583. * char ucMessageID;
  584. * char ucData[ 20 ];
  585. * } xMessage;
  586. *
  587. * QueueHandle_t xQueue;
  588. *
  589. * // Task to create a queue and post a value.
  590. * void vATask( void *pvParameters )
  591. * {
  592. * struct AMessage *pxMessage;
  593. *
  594. * // Create a queue capable of containing 10 pointers to AMessage structures.
  595. * // These should be passed by pointer as they contain a lot of data.
  596. * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  597. * if( xQueue == 0 )
  598. * {
  599. * // Failed to create the queue.
  600. * }
  601. *
  602. * // ...
  603. *
  604. * // Send a pointer to a struct AMessage object. Don't block if the
  605. * // queue is already full.
  606. * pxMessage = & xMessage;
  607. * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
  608. *
  609. * // ... Rest of task code.
  610. * }
  611. *
  612. * // Task to receive from the queue.
  613. * void vADifferentTask( void *pvParameters )
  614. * {
  615. * struct AMessage *pxRxedMessage;
  616. *
  617. * if( xQueue != 0 )
  618. * {
  619. * // Receive a message on the created queue. Block for 10 ticks if a
  620. * // message is not immediately available.
  621. * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
  622. * {
  623. * // pcRxedMessage now points to the struct AMessage variable posted
  624. * // by vATask.
  625. * }
  626. * }
  627. *
  628. * // ... Rest of task code.
  629. * }
  630. * @endcode
  631. * \defgroup xQueueReceive xQueueReceive
  632. * \ingroup QueueManagement
  633. */
  634. BaseType_t xQueueReceive( QueueHandle_t xQueue,
  635. void * const pvBuffer,
  636. TickType_t xTicksToWait );
  637. /**
  638. * queue. h
  639. * @code{c}
  640. * void vQueueDelete( QueueHandle_t xQueue );
  641. * @endcode
  642. *
  643. * Delete a queue - freeing all the memory allocated for storing of items
  644. * placed on the queue.
  645. *
  646. * @param xQueue A handle to the queue to be deleted.
  647. *
  648. * \defgroup vQueueDelete vQueueDelete
  649. * \ingroup QueueManagement
  650. */
  651. void vQueueDelete( QueueHandle_t xQueue );
  652. BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
  653. BaseType_t * const pxHigherPriorityTaskWoken );
  654. /**
  655. * queue. h
  656. * @code{c}
  657. * BaseType_t xQueueReceiveFromISR(
  658. * QueueHandle_t xQueue,
  659. * void *pvBuffer,
  660. * BaseType_t *pxTaskWoken
  661. * );
  662. * @endcode
  663. *
  664. * Receive an item from a queue. It is safe to use this function from within an
  665. * interrupt service routine.
  666. *
  667. * @param xQueue The handle to the queue from which the item is to be
  668. * received.
  669. *
  670. * @param pvBuffer Pointer to the buffer into which the received item will
  671. * be copied.
  672. *
  673. * @param pxTaskWoken A task may be blocked waiting for space to become
  674. * available on the queue. If xQueueReceiveFromISR causes such a task to
  675. * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  676. * remain unchanged.
  677. *
  678. * @return pdTRUE if an item was successfully received from the queue,
  679. * otherwise pdFALSE.
  680. *
  681. * Example usage:
  682. * @code{c}
  683. *
  684. * QueueHandle_t xQueue;
  685. *
  686. * // Function to create a queue and post some values.
  687. * void vAFunction( void *pvParameters )
  688. * {
  689. * char cValueToPost;
  690. * const TickType_t xTicksToWait = ( TickType_t )0xff;
  691. *
  692. * // Create a queue capable of containing 10 characters.
  693. * xQueue = xQueueCreate( 10, sizeof( char ) );
  694. * if( xQueue == 0 )
  695. * {
  696. * // Failed to create the queue.
  697. * }
  698. *
  699. * // ...
  700. *
  701. * // Post some characters that will be used within an ISR. If the queue
  702. * // is full then this task will block for xTicksToWait ticks.
  703. * cValueToPost = 'a';
  704. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  705. * cValueToPost = 'b';
  706. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  707. *
  708. * // ... keep posting characters ... this task may block when the queue
  709. * // becomes full.
  710. *
  711. * cValueToPost = 'c';
  712. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  713. * }
  714. *
  715. * // ISR that outputs all the characters received on the queue.
  716. * void vISR_Routine( void )
  717. * {
  718. * BaseType_t xTaskWokenByReceive = pdFALSE;
  719. * char cRxedChar;
  720. *
  721. * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
  722. * {
  723. * // A character was received. Output the character now.
  724. * vOutputCharacter( cRxedChar );
  725. *
  726. * // If removing the character from the queue woke the task that was
  727. * // posting onto the queue cTaskWokenByReceive will have been set to
  728. * // pdTRUE. No matter how many times this loop iterates only one
  729. * // task will be woken.
  730. * }
  731. *
  732. * if( cTaskWokenByPost != ( char ) pdFALSE;
  733. * {
  734. * taskYIELD ();
  735. * }
  736. * }
  737. * @endcode
  738. * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
  739. * \ingroup QueueManagement
  740. */
  741. BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
  742. void * const pvBuffer,
  743. BaseType_t * const pxHigherPriorityTaskWoken );
  744. /*
  745. * For internal use only. Use xSemaphoreCreateMutex(),
  746. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  747. * these functions directly.
  748. */
  749. QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType );
  750. QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  751. StaticQueue_t * pxStaticQueue );
  752. QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
  753. const UBaseType_t uxInitialCount );
  754. QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
  755. const UBaseType_t uxInitialCount,
  756. StaticQueue_t * pxStaticQueue );
  757. BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  758. TickType_t xTicksToWait );
  759. /*
  760. * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  761. * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  762. */
  763. BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  764. TickType_t xTicksToWait );
  765. BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex );
  766. /*
  767. * Generic version of the function used to create a queue using dynamic memory
  768. * allocation. This is called by other functions and macros that create other
  769. * RTOS objects that use the queue structure as their base.
  770. */
  771. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  772. QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  773. const UBaseType_t uxItemSize,
  774. const uint8_t ucQueueType );
  775. #endif
  776. /*
  777. * Generic version of the function used to create a queue using dynamic memory
  778. * allocation. This is called by other functions and macros that create other
  779. * RTOS objects that use the queue structure as their base.
  780. */
  781. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  782. QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  783. const UBaseType_t uxItemSize,
  784. uint8_t * pucQueueStorage,
  785. StaticQueue_t * pxStaticQueue,
  786. const uint8_t ucQueueType );
  787. #endif
  788. /* *INDENT-OFF* */
  789. #ifdef __cplusplus
  790. }
  791. #endif
  792. /* *INDENT-ON* */
  793. #endif /* QUEUE_H */