queue.h 68 KB

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