queue.h 64 KB

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