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