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