queue.h 59 KB

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