queue.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. /*
  2. * FreeRTOS Kernel <DEVELOPMENT BRANCH>
  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. #include "task.h"
  34. /* *INDENT-OFF* */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* *INDENT-ON* */
  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_MUTEX ( ( uint8_t ) 1U )
  65. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
  66. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
  67. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
  68. #define queueQUEUE_TYPE_SET ( ( uint8_t ) 5U )
  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 NULL 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 == NULL )
  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 == NULL )
  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 = xQueueCreateStatic( 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 pdPASS 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 pdPASS 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 pdPASS 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 pdPASS 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 pdPASS if an item was successfully received from the queue,
  707. * otherwise errQUEUE_EMPTY.
  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 pdPASS if an item was successfully received from the queue,
  794. * otherwise pdFAIL.
  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 pdPASS if an item was successfully received from the queue,
  834. * otherwise errQUEUE_EMPTY.
  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 pdPASS 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. * // As xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1004. * // switch should be requested. The macro used is port specific and
  1005. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  1006. * // refer to the documentation page for the port being used.
  1007. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1008. * }
  1009. * }
  1010. * @endcode
  1011. *
  1012. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1013. * \ingroup QueueManagement
  1014. */
  1015. #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1016. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
  1017. /**
  1018. * queue. h
  1019. * @code{c}
  1020. * BaseType_t xQueueSendToBackFromISR(
  1021. * QueueHandle_t xQueue,
  1022. * const void *pvItemToQueue,
  1023. * BaseType_t *pxHigherPriorityTaskWoken
  1024. * );
  1025. * @endcode
  1026. *
  1027. * This is a macro that calls xQueueGenericSendFromISR().
  1028. *
  1029. * Post an item to the back of a queue. It is safe to use this macro from
  1030. * within an interrupt service routine.
  1031. *
  1032. * Items are queued by copy not reference so it is preferable to only
  1033. * queue small items, especially when called from an ISR. In most cases
  1034. * it would be preferable to store a pointer to the item being queued.
  1035. *
  1036. * @param xQueue The handle to the queue on which the item is to be posted.
  1037. *
  1038. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1039. * queue. The size of the items the queue will hold was defined when the
  1040. * queue was created, so this many bytes will be copied from pvItemToQueue
  1041. * into the queue storage area.
  1042. *
  1043. * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
  1044. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1045. * to unblock, and the unblocked task has a priority higher than the currently
  1046. * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
  1047. * a context switch should be requested before the interrupt is exited.
  1048. *
  1049. * @return pdPASS if the data was successfully sent to the queue, otherwise
  1050. * errQUEUE_FULL.
  1051. *
  1052. * Example usage for buffered IO (where the ISR can obtain more than one value
  1053. * per call):
  1054. * @code{c}
  1055. * void vBufferISR( void )
  1056. * {
  1057. * char cIn;
  1058. * BaseType_t xHigherPriorityTaskWoken;
  1059. *
  1060. * // We have not woken a task at the start of the ISR.
  1061. * xHigherPriorityTaskWoken = pdFALSE;
  1062. *
  1063. * // Loop until the buffer is empty.
  1064. * do
  1065. * {
  1066. * // Obtain a byte from the buffer.
  1067. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1068. *
  1069. * // Post the byte.
  1070. * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  1071. *
  1072. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1073. *
  1074. * // Now the buffer is empty we can switch context if necessary.
  1075. * if( xHigherPriorityTaskWoken )
  1076. * {
  1077. * // As xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1078. * // switch should be requested. The macro used is port specific and
  1079. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  1080. * // refer to the documentation page for the port being used.
  1081. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1082. * }
  1083. * }
  1084. * @endcode
  1085. *
  1086. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1087. * \ingroup QueueManagement
  1088. */
  1089. #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1090. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  1091. /**
  1092. * queue. h
  1093. * @code{c}
  1094. * BaseType_t xQueueOverwriteFromISR(
  1095. * QueueHandle_t xQueue,
  1096. * const void * pvItemToQueue,
  1097. * BaseType_t *pxHigherPriorityTaskWoken
  1098. * );
  1099. * @endcode
  1100. *
  1101. * A version of xQueueOverwrite() that can be used in an interrupt service
  1102. * routine (ISR).
  1103. *
  1104. * Only for use with queues that can hold a single item - so the queue is either
  1105. * empty or full.
  1106. *
  1107. * Post an item on a queue. If the queue is already full then overwrite the
  1108. * value held in the queue. The item is queued by copy, not by reference.
  1109. *
  1110. * @param xQueue The handle to the queue on which the item is to be posted.
  1111. *
  1112. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1113. * queue. The size of the items the queue will hold was defined when the
  1114. * queue was created, so this many bytes will be copied from pvItemToQueue
  1115. * into the queue storage area.
  1116. *
  1117. * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
  1118. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1119. * to unblock, and the unblocked task has a priority higher than the currently
  1120. * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
  1121. * a context switch should be requested before the interrupt is exited.
  1122. *
  1123. * @return xQueueOverwriteFromISR() is a macro that calls
  1124. * xQueueGenericSendFromISR(), and therefore has the same return values as
  1125. * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
  1126. * returned because xQueueOverwriteFromISR() will write to the queue even when
  1127. * the queue is already full.
  1128. *
  1129. * Example usage:
  1130. * @code{c}
  1131. *
  1132. * QueueHandle_t xQueue;
  1133. *
  1134. * void vFunction( void *pvParameters )
  1135. * {
  1136. * // Create a queue to hold one uint32_t value. It is strongly
  1137. * // recommended *not* to use xQueueOverwriteFromISR() on queues that can
  1138. * // contain more than one value, and doing so will trigger an assertion
  1139. * // if configASSERT() is defined.
  1140. * xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
  1141. * }
  1142. *
  1143. * void vAnInterruptHandler( void )
  1144. * {
  1145. * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
  1146. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  1147. * uint32_t ulVarToSend, ulValReceived;
  1148. *
  1149. * // Write the value 10 to the queue using xQueueOverwriteFromISR().
  1150. * ulVarToSend = 10;
  1151. * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
  1152. *
  1153. * // The queue is full, but calling xQueueOverwriteFromISR() again will still
  1154. * // pass because the value held in the queue will be overwritten with the
  1155. * // new value.
  1156. * ulVarToSend = 100;
  1157. * xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
  1158. *
  1159. * // Reading from the queue will now return 100.
  1160. *
  1161. * // ...
  1162. *
  1163. * if( xHigherPrioritytaskWoken == pdTRUE )
  1164. * {
  1165. * // Writing to the queue caused a task to unblock and the unblocked task
  1166. * // has a priority higher than or equal to the priority of the currently
  1167. * // executing task (the task this interrupt interrupted). Perform a context
  1168. * // switch so this interrupt returns directly to the unblocked task.
  1169. * // The macro used is port specific and will be either
  1170. * // portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to the documentation
  1171. * // page for the port being used.
  1172. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1173. * }
  1174. * }
  1175. * @endcode
  1176. * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
  1177. * \ingroup QueueManagement
  1178. */
  1179. #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1180. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
  1181. /**
  1182. * queue. h
  1183. * @code{c}
  1184. * BaseType_t xQueueSendFromISR(
  1185. * QueueHandle_t xQueue,
  1186. * const void *pvItemToQueue,
  1187. * BaseType_t *pxHigherPriorityTaskWoken
  1188. * );
  1189. * @endcode
  1190. *
  1191. * This is a macro that calls xQueueGenericSendFromISR(). It is included
  1192. * for backward compatibility with versions of FreeRTOS.org that did not
  1193. * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
  1194. * macros.
  1195. *
  1196. * Post an item to the back of a queue. It is safe to use this function from
  1197. * within an interrupt service routine.
  1198. *
  1199. * Items are queued by copy not reference so it is preferable to only
  1200. * queue small items, especially when called from an ISR. In most cases
  1201. * it would be preferable to store a pointer to the item being queued.
  1202. *
  1203. * @param xQueue The handle to the queue on which the item is to be posted.
  1204. *
  1205. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1206. * queue. The size of the items the queue will hold was defined when the
  1207. * queue was created, so this many bytes will be copied from pvItemToQueue
  1208. * into the queue storage area.
  1209. *
  1210. * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
  1211. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1212. * to unblock, and the unblocked task has a priority higher than the currently
  1213. * running task. If xQueueSendFromISR() sets this value to pdTRUE then
  1214. * a context switch should be requested before the interrupt is exited.
  1215. *
  1216. * @return pdPASS if the data was successfully sent to the queue, otherwise
  1217. * errQUEUE_FULL.
  1218. *
  1219. * Example usage for buffered IO (where the ISR can obtain more than one value
  1220. * per call):
  1221. * @code{c}
  1222. * void vBufferISR( void )
  1223. * {
  1224. * char cIn;
  1225. * BaseType_t xHigherPriorityTaskWoken;
  1226. *
  1227. * // We have not woken a task at the start of the ISR.
  1228. * xHigherPriorityTaskWoken = pdFALSE;
  1229. *
  1230. * // Loop until the buffer is empty.
  1231. * do
  1232. * {
  1233. * // Obtain a byte from the buffer.
  1234. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1235. *
  1236. * // Post the byte.
  1237. * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  1238. *
  1239. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1240. *
  1241. * // Now the buffer is empty we can switch context if necessary.
  1242. * if( xHigherPriorityTaskWoken )
  1243. * {
  1244. * // As xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1245. * // switch should be requested. The macro used is port specific and
  1246. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  1247. * // refer to the documentation page for the port being used.
  1248. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1249. * }
  1250. * }
  1251. * @endcode
  1252. *
  1253. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1254. * \ingroup QueueManagement
  1255. */
  1256. #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  1257. xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  1258. /**
  1259. * queue. h
  1260. * @code{c}
  1261. * BaseType_t xQueueGenericSendFromISR(
  1262. * QueueHandle_t xQueue,
  1263. * const void *pvItemToQueue,
  1264. * BaseType_t *pxHigherPriorityTaskWoken,
  1265. * BaseType_t xCopyPosition
  1266. * );
  1267. * @endcode
  1268. *
  1269. * It is preferred that the macros xQueueSendFromISR(),
  1270. * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
  1271. * of calling this function directly. xQueueGiveFromISR() is an
  1272. * equivalent for use by semaphores that don't actually copy any data.
  1273. *
  1274. * Post an item on a queue. It is safe to use this function from within an
  1275. * interrupt service routine.
  1276. *
  1277. * Items are queued by copy not reference so it is preferable to only
  1278. * queue small items, especially when called from an ISR. In most cases
  1279. * it would be preferable to store a pointer to the item being queued.
  1280. *
  1281. * @param xQueue The handle to the queue on which the item is to be posted.
  1282. *
  1283. * @param pvItemToQueue A pointer to the item that is to be placed on the
  1284. * queue. The size of the items the queue will hold was defined when the
  1285. * queue was created, so this many bytes will be copied from pvItemToQueue
  1286. * into the queue storage area.
  1287. *
  1288. * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
  1289. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  1290. * to unblock, and the unblocked task has a priority higher than the currently
  1291. * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
  1292. * a context switch should be requested before the interrupt is exited.
  1293. *
  1294. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  1295. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  1296. * at the front of the queue (for high priority messages).
  1297. *
  1298. * @return pdPASS if the data was successfully sent to the queue, otherwise
  1299. * errQUEUE_FULL.
  1300. *
  1301. * Example usage for buffered IO (where the ISR can obtain more than one value
  1302. * per call):
  1303. * @code{c}
  1304. * void vBufferISR( void )
  1305. * {
  1306. * char cIn;
  1307. * BaseType_t xHigherPriorityTaskWokenByPost;
  1308. *
  1309. * // We have not woken a task at the start of the ISR.
  1310. * xHigherPriorityTaskWokenByPost = pdFALSE;
  1311. *
  1312. * // Loop until the buffer is empty.
  1313. * do
  1314. * {
  1315. * // Obtain a byte from the buffer.
  1316. * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  1317. *
  1318. * // Post each byte.
  1319. * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
  1320. *
  1321. * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  1322. *
  1323. * // Now the buffer is empty we can switch context if necessary.
  1324. * if( xHigherPriorityTaskWokenByPost )
  1325. * {
  1326. * // As xHigherPriorityTaskWokenByPost is now set to pdTRUE then a context
  1327. * // switch should be requested. The macro used is port specific and
  1328. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  1329. * // refer to the documentation page for the port being used.
  1330. * portYIELD_FROM_ISR( xHigherPriorityTaskWokenByPost );
  1331. * }
  1332. * }
  1333. * @endcode
  1334. *
  1335. * \defgroup xQueueSendFromISR xQueueSendFromISR
  1336. * \ingroup QueueManagement
  1337. */
  1338. BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
  1339. const void * const pvItemToQueue,
  1340. BaseType_t * const pxHigherPriorityTaskWoken,
  1341. const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
  1342. BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
  1343. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1344. /**
  1345. * queue. h
  1346. * @code{c}
  1347. * BaseType_t xQueueReceiveFromISR(
  1348. * QueueHandle_t xQueue,
  1349. * void *pvBuffer,
  1350. * BaseType_t *pxTaskWoken
  1351. * );
  1352. * @endcode
  1353. *
  1354. * Receive an item from a queue. It is safe to use this function from within an
  1355. * interrupt service routine.
  1356. *
  1357. * @param xQueue The handle to the queue from which the item is to be
  1358. * received.
  1359. *
  1360. * @param pvBuffer Pointer to the buffer into which the received item will
  1361. * be copied.
  1362. *
  1363. * @param pxHigherPriorityTaskWoken A task may be blocked waiting for space to
  1364. * become available on the queue. If xQueueReceiveFromISR causes such a task
  1365. * to unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  1366. * remain unchanged.
  1367. *
  1368. * @return pdPASS if an item was successfully received from the queue,
  1369. * otherwise pdFAIL.
  1370. *
  1371. * Example usage:
  1372. * @code{c}
  1373. *
  1374. * QueueHandle_t xQueue;
  1375. *
  1376. * // Function to create a queue and post some values.
  1377. * void vAFunction( void *pvParameters )
  1378. * {
  1379. * char cValueToPost;
  1380. * const TickType_t xTicksToWait = ( TickType_t )0xff;
  1381. *
  1382. * // Create a queue capable of containing 10 characters.
  1383. * xQueue = xQueueCreate( 10, sizeof( char ) );
  1384. * if( xQueue == 0 )
  1385. * {
  1386. * // Failed to create the queue.
  1387. * }
  1388. *
  1389. * // ...
  1390. *
  1391. * // Post some characters that will be used within an ISR. If the queue
  1392. * // is full then this task will block for xTicksToWait ticks.
  1393. * cValueToPost = 'a';
  1394. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1395. * cValueToPost = 'b';
  1396. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1397. *
  1398. * // ... keep posting characters ... this task may block when the queue
  1399. * // becomes full.
  1400. *
  1401. * cValueToPost = 'c';
  1402. * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  1403. * }
  1404. *
  1405. * // ISR that outputs all the characters received on the queue.
  1406. * void vISR_Routine( void )
  1407. * {
  1408. * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  1409. * char cRxedChar;
  1410. *
  1411. * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xHigherPriorityTaskWoken) )
  1412. * {
  1413. * // A character was received. Output the character now.
  1414. * vOutputCharacter( cRxedChar );
  1415. *
  1416. * // If removing the character from the queue woke the task that was
  1417. * // posting onto the queue xHigherPriorityTaskWoken will have been set to
  1418. * // pdTRUE. No matter how many times this loop iterates only one
  1419. * // task will be woken.
  1420. * }
  1421. *
  1422. * if( xHigherPrioritytaskWoken == pdTRUE );
  1423. * {
  1424. * // As xHigherPriorityTaskWoken is now set to pdTRUE then a context
  1425. * // switch should be requested. The macro used is port specific and
  1426. * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  1427. * // refer to the documentation page for the port being used.
  1428. * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  1429. * }
  1430. * }
  1431. * @endcode
  1432. * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
  1433. * \ingroup QueueManagement
  1434. */
  1435. BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
  1436. void * const pvBuffer,
  1437. BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1438. /*
  1439. * Utilities to query queues that are safe to use from an ISR. These utilities
  1440. * should be used only from within an ISR, or within a critical section.
  1441. */
  1442. BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1443. BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1444. UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1445. #if ( configUSE_CO_ROUTINES == 1 )
  1446. /*
  1447. * The functions defined above are for passing data to and from tasks. The
  1448. * functions below are the equivalents for passing data to and from
  1449. * co-routines.
  1450. *
  1451. * These functions are called from the co-routine macro implementation and
  1452. * should not be called directly from application code. Instead use the macro
  1453. * wrappers defined within croutine.h.
  1454. */
  1455. BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue,
  1456. const void * pvItemToQueue,
  1457. BaseType_t xCoRoutinePreviouslyWoken );
  1458. BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue,
  1459. void * pvBuffer,
  1460. BaseType_t * pxTaskWoken );
  1461. BaseType_t xQueueCRSend( QueueHandle_t xQueue,
  1462. const void * pvItemToQueue,
  1463. TickType_t xTicksToWait );
  1464. BaseType_t xQueueCRReceive( QueueHandle_t xQueue,
  1465. void * pvBuffer,
  1466. TickType_t xTicksToWait );
  1467. #endif /* if ( configUSE_CO_ROUTINES == 1 ) */
  1468. /*
  1469. * For internal use only. Use xSemaphoreCreateMutex(),
  1470. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  1471. * these functions directly.
  1472. */
  1473. QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1474. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1475. QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  1476. StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
  1477. #endif
  1478. #if ( configUSE_COUNTING_SEMAPHORES == 1 )
  1479. QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
  1480. const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
  1481. #endif
  1482. #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  1483. QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
  1484. const UBaseType_t uxInitialCount,
  1485. StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
  1486. #endif
  1487. BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  1488. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1489. #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
  1490. TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
  1491. TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
  1492. #endif
  1493. /*
  1494. * For internal use only. Use xSemaphoreTakeRecursive() or
  1495. * xSemaphoreGiveRecursive() instead of calling these functions directly.
  1496. */
  1497. BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  1498. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1499. BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
  1500. /*
  1501. * Reset a queue back to its original empty state. The return value is now
  1502. * obsolete and is always set to pdPASS.
  1503. */
  1504. #define xQueueReset( xQueue ) xQueueGenericReset( ( xQueue ), pdFALSE )
  1505. /*
  1506. * The registry is provided as a means for kernel aware debuggers to
  1507. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  1508. * a queue, semaphore or mutex handle to the registry if you want the handle
  1509. * to be available to a kernel aware debugger. If you are not using a kernel
  1510. * aware debugger then this function can be ignored.
  1511. *
  1512. * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
  1513. * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
  1514. * within FreeRTOSConfig.h for the registry to be available. Its value
  1515. * does not affect the number of queues, semaphores and mutexes that can be
  1516. * created - just the number that the registry can hold.
  1517. *
  1518. * If vQueueAddToRegistry is called more than once with the same xQueue
  1519. * parameter, the registry will store the pcQueueName parameter from the
  1520. * most recent call to vQueueAddToRegistry.
  1521. *
  1522. * @param xQueue The handle of the queue being added to the registry. This
  1523. * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
  1524. * handles can also be passed in here.
  1525. *
  1526. * @param pcQueueName The name to be associated with the handle. This is the
  1527. * name that the kernel aware debugger will display. The queue registry only
  1528. * stores a pointer to the string - so the string must be persistent (global or
  1529. * preferably in ROM/Flash), not on the stack.
  1530. */
  1531. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1532. void vQueueAddToRegistry( QueueHandle_t xQueue,
  1533. const char * pcQueueName ) PRIVILEGED_FUNCTION;
  1534. #endif
  1535. /*
  1536. * The registry is provided as a means for kernel aware debuggers to
  1537. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  1538. * a queue, semaphore or mutex handle to the registry if you want the handle
  1539. * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
  1540. * remove the queue, semaphore or mutex from the register. If you are not using
  1541. * a kernel aware debugger then this function can be ignored.
  1542. *
  1543. * @param xQueue The handle of the queue being removed from the registry.
  1544. */
  1545. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1546. void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1547. #endif
  1548. /*
  1549. * The queue registry is provided as a means for kernel aware debuggers to
  1550. * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
  1551. * up and return the name of a queue in the queue registry from the queue's
  1552. * handle.
  1553. *
  1554. * @param xQueue The handle of the queue the name of which will be returned.
  1555. * @return If the queue is in the registry then a pointer to the name of the
  1556. * queue is returned. If the queue is not in the registry then NULL is
  1557. * returned.
  1558. */
  1559. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  1560. const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1561. #endif
  1562. /*
  1563. * Generic version of the function used to create a queue using dynamic memory
  1564. * allocation. This is called by other functions and macros that create other
  1565. * RTOS objects that use the queue structure as their base.
  1566. */
  1567. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  1568. QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  1569. const UBaseType_t uxItemSize,
  1570. const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1571. #endif
  1572. /*
  1573. * Generic version of the function used to create a queue using dynamic memory
  1574. * allocation. This is called by other functions and macros that create other
  1575. * RTOS objects that use the queue structure as their base.
  1576. */
  1577. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1578. QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  1579. const UBaseType_t uxItemSize,
  1580. uint8_t * pucQueueStorage,
  1581. StaticQueue_t * pxStaticQueue,
  1582. const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
  1583. #endif
  1584. /*
  1585. * Generic version of the function used to retrieve the buffers of statically
  1586. * created queues. This is called by other functions and macros that retrieve
  1587. * the buffers of other statically created RTOS objects that use the queue
  1588. * structure as their base.
  1589. */
  1590. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1591. BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
  1592. uint8_t ** ppucQueueStorage,
  1593. StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION;
  1594. #endif
  1595. /*
  1596. * Queue sets provide a mechanism to allow a task to block (pend) on a read
  1597. * operation from multiple queues or semaphores simultaneously.
  1598. *
  1599. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1600. * function.
  1601. *
  1602. * A queue set must be explicitly created using a call to xQueueCreateSet() or
  1603. * xQueueCreateSetStatic() before it can be used. Once created, standard
  1604. * FreeRTOS queues and semaphores can be added to the set using calls to
  1605. * xQueueAddToSet(). xQueueSelectFromSet() is then used to determine which, if
  1606. * any, of the queues or semaphores contained in the set is in a state where a
  1607. * queue read or semaphore take operation would be successful.
  1608. *
  1609. * Note 1: See the documentation on https://www.freertos.org/Documentation/02-Kernel/04-API-references/07-Queue-sets/00-RTOS-queue-sets
  1610. * for reasons why queue sets are very rarely needed in practice as there are
  1611. * simpler methods of blocking on multiple objects.
  1612. *
  1613. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  1614. * mutex holder to inherit the priority of the blocked task.
  1615. *
  1616. * Note 3: An additional 4 bytes of RAM is required for each space in a every
  1617. * queue added to a queue set. Therefore counting semaphores that have a high
  1618. * maximum count value should not be added to a queue set.
  1619. *
  1620. * Note 4: A receive (in the case of a queue) or take (in the case of a
  1621. * semaphore) operation must not be performed on a member of a queue set unless
  1622. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1623. *
  1624. * @param uxEventQueueLength Queue sets store events that occur on
  1625. * the queues and semaphores contained in the set. uxEventQueueLength specifies
  1626. * the maximum number of events that can be queued at once. To be absolutely
  1627. * certain that events are not lost uxEventQueueLength should be set to the
  1628. * total sum of the length of the queues added to the set, where binary
  1629. * semaphores and mutexes have a length of 1, and counting semaphores have a
  1630. * length set by their maximum count value. Examples:
  1631. * + If a queue set is to hold a queue of length 5, another queue of length 12,
  1632. * and a binary semaphore, then uxEventQueueLength should be set to
  1633. * (5 + 12 + 1), or 18.
  1634. * + If a queue set is to hold three binary semaphores then uxEventQueueLength
  1635. * should be set to (1 + 1 + 1 ), or 3.
  1636. * + If a queue set is to hold a counting semaphore that has a maximum count of
  1637. * 5, and a counting semaphore that has a maximum count of 3, then
  1638. * uxEventQueueLength should be set to (5 + 3), or 8.
  1639. *
  1640. * @return If the queue set is created successfully then a handle to the created
  1641. * queue set is returned. Otherwise NULL is returned.
  1642. */
  1643. #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
  1644. QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
  1645. #endif
  1646. /*
  1647. * Queue sets provide a mechanism to allow a task to block (pend) on a read
  1648. * operation from multiple queues or semaphores simultaneously.
  1649. *
  1650. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1651. * function.
  1652. *
  1653. * A queue set must be explicitly created using a call to xQueueCreateSet()
  1654. * or xQueueCreateSetStatic() before it can be used. Once created, standard
  1655. * FreeRTOS queues and semaphores can be added to the set using calls to
  1656. * xQueueAddToSet(). xQueueSelectFromSet() is then used to determine which, if
  1657. * any, of the queues or semaphores contained in the set is in a state where a
  1658. * queue read or semaphore take operation would be successful.
  1659. *
  1660. * Note 1: See the documentation on https://www.freertos.org/Documentation/02-Kernel/04-API-references/07-Queue-sets/00-RTOS-queue-sets
  1661. * for reasons why queue sets are very rarely needed in practice as there are
  1662. * simpler methods of blocking on multiple objects.
  1663. *
  1664. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  1665. * mutex holder to inherit the priority of the blocked task.
  1666. *
  1667. * Note 3: An additional 4 bytes of RAM is required for each space in a every
  1668. * queue added to a queue set. Therefore counting semaphores that have a high
  1669. * maximum count value should not be added to a queue set.
  1670. *
  1671. * Note 4: A receive (in the case of a queue) or take (in the case of a
  1672. * semaphore) operation must not be performed on a member of a queue set unless
  1673. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1674. *
  1675. * @param uxEventQueueLength Queue sets store events that occur on
  1676. * the queues and semaphores contained in the set. uxEventQueueLength specifies
  1677. * the maximum number of events that can be queued at once. To be absolutely
  1678. * certain that events are not lost uxEventQueueLength should be set to the
  1679. * total sum of the length of the queues added to the set, where binary
  1680. * semaphores and mutexes have a length of 1, and counting semaphores have a
  1681. * length set by their maximum count value. Examples:
  1682. * + If a queue set is to hold a queue of length 5, another queue of length 12,
  1683. * and a binary semaphore, then uxEventQueueLength should be set to
  1684. * (5 + 12 + 1), or 18.
  1685. * + If a queue set is to hold three binary semaphores then uxEventQueueLength
  1686. * should be set to (1 + 1 + 1 ), or 3.
  1687. * + If a queue set is to hold a counting semaphore that has a maximum count of
  1688. * 5, and a counting semaphore that has a maximum count of 3, then
  1689. * uxEventQueueLength should be set to (5 + 3), or 8.
  1690. *
  1691. * @param pucQueueStorage pucQueueStorage must point to a uint8_t array that is
  1692. * at least large enough to hold uxEventQueueLength events.
  1693. *
  1694. * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
  1695. * will be used to hold the queue's data structure.
  1696. *
  1697. * @return If the queue set is created successfully then a handle to the created
  1698. * queue set is returned. If pxQueueBuffer is NULL then NULL is returned.
  1699. */
  1700. #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  1701. QueueSetHandle_t xQueueCreateSetStatic( const UBaseType_t uxEventQueueLength,
  1702. uint8_t * pucQueueStorage,
  1703. StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION;
  1704. #endif
  1705. /*
  1706. * Adds a queue or semaphore to a queue set that was previously created by a
  1707. * call to xQueueCreateSet() or xQueueCreateSetStatic().
  1708. *
  1709. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1710. * function.
  1711. *
  1712. * Note 1: A receive (in the case of a queue) or take (in the case of a
  1713. * semaphore) operation must not be performed on a member of a queue set unless
  1714. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1715. *
  1716. * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
  1717. * the queue set (cast to an QueueSetMemberHandle_t type).
  1718. *
  1719. * @param xQueueSet The handle of the queue set to which the queue or semaphore
  1720. * is being added.
  1721. *
  1722. * @return If the queue or semaphore was successfully added to the queue set
  1723. * then pdPASS is returned. If the queue could not be successfully added to the
  1724. * queue set because it is already a member of a different queue set then pdFAIL
  1725. * is returned.
  1726. */
  1727. #if ( configUSE_QUEUE_SETS == 1 )
  1728. BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  1729. QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1730. #endif
  1731. /*
  1732. * Removes a queue or semaphore from a queue set. A queue or semaphore can only
  1733. * be removed from a set if the queue or semaphore is empty.
  1734. *
  1735. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1736. * function.
  1737. *
  1738. * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
  1739. * from the queue set (cast to an QueueSetMemberHandle_t type).
  1740. *
  1741. * @param xQueueSet The handle of the queue set in which the queue or semaphore
  1742. * is included.
  1743. *
  1744. * @return If the queue or semaphore was successfully removed from the queue set
  1745. * then pdPASS is returned. If the queue was not in the queue set, or the
  1746. * queue (or semaphore) was not empty, then pdFAIL is returned.
  1747. */
  1748. #if ( configUSE_QUEUE_SETS == 1 )
  1749. BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  1750. QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1751. #endif
  1752. /*
  1753. * xQueueSelectFromSet() selects from the members of a queue set a queue or
  1754. * semaphore that either contains data (in the case of a queue) or is available
  1755. * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
  1756. * allows a task to block (pend) on a read operation on all the queues and
  1757. * semaphores in a queue set simultaneously.
  1758. *
  1759. * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
  1760. * function.
  1761. *
  1762. * Note 1: See the documentation on https://www.freertos.org/Documentation/02-Kernel/04-API-references/07-Queue-sets/00-RTOS-queue-sets
  1763. * for reasons why queue sets are very rarely needed in practice as there are
  1764. * simpler methods of blocking on multiple objects.
  1765. *
  1766. * Note 2: Blocking on a queue set that contains a mutex will not cause the
  1767. * mutex holder to inherit the priority of the blocked task.
  1768. *
  1769. * Note 3: A receive (in the case of a queue) or take (in the case of a
  1770. * semaphore) operation must not be performed on a member of a queue set unless
  1771. * a call to xQueueSelectFromSet() has first returned a handle to that set member.
  1772. *
  1773. * @param xQueueSet The queue set on which the task will (potentially) block.
  1774. *
  1775. * @param xTicksToWait The maximum time, in ticks, that the calling task will
  1776. * remain in the Blocked state (with other tasks executing) to wait for a member
  1777. * of the queue set to be ready for a successful queue read or semaphore take
  1778. * operation.
  1779. *
  1780. * @return xQueueSelectFromSet() will return the handle of a queue (cast to
  1781. * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
  1782. * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
  1783. * in the queue set that is available, or NULL if no such queue or semaphore
  1784. * exists before before the specified block time expires.
  1785. */
  1786. #if ( configUSE_QUEUE_SETS == 1 )
  1787. QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
  1788. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1789. #endif
  1790. /*
  1791. * A version of xQueueSelectFromSet() that can be used from an ISR.
  1792. */
  1793. #if ( configUSE_QUEUE_SETS == 1 )
  1794. QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
  1795. #endif
  1796. /* Not public API functions. */
  1797. void vQueueWaitForMessageRestricted( QueueHandle_t xQueue,
  1798. TickType_t xTicksToWait,
  1799. const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  1800. BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
  1801. BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
  1802. #if ( configUSE_TRACE_FACILITY == 1 )
  1803. void vQueueSetQueueNumber( QueueHandle_t xQueue,
  1804. UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
  1805. #endif
  1806. #if ( configUSE_TRACE_FACILITY == 1 )
  1807. UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1808. #endif
  1809. #if ( configUSE_TRACE_FACILITY == 1 )
  1810. uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1811. #endif
  1812. UBaseType_t uxQueueGetQueueItemSize( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1813. UBaseType_t uxQueueGetQueueLength( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
  1814. /* *INDENT-OFF* */
  1815. #ifdef __cplusplus
  1816. }
  1817. #endif
  1818. /* *INDENT-ON* */
  1819. #endif /* QUEUE_H */