queue.h 59 KB

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