queue.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*
  2. FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
  3. FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
  4. http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  5. ***************************************************************************
  6. * *
  7. * FreeRTOS tutorial books are available in pdf and paperback. *
  8. * Complete, revised, and edited pdf reference manuals are also *
  9. * available. *
  10. * *
  11. * Purchasing FreeRTOS documentation will not only help you, by *
  12. * ensuring you get running as quickly as possible and with an *
  13. * in-depth knowledge of how to use FreeRTOS, it will also help *
  14. * the FreeRTOS project to continue with its mission of providing *
  15. * professional grade, cross platform, de facto standard solutions *
  16. * for microcontrollers - completely free of charge! *
  17. * *
  18. * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
  19. * *
  20. * Thank you for using FreeRTOS, and thank you for your support! *
  21. * *
  22. ***************************************************************************
  23. This file is part of the FreeRTOS distribution.
  24. FreeRTOS is free software; you can redistribute it and/or modify it under
  25. the terms of the GNU General Public License (version 2) as published by the
  26. Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  27. >>>NOTE<<< The modification to the GPL is included to allow you to
  28. distribute a combined work that includes FreeRTOS without being obliged to
  29. provide the source code for proprietary components outside of the FreeRTOS
  30. kernel. FreeRTOS is distributed in the hope that it will be useful, but
  31. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  32. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  33. more details. You should have received a copy of the GNU General Public
  34. License and the FreeRTOS license exception along with FreeRTOS; if not it
  35. can be viewed here: http://www.freertos.org/a00114.html and also obtained
  36. by writing to Richard Barry, contact details for whom are available on the
  37. FreeRTOS WEB site.
  38. 1 tab == 4 spaces!
  39. ***************************************************************************
  40. * *
  41. * Having a problem? Start by reading the FAQ "My application does *
  42. * not run, what could be wrong?" *
  43. * *
  44. * http://www.FreeRTOS.org/FAQHelp.html *
  45. * *
  46. ***************************************************************************
  47. http://www.FreeRTOS.org - Documentation, training, latest versions, license
  48. and contact details.
  49. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  50. including FreeRTOS+Trace - an indispensable productivity tool.
  51. Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
  52. the code with commercial support, indemnification, and middleware, under
  53. the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
  54. provide a safety engineered and independently SIL3 certified version under
  55. the SafeRTOS brand: http://www.SafeRTOS.com.
  56. */
  57. #ifndef QUEUE_H
  58. #define QUEUE_H
  59. #ifndef INC_FREERTOS_H
  60. #error "include FreeRTOS.h" must appear in source files before "include queue.h"
  61. #endif
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. #include "mpu_wrappers.h"
  66. /**
  67. * Type by which queues are referenced. For example, a call to xQueueCreate
  68. * returns (via a pointer parameter) an xQueueHandle variable that can then
  69. * be used as a parameter to xQueueSend(), xQueueReceive(), etc.
  70. */
  71. typedef void * xQueueHandle;
  72. /* For internal use only. */
  73. #define queueSEND_TO_BACK ( 0 )
  74. #define queueSEND_TO_FRONT ( 1 )
  75. /* For internal use only. These definitions *must* match those in queue.c. */
  76. #define queueQUEUE_TYPE_BASE ( 0U )
  77. #define queueQUEUE_TYPE_MUTEX ( 1U )
  78. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U )
  79. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U )
  80. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U )
  81. /**
  82. * queue. h
  83. * <pre>
  84. xQueueHandle xQueueCreate(
  85. unsigned portBASE_TYPE uxQueueLength,
  86. unsigned portBASE_TYPE uxItemSize
  87. );
  88. * </pre>
  89. *
  90. * Creates a new queue instance. This allocates the storage required by the
  91. * new queue and returns a handle for the queue.
  92. *
  93. * @param uxQueueLength The maximum number of items that the queue can contain.
  94. *
  95. * @param uxItemSize The number of bytes each item in the queue will require.
  96. * Items are queued by copy, not by reference, so this is the number of bytes
  97. * that will be copied for each posted item. Each item on the queue must be
  98. * the same size.
  99. *
  100. * @return If the queue is successfully create then a handle to the newly
  101. * created queue is returned. If the queue cannot be created then 0 is
  102. * returned.
  103. *
  104. * Example usage:
  105. <pre>
  106. struct AMessage
  107. {
  108. char ucMessageID;
  109. char ucData[ 20 ];
  110. };
  111. void vATask( void *pvParameters )
  112. {
  113. xQueueHandle xQueue1, xQueue2;
  114. // Create a queue capable of containing 10 unsigned long values.
  115. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
  116. if( xQueue1 == 0 )
  117. {
  118. // Queue was not created and must not be used.
  119. }
  120. // Create a queue capable of containing 10 pointers to AMessage structures.
  121. // These should be passed by pointer as they contain a lot of data.
  122. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  123. if( xQueue2 == 0 )
  124. {
  125. // Queue was not created and must not be used.
  126. }
  127. // ... Rest of task code.
  128. }
  129. </pre>
  130. * \defgroup xQueueCreate xQueueCreate
  131. * \ingroup QueueManagement
  132. */
  133. #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
  134. /**
  135. * queue. h
  136. * <pre>
  137. portBASE_TYPE xQueueSendToToFront(
  138. xQueueHandle xQueue,
  139. const void * pvItemToQueue,
  140. portTickType xTicksToWait
  141. );
  142. * </pre>
  143. *
  144. * This is a macro that calls xQueueGenericSend().
  145. *
  146. * Post an item to the front of a queue. The item is queued by copy, not by
  147. * reference. This function must not be called from an interrupt service
  148. * routine. See xQueueSendFromISR () for an alternative which may be used
  149. * in an ISR.
  150. *
  151. * @param xQueue The handle to the queue on which the item is to be posted.
  152. *
  153. * @param pvItemToQueue A pointer to the item that is to be placed on the
  154. * queue. The size of the items the queue will hold was defined when the
  155. * queue was created, so this many bytes will be copied from pvItemToQueue
  156. * into the queue storage area.
  157. *
  158. * @param xTicksToWait The maximum amount of time the task should block
  159. * waiting for space to become available on the queue, should it already
  160. * be full. The call will return immediately if this is set to 0 and the
  161. * queue is full. The time is defined in tick periods so the constant
  162. * portTICK_RATE_MS should be used to convert to real time if this is required.
  163. *
  164. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  165. *
  166. * Example usage:
  167. <pre>
  168. struct AMessage
  169. {
  170. char ucMessageID;
  171. char ucData[ 20 ];
  172. } xMessage;
  173. unsigned long ulVar = 10UL;
  174. void vATask( void *pvParameters )
  175. {
  176. xQueueHandle xQueue1, xQueue2;
  177. struct AMessage *pxMessage;
  178. // Create a queue capable of containing 10 unsigned long values.
  179. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
  180. // Create a queue capable of containing 10 pointers to AMessage structures.
  181. // These should be passed by pointer as they contain a lot of data.
  182. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  183. // ...
  184. if( xQueue1 != 0 )
  185. {
  186. // Send an unsigned long. Wait for 10 ticks for space to become
  187. // available if necessary.
  188. if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
  189. {
  190. // Failed to post the message, even after 10 ticks.
  191. }
  192. }
  193. if( xQueue2 != 0 )
  194. {
  195. // Send a pointer to a struct AMessage object. Don't block if the
  196. // queue is already full.
  197. pxMessage = & xMessage;
  198. xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
  199. }
  200. // ... Rest of task code.
  201. }
  202. </pre>
  203. * \defgroup xQueueSend xQueueSend
  204. * \ingroup QueueManagement
  205. */
  206. #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
  207. /**
  208. * queue. h
  209. * <pre>
  210. portBASE_TYPE xQueueSendToBack(
  211. xQueueHandle xQueue,
  212. const void * pvItemToQueue,
  213. portTickType xTicksToWait
  214. );
  215. * </pre>
  216. *
  217. * This is a macro that calls xQueueGenericSend().
  218. *
  219. * Post an item to the back of a queue. The item is queued by copy, not by
  220. * reference. This function must not be called from an interrupt service
  221. * routine. See xQueueSendFromISR () for an alternative which may be used
  222. * in an ISR.
  223. *
  224. * @param xQueue The handle to the queue on which the item is to be posted.
  225. *
  226. * @param pvItemToQueue A pointer to the item that is to be placed on the
  227. * queue. The size of the items the queue will hold was defined when the
  228. * queue was created, so this many bytes will be copied from pvItemToQueue
  229. * into the queue storage area.
  230. *
  231. * @param xTicksToWait The maximum amount of time the task should block
  232. * waiting for space to become available on the queue, should it already
  233. * be full. The call will return immediately if this is set to 0 and the queue
  234. * is full. The time is defined in tick periods so the constant
  235. * portTICK_RATE_MS should be used to convert to real time if this is required.
  236. *
  237. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  238. *
  239. * Example usage:
  240. <pre>
  241. struct AMessage
  242. {
  243. char ucMessageID;
  244. char ucData[ 20 ];
  245. } xMessage;
  246. unsigned long ulVar = 10UL;
  247. void vATask( void *pvParameters )
  248. {
  249. xQueueHandle xQueue1, xQueue2;
  250. struct AMessage *pxMessage;
  251. // Create a queue capable of containing 10 unsigned long values.
  252. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
  253. // Create a queue capable of containing 10 pointers to AMessage structures.
  254. // These should be passed by pointer as they contain a lot of data.
  255. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  256. // ...
  257. if( xQueue1 != 0 )
  258. {
  259. // Send an unsigned long. Wait for 10 ticks for space to become
  260. // available if necessary.
  261. if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
  262. {
  263. // Failed to post the message, even after 10 ticks.
  264. }
  265. }
  266. if( xQueue2 != 0 )
  267. {
  268. // Send a pointer to a struct AMessage object. Don't block if the
  269. // queue is already full.
  270. pxMessage = & xMessage;
  271. xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
  272. }
  273. // ... Rest of task code.
  274. }
  275. </pre>
  276. * \defgroup xQueueSend xQueueSend
  277. * \ingroup QueueManagement
  278. */
  279. #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  280. /**
  281. * queue. h
  282. * <pre>
  283. portBASE_TYPE xQueueSend(
  284. xQueueHandle xQueue,
  285. const void * pvItemToQueue,
  286. portTickType xTicksToWait
  287. );
  288. * </pre>
  289. *
  290. * This is a macro that calls xQueueGenericSend(). It is included for
  291. * backward compatibility with versions of FreeRTOS.org that did not
  292. * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
  293. * equivalent to xQueueSendToBack().
  294. *
  295. * Post an item on a queue. The item is queued by copy, not by reference.
  296. * This function must not be called from an interrupt service routine.
  297. * See xQueueSendFromISR () for an alternative which may be used 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
  309. * queue is full. The time is defined in tick periods so the constant
  310. * portTICK_RATE_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. unsigned long ulVar = 10UL;
  322. void vATask( void *pvParameters )
  323. {
  324. xQueueHandle xQueue1, xQueue2;
  325. struct AMessage *pxMessage;
  326. // Create a queue capable of containing 10 unsigned long values.
  327. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
  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 unsigned long. Wait for 10 ticks for space to become
  335. // available if necessary.
  336. if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 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. xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
  347. }
  348. // ... Rest of task code.
  349. }
  350. </pre>
  351. * \defgroup xQueueSend xQueueSend
  352. * \ingroup QueueManagement
  353. */
  354. #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  355. /**
  356. * queue. h
  357. * <pre>
  358. portBASE_TYPE xQueueGenericSend(
  359. xQueueHandle xQueue,
  360. const void * pvItemToQueue,
  361. portTickType xTicksToWait
  362. portBASE_TYPE xCopyPosition
  363. );
  364. * </pre>
  365. *
  366. * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
  367. * xQueueSendToBack() are used in place of calling this function directly.
  368. *
  369. * Post an item on a queue. The item is queued by copy, not by reference.
  370. * This function must not be called from an interrupt service routine.
  371. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  372. *
  373. * @param xQueue The handle to the queue on which the item is to be posted.
  374. *
  375. * @param pvItemToQueue A pointer to the item that is to be placed on the
  376. * queue. The size of the items the queue will hold was defined when the
  377. * queue was created, so this many bytes will be copied from pvItemToQueue
  378. * into the queue storage area.
  379. *
  380. * @param xTicksToWait The maximum amount of time the task should block
  381. * waiting for space to become available on the queue, should it already
  382. * be full. The call will return immediately if this is set to 0 and the
  383. * queue is full. The time is defined in tick periods so the constant
  384. * portTICK_RATE_MS should be used to convert to real time if this is required.
  385. *
  386. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  387. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  388. * at the front of the queue (for high priority messages).
  389. *
  390. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  391. *
  392. * Example usage:
  393. <pre>
  394. struct AMessage
  395. {
  396. char ucMessageID;
  397. char ucData[ 20 ];
  398. } xMessage;
  399. unsigned long ulVar = 10UL;
  400. void vATask( void *pvParameters )
  401. {
  402. xQueueHandle xQueue1, xQueue2;
  403. struct AMessage *pxMessage;
  404. // Create a queue capable of containing 10 unsigned long values.
  405. xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
  406. // Create a queue capable of containing 10 pointers to AMessage structures.
  407. // These should be passed by pointer as they contain a lot of data.
  408. xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  409. // ...
  410. if( xQueue1 != 0 )
  411. {
  412. // Send an unsigned long. Wait for 10 ticks for space to become
  413. // available if necessary.
  414. if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
  415. {
  416. // Failed to post the message, even after 10 ticks.
  417. }
  418. }
  419. if( xQueue2 != 0 )
  420. {
  421. // Send a pointer to a struct AMessage object. Don't block if the
  422. // queue is already full.
  423. pxMessage = & xMessage;
  424. xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
  425. }
  426. // ... Rest of task code.
  427. }
  428. </pre>
  429. * \defgroup xQueueSend xQueueSend
  430. * \ingroup QueueManagement
  431. */
  432. signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
  433. /**
  434. * queue. h
  435. * <pre>
  436. portBASE_TYPE xQueuePeek(
  437. xQueueHandle xQueue,
  438. void *pvBuffer,
  439. portTickType xTicksToWait
  440. );</pre>
  441. *
  442. * This is a macro that calls the xQueueGenericReceive() function.
  443. *
  444. * Receive an item from a queue without removing the item from the queue.
  445. * The item is received by copy so a buffer of adequate size must be
  446. * provided. The number of bytes copied into the buffer was defined when
  447. * the queue was created.
  448. *
  449. * Successfully received items remain on the queue so will be returned again
  450. * by the next call, or a call to xQueueReceive().
  451. *
  452. * This macro must not be used in an interrupt service routine.
  453. *
  454. * @param pxQueue The handle to the queue from which the item is to be
  455. * received.
  456. *
  457. * @param pvBuffer Pointer to the buffer into which the received item will
  458. * be copied.
  459. *
  460. * @param xTicksToWait The maximum amount of time the task should block
  461. * waiting for an item to receive should the queue be empty at the time
  462. * of the call. The time is defined in tick periods so the constant
  463. * portTICK_RATE_MS should be used to convert to real time if this is required.
  464. * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
  465. * is empty.
  466. *
  467. * @return pdTRUE if an item was successfully received from the queue,
  468. * otherwise pdFALSE.
  469. *
  470. * Example usage:
  471. <pre>
  472. struct AMessage
  473. {
  474. char ucMessageID;
  475. char ucData[ 20 ];
  476. } xMessage;
  477. xQueueHandle xQueue;
  478. // Task to create a queue and post a value.
  479. void vATask( void *pvParameters )
  480. {
  481. struct AMessage *pxMessage;
  482. // Create a queue capable of containing 10 pointers to AMessage structures.
  483. // These should be passed by pointer as they contain a lot of data.
  484. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  485. if( xQueue == 0 )
  486. {
  487. // Failed to create the queue.
  488. }
  489. // ...
  490. // Send a pointer to a struct AMessage object. Don't block if the
  491. // queue is already full.
  492. pxMessage = & xMessage;
  493. xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
  494. // ... Rest of task code.
  495. }
  496. // Task to peek the data from the queue.
  497. void vADifferentTask( void *pvParameters )
  498. {
  499. struct AMessage *pxRxedMessage;
  500. if( xQueue != 0 )
  501. {
  502. // Peek a message on the created queue. Block for 10 ticks if a
  503. // message is not immediately available.
  504. if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
  505. {
  506. // pcRxedMessage now points to the struct AMessage variable posted
  507. // by vATask, but the item still remains on the queue.
  508. }
  509. }
  510. // ... Rest of task code.
  511. }
  512. </pre>
  513. * \defgroup xQueueReceive xQueueReceive
  514. * \ingroup QueueManagement
  515. */
  516. #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
  517. /**
  518. * queue. h
  519. * <pre>
  520. portBASE_TYPE xQueueReceive(
  521. xQueueHandle xQueue,
  522. void *pvBuffer,
  523. portTickType xTicksToWait
  524. );</pre>
  525. *
  526. * This is a macro that calls the xQueueGenericReceive() function.
  527. *
  528. * Receive an item from a queue. The item is received by copy so a buffer of
  529. * adequate size must be provided. The number of bytes copied into the buffer
  530. * was defined when the queue was created.
  531. *
  532. * Successfully received items are removed from the queue.
  533. *
  534. * This function must not be used in an interrupt service routine. See
  535. * xQueueReceiveFromISR for an alternative that can.
  536. *
  537. * @param pxQueue The handle to the queue from which the item is to be
  538. * received.
  539. *
  540. * @param pvBuffer Pointer to the buffer into which the received item will
  541. * be copied.
  542. *
  543. * @param xTicksToWait The maximum amount of time the task should block
  544. * waiting for an item to receive should the queue be empty at the time
  545. * of the call. xQueueReceive() will return immediately if xTicksToWait
  546. * is zero and the queue is empty. The time is defined in tick periods so the
  547. * constant portTICK_RATE_MS should be used to convert to real time if this is
  548. * required.
  549. *
  550. * @return pdTRUE if an item was successfully received from the queue,
  551. * otherwise pdFALSE.
  552. *
  553. * Example usage:
  554. <pre>
  555. struct AMessage
  556. {
  557. char ucMessageID;
  558. char ucData[ 20 ];
  559. } xMessage;
  560. xQueueHandle xQueue;
  561. // Task to create a queue and post a value.
  562. void vATask( void *pvParameters )
  563. {
  564. struct AMessage *pxMessage;
  565. // Create a queue capable of containing 10 pointers to AMessage structures.
  566. // These should be passed by pointer as they contain a lot of data.
  567. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  568. if( xQueue == 0 )
  569. {
  570. // Failed to create the queue.
  571. }
  572. // ...
  573. // Send a pointer to a struct AMessage object. Don't block if the
  574. // queue is already full.
  575. pxMessage = & xMessage;
  576. xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
  577. // ... Rest of task code.
  578. }
  579. // Task to receive from the queue.
  580. void vADifferentTask( void *pvParameters )
  581. {
  582. struct AMessage *pxRxedMessage;
  583. if( xQueue != 0 )
  584. {
  585. // Receive a message on the created queue. Block for 10 ticks if a
  586. // message is not immediately available.
  587. if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
  588. {
  589. // pcRxedMessage now points to the struct AMessage variable posted
  590. // by vATask.
  591. }
  592. }
  593. // ... Rest of task code.
  594. }
  595. </pre>
  596. * \defgroup xQueueReceive xQueueReceive
  597. * \ingroup QueueManagement
  598. */
  599. #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
  600. /**
  601. * queue. h
  602. * <pre>
  603. portBASE_TYPE xQueueGenericReceive(
  604. xQueueHandle xQueue,
  605. void *pvBuffer,
  606. portTickType xTicksToWait
  607. portBASE_TYPE xJustPeek
  608. );</pre>
  609. *
  610. * It is preferred that the macro xQueueReceive() be used rather than calling
  611. * this function directly.
  612. *
  613. * Receive an item from a queue. The item is received by copy so a buffer of
  614. * adequate size must be provided. The number of bytes copied into the buffer
  615. * was defined when the queue was created.
  616. *
  617. * This function must not be used in an interrupt service routine. See
  618. * xQueueReceiveFromISR for an alternative that can.
  619. *
  620. * @param pxQueue The handle to the queue from which the item is to be
  621. * received.
  622. *
  623. * @param pvBuffer Pointer to the buffer into which the received item will
  624. * be copied.
  625. *
  626. * @param xTicksToWait The maximum amount of time the task should block
  627. * waiting for an item to receive should the queue be empty at the time
  628. * of the call. The time is defined in tick periods so the constant
  629. * portTICK_RATE_MS should be used to convert to real time if this is required.
  630. * xQueueGenericReceive() will return immediately if the queue is empty and
  631. * xTicksToWait is 0.
  632. *
  633. * @param xJustPeek When set to true, the item received from the queue is not
  634. * actually removed from the queue - meaning a subsequent call to
  635. * xQueueReceive() will return the same item. When set to false, the item
  636. * being received from the queue is also removed from the queue.
  637. *
  638. * @return pdTRUE if an item was successfully received from the queue,
  639. * otherwise pdFALSE.
  640. *
  641. * Example usage:
  642. <pre>
  643. struct AMessage
  644. {
  645. char ucMessageID;
  646. char ucData[ 20 ];
  647. } xMessage;
  648. xQueueHandle xQueue;
  649. // Task to create a queue and post a value.
  650. void vATask( void *pvParameters )
  651. {
  652. struct AMessage *pxMessage;
  653. // Create a queue capable of containing 10 pointers to AMessage structures.
  654. // These should be passed by pointer as they contain a lot of data.
  655. xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  656. if( xQueue == 0 )
  657. {
  658. // Failed to create the queue.
  659. }
  660. // ...
  661. // Send a pointer to a struct AMessage object. Don't block if the
  662. // queue is already full.
  663. pxMessage = & xMessage;
  664. xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
  665. // ... Rest of task code.
  666. }
  667. // Task to receive from the queue.
  668. void vADifferentTask( void *pvParameters )
  669. {
  670. struct AMessage *pxRxedMessage;
  671. if( xQueue != 0 )
  672. {
  673. // Receive a message on the created queue. Block for 10 ticks if a
  674. // message is not immediately available.
  675. if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
  676. {
  677. // pcRxedMessage now points to the struct AMessage variable posted
  678. // by vATask.
  679. }
  680. }
  681. // ... Rest of task code.
  682. }
  683. </pre>
  684. * \defgroup xQueueReceive xQueueReceive
  685. * \ingroup QueueManagement
  686. */
  687. signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
  688. /**
  689. * queue. h
  690. * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
  691. *
  692. * Return the number of messages stored in a queue.
  693. *
  694. * @param xQueue A handle to the queue being queried.
  695. *
  696. * @return The number of messages available in the queue.
  697. *
  698. * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
  699. * \ingroup QueueManagement
  700. */
  701. unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
  702. /**
  703. * queue. h
  704. * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
  705. *
  706. * Delete a queue - freeing all the memory allocated for storing of items
  707. * placed on the queue.
  708. *
  709. * @param xQueue A handle to the queue to be deleted.
  710. *
  711. * \page vQueueDelete vQueueDelete
  712. * \ingroup QueueManagement
  713. */
  714. void vQueueDelete( xQueueHandle pxQueue );
  715. /**
  716. * queue. h
  717. * <pre>
  718. portBASE_TYPE xQueueSendToFrontFromISR(
  719. xQueueHandle pxQueue,
  720. const void *pvItemToQueue,
  721. portBASE_TYPE *pxHigherPriorityTaskWoken
  722. );
  723. </pre>
  724. *
  725. * This is a macro that calls xQueueGenericSendFromISR().
  726. *
  727. * Post an item to the front of a queue. It is safe to use this macro from
  728. * within an interrupt service routine.
  729. *
  730. * Items are queued by copy not reference so it is preferable to only
  731. * queue small items, especially when called from an ISR. In most cases
  732. * it would be preferable to store a pointer to the item being queued.
  733. *
  734. * @param xQueue The handle to the queue on which the item is to be posted.
  735. *
  736. * @param pvItemToQueue A pointer to the item that is to be placed on the
  737. * queue. The size of the items the queue will hold was defined when the
  738. * queue was created, so this many bytes will be copied from pvItemToQueue
  739. * into the queue storage area.
  740. *
  741. * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
  742. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  743. * to unblock, and the unblocked task has a priority higher than the currently
  744. * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
  745. * a context switch should be requested before the interrupt is exited.
  746. *
  747. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  748. * errQUEUE_FULL.
  749. *
  750. * Example usage for buffered IO (where the ISR can obtain more than one value
  751. * per call):
  752. <pre>
  753. void vBufferISR( void )
  754. {
  755. char cIn;
  756. portBASE_TYPE xHigherPrioritTaskWoken;
  757. // We have not woken a task at the start of the ISR.
  758. xHigherPriorityTaskWoken = pdFALSE;
  759. // Loop until the buffer is empty.
  760. do
  761. {
  762. // Obtain a byte from the buffer.
  763. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  764. // Post the byte.
  765. xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  766. } while( portINPUT_BYTE( BUFFER_COUNT ) );
  767. // Now the buffer is empty we can switch context if necessary.
  768. if( xHigherPriorityTaskWoken )
  769. {
  770. taskYIELD ();
  771. }
  772. }
  773. </pre>
  774. *
  775. * \defgroup xQueueSendFromISR xQueueSendFromISR
  776. * \ingroup QueueManagement
  777. */
  778. #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
  779. /**
  780. * queue. h
  781. * <pre>
  782. portBASE_TYPE xQueueSendToBackFromISR(
  783. xQueueHandle pxQueue,
  784. const void *pvItemToQueue,
  785. portBASE_TYPE *pxHigherPriorityTaskWoken
  786. );
  787. </pre>
  788. *
  789. * This is a macro that calls xQueueGenericSendFromISR().
  790. *
  791. * Post an item to the back of a queue. It is safe to use this macro from
  792. * within an interrupt service routine.
  793. *
  794. * Items are queued by copy not reference so it is preferable to only
  795. * queue small items, especially when called from an ISR. In most cases
  796. * it would be preferable to store a pointer to the item being queued.
  797. *
  798. * @param xQueue The handle to the queue on which the item is to be posted.
  799. *
  800. * @param pvItemToQueue A pointer to the item that is to be placed on the
  801. * queue. The size of the items the queue will hold was defined when the
  802. * queue was created, so this many bytes will be copied from pvItemToQueue
  803. * into the queue storage area.
  804. *
  805. * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
  806. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  807. * to unblock, and the unblocked task has a priority higher than the currently
  808. * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
  809. * a context switch should be requested before the interrupt is exited.
  810. *
  811. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  812. * errQUEUE_FULL.
  813. *
  814. * Example usage for buffered IO (where the ISR can obtain more than one value
  815. * per call):
  816. <pre>
  817. void vBufferISR( void )
  818. {
  819. char cIn;
  820. portBASE_TYPE xHigherPriorityTaskWoken;
  821. // We have not woken a task at the start of the ISR.
  822. xHigherPriorityTaskWoken = pdFALSE;
  823. // Loop until the buffer is empty.
  824. do
  825. {
  826. // Obtain a byte from the buffer.
  827. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  828. // Post the byte.
  829. xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  830. } while( portINPUT_BYTE( BUFFER_COUNT ) );
  831. // Now the buffer is empty we can switch context if necessary.
  832. if( xHigherPriorityTaskWoken )
  833. {
  834. taskYIELD ();
  835. }
  836. }
  837. </pre>
  838. *
  839. * \defgroup xQueueSendFromISR xQueueSendFromISR
  840. * \ingroup QueueManagement
  841. */
  842. #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  843. /**
  844. * queue. h
  845. * <pre>
  846. portBASE_TYPE xQueueSendFromISR(
  847. xQueueHandle pxQueue,
  848. const void *pvItemToQueue,
  849. portBASE_TYPE *pxHigherPriorityTaskWoken
  850. );
  851. </pre>
  852. *
  853. * This is a macro that calls xQueueGenericSendFromISR(). It is included
  854. * for backward compatibility with versions of FreeRTOS.org that did not
  855. * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
  856. * macros.
  857. *
  858. * Post an item to the back of a queue. It is safe to use this function from
  859. * within an interrupt service routine.
  860. *
  861. * Items are queued by copy not reference so it is preferable to only
  862. * queue small items, especially when called from an ISR. In most cases
  863. * it would be preferable to store a pointer to the item being queued.
  864. *
  865. * @param xQueue The handle to the queue on which the item is to be posted.
  866. *
  867. * @param pvItemToQueue A pointer to the item that is to be placed on the
  868. * queue. The size of the items the queue will hold was defined when the
  869. * queue was created, so this many bytes will be copied from pvItemToQueue
  870. * into the queue storage area.
  871. *
  872. * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
  873. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  874. * to unblock, and the unblocked task has a priority higher than the currently
  875. * running task. If xQueueSendFromISR() sets this value to pdTRUE then
  876. * a context switch should be requested before the interrupt is exited.
  877. *
  878. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  879. * errQUEUE_FULL.
  880. *
  881. * Example usage for buffered IO (where the ISR can obtain more than one value
  882. * per call):
  883. <pre>
  884. void vBufferISR( void )
  885. {
  886. char cIn;
  887. portBASE_TYPE xHigherPriorityTaskWoken;
  888. // We have not woken a task at the start of the ISR.
  889. xHigherPriorityTaskWoken = pdFALSE;
  890. // Loop until the buffer is empty.
  891. do
  892. {
  893. // Obtain a byte from the buffer.
  894. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  895. // Post the byte.
  896. xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  897. } while( portINPUT_BYTE( BUFFER_COUNT ) );
  898. // Now the buffer is empty we can switch context if necessary.
  899. if( xHigherPriorityTaskWoken )
  900. {
  901. // Actual macro used here is port specific.
  902. taskYIELD_FROM_ISR ();
  903. }
  904. }
  905. </pre>
  906. *
  907. * \defgroup xQueueSendFromISR xQueueSendFromISR
  908. * \ingroup QueueManagement
  909. */
  910. #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  911. /**
  912. * queue. h
  913. * <pre>
  914. portBASE_TYPE xQueueGenericSendFromISR(
  915. xQueueHandle pxQueue,
  916. const void *pvItemToQueue,
  917. portBASE_TYPE *pxHigherPriorityTaskWoken,
  918. portBASE_TYPE xCopyPosition
  919. );
  920. </pre>
  921. *
  922. * It is preferred that the macros xQueueSendFromISR(),
  923. * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
  924. * of calling this function directly.
  925. *
  926. * Post an item on a queue. It is safe to use this function from within an
  927. * interrupt service routine.
  928. *
  929. * Items are queued by copy not reference so it is preferable to only
  930. * queue small items, especially when called from an ISR. In most cases
  931. * it would be preferable to store a pointer to the item being queued.
  932. *
  933. * @param xQueue The handle to the queue on which the item is to be posted.
  934. *
  935. * @param pvItemToQueue A pointer to the item that is to be placed on the
  936. * queue. The size of the items the queue will hold was defined when the
  937. * queue was created, so this many bytes will be copied from pvItemToQueue
  938. * into the queue storage area.
  939. *
  940. * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
  941. * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  942. * to unblock, and the unblocked task has a priority higher than the currently
  943. * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
  944. * a context switch should be requested before the interrupt is exited.
  945. *
  946. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  947. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  948. * at the front of the queue (for high priority messages).
  949. *
  950. * @return pdTRUE if the data was successfully sent to the queue, otherwise
  951. * errQUEUE_FULL.
  952. *
  953. * Example usage for buffered IO (where the ISR can obtain more than one value
  954. * per call):
  955. <pre>
  956. void vBufferISR( void )
  957. {
  958. char cIn;
  959. portBASE_TYPE xHigherPriorityTaskWokenByPost;
  960. // We have not woken a task at the start of the ISR.
  961. xHigherPriorityTaskWokenByPost = pdFALSE;
  962. // Loop until the buffer is empty.
  963. do
  964. {
  965. // Obtain a byte from the buffer.
  966. cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  967. // Post each byte.
  968. xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
  969. } while( portINPUT_BYTE( BUFFER_COUNT ) );
  970. // Now the buffer is empty we can switch context if necessary. Note that the
  971. // name of the yield function required is port specific.
  972. if( xHigherPriorityTaskWokenByPost )
  973. {
  974. taskYIELD_YIELD_FROM_ISR();
  975. }
  976. }
  977. </pre>
  978. *
  979. * \defgroup xQueueSendFromISR xQueueSendFromISR
  980. * \ingroup QueueManagement
  981. */
  982. signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
  983. /**
  984. * queue. h
  985. * <pre>
  986. portBASE_TYPE xQueueReceiveFromISR(
  987. xQueueHandle pxQueue,
  988. void *pvBuffer,
  989. portBASE_TYPE *pxTaskWoken
  990. );
  991. * </pre>
  992. *
  993. * Receive an item from a queue. It is safe to use this function from within an
  994. * interrupt service routine.
  995. *
  996. * @param pxQueue The handle to the queue from which the item is to be
  997. * received.
  998. *
  999. * @param pvBuffer Pointer to the buffer into which the received item will
  1000. * be copied.
  1001. *
  1002. * @param pxTaskWoken A task may be blocked waiting for space to become
  1003. * available on the queue. If xQueueReceiveFromISR causes such a task to
  1004. * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  1005. * remain unchanged.
  1006. *
  1007. * @return pdTRUE if an item was successfully received from the queue,
  1008. * otherwise pdFALSE.
  1009. *
  1010. * Example usage:
  1011. <pre>
  1012. xQueueHandle xQueue;
  1013. // Function to create a queue and post some values.
  1014. void vAFunction( void *pvParameters )
  1015. {
  1016. char cValueToPost;
  1017. const portTickType xBlockTime = ( portTickType )0xff;
  1018. // Create a queue capable of containing 10 characters.
  1019. xQueue = xQueueCreate( 10, sizeof( char ) );
  1020. if( xQueue == 0 )
  1021. {
  1022. // Failed to create the queue.
  1023. }
  1024. // ...
  1025. // Post some characters that will be used within an ISR. If the queue
  1026. // is full then this task will block for xBlockTime ticks.
  1027. cValueToPost = 'a';
  1028. xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
  1029. cValueToPost = 'b';
  1030. xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
  1031. // ... keep posting characters ... this task may block when the queue
  1032. // becomes full.
  1033. cValueToPost = 'c';
  1034. xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
  1035. }
  1036. // ISR that outputs all the characters received on the queue.
  1037. void vISR_Routine( void )
  1038. {
  1039. portBASE_TYPE xTaskWokenByReceive = pdFALSE;
  1040. char cRxedChar;
  1041. while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
  1042. {
  1043. // A character was received. Output the character now.
  1044. vOutputCharacter( cRxedChar );
  1045. // If removing the character from the queue woke the task that was
  1046. // posting onto the queue cTaskWokenByReceive will have been set to
  1047. // pdTRUE. No matter how many times this loop iterates only one
  1048. // task will be woken.
  1049. }
  1050. if( cTaskWokenByPost != ( char ) pdFALSE;
  1051. {
  1052. taskYIELD ();
  1053. }
  1054. }
  1055. </pre>
  1056. * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
  1057. * \ingroup QueueManagement
  1058. */
  1059. signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken );
  1060. /*
  1061. * Utilities to query queues that are safe to use from an ISR. These utilities
  1062. * should be used only from witin an ISR, or within a critical section.
  1063. */
  1064. signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
  1065. signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
  1066. unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
  1067. /*
  1068. * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
  1069. * Likewise xQueueAltGenericReceive() is an alternative version of
  1070. * xQueueGenericReceive().
  1071. *
  1072. * The source code that implements the alternative (Alt) API is much
  1073. * simpler because it executes everything from within a critical section.
  1074. * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
  1075. * preferred fully featured API too. The fully featured API has more
  1076. * complex code that takes longer to execute, but makes much less use of
  1077. * critical sections. Therefore the alternative API sacrifices interrupt
  1078. * responsiveness to gain execution speed, whereas the fully featured API
  1079. * sacrifices execution speed to ensure better interrupt responsiveness.
  1080. */
  1081. signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
  1082. signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
  1083. #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
  1084. #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  1085. #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
  1086. #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
  1087. /*
  1088. * The functions defined above are for passing data to and from tasks. The
  1089. * functions below are the equivalents for passing data to and from
  1090. * co-routines.
  1091. *
  1092. * These functions are called from the co-routine macro implementation and
  1093. * should not be called directly from application code. Instead use the macro
  1094. * wrappers defined within croutine.h.
  1095. */
  1096. signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
  1097. signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
  1098. signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
  1099. signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
  1100. /*
  1101. * For internal use only. Use xSemaphoreCreateMutex(),
  1102. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  1103. * these functions directly.
  1104. */
  1105. xQueueHandle xQueueCreateMutex( unsigned char ucQueueType );
  1106. xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
  1107. void* xQueueGetMutexHolder( xQueueHandle xSemaphore );
  1108. /*
  1109. * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  1110. * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  1111. */
  1112. portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
  1113. portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
  1114. /*
  1115. * Reset a queue back to its original empty state. pdPASS is returned if the
  1116. * queue is successfully reset. pdFAIL is returned if the queue could not be
  1117. * reset because there are tasks blocked on the queue waiting to either
  1118. * receive from the queue or send to the queue.
  1119. */
  1120. #define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE )
  1121. /*
  1122. * The registry is provided as a means for kernel aware debuggers to
  1123. * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
  1124. * a queue, semaphore or mutex handle to the registry if you want the handle
  1125. * to be available to a kernel aware debugger. If you are not using a kernel
  1126. * aware debugger then this function can be ignored.
  1127. *
  1128. * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
  1129. * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
  1130. * within FreeRTOSConfig.h for the registry to be available. Its value
  1131. * does not effect the number of queues, semaphores and mutexes that can be
  1132. * created - just the number that the registry can hold.
  1133. *
  1134. * @param xQueue The handle of the queue being added to the registry. This
  1135. * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
  1136. * handles can also be passed in here.
  1137. *
  1138. * @param pcName The name to be associated with the handle. This is the
  1139. * name that the kernel aware debugger will display.
  1140. */
  1141. #if configQUEUE_REGISTRY_SIZE > 0U
  1142. void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
  1143. #endif
  1144. /*
  1145. * Generic version of the queue creation function, which is in turn called by
  1146. * any queue, semaphore or mutex creation function or macro.
  1147. */
  1148. xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
  1149. /* Not public API functions. */
  1150. void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
  1151. portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue );
  1152. #ifdef __cplusplus
  1153. }
  1154. #endif
  1155. #endif /* QUEUE_H */