queue.h 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  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. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h" must appear in source files before "include queue.h"
  32. #endif
  33. /* *INDENT-OFF* */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* *INDENT-ON* */
  38. #include "task.h"
  39. /**
  40. * Type by which queues are referenced. For example, a call to xQueueCreate()
  41. * returns an QueueHandle_t variable that can then be used as a parameter to
  42. * xQueueSend(), xQueueReceive(), etc.
  43. */
  44. struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
  45. typedef struct QueueDefinition * QueueHandle_t;
  46. /**
  47. * Type by which queue sets are referenced. For example, a call to
  48. * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
  49. * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
  50. */
  51. typedef struct QueueDefinition * QueueSetHandle_t;
  52. /**
  53. * Queue sets can contain both queues and semaphores, so the
  54. * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
  55. * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
  56. */
  57. typedef struct QueueDefinition * QueueSetMemberHandle_t;
  58. /* For internal use only. */
  59. #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
  60. #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
  61. #define queueOVERWRITE ( ( BaseType_t ) 2 )
  62. /* For internal use only. These definitions *must* match those in queue.c. */
  63. #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
  64. #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
  65. #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
  66. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
  67. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
  68. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
  69. /**
  70. * queue. h
  71. * @code{c}
  72. * QueueHandle_t xQueueCreate(
  73. * UBaseType_t uxQueueLength,
  74. * UBaseType_t uxItemSize
  75. * );
  76. * @endcode
  77. *
  78. * Creates a new queue instance, and returns a handle by which the new queue
  79. * can be referenced.
  80. *
  81. * Internally, within the FreeRTOS implementation, queues use two blocks of
  82. * memory. The first block is used to hold the queue's data structures. The
  83. * second block is used to hold items placed into the queue. If a queue is
  84. * created using xQueueCreate() then both blocks of memory are automatically
  85. * dynamically allocated inside the xQueueCreate() function. (see
  86. * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  87. * xQueueCreateStatic() then the application writer must provide the memory that
  88. * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  89. * be created without using any dynamic memory allocation.
  90. *
  91. * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  92. *
  93. * @param uxQueueLength The maximum number of items that the queue can contain.
  94. *
  95. * @param uxItemSize The number of bytes each item in the queue will require.
  96. * Items are queued by copy, not by reference, so this is the number of bytes
  97. * that will be copied for each posted item. Each item on the queue must be
  98. * the same size.
  99. *
  100. * @return If the queue is successfully create then a handle to the newly
  101. * created queue is returned. If the queue cannot be created then 0 is
  102. * returned.
  103. *
  104. * Example usage:
  105. * @code{c}
  106. * struct AMessage
  107. * {
  108. * char ucMessageID;
  109. * char ucData[ 20 ];
  110. * };
  111. *
  112. * void vATask( void *pvParameters )
  113. * {
  114. * QueueHandle_t xQueue1, xQueue2;
  115. *
  116. * // Create a queue capable of containing 10 uint32_t values.
  117. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  118. * if( xQueue1 == 0 )
  119. * {
  120. * // Queue was not created and must not be used.
  121. * }
  122. *
  123. * // Create a queue capable of containing 10 pointers to AMessage structures.
  124. * // These should be passed by pointer as they contain a lot of data.
  125. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  126. * if( xQueue2 == 0 )
  127. * {
  128. * // Queue was not created and must not be used.
  129. * }
  130. *
  131. * // ... Rest of task code.
  132. * }
  133. * @endcode
  134. * \defgroup xQueueCreate xQueueCreate
  135. * \ingroup QueueManagement
  136. */
  137. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  138. #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
  139. #endif
  140. /**
  141. * queue. h
  142. * @code{c}
  143. * QueueHandle_t xQueueCreateStatic(
  144. * UBaseType_t uxQueueLength,
  145. * UBaseType_t uxItemSize,
  146. * uint8_t *pucQueueStorage,
  147. * StaticQueue_t *pxQueueBuffer
  148. * );
  149. * @endcode
  150. *
  151. * Creates a new queue instance, and returns a handle by which the new queue
  152. * can be referenced.
  153. *
  154. * Internally, within the FreeRTOS implementation, queues use two blocks of
  155. * memory. The first block is used to hold the queue's data structures. The
  156. * second block is used to hold items placed into the queue. If a queue is
  157. * created using xQueueCreate() then both blocks of memory are automatically
  158. * dynamically allocated inside the xQueueCreate() function. (see
  159. * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  160. * xQueueCreateStatic() then the application writer must provide the memory that
  161. * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  162. * be created without using any dynamic memory allocation.
  163. *
  164. * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  165. *
  166. * @param uxQueueLength The maximum number of items that the queue can contain.
  167. *
  168. * @param uxItemSize The number of bytes each item in the queue will require.
  169. * Items are queued by copy, not by reference, so this is the number of bytes
  170. * that will be copied for each posted item. Each item on the queue must be
  171. * the same size.
  172. *
  173. * @param pucQueueStorage If uxItemSize is not zero then
  174. * pucQueueStorage must point to a uint8_t array that is at least large
  175. * enough to hold the maximum number of items that can be in the queue at any
  176. * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
  177. * zero then pucQueueStorage can be NULL.
  178. *
  179. * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
  180. * will be used to hold the queue's data structure.
  181. *
  182. * @return If the queue is created then a handle to the created queue is
  183. * returned. If pxQueueBuffer is NULL then NULL is returned.
  184. *
  185. * Example usage:
  186. * @code{c}
  187. * struct AMessage
  188. * {
  189. * char ucMessageID;
  190. * char ucData[ 20 ];
  191. * };
  192. *
  193. #define QUEUE_LENGTH 10
  194. #define ITEM_SIZE sizeof( uint32_t )
  195. *
  196. * // xQueueBuffer will hold the queue structure.
  197. * StaticQueue_t xQueueBuffer;
  198. *
  199. * // ucQueueStorage will hold the items posted to the queue. Must be at least
  200. * // [(queue length) * ( queue item size)] bytes long.
  201. * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
  202. *
  203. * void vATask( void *pvParameters )
  204. * {
  205. * QueueHandle_t xQueue1;
  206. *
  207. * // Create a queue capable of containing 10 uint32_t values.
  208. * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
  209. * ITEM_SIZE // The size of each item in the queue
  210. * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
  211. * &xQueueBuffer ); // The buffer that will hold the queue structure.
  212. *
  213. * // The queue is guaranteed to be created successfully as no dynamic memory
  214. * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
  215. *
  216. * // ... Rest of task code.
  217. * }
  218. * @endcode
  219. * \defgroup xQueueCreateStatic xQueueCreateStatic
  220. * \ingroup QueueManagement
  221. */
  222. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  223. #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
  224. #endif /* configSUPPORT_STATIC_ALLOCATION */
  225. /**
  226. * queue. h
  227. * @code{c}
  228. * BaseType_t xQueueSendToToFront(
  229. * QueueHandle_t xQueue,
  230. * const void *pvItemToQueue,
  231. * TickType_t xTicksToWait
  232. * );
  233. * @endcode
  234. *
  235. * Post an item to the front of a queue. The item is queued by copy, not by
  236. * reference. This function must not be called from an interrupt service
  237. * routine. See xQueueSendFromISR () for an alternative which may be used
  238. * in an ISR.
  239. *
  240. * @param xQueue The handle to the queue on which the item is to be posted.
  241. *
  242. * @param pvItemToQueue A pointer to the item that is to be placed on the
  243. * queue. The size of the items the queue will hold was defined when the
  244. * queue was created, so this many bytes will be copied from pvItemToQueue
  245. * into the queue storage area.
  246. *
  247. * @param xTicksToWait The maximum amount of time the task should block
  248. * waiting for space to become available on the queue, should it already
  249. * be full. The call will return immediately if this is set to 0 and the
  250. * queue is full. The time is defined in tick periods so the constant
  251. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  252. *
  253. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  254. *
  255. * Example usage:
  256. * @code{c}
  257. * struct AMessage
  258. * {
  259. * char ucMessageID;
  260. * char ucData[ 20 ];
  261. * } xMessage;
  262. *
  263. * uint32_t ulVar = 10UL;
  264. *
  265. * void vATask( void *pvParameters )
  266. * {
  267. * QueueHandle_t xQueue1, xQueue2;
  268. * struct AMessage *pxMessage;
  269. *
  270. * // Create a queue capable of containing 10 uint32_t values.
  271. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  272. *
  273. * // Create a queue capable of containing 10 pointers to AMessage structures.
  274. * // These should be passed by pointer as they contain a lot of data.
  275. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  276. *
  277. * // ...
  278. *
  279. * if( xQueue1 != 0 )
  280. * {
  281. * // Send an uint32_t. Wait for 10 ticks for space to become
  282. * // available if necessary.
  283. * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  284. * {
  285. * // Failed to post the message, even after 10 ticks.
  286. * }
  287. * }
  288. *
  289. * if( xQueue2 != 0 )
  290. * {
  291. * // Send a pointer to a struct AMessage object. Don't block if the
  292. * // queue is already full.
  293. * pxMessage = & xMessage;
  294. * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  295. * }
  296. *
  297. * // ... Rest of task code.
  298. * }
  299. * @endcode
  300. * \defgroup xQueueSend xQueueSend
  301. * \ingroup QueueManagement
  302. */
  303. #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
  304. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
  305. /**
  306. * queue. h
  307. * @code{c}
  308. * BaseType_t xQueueSendToBack(
  309. * QueueHandle_t xQueue,
  310. * const void *pvItemToQueue,
  311. * TickType_t xTicksToWait
  312. * );
  313. * @endcode
  314. *
  315. * This is a macro that calls xQueueGenericSend().
  316. *
  317. * Post an item to the back of a queue. The item is queued by copy, not by
  318. * reference. This function must not be called from an interrupt service
  319. * routine. See xQueueSendFromISR () for an alternative which may be used
  320. * in an ISR.
  321. *
  322. * @param xQueue The handle to the queue on which the item is to be posted.
  323. *
  324. * @param pvItemToQueue A pointer to the item that is to be placed on the
  325. * queue. The size of the items the queue will hold was defined when the
  326. * queue was created, so this many bytes will be copied from pvItemToQueue
  327. * into the queue storage area.
  328. *
  329. * @param xTicksToWait The maximum amount of time the task should block
  330. * waiting for space to become available on the queue, should it already
  331. * be full. The call will return immediately if this is set to 0 and the queue
  332. * is full. The time is defined in tick periods so the constant
  333. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  334. *
  335. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  336. *
  337. * Example usage:
  338. * @code{c}
  339. * struct AMessage
  340. * {
  341. * char ucMessageID;
  342. * char ucData[ 20 ];
  343. * } xMessage;
  344. *
  345. * uint32_t ulVar = 10UL;
  346. *
  347. * void vATask( void *pvParameters )
  348. * {
  349. * QueueHandle_t xQueue1, xQueue2;
  350. * struct AMessage *pxMessage;
  351. *
  352. * // Create a queue capable of containing 10 uint32_t values.
  353. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  354. *
  355. * // Create a queue capable of containing 10 pointers to AMessage structures.
  356. * // These should be passed by pointer as they contain a lot of data.
  357. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  358. *
  359. * // ...
  360. *
  361. * if( xQueue1 != 0 )
  362. * {
  363. * // Send an uint32_t. Wait for 10 ticks for space to become
  364. * // available if necessary.
  365. * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  366. * {
  367. * // Failed to post the message, even after 10 ticks.
  368. * }
  369. * }
  370. *
  371. * if( xQueue2 != 0 )
  372. * {
  373. * // Send a pointer to a struct AMessage object. Don't block if the
  374. * // queue is already full.
  375. * pxMessage = & xMessage;
  376. * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  377. * }
  378. *
  379. * // ... Rest of task code.
  380. * }
  381. * @endcode
  382. * \defgroup xQueueSend xQueueSend
  383. * \ingroup QueueManagement
  384. */
  385. #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
  386. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  387. /**
  388. * queue. h
  389. * @code{c}
  390. * BaseType_t xQueueSend(
  391. * QueueHandle_t xQueue,
  392. * const void * pvItemToQueue,
  393. * TickType_t xTicksToWait
  394. * );
  395. * @endcode
  396. *
  397. * This is a macro that calls xQueueGenericSend(). It is included for
  398. * backward compatibility with versions of FreeRTOS.org that did not
  399. * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
  400. * equivalent to xQueueSendToBack().
  401. *
  402. * Post an item on a queue. The item is queued by copy, not by reference.
  403. * This function must not be called from an interrupt service routine.
  404. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  405. *
  406. * @param xQueue The handle to the queue on which the item is to be posted.
  407. *
  408. * @param pvItemToQueue A pointer to the item that is to be placed on the
  409. * queue. The size of the items the queue will hold was defined when the
  410. * queue was created, so this many bytes will be copied from pvItemToQueue
  411. * into the queue storage area.
  412. *
  413. * @param xTicksToWait The maximum amount of time the task should block
  414. * waiting for space to become available on the queue, should it already
  415. * be full. The call will return immediately if this is set to 0 and the
  416. * queue is full. The time is defined in tick periods so the constant
  417. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  418. *
  419. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  420. *
  421. * Example usage:
  422. * @code{c}
  423. * struct AMessage
  424. * {
  425. * char ucMessageID;
  426. * char ucData[ 20 ];
  427. * } xMessage;
  428. *
  429. * uint32_t ulVar = 10UL;
  430. *
  431. * void vATask( void *pvParameters )
  432. * {
  433. * QueueHandle_t xQueue1, xQueue2;
  434. * struct AMessage *pxMessage;
  435. *
  436. * // Create a queue capable of containing 10 uint32_t values.
  437. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  438. *
  439. * // Create a queue capable of containing 10 pointers to AMessage structures.
  440. * // These should be passed by pointer as they contain a lot of data.
  441. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  442. *
  443. * // ...
  444. *
  445. * if( xQueue1 != 0 )
  446. * {
  447. * // Send an uint32_t. Wait for 10 ticks for space to become
  448. * // available if necessary.
  449. * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  450. * {
  451. * // Failed to post the message, even after 10 ticks.
  452. * }
  453. * }
  454. *
  455. * if( xQueue2 != 0 )
  456. * {
  457. * // Send a pointer to a struct AMessage object. Don't block if the
  458. * // queue is already full.
  459. * pxMessage = & xMessage;
  460. * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  461. * }
  462. *
  463. * // ... Rest of task code.
  464. * }
  465. * @endcode
  466. * \defgroup xQueueSend xQueueSend
  467. * \ingroup QueueManagement
  468. */
  469. #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
  470. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  471. /**
  472. * queue. h
  473. * @code{c}
  474. * BaseType_t xQueueOverwrite(
  475. * QueueHandle_t xQueue,
  476. * const void * pvItemToQueue
  477. * );
  478. * @endcode
  479. *
  480. * Only for use with queues that have a length of one - so the queue is either
  481. * empty or full.
  482. *
  483. * Post an item on a queue. If the queue is already full then overwrite the
  484. * value held in the queue. The item is queued by copy, not by reference.
  485. *
  486. * This function must not be called from an interrupt service routine.
  487. * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
  488. *
  489. * @param xQueue The handle of the queue to which the data is being sent.
  490. *
  491. * @param pvItemToQueue A pointer to the item that is to be placed on the
  492. * queue. The size of the items the queue will hold was defined when the
  493. * queue was created, so this many bytes will be copied from pvItemToQueue
  494. * into the queue storage area.
  495. *
  496. * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
  497. * therefore has the same return values as xQueueSendToFront(). However, pdPASS
  498. * is the only value that can be returned because xQueueOverwrite() will write
  499. * to the queue even when the queue is already full.
  500. *
  501. * Example usage:
  502. * @code{c}
  503. *
  504. * void vFunction( void *pvParameters )
  505. * {
  506. * QueueHandle_t xQueue;
  507. * uint32_t ulVarToSend, ulValReceived;
  508. *
  509. * // Create a queue to hold one uint32_t value. It is strongly
  510. * // recommended *not* to use xQueueOverwrite() on queues that can
  511. * // contain more than one value, and doing so will trigger an assertion
  512. * // if configASSERT() is defined.
  513. * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
  514. *
  515. * // Write the value 10 to the queue using xQueueOverwrite().
  516. * ulVarToSend = 10;
  517. * xQueueOverwrite( xQueue, &ulVarToSend );
  518. *
  519. * // Peeking the queue should now return 10, but leave the value 10 in
  520. * // the queue. A block time of zero is used as it is known that the
  521. * // queue holds a value.
  522. * ulValReceived = 0;
  523. * xQueuePeek( xQueue, &ulValReceived, 0 );
  524. *
  525. * if( ulValReceived != 10 )
  526. * {
  527. * // Error unless the item was removed by a different task.
  528. * }
  529. *
  530. * // The queue is still full. Use xQueueOverwrite() to overwrite the
  531. * // value held in the queue with 100.
  532. * ulVarToSend = 100;
  533. * xQueueOverwrite( xQueue, &ulVarToSend );
  534. *
  535. * // This time read from the queue, leaving the queue empty once more.
  536. * // A block time of 0 is used again.
  537. * xQueueReceive( xQueue, &ulValReceived, 0 );
  538. *
  539. * // The value read should be the last value written, even though the
  540. * // queue was already full when the value was written.
  541. * if( ulValReceived != 100 )
  542. * {
  543. * // Error!
  544. * }
  545. *
  546. * // ...
  547. * }
  548. * @endcode
  549. * \defgroup xQueueOverwrite xQueueOverwrite
  550. * \ingroup QueueManagement
  551. */
  552. #define xQueueOverwrite( xQueue, pvItemToQueue ) \
  553. xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
  554. /**
  555. * queue. h
  556. * @code{c}
  557. * BaseType_t xQueueGenericSend(
  558. * QueueHandle_t xQueue,
  559. * const void * pvItemToQueue,
  560. * TickType_t xTicksToWait
  561. * BaseType_t xCopyPosition
  562. * );
  563. * @endcode
  564. *
  565. * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
  566. * xQueueSendToBack() are used in place of calling this function directly.
  567. *
  568. * Post an item on a queue. The item is queued by copy, not by reference.
  569. * This function must not be called from an interrupt service routine.
  570. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  571. *
  572. * @param xQueue The handle to the queue on which the item is to be posted.
  573. *
  574. * @param pvItemToQueue A pointer to the item that is to be placed on the
  575. * queue. The size of the items the queue will hold was defined when the
  576. * queue was created, so this many bytes will be copied from pvItemToQueue
  577. * into the queue storage area.
  578. *
  579. * @param xTicksToWait The maximum amount of time the task should block
  580. * waiting for space to become available on the queue, should it already
  581. * be full. The call will return immediately if this is set to 0 and the
  582. * queue is full. The time is defined in tick periods so the constant
  583. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  584. *
  585. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  586. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  587. * at the front of the queue (for high priority messages).
  588. *
  589. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  590. *
  591. * Example usage:
  592. * @code{c}
  593. * struct AMessage
  594. * {
  595. * char ucMessageID;
  596. * char ucData[ 20 ];
  597. * } xMessage;
  598. *
  599. * uint32_t ulVar = 10UL;
  600. *
  601. * void vATask( void *pvParameters )
  602. * {
  603. * QueueHandle_t xQueue1, xQueue2;
  604. * struct AMessage *pxMessage;
  605. *
  606. * // Create a queue capable of containing 10 uint32_t values.
  607. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  608. *
  609. * // Create a queue capable of containing 10 pointers to AMessage structures.
  610. * // These should be passed by pointer as they contain a lot of data.
  611. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  612. *
  613. * // ...
  614. *
  615. * if( xQueue1 != 0 )
  616. * {
  617. * // Send an uint32_t. Wait for 10 ticks for space to become
  618. * // available if necessary.
  619. * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
  620. * {
  621. * // Failed to post the message, even after 10 ticks.
  622. * }
  623. * }
  624. *
  625. * if( xQueue2 != 0 )
  626. * {
  627. * // Send a pointer to a struct AMessage object. Don't block if the
  628. * // queue is already full.
  629. * pxMessage = & xMessage;
  630. * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
  631. * }
  632. *
  633. * // ... Rest of task code.
  634. * }
  635. * @endcode
  636. * \defgroup xQueueSend xQueueSend
  637. * \ingroup QueueManagement
  638. */
  639. BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
  640. const void * const pvItemToQueue,
  641. TickType_t xTicksToWait,
  642. const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
  643. /**
  644. * queue. h
  645. * @code{c}
  646. * BaseType_t xQueuePeek(
  647. * QueueHandle_t xQueue,
  648. * void * const pvBuffer,
  649. * TickType_t xTicksToWait
  650. * );
  651. * @endcode
  652. *
  653. * Receive an item from a queue without removing the item from the queue.
  654. * The item is received by copy so a buffer of adequate size must be
  655. * provided. The number of bytes copied into the buffer was defined when
  656. * the queue was created.
  657. *
  658. * Successfully received items remain on the queue so will be returned again
  659. * by the next call, or a call to xQueueReceive().
  660. *
  661. * This macro must not be used in an interrupt service routine. See
  662. * xQueuePeekFromISR() for an alternative that can be called from an interrupt
  663. * service routine.
  664. *
  665. * @param xQueue The handle to the queue from which the item is to be
  666. * received.
  667. *
  668. * @param pvBuffer Pointer to the buffer into which the received item will
  669. * be copied.
  670. *
  671. * @param xTicksToWait The maximum amount of time the task should block
  672. * waiting for an item to receive should the queue be empty at the time
  673. * of the call. The time is defined in tick periods so the constant
  674. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  675. * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
  676. * is empty.
  677. *
  678. * @return pdTRUE if an item was successfully received from the queue,
  679. * otherwise pdFALSE.
  680. *
  681. * Example usage:
  682. * @code{c}
  683. * struct AMessage
  684. * {
  685. * char ucMessageID;
  686. * char ucData[ 20 ];
  687. * } xMessage;
  688. *
  689. * QueueHandle_t xQueue;
  690. *
  691. * // Task to create a queue and post a value.
  692. * void vATask( void *pvParameters )
  693. * {
  694. * struct AMessage *pxMessage;
  695. *
  696. * // Create a queue capable of containing 10 pointers to AMessage structures.
  697. * // These should be passed by pointer as they contain a lot of data.
  698. * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  699. * if( xQueue == 0 )
  700. * {
  701. * // Failed to create the queue.
  702. * }
  703. *
  704. * // ...
  705. *
  706. * // Send a pointer to a struct AMessage object. Don't block if the
  707. * // queue is already full.
  708. * pxMessage = & xMessage;
  709. * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
  710. *
  711. * // ... Rest of task code.
  712. * }
  713. *
  714. * // Task to peek the data from the queue.
  715. * void vADifferentTask( void *pvParameters )
  716. * {
  717. * struct AMessage *pxRxedMessage;
  718. *
  719. * if( xQueue != 0 )
  720. * {
  721. * // Peek a message on the created queue. Block for 10 ticks if a
  722. * // message is not immediately available.
  723. * if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
  724. * {
  725. * // pcRxedMessage now points to the struct AMessage variable posted
  726. * // by vATask, but the item still remains on the queue.
  727. * }
  728. * }
  729. *
  730. * // ... Rest of task code.
  731. * }
  732. * @endcode
  733. * \defgroup xQueuePeek xQueuePeek
  734. * \ingroup QueueManagement
  735. */
  736. BaseType_t xQueuePeek( QueueHandle_t xQueue,
  737. void * const pvBuffer,
  738. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  739. /**
  740. * queue. h
  741. * @code{c}
  742. * BaseType_t xQueuePeekFromISR(
  743. * QueueHandle_t xQueue,
  744. * void *pvBuffer,
  745. * );
  746. * @endcode
  747. *
  748. * A version of xQueuePeek() that can be called from an interrupt service
  749. * routine (ISR).
  750. *
  751. * Receive an item from a queue without removing the item from the queue.
  752. * The item is received by copy so a buffer of adequate size must be
  753. * provided. The number of bytes copied into the buffer was defined when
  754. * the queue was created.
  755. *
  756. * Successfully received items remain on the queue so will be returned again
  757. * by the next call, or a call to xQueueReceive().
  758. *
  759. * @param xQueue The handle to the queue from which the item is to be
  760. * received.
  761. *
  762. * @param pvBuffer Pointer to the buffer into which the received item will
  763. * be copied.
  764. *
  765. * @return pdTRUE if an item was successfully received from the queue,
  766. * otherwise pdFALSE.
  767. *
  768. * \defgroup xQueuePeekFromISR xQueuePeekFromISR
  769. * \ingroup QueueManagement
  770. */
  771. BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
  772. void * const pvBuffer ) PRIVILEGED_FUNCTION;
  773. /**
  774. * queue. h
  775. * @code{c}
  776. * BaseType_t xQueueReceive(
  777. * QueueHandle_t xQueue,
  778. * void *pvBuffer,
  779. * TickType_t xTicksToWait
  780. * );
  781. * @endcode
  782. *
  783. * Receive an item from a queue. The item is received by copy so a buffer of
  784. * adequate size must be provided. The number of bytes copied into the buffer
  785. * was defined when the queue was created.
  786. *
  787. * Successfully received items are removed from the queue.
  788. *
  789. * This function must not be used in an interrupt service routine. See
  790. * xQueueReceiveFromISR for an alternative that can.
  791. *
  792. * @param xQueue The handle to the queue from which the item is to be
  793. * received.
  794. *
  795. * @param pvBuffer Pointer to the buffer into which the received item will
  796. * be copied.
  797. *
  798. * @param xTicksToWait The maximum amount of time the task should block
  799. * waiting for an item to receive should the queue be empty at the time
  800. * of the call. xQueueReceive() will return immediately if xTicksToWait
  801. * is zero and the queue is empty. The time is defined in tick periods so the
  802. * constant portTICK_PERIOD_MS should be used to convert to real time if this is
  803. * required.
  804. *
  805. * @return pdTRUE if an item was successfully received from the queue,
  806. * otherwise pdFALSE.
  807. *
  808. * Example usage:
  809. * @code{c}
  810. * struct AMessage
  811. * {
  812. * char ucMessageID;
  813. * char ucData[ 20 ];
  814. * } xMessage;
  815. *
  816. * QueueHandle_t xQueue;
  817. *
  818. * // Task to create a queue and post a value.
  819. * void vATask( void *pvParameters )
  820. * {
  821. * struct AMessage *pxMessage;
  822. *
  823. * // Create a queue capable of containing 10 pointers to AMessage structures.
  824. * // These should be passed by pointer as they contain a lot of data.
  825. * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  826. * if( xQueue == 0 )
  827. * {
  828. * // Failed to create the queue.
  829. * }
  830. *
  831. * // ...
  832. *
  833. * // Send a pointer to a struct AMessage object. Don't block if the
  834. * // queue is already full.
  835. * pxMessage = & xMessage;
  836. * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
  837. *
  838. * // ... Rest of task code.
  839. * }
  840. *
  841. * // Task to receive from the queue.
  842. * void vADifferentTask( void *pvParameters )
  843. * {
  844. * struct AMessage *pxRxedMessage;
  845. *
  846. * if( xQueue != 0 )
  847. * {
  848. * // Receive a message on the created queue. Block for 10 ticks if a
  849. * // message is not immediately available.
  850. * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
  851. * {
  852. * // pcRxedMessage now points to the struct AMessage variable posted
  853. * // by vATask.
  854. * }
  855. * }
  856. *
  857. * // ... Rest of task code.
  858. * }
  859. * @endcode
  860. * \defgroup xQueueReceive xQueueReceive
  861. * \ingroup QueueManagement
  862. */
  863. BaseType_t xQueueReceive( QueueHandle_t xQueue,
  864. void * const pvBuffer,
  865. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  866. /**
  867. * queue. h
  868. * @code{c}
  869. * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
  870. * @endcode
  871. *
  872. * Return the number of messages stored in a queue.
  873. *
  874. * @param xQueue A handle to the queue being queried.
  875. *
  876. * @return The number of messages available in the queue.
  877. *
  878. * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  879. * \ingroup QueueManagement
  880. */
  881. UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  882. /**
  883. * queue. h
  884. * @code{c}
  885. * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
  886. * @endcode
  887. *
  888. * Return the number of free spaces available in a queue. This is equal to the
  889. * number of items that can be sent to the queue before the queue becomes full
  890. * if no items are removed.
  891. *
  892. * @param xQueue A handle to the queue being queried.
  893. *
  894. * @return The number of spaces available in the queue.
  895. *
  896. * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  897. * \ingroup QueueManagement
  898. */
  899. UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  900. /**
  901. * queue. h
  902. * @code{c}
  903. * void vQueueDelete( QueueHandle_t xQueue );
  904. * @endcode
  905. *
  906. * Delete a queue - freeing all the memory allocated for storing of items
  907. * placed on the queue.
  908. *
  909. * @param xQueue A handle to the queue to be deleted.
  910. *
  911. * \defgroup vQueueDelete vQueueDelete
  912. * \ingroup QueueManagement
  913. */
  914. void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  915. /**
  916. * queue. h
  917. * @code{c}
  918. * BaseType_t xQueueSendToFrontFromISR(
  919. * QueueHandle_t xQueue,
  920. * const void *pvItemToQueue,
  921. * BaseType_t *pxHigherPriorityTaskWoken
  922. * );
  923. * @endcode
  924. *
  925. * This is a macro that calls xQueueGenericSendFromISR().
  926. *
  927. * Post an item to the front of a queue. It is safe to use this macro from
  928. * within an interrupt service routine.
  929. *
  930. * Items are queued by copy not reference so it is preferable to only
  931. * queue small items, especially when called from an ISR. In most cases
  932. * it would be preferable to store a pointer to the item being queued.
  933. *
  934. * @param xQueue The handle to the queue on which the item is to be posted.
  935. *
  936. * @param pvItemToQueue A pointer to the item that is to be placed on the
  937. * queue. The size of the items the queue will hold was defined when the
  938. * queue was created, so this many bytes will be copied from pvItemToQueue
  939. * into the queue storage area.
  940. *
  941. * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
  942. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  943. * to unblock, and the unblocked task has a priority higher than the currently
  944. * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
  945. * a context switch should be requested before the interrupt is exited.
  946. *
  947. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  948. * errQUEUE_FULL.
  949. *
  950. * Example usage for buffered IO (where the ISR can obtain more than one value
  951. * per call):
  952. * @code{c}
  953. * void vBufferISR( void )
  954. * {
  955. * char cIn;
  956. * BaseType_t xHigherPrioritTaskWoken;
  957. *
  958. * // We have not woken a task at the start of the ISR.
  959. * xHigherPriorityTaskWoken = pdFALSE;
  960. *
  961. * // Loop until the buffer is empty.
  962. * do
  963. * {
  964. * // Obtain a byte from the buffer.
  965. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  966. *
  967. * // Post the byte.
  968. * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  969. *
  970. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  971. *
  972. * // Now the buffer is empty we can switch context if necessary.
  973. * if( xHigherPriorityTaskWoken )
  974. * {
  975. * taskYIELD ();
  976. * }
  977. * }
  978. * @endcode
  979. *
  980. * \defgroup xQueueSendFromISR xQueueSendFromISR
  981. * \ingroup QueueManagement
  982. */
  983. #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  984. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
  985. /**
  986. * queue. h
  987. * @code{c}
  988. * BaseType_t xQueueSendToBackFromISR(
  989. * QueueHandle_t xQueue,
  990. * const void *pvItemToQueue,
  991. * BaseType_t *pxHigherPriorityTaskWoken
  992. * );
  993. * @endcode
  994. *
  995. * This is a macro that calls xQueueGenericSendFromISR().
  996. *
  997. * Post an item to the back of a queue. It is safe to use this macro from
  998. * within an interrupt service routine.
  999. *
  1000. * Items are queued by copy not reference so it is preferable to only
  1001. * queue small items, especially when called from an ISR. In most cases
  1002. * it would be preferable to store a pointer to the item being queued.
  1003. *
  1004. * @param xQueue The handle to the queue on which the item is to be posted.
  1005. *
  1006. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1007. * queue. The size of the items the queue will hold was defined when the
  1008. * queue was created, so this many bytes will be copied from pvItemToQueue
  1009. * into the queue storage area.
  1010. *
  1011. * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
  1012. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1013. * to unblock, and the unblocked task has a priority higher than the currently
  1014. * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
  1015. * a context switch should be requested before the interrupt is exited.
  1016. *
  1017. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  1018. * errQUEUE_FULL.
  1019. *
  1020. * Example usage for buffered IO (where the ISR can obtain more than one value
  1021. * per call):
  1022. * @code{c}
  1023. * void vBufferISR( void )
  1024. * {
  1025. * char cIn;
  1026. * BaseType_t xHigherPriorityTaskWoken;
  1027. *
  1028. * // We have not woken a task at the start of the ISR.
  1029. * xHigherPriorityTaskWoken = pdFALSE;
  1030. *
  1031. * // Loop until the buffer is empty.
  1032. * do
  1033. * {
  1034. * // Obtain a byte from the buffer.
  1035. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1036. *
  1037. * // Post the byte.
  1038. * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  1039. *
  1040. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1041. *
  1042. * // Now the buffer is empty we can switch context if necessary.
  1043. * if( xHigherPriorityTaskWoken )
  1044. * {
  1045. * taskYIELD ();
  1046. * }
  1047. * }
  1048. * @endcode
  1049. *
  1050. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1051. * \ingroup QueueManagement
  1052. */
  1053. #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1054. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  1055. /**
  1056. * queue. h
  1057. * @code{c}
  1058. * BaseType_t xQueueOverwriteFromISR(
  1059. * QueueHandle_t xQueue,
  1060. * const void * pvItemToQueue,
  1061. * BaseType_t *pxHigherPriorityTaskWoken
  1062. * );
  1063. * @endcode
  1064. *
  1065. * A version of xQueueOverwrite() that can be used in an interrupt service
  1066. * routine (ISR).
  1067. *
  1068. * Only for use with queues that can hold a single item - so the queue is either
  1069. * empty or full.
  1070. *
  1071. * Post an item on a queue. If the queue is already full then overwrite the
  1072. * value held in the queue. The item is queued by copy, not by reference.
  1073. *
  1074. * @param xQueue The handle to the queue on which the item is to be posted.
  1075. *
  1076. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1077. * queue. The size of the items the queue will hold was defined when the
  1078. * queue was created, so this many bytes will be copied from pvItemToQueue
  1079. * into the queue storage area.
  1080. *
  1081. * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
  1082. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1083. * to unblock, and the unblocked task has a priority higher than the currently
  1084. * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
  1085. * a context switch should be requested before the interrupt is exited.
  1086. *
  1087. * @return xQueueOverwriteFromISR() is a macro that calls
  1088. * xQueueGenericSendFromISR(), and therefore has the same return values as
  1089. * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
  1090. * returned because xQueueOverwriteFromISR() will write to the queue even when
  1091. * the queue is already full.
  1092. *
  1093. * Example usage:
  1094. * @code{c}
  1095. *
  1096. * QueueHandle_t xQueue;
  1097. *
  1098. * void vFunction( void *pvParameters )
  1099. * {
  1100. * // Create a queue to hold one uint32_t value. It is strongly
  1101. * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
  1102. * // contain more than one value, and doing so will trigger an assertion
  1103. * // if configASSERT() is defined.
  1104. * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
  1105. * }
  1106. *
  1107. * void vAnInterruptHandler( void )
  1108. * {
  1109. * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
  1110. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  1111. * uint32_t ulVarToSend, ulValReceived;
  1112. *
  1113. * // Write the value 10 to the queue using xQueueOverwriteFromISR().
  1114. * ulVarToSend = 10;
  1115. * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
  1116. *
  1117. * // The queue is full, but calling xQueueOverwriteFromISR() again will still
  1118. * // pass because the value held in the queue will be overwritten with the
  1119. * // new value.
  1120. * ulVarToSend = 100;
  1121. * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
  1122. *
  1123. * // Reading from the queue will now return 100.
  1124. *
  1125. * // ...
  1126. *
  1127. * if( xHigherPrioritytaskWoken == pdTRUE )
  1128. * {
  1129. * // Writing to the queue caused a task to unblock and the unblocked task
  1130. * // has a priority higher than or equal to the priority of the currently
  1131. * // executing task (the task this interrupt interrupted). Perform a context
  1132. * // switch so this interrupt returns directly to the unblocked task.
  1133. * portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
  1134. * }
  1135. * }
  1136. * @endcode
  1137. * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
  1138. * \ingroup QueueManagement
  1139. */
  1140. #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1141. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
  1142. /**
  1143. * queue. h
  1144. * @code{c}
  1145. * BaseType_t xQueueSendFromISR(
  1146. * QueueHandle_t xQueue,
  1147. * const void *pvItemToQueue,
  1148. * BaseType_t *pxHigherPriorityTaskWoken
  1149. * );
  1150. * @endcode
  1151. *
  1152. * This is a macro that calls xQueueGenericSendFromISR(). It is included
  1153. * for backward compatibility with versions of FreeRTOS.org that did not
  1154. * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
  1155. * macros.
  1156. *
  1157. * Post an item to the back of a queue. It is safe to use this function from
  1158. * within an interrupt service routine.
  1159. *
  1160. * Items are queued by copy not reference so it is preferable to only
  1161. * queue small items, especially when called from an ISR. In most cases
  1162. * it would be preferable to store a pointer to the item being queued.
  1163. *
  1164. * @param xQueue The handle to the queue on which the item is to be posted.
  1165. *
  1166. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1167. * queue. The size of the items the queue will hold was defined when the
  1168. * queue was created, so this many bytes will be copied from pvItemToQueue
  1169. * into the queue storage area.
  1170. *
  1171. * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
  1172. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1173. * to unblock, and the unblocked task has a priority higher than the currently
  1174. * running task. If xQueueSendFromISR() sets this value to pdTRUE then
  1175. * a context switch should be requested before the interrupt is exited.
  1176. *
  1177. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  1178. * errQUEUE_FULL.
  1179. *
  1180. * Example usage for buffered IO (where the ISR can obtain more than one value
  1181. * per call):
  1182. * @code{c}
  1183. * void vBufferISR( void )
  1184. * {
  1185. * char cIn;
  1186. * BaseType_t xHigherPriorityTaskWoken;
  1187. *
  1188. * // We have not woken a task at the start of the ISR.
  1189. * xHigherPriorityTaskWoken = pdFALSE;
  1190. *
  1191. * // Loop until the buffer is empty.
  1192. * do
  1193. * {
  1194. * // Obtain a byte from the buffer.
  1195. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1196. *
  1197. * // Post the byte.
  1198. * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  1199. *
  1200. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1201. *
  1202. * // Now the buffer is empty we can switch context if necessary.
  1203. * if( xHigherPriorityTaskWoken )
  1204. * {
  1205. * // Actual macro used here is port specific.
  1206. * portYIELD_FROM_ISR ();
  1207. * }
  1208. * }
  1209. * @endcode
  1210. *
  1211. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1212. * \ingroup QueueManagement
  1213. */
  1214. #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1215. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  1216. /**
  1217. * queue. h
  1218. * @code{c}
  1219. * BaseType_t xQueueGenericSendFromISR(
  1220. * QueueHandle_t xQueue,
  1221. * const void *pvItemToQueue,
  1222. * BaseType_t *pxHigherPriorityTaskWoken,
  1223. * BaseType_t xCopyPosition
  1224. * );
  1225. * @endcode
  1226. *
  1227. * It is preferred that the macros xQueueSendFromISR(),
  1228. * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
  1229. * of calling this function directly. xQueueGiveFromISR() is an
  1230. * equivalent for use by semaphores that don't actually copy any data.
  1231. *
  1232. * Post an item on a queue. It is safe to use this function from within an
  1233. * interrupt service routine.
  1234. *
  1235. * Items are queued by copy not reference so it is preferable to only
  1236. * queue small items, especially when called from an ISR. In most cases
  1237. * it would be preferable to store a pointer to the item being queued.
  1238. *
  1239. * @param xQueue The handle to the queue on which the item is to be posted.
  1240. *
  1241. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1242. * queue. The size of the items the queue will hold was defined when the
  1243. * queue was created, so this many bytes will be copied from pvItemToQueue
  1244. * into the queue storage area.
  1245. *
  1246. * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
  1247. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1248. * to unblock, and the unblocked task has a priority higher than the currently
  1249. * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
  1250. * a context switch should be requested before the interrupt is exited.
  1251. *
  1252. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  1253. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  1254. * at the front of the queue (for high priority messages).
  1255. *
  1256. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  1257. * errQUEUE_FULL.
  1258. *
  1259. * Example usage for buffered IO (where the ISR can obtain more than one value
  1260. * per call):
  1261. * @code{c}
  1262. * void vBufferISR( void )
  1263. * {
  1264. * char cIn;
  1265. * BaseType_t xHigherPriorityTaskWokenByPost;
  1266. *
  1267. * // We have not woken a task at the start of the ISR.
  1268. * xHigherPriorityTaskWokenByPost = pdFALSE;
  1269. *
  1270. * // Loop until the buffer is empty.
  1271. * do
  1272. * {
  1273. * // Obtain a byte from the buffer.
  1274. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1275. *
  1276. * // Post each byte.
  1277. * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
  1278. *
  1279. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1280. *
  1281. * // Now the buffer is empty we can switch context if necessary. Note that the
  1282. * // name of the yield function required is port specific.
  1283. * if( xHigherPriorityTaskWokenByPost )
  1284. * {
  1285. * portYIELD_FROM_ISR();
  1286. * }
  1287. * }
  1288. * @endcode
  1289. *
  1290. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1291. * \ingroup QueueManagement
  1292. */
  1293. BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
  1294. const void * const pvItemToQueue,
  1295. BaseType_t * const pxHigherPriorityTaskWoken,
  1296. const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
  1297. BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
  1298. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1299. /**
  1300. * queue. h
  1301. * @code{c}
  1302. * BaseType_t xQueueReceiveFromISR(
  1303. * QueueHandle_t xQueue,
  1304. * void *pvBuffer,
  1305. * BaseType_t *pxTaskWoken
  1306. * );
  1307. * @endcode
  1308. *
  1309. * Receive an item from a queue. It is safe to use this function from within an
  1310. * interrupt service routine.
  1311. *
  1312. * @param xQueue The handle to the queue from which the item is to be
  1313. * received.
  1314. *
  1315. * @param pvBuffer Pointer to the buffer into which the received item will
  1316. * be copied.
  1317. *
  1318. * @param pxTaskWoken A task may be blocked waiting for space to become
  1319. * available on the queue. If xQueueReceiveFromISR causes such a task to
  1320. * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  1321. * remain unchanged.
  1322. *
  1323. * @return pdTRUE if an item was successfully received from the queue,
  1324. * otherwise pdFALSE.
  1325. *
  1326. * Example usage:
  1327. * @code{c}
  1328. *
  1329. * QueueHandle_t xQueue;
  1330. *
  1331. * // Function to create a queue and post some values.
  1332. * void vAFunction( void *pvParameters )
  1333. * {
  1334. * char cValueToPost;
  1335. * const TickType_t xTicksToWait = ( TickType_t )0xff;
  1336. *
  1337. * // Create a queue capable of containing 10 characters.
  1338. * xQueue = xQueueCreate( 10, sizeof( char ) );
  1339. * if( xQueue == 0 )
  1340. * {
  1341. * // Failed to create the queue.
  1342. * }
  1343. *
  1344. * // ...
  1345. *
  1346. * // Post some characters that will be used within an ISR. If the queue
  1347. * // is full then this task will block for xTicksToWait ticks.
  1348. * cValueToPost = 'a';
  1349. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1350. * cValueToPost = 'b';
  1351. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1352. *
  1353. * // ... keep posting characters ... this task may block when the queue
  1354. * // becomes full.
  1355. *
  1356. * cValueToPost = 'c';
  1357. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1358. * }
  1359. *
  1360. * // ISR that outputs all the characters received on the queue.
  1361. * void vISR_Routine( void )
  1362. * {
  1363. * BaseType_t xTaskWokenByReceive = pdFALSE;
  1364. * char cRxedChar;
  1365. *
  1366. * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
  1367. * {
  1368. * // A character was received. Output the character now.
  1369. * vOutputCharacter( cRxedChar );
  1370. *
  1371. * // If removing the character from the queue woke the task that was
  1372. * // posting onto the queue cTaskWokenByReceive will have been set to
  1373. * // pdTRUE. No matter how many times this loop iterates only one
  1374. * // task will be woken.
  1375. * }
  1376. *
  1377. * if( cTaskWokenByPost != ( char ) pdFALSE;
  1378. * {
  1379. * taskYIELD ();
  1380. * }
  1381. * }
  1382. * @endcode
  1383. * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
  1384. * \ingroup QueueManagement
  1385. */
  1386. BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
  1387. void * const pvBuffer,
  1388. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1389. /*
  1390. * Utilities to query queues that are safe to use from an ISR. These utilities
  1391. * should be used only from witin an ISR, or within a critical section.
  1392. */
  1393. BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1394. BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1395. UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1396. /*
  1397. * The functions defined above are for passing data to and from tasks. The
  1398. * functions below are the equivalents for passing data to and from
  1399. * co-routines.
  1400. *
  1401. * These functions are called from the co-routine macro implementation and
  1402. * should not be called directly from application code. Instead use the macro
  1403. * wrappers defined within croutine.h.
  1404. */
  1405. BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
  1406. const void * pvItemToQueue,
  1407. BaseType_t xCoRoutinePreviouslyWoken );
  1408. BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
  1409. void * pvBuffer,
  1410. BaseType_t * pxTaskWoken );
  1411. BaseType_t xQueueCRSend( QueueHandle_t xQueue,
  1412. const void * pvItemToQueue,
  1413. TickType_t xTicksToWait );
  1414. BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
  1415. void * pvBuffer,
  1416. TickType_t xTicksToWait );
  1417. /*
  1418. * For internal use only. Use xSemaphoreCreateMutex(),
  1419. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  1420. * these functions directly.
  1421. */
  1422. QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1423. QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  1424. StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
  1425. QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
  1426. const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
  1427. QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
  1428. const UBaseType_t uxInitialCount,
  1429. StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
  1430. BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  1431. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1432. TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
  1433. TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
  1434. /*
  1435. * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  1436. * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  1437. */
  1438. BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  1439. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1440. BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
  1441. /*
  1442. * Reset a queue back to its original empty state. The return value is now
  1443. * obsolete and is always set to pdPASS.
  1444. */
  1445. #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
  1446. /*
  1447. * The registry is provided as a means for kernel aware debuggers to
  1448. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  1449. * a queue, semaphore or mutex handle to the registry if you want the handle
  1450. * to be available to a kernel aware debugger. If you are not using a kernel
  1451. * aware debugger then this function can be ignored.
  1452. *
  1453. * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
  1454. * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
  1455. * within FreeRTOSConfig.h for the registry to be available. Its value
  1456. * does not effect the number of queues, semaphores and mutexes that can be
  1457. * created - just the number that the registry can hold.
  1458. *
  1459. * If vQueueAddToRegistry is called more than once with the same xQueue
  1460. * parameter, the registry will store the pcQueueName parameter from the
  1461. * most recent call to vQueueAddToRegistry.
  1462. *
  1463. * @param xQueue The handle of the queue being added to the registry. This
  1464. * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
  1465. * handles can also be passed in here.
  1466. *
  1467. * @param pcQueueName The name to be associated with the handle. This is the
  1468. * name that the kernel aware debugger will display. The queue registry only
  1469. * stores a pointer to the string - so the string must be persistent (global or
  1470. * preferably in ROM/Flash), not on the stack.
  1471. */
  1472. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1473. void vQueueAddToRegistry( QueueHandle_t xQueue,
  1474. const char * pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1475. #endif
  1476. /*
  1477. * The registry is provided as a means for kernel aware debuggers to
  1478. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  1479. * a queue, semaphore or mutex handle to the registry if you want the handle
  1480. * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
  1481. * remove the queue, semaphore or mutex from the register. If you are not using
  1482. * a kernel aware debugger then this function can be ignored.
  1483. *
  1484. * @param xQueue The handle of the queue being removed from the registry.
  1485. */
  1486. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1487. void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1488. #endif
  1489. /*
  1490. * The queue registry is provided as a means for kernel aware debuggers to
  1491. * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
  1492. * up and return the name of a queue in the queue registry from the queue's
  1493. * handle.
  1494. *
  1495. * @param xQueue The handle of the queue the name of which will be returned.
  1496. * @return If the queue is in the registry then a pointer to the name of the
  1497. * queue is returned. If the queue is not in the registry then NULL is
  1498. * returned.
  1499. */
  1500. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1501. const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1502. #endif
  1503. /*
  1504. * Generic version of the function used to create a queue using dynamic memory
  1505. * allocation. This is called by other functions and macros that create other
  1506. * RTOS objects that use the queue structure as their base.
  1507. */
  1508. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  1509. QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  1510. const UBaseType_t uxItemSize,
  1511. const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1512. #endif
  1513. /*
  1514. * Generic version of the function used to create a queue using dynamic memory
  1515. * allocation. This is called by other functions and macros that create other
  1516. * RTOS objects that use the queue structure as their base.
  1517. */
  1518. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1519. QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  1520. const UBaseType_t uxItemSize,
  1521. uint8_t * pucQueueStorage,
  1522. StaticQueue_t * pxStaticQueue,
  1523. const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1524. #endif
  1525. /*
  1526. * Queue sets provide a mechanism to allow a task to block (pend) on a read
  1527. * operation from multiple queues or semaphores simultaneously.
  1528. *
  1529. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1530. * function.
  1531. *
  1532. * A queue set must be explicitly created using a call to xQueueCreateSet()
  1533. * before it can be used. Once created, standard FreeRTOS queues and semaphores
  1534. * can be added to the set using calls to xQueueAddToSet().
  1535. * xQueueSelectFromSet() is then used to determine which, if any, of the queues
  1536. * or semaphores contained in the set is in a state where a queue read or
  1537. * semaphore take operation would be successful.
  1538. *
  1539. * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
  1540. * for reasons why queue sets are very rarely needed in practice as there are
  1541. * simpler methods of blocking on multiple objects.
  1542. *
  1543. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  1544. * mutex holder to inherit the priority of the blocked task.
  1545. *
  1546. * Note 3: An additional 4 bytes of RAM is required for each space in a every
  1547. * queue added to a queue set. Therefore counting semaphores that have a high
  1548. * maximum count value should not be added to a queue set.
  1549. *
  1550. * Note 4: A receive (in the case of a queue) or take (in the case of a
  1551. * semaphore) operation must not be performed on a member of a queue set unless
  1552. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1553. *
  1554. * @param uxEventQueueLength Queue sets store events that occur on
  1555. * the queues and semaphores contained in the set. uxEventQueueLength specifies
  1556. * the maximum number of events that can be queued at once. To be absolutely
  1557. * certain that events are not lost uxEventQueueLength should be set to the
  1558. * total sum of the length of the queues added to the set, where binary
  1559. * semaphores and mutexes have a length of 1, and counting semaphores have a
  1560. * length set by their maximum count value. Examples:
  1561. * + If a queue set is to hold a queue of length 5, another queue of length 12,
  1562. * and a binary semaphore, then uxEventQueueLength should be set to
  1563. * (5 + 12 + 1), or 18.
  1564. * + If a queue set is to hold three binary semaphores then uxEventQueueLength
  1565. * should be set to (1 + 1 + 1 ), or 3.
  1566. * + If a queue set is to hold a counting semaphore that has a maximum count of
  1567. * 5, and a counting semaphore that has a maximum count of 3, then
  1568. * uxEventQueueLength should be set to (5 + 3), or 8.
  1569. *
  1570. * @return If the queue set is created successfully then a handle to the created
  1571. * queue set is returned. Otherwise NULL is returned.
  1572. */
  1573. QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
  1574. /*
  1575. * Adds a queue or semaphore to a queue set that was previously created by a
  1576. * call to xQueueCreateSet().
  1577. *
  1578. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1579. * function.
  1580. *
  1581. * Note 1: A receive (in the case of a queue) or take (in the case of a
  1582. * semaphore) operation must not be performed on a member of a queue set unless
  1583. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1584. *
  1585. * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
  1586. * the queue set (cast to an QueueSetMemberHandle_t type).
  1587. *
  1588. * @param xQueueSet The handle of the queue set to which the queue or semaphore
  1589. * is being added.
  1590. *
  1591. * @return If the queue or semaphore was successfully added to the queue set
  1592. * then pdPASS is returned. If the queue could not be successfully added to the
  1593. * queue set because it is already a member of a different queue set then pdFAIL
  1594. * is returned.
  1595. */
  1596. BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  1597. QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1598. /*
  1599. * Removes a queue or semaphore from a queue set. A queue or semaphore can only
  1600. * be removed from a set if the queue or semaphore is empty.
  1601. *
  1602. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1603. * function.
  1604. *
  1605. * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
  1606. * from the queue set (cast to an QueueSetMemberHandle_t type).
  1607. *
  1608. * @param xQueueSet The handle of the queue set in which the queue or semaphore
  1609. * is included.
  1610. *
  1611. * @return If the queue or semaphore was successfully removed from the queue set
  1612. * then pdPASS is returned. If the queue was not in the queue set, or the
  1613. * queue (or semaphore) was not empty, then pdFAIL is returned.
  1614. */
  1615. BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  1616. QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1617. /*
  1618. * xQueueSelectFromSet() selects from the members of a queue set a queue or
  1619. * semaphore that either contains data (in the case of a queue) or is available
  1620. * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
  1621. * allows a task to block (pend) on a read operation on all the queues and
  1622. * semaphores in a queue set simultaneously.
  1623. *
  1624. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1625. * function.
  1626. *
  1627. * Note 1: See the documentation on https://www.FreeRTOS.org/RTOS-queue-sets.html
  1628. * for reasons why queue sets are very rarely needed in practice as there are
  1629. * simpler methods of blocking on multiple objects.
  1630. *
  1631. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  1632. * mutex holder to inherit the priority of the blocked task.
  1633. *
  1634. * Note 3: A receive (in the case of a queue) or take (in the case of a
  1635. * semaphore) operation must not be performed on a member of a queue set unless
  1636. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1637. *
  1638. * @param xQueueSet The queue set on which the task will (potentially) block.
  1639. *
  1640. * @param xTicksToWait The maximum time, in ticks, that the calling task will
  1641. * remain in the Blocked state (with other tasks executing) to wait for a member
  1642. * of the queue set to be ready for a successful queue read or semaphore take
  1643. * operation.
  1644. *
  1645. * @return xQueueSelectFromSet() will return the handle of a queue (cast to
  1646. * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
  1647. * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
  1648. * in the queue set that is available, or NULL if no such queue or semaphore
  1649. * exists before before the specified block time expires.
  1650. */
  1651. QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
  1652. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1653. /*
  1654. * A version of xQueueSelectFromSet() that can be used from an ISR.
  1655. */
  1656. QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1657. /* Not public API functions. */
  1658. void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
  1659. TickType_t xTicksToWait,
  1660. const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  1661. BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
  1662. BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
  1663. void vQueueSetQueueNumber( QueueHandle_t xQueue,
  1664. UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
  1665. UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1666. uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1667. /* *INDENT-OFF* */
  1668. #ifdef __cplusplus
  1669. }
  1670. #endif
  1671. /* *INDENT-ON* */
  1672. #endif /* QUEUE_H */