queue.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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 */