queue.h 67 KB

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