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