forked from FreeRTOS/FreeRTOS-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.h
1810 lines (1748 loc) · 67.4 KB
/
queue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef QUEUE_H
#define QUEUE_H
#ifndef INC_FREERTOS_H
#error "include FreeRTOS.h" must appear in source files before "include queue.h"
#endif
#include "task.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* Type by which queues are referenced. For example, a call to xQueueCreate()
* returns an QueueHandle_t variable that can then be used as a parameter to
* xQueueSend(), xQueueReceive(), etc.
*/
struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
typedef struct QueueDefinition * QueueHandle_t;
/**
* Type by which queue sets are referenced. For example, a call to
* xQueueCreateSet() returns an xQueueSet variable that can then be used as a
* parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
*/
typedef struct QueueDefinition * QueueSetHandle_t;
/**
* Queue sets can contain both queues and semaphores, so the
* QueueSetMemberHandle_t is defined as a type to be used where a parameter or
* return value can be either an QueueHandle_t or an SemaphoreHandle_t.
*/
typedef struct QueueDefinition * QueueSetMemberHandle_t;
/* For internal use only. */
#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
#define queueOVERWRITE ( ( BaseType_t ) 2 )
/* For internal use only. These definitions *must* match those in queue.c. */
#define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
#define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
/**
* queue. h
* @code{c}
* QueueHandle_t xQueueCreate(
* UBaseType_t uxQueueLength,
* UBaseType_t uxItemSize
* );
* @endcode
*
* Creates a new queue instance, and returns a handle by which the new queue
* can be referenced.
*
* Internally, within the FreeRTOS implementation, queues use two blocks of
* memory. The first block is used to hold the queue's data structures. The
* second block is used to hold items placed into the queue. If a queue is
* created using xQueueCreate() then both blocks of memory are automatically
* dynamically allocated inside the xQueueCreate() function. (see
* https://www.FreeRTOS.org/a00111.html). If a queue is created using
* xQueueCreateStatic() then the application writer must provide the memory that
* will get used by the queue. xQueueCreateStatic() therefore allows a queue to
* be created without using any dynamic memory allocation.
*
* https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
*
* @param uxQueueLength The maximum number of items that the queue can contain.
*
* @param uxItemSize The number of bytes each item in the queue will require.
* Items are queued by copy, not by reference, so this is the number of bytes
* that will be copied for each posted item. Each item on the queue must be
* the same size.
*
* @return If the queue is successfully create then a handle to the newly
* created queue is returned. If the queue cannot be created then 0 is
* returned.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* };
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1, xQueue2;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
* if( xQueue1 == 0 )
* {
* // Queue was not created and must not be used.
* }
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
* if( xQueue2 == 0 )
* {
* // Queue was not created and must not be used.
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueCreate xQueueCreate
* \ingroup QueueManagement
*/
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
#define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
#endif
/**
* queue. h
* @code{c}
* QueueHandle_t xQueueCreateStatic(
* UBaseType_t uxQueueLength,
* UBaseType_t uxItemSize,
* uint8_t *pucQueueStorage,
* StaticQueue_t *pxQueueBuffer
* );
* @endcode
*
* Creates a new queue instance, and returns a handle by which the new queue
* can be referenced.
*
* Internally, within the FreeRTOS implementation, queues use two blocks of
* memory. The first block is used to hold the queue's data structures. The
* second block is used to hold items placed into the queue. If a queue is
* created using xQueueCreate() then both blocks of memory are automatically
* dynamically allocated inside the xQueueCreate() function. (see
* https://www.FreeRTOS.org/a00111.html). If a queue is created using
* xQueueCreateStatic() then the application writer must provide the memory that
* will get used by the queue. xQueueCreateStatic() therefore allows a queue to
* be created without using any dynamic memory allocation.
*
* https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
*
* @param uxQueueLength The maximum number of items that the queue can contain.
*
* @param uxItemSize The number of bytes each item in the queue will require.
* Items are queued by copy, not by reference, so this is the number of bytes
* that will be copied for each posted item. Each item on the queue must be
* the same size.
*
* @param pucQueueStorage If uxItemSize is not zero then
* pucQueueStorage must point to a uint8_t array that is at least large
* enough to hold the maximum number of items that can be in the queue at any
* one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
* zero then pucQueueStorage can be NULL.
*
* @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
* will be used to hold the queue's data structure.
*
* @return If the queue is created then a handle to the created queue is
* returned. If pxQueueBuffer is NULL then NULL is returned.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* };
*
#define QUEUE_LENGTH 10
#define ITEM_SIZE sizeof( uint32_t )
*
* // xQueueBuffer will hold the queue structure.
* StaticQueue_t xQueueBuffer;
*
* // ucQueueStorage will hold the items posted to the queue. Must be at least
* // [(queue length) * ( queue item size)] bytes long.
* uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
* ITEM_SIZE // The size of each item in the queue
* &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
* &xQueueBuffer ); // The buffer that will hold the queue structure.
*
* // The queue is guaranteed to be created successfully as no dynamic memory
* // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueCreateStatic xQueueCreateStatic
* \ingroup QueueManagement
*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
#define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
#endif /* configSUPPORT_STATIC_ALLOCATION */
/**
* queue. h
* @code{c}
* BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue,
* uint8_t ** ppucQueueStorage,
* StaticQueue_t ** ppxStaticQueue );
* @endcode
*
* Retrieve pointers to a statically created queue's data structure buffer
* and storage area buffer. These are the same buffers that are supplied
* at the time of creation.
*
* @param xQueue The queue for which to retrieve the buffers.
*
* @param ppucQueueStorage Used to return a pointer to the queue's storage
* area buffer.
*
* @param ppxStaticQueue Used to return a pointer to the queue's data
* structure buffer.
*
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
*
* \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers
* \ingroup QueueManagement
*/
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
#define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) )
#endif /* configSUPPORT_STATIC_ALLOCATION */
/**
* queue. h
* @code{c}
* BaseType_t xQueueSendToFront(
* QueueHandle_t xQueue,
* const void *pvItemToQueue,
* TickType_t xTicksToWait
* );
* @endcode
*
* Post an item to the front of a queue. The item is queued by copy, not by
* reference. This function must not be called from an interrupt service
* routine. See xQueueSendFromISR () for an alternative which may be used
* in an ISR.
*
* @param xQueue The handle to the queue on which the item is to be posted.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for space to become available on the queue, should it already
* be full. The call will return immediately if this is set to 0 and the
* queue is full. The time is defined in tick periods so the constant
* portTICK_PERIOD_MS should be used to convert to real time if this is required.
*
* @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* uint32_t ulVar = 10U;
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1, xQueue2;
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
*
* // ...
*
* if( xQueue1 != 0 )
* {
* // Send an uint32_t. Wait for 10 ticks for space to become
* // available if necessary.
* if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
* {
* // Failed to post the message, even after 10 ticks.
* }
* }
*
* if( xQueue2 != 0 )
* {
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueSend xQueueSend
* \ingroup QueueManagement
*/
#define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
/**
* queue. h
* @code{c}
* BaseType_t xQueueSendToBack(
* QueueHandle_t xQueue,
* const void *pvItemToQueue,
* TickType_t xTicksToWait
* );
* @endcode
*
* This is a macro that calls xQueueGenericSend().
*
* Post an item to the back of a queue. The item is queued by copy, not by
* reference. This function must not be called from an interrupt service
* routine. See xQueueSendFromISR () for an alternative which may be used
* in an ISR.
*
* @param xQueue The handle to the queue on which the item is to be posted.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for space to become available on the queue, should it already
* be full. The call will return immediately if this is set to 0 and the queue
* is full. The time is defined in tick periods so the constant
* portTICK_PERIOD_MS should be used to convert to real time if this is required.
*
* @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* uint32_t ulVar = 10U;
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1, xQueue2;
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
*
* // ...
*
* if( xQueue1 != 0 )
* {
* // Send an uint32_t. Wait for 10 ticks for space to become
* // available if necessary.
* if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
* {
* // Failed to post the message, even after 10 ticks.
* }
* }
*
* if( xQueue2 != 0 )
* {
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueSend xQueueSend
* \ingroup QueueManagement
*/
#define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
/**
* queue. h
* @code{c}
* BaseType_t xQueueSend(
* QueueHandle_t xQueue,
* const void * pvItemToQueue,
* TickType_t xTicksToWait
* );
* @endcode
*
* This is a macro that calls xQueueGenericSend(). It is included for
* backward compatibility with versions of FreeRTOS.org that did not
* include the xQueueSendToFront() and xQueueSendToBack() macros. It is
* equivalent to xQueueSendToBack().
*
* Post an item on a queue. The item is queued by copy, not by reference.
* This function must not be called from an interrupt service routine.
* See xQueueSendFromISR () for an alternative which may be used in an ISR.
*
* @param xQueue The handle to the queue on which the item is to be posted.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for space to become available on the queue, should it already
* be full. The call will return immediately if this is set to 0 and the
* queue is full. The time is defined in tick periods so the constant
* portTICK_PERIOD_MS should be used to convert to real time if this is required.
*
* @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* uint32_t ulVar = 10U;
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1, xQueue2;
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
*
* // ...
*
* if( xQueue1 != 0 )
* {
* // Send an uint32_t. Wait for 10 ticks for space to become
* // available if necessary.
* if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
* {
* // Failed to post the message, even after 10 ticks.
* }
* }
*
* if( xQueue2 != 0 )
* {
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueSend xQueueSend
* \ingroup QueueManagement
*/
#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
/**
* queue. h
* @code{c}
* BaseType_t xQueueOverwrite(
* QueueHandle_t xQueue,
* const void * pvItemToQueue
* );
* @endcode
*
* Only for use with queues that have a length of one - so the queue is either
* empty or full.
*
* Post an item on a queue. If the queue is already full then overwrite the
* value held in the queue. The item is queued by copy, not by reference.
*
* This function must not be called from an interrupt service routine.
* See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
*
* @param xQueue The handle of the queue to which the data is being sent.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
* therefore has the same return values as xQueueSendToFront(). However, pdPASS
* is the only value that can be returned because xQueueOverwrite() will write
* to the queue even when the queue is already full.
*
* Example usage:
* @code{c}
*
* void vFunction( void *pvParameters )
* {
* QueueHandle_t xQueue;
* uint32_t ulVarToSend, ulValReceived;
*
* // Create a queue to hold one uint32_t value. It is strongly
* // recommended *not* to use xQueueOverwrite() on queues that can
* // contain more than one value, and doing so will trigger an assertion
* // if configASSERT() is defined.
* xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
*
* // Write the value 10 to the queue using xQueueOverwrite().
* ulVarToSend = 10;
* xQueueOverwrite( xQueue, &ulVarToSend );
*
* // Peeking the queue should now return 10, but leave the value 10 in
* // the queue. A block time of zero is used as it is known that the
* // queue holds a value.
* ulValReceived = 0;
* xQueuePeek( xQueue, &ulValReceived, 0 );
*
* if( ulValReceived != 10 )
* {
* // Error unless the item was removed by a different task.
* }
*
* // The queue is still full. Use xQueueOverwrite() to overwrite the
* // value held in the queue with 100.
* ulVarToSend = 100;
* xQueueOverwrite( xQueue, &ulVarToSend );
*
* // This time read from the queue, leaving the queue empty once more.
* // A block time of 0 is used again.
* xQueueReceive( xQueue, &ulValReceived, 0 );
*
* // The value read should be the last value written, even though the
* // queue was already full when the value was written.
* if( ulValReceived != 100 )
* {
* // Error!
* }
*
* // ...
* }
* @endcode
* \defgroup xQueueOverwrite xQueueOverwrite
* \ingroup QueueManagement
*/
#define xQueueOverwrite( xQueue, pvItemToQueue ) \
xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
/**
* queue. h
* @code{c}
* BaseType_t xQueueGenericSend(
* QueueHandle_t xQueue,
* const void * pvItemToQueue,
* TickType_t xTicksToWait
* BaseType_t xCopyPosition
* );
* @endcode
*
* It is preferred that the macros xQueueSend(), xQueueSendToFront() and
* xQueueSendToBack() are used in place of calling this function directly.
*
* Post an item on a queue. The item is queued by copy, not by reference.
* This function must not be called from an interrupt service routine.
* See xQueueSendFromISR () for an alternative which may be used in an ISR.
*
* @param xQueue The handle to the queue on which the item is to be posted.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for space to become available on the queue, should it already
* be full. The call will return immediately if this is set to 0 and the
* queue is full. The time is defined in tick periods so the constant
* portTICK_PERIOD_MS should be used to convert to real time if this is required.
*
* @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
* item at the back of the queue, or queueSEND_TO_FRONT to place the item
* at the front of the queue (for high priority messages).
*
* @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* uint32_t ulVar = 10U;
*
* void vATask( void *pvParameters )
* {
* QueueHandle_t xQueue1, xQueue2;
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 uint32_t values.
* xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
*
* // ...
*
* if( xQueue1 != 0 )
* {
* // Send an uint32_t. Wait for 10 ticks for space to become
* // available if necessary.
* if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
* {
* // Failed to post the message, even after 10 ticks.
* }
* }
*
* if( xQueue2 != 0 )
* {
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueSend xQueueSend
* \ingroup QueueManagement
*/
BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
const void * const pvItemToQueue,
TickType_t xTicksToWait,
const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* BaseType_t xQueuePeek(
* QueueHandle_t xQueue,
* void * const pvBuffer,
* TickType_t xTicksToWait
* );
* @endcode
*
* Receive an item from a queue without removing the item from the queue.
* The item is received by copy so a buffer of adequate size must be
* provided. The number of bytes copied into the buffer was defined when
* the queue was created.
*
* Successfully received items remain on the queue so will be returned again
* by the next call, or a call to xQueueReceive().
*
* This macro must not be used in an interrupt service routine. See
* xQueuePeekFromISR() for an alternative that can be called from an interrupt
* service routine.
*
* @param xQueue The handle to the queue from which the item is to be
* received.
*
* @param pvBuffer Pointer to the buffer into which the received item will
* be copied.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for an item to receive should the queue be empty at the time
* of the call. The time is defined in tick periods so the constant
* portTICK_PERIOD_MS should be used to convert to real time if this is required.
* xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
* is empty.
*
* @return pdTRUE if an item was successfully received from the queue,
* otherwise pdFALSE.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* QueueHandle_t xQueue;
*
* // Task to create a queue and post a value.
* void vATask( void *pvParameters )
* {
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
* if( xQueue == 0 )
* {
* // Failed to create the queue.
* }
*
* // ...
*
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
*
* // ... Rest of task code.
* }
*
* // Task to peek the data from the queue.
* void vADifferentTask( void *pvParameters )
* {
* struct AMessage *pxRxedMessage;
*
* if( xQueue != 0 )
* {
* // Peek a message on the created queue. Block for 10 ticks if a
* // message is not immediately available.
* if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
* {
* // pcRxedMessage now points to the struct AMessage variable posted
* // by vATask, but the item still remains on the queue.
* }
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueuePeek xQueuePeek
* \ingroup QueueManagement
*/
BaseType_t xQueuePeek( QueueHandle_t xQueue,
void * const pvBuffer,
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* BaseType_t xQueuePeekFromISR(
* QueueHandle_t xQueue,
* void *pvBuffer,
* );
* @endcode
*
* A version of xQueuePeek() that can be called from an interrupt service
* routine (ISR).
*
* Receive an item from a queue without removing the item from the queue.
* The item is received by copy so a buffer of adequate size must be
* provided. The number of bytes copied into the buffer was defined when
* the queue was created.
*
* Successfully received items remain on the queue so will be returned again
* by the next call, or a call to xQueueReceive().
*
* @param xQueue The handle to the queue from which the item is to be
* received.
*
* @param pvBuffer Pointer to the buffer into which the received item will
* be copied.
*
* @return pdTRUE if an item was successfully received from the queue,
* otherwise pdFALSE.
*
* \defgroup xQueuePeekFromISR xQueuePeekFromISR
* \ingroup QueueManagement
*/
BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
void * const pvBuffer ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* BaseType_t xQueueReceive(
* QueueHandle_t xQueue,
* void *pvBuffer,
* TickType_t xTicksToWait
* );
* @endcode
*
* Receive an item from a queue. The item is received by copy so a buffer of
* adequate size must be provided. The number of bytes copied into the buffer
* was defined when the queue was created.
*
* Successfully received items are removed from the queue.
*
* This function must not be used in an interrupt service routine. See
* xQueueReceiveFromISR for an alternative that can.
*
* @param xQueue The handle to the queue from which the item is to be
* received.
*
* @param pvBuffer Pointer to the buffer into which the received item will
* be copied.
*
* @param xTicksToWait The maximum amount of time the task should block
* waiting for an item to receive should the queue be empty at the time
* of the call. xQueueReceive() will return immediately if xTicksToWait
* is zero and the queue is empty. The time is defined in tick periods so the
* constant portTICK_PERIOD_MS should be used to convert to real time if this is
* required.
*
* @return pdTRUE if an item was successfully received from the queue,
* otherwise pdFALSE.
*
* Example usage:
* @code{c}
* struct AMessage
* {
* char ucMessageID;
* char ucData[ 20 ];
* } xMessage;
*
* QueueHandle_t xQueue;
*
* // Task to create a queue and post a value.
* void vATask( void *pvParameters )
* {
* struct AMessage *pxMessage;
*
* // Create a queue capable of containing 10 pointers to AMessage structures.
* // These should be passed by pointer as they contain a lot of data.
* xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
* if( xQueue == 0 )
* {
* // Failed to create the queue.
* }
*
* // ...
*
* // Send a pointer to a struct AMessage object. Don't block if the
* // queue is already full.
* pxMessage = & xMessage;
* xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
*
* // ... Rest of task code.
* }
*
* // Task to receive from the queue.
* void vADifferentTask( void *pvParameters )
* {
* struct AMessage *pxRxedMessage;
*
* if( xQueue != 0 )
* {
* // Receive a message on the created queue. Block for 10 ticks if a
* // message is not immediately available.
* if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
* {
* // pcRxedMessage now points to the struct AMessage variable posted
* // by vATask.
* }
* }
*
* // ... Rest of task code.
* }
* @endcode
* \defgroup xQueueReceive xQueueReceive
* \ingroup QueueManagement
*/
BaseType_t xQueueReceive( QueueHandle_t xQueue,
void * const pvBuffer,
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
* @endcode
*
* Return the number of messages stored in a queue.
*
* @param xQueue A handle to the queue being queried.
*
* @return The number of messages available in the queue.
*
* \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
* \ingroup QueueManagement
*/
UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
* @endcode
*
* Return the number of free spaces available in a queue. This is equal to the
* number of items that can be sent to the queue before the queue becomes full
* if no items are removed.
*
* @param xQueue A handle to the queue being queried.
*
* @return The number of spaces available in the queue.
*
* \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
* \ingroup QueueManagement
*/
UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* void vQueueDelete( QueueHandle_t xQueue );
* @endcode
*
* Delete a queue - freeing all the memory allocated for storing of items
* placed on the queue.
*
* @param xQueue A handle to the queue to be deleted.
*
* \defgroup vQueueDelete vQueueDelete
* \ingroup QueueManagement
*/
void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
/**
* queue. h
* @code{c}
* BaseType_t xQueueSendToFrontFromISR(
* QueueHandle_t xQueue,
* const void *pvItemToQueue,
* BaseType_t *pxHigherPriorityTaskWoken
* );
* @endcode
*
* This is a macro that calls xQueueGenericSendFromISR().
*
* Post an item to the front of a queue. It is safe to use this macro from
* within an interrupt service routine.
*
* Items are queued by copy not reference so it is preferable to only
* queue small items, especially when called from an ISR. In most cases
* it would be preferable to store a pointer to the item being queued.
*
* @param xQueue The handle to the queue on which the item is to be posted.
*
* @param pvItemToQueue A pointer to the item that is to be placed on the
* queue. The size of the items the queue will hold was defined when the
* queue was created, so this many bytes will be copied from pvItemToQueue
* into the queue storage area.
*
* @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
* *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
* to unblock, and the unblocked task has a priority higher than the currently
* running task. If xQueueSendToFrontFromISR() sets this value to pdTRUE then
* a context switch should be requested before the interrupt is exited.
*