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
|
/*
FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to distribute
>>! a combined work that includes FreeRTOS without being obliged to provide
>>! the source code for proprietary components outside of the FreeRTOS
>>! kernel.
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
/*
* Tests the use of queue sets.
*
* A receive task creates a number of queues and adds them to a queue set before
* blocking on the queue set receive. A transmit task and (optionally) an
* interrupt repeatedly unblocks the receive task by sending messages to the
* queues in a pseudo random order. The receive task removes the messages from
* the queues and flags an error if the received message does not match that
* expected. The task sends values in the range 0 to
* queuesetINITIAL_ISR_TX_VALUE, and the ISR sends value in the range
* queuesetINITIAL_ISR_TX_VALUE to ULONG_MAX.
*/
/* Standard includes. */
#include <stdlib.h>
#include <limits.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
/* Demo includes. */
#include "QueueSet.h"
/* The number of queues that are created and added to the queue set. */
#define queuesetNUM_QUEUES_IN_SET 3
/* The length of each created queue. */
#define queuesetQUEUE_LENGTH 3
/* Block times used in this demo. A block time or 0 means "don't block". */
#define queuesetSHORT_DELAY 200
#define queuesetDONT_BLOCK 0
/* Messages are sent in incrementing order from both a task and an interrupt.
The task sends values in the range 0 to 0xfffe, and the interrupt sends values
in the range of 0xffff to ULONG_MAX. */
#define queuesetINITIAL_ISR_TX_VALUE 0xffffUL
/* The priorities used in this demo. */
#define queuesetLOW_PRIORITY ( tskIDLE_PRIORITY )
#define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )
/* For test purposes the priority of the sending task is changed after every
queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
#define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )
/* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
#define queuesetISR_TX_PERIOD ( 100UL )
/* A delay inserted when the Tx task changes its priority to be above the idle
task priority to ensure the idle priority tasks get some CPU time before the
next iteration of the queue set Tx task. */
#define queuesetTX_LOOP_DELAY ( 200 / portTICK_PERIOD_MS )
/* The allowable maximum deviation between a received value and the expected
received value. A deviation will occur when data is received from a queue
inside an ISR in between a task receiving from a queue and the task checking
the received value. */
#define queuesetALLOWABLE_RX_DEVIATION 3
/* Ignore values that are at the boundaries of allowable values to make the
testing of limits easier (don't have to deal with wrapping values). */
#define queuesetIGNORED_BOUNDARY ( queuesetALLOWABLE_RX_DEVIATION * 2 )
typedef enum
{
eEqualPriority = 0, /* Tx and Rx tasks have the same priority. */
eTxHigherPriority, /* The priority of the Tx task is above that of the Rx task. */
eTxLowerPriority /* The priority of the Tx task is below that of the Rx task. */
} eRelativePriorities;
/*
* The task that periodically sends to the queue set.
*/
static void prvQueueSetSendingTask( void *pvParameters );
/*
* The task that reads from the queue set.
*/
static void prvQueueSetReceivingTask( void *pvParameters );
/*
* Check the value received from a queue is the expected value. Some values
* originate from the send task, some values originate from the ISR, with the
* range of the value being used to distinguish between the two message
* sources.
*/
static void prvCheckReceivedValue( unsigned long ulReceived );
/*
* For purposes of test coverage, functions that read from and write to a
* queue set from an ISR respectively.
*/
static void prvReceiveFromQueueInSetFromISR( void );
static void prvSendToQueueInSetFromISR( void );
/*
* Create the queues and add them to a queue set before resuming the Tx
* task.
*/
static void prvSetupTest( void );
/*
* Checks a value received from a queue falls within the range of expected
* values.
*/
static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived );
/*
* Increase test coverage by occasionally change the priorities of the two tasks
* relative to each other. */
static void prvChangeRelativePriorities( void );
/*
* Local pseudo random number seed and return functions. Used to avoid calls
* to the standard library.
*/
static unsigned long prvRand( void );
static void prvSRand( unsigned long ulSeed );
/*-----------------------------------------------------------*/
/* The queues that are added to the set. */
static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
/* Counts how many times each queue in the set is used to ensure all the
queues are used. */
static unsigned long ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
/* The handle of the queue set to which the queues are added. */
static QueueSetHandle_t xQueueSet;
/* If the prvQueueSetReceivingTask() task has not detected any errors then
it increments ulCycleCounter on each iteration.
xAreQueueSetTasksStillRunning() returns pdPASS if the value of
ulCycleCounter has changed between consecutive calls, and pdFALSE if
ulCycleCounter has stopped incrementing (indicating an error condition). */
static volatile unsigned long ulCycleCounter = 0UL;
/* Set to pdFAIL if an error is detected by any queue set task.
ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
static volatile portBASE_TYPE xQueueSetTasksStatus = pdPASS;
/* Just a flag to let the function that writes to a queue from an ISR know that
the queues are setup and can be used. */
static volatile portBASE_TYPE xSetupComplete = pdFALSE;
/* The value sent to the queue from the ISR is file scope so the
xAreQueeuSetTasksStillRunning() function can check it is incrementing as
expected. */
static volatile unsigned long ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
/* Used by the pseudo random number generator. */
static unsigned long ulNextRand = 0;
/* The task handles are stored so their priorities can be changed. */
TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;
/*-----------------------------------------------------------*/
void vStartQueueSetTasks( void )
{
/* Create the tasks. */
xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );
xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );
/* It is important that the sending task does not attempt to write to a
queue before the queue has been created. It is therefore placed into the
suspended state before the scheduler has started. It is resumed by the
receiving task after the receiving task has created the queues and added the
queues to the queue set. */
vTaskSuspend( xQueueSetSendingTask );
}
/*-----------------------------------------------------------*/
portBASE_TYPE xAreQueueSetTasksStillRunning( void )
{
static unsigned long ulLastCycleCounter, ulLastISRTxValue = 0;
static unsigned long ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
portBASE_TYPE xReturn = pdPASS, x;
if( ulLastCycleCounter == ulCycleCounter )
{
/* The cycle counter is no longer being incremented. Either one of the
tasks is stalled or an error has been detected. */
xReturn = pdFAIL;
}
ulLastCycleCounter = ulCycleCounter;
/* Ensure that all the queues in the set have been used. This ensures the
test is working as intended and guards against the rand() in the Tx task
missing some values. */
for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
{
if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )
{
xReturn = pdFAIL;
}
ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];
}
/* Check the global status flag. */
if( xQueueSetTasksStatus != pdPASS )
{
xReturn = pdFAIL;
}
/* Check that the ISR is still sending values to the queues too. */
if( ulISRTxValue == ulLastISRTxValue )
{
xReturn = pdFAIL;
}
else
{
ulLastISRTxValue = ulISRTxValue;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static void prvQueueSetSendingTask( void *pvParameters )
{
unsigned long ulTaskTxValue = 0, ulQueueToWriteTo;
QueueHandle_t xQueueInUse;
/* Remove compiler warning about the unused parameter. */
( void ) pvParameters;
/* Seed mini pseudo random number generator. */
prvSRand( ( unsigned long ) &ulTaskTxValue );
for( ;; )
{
/* Generate the index for the queue to which a value is to be sent. */
ulQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
xQueueInUse = xQueues[ ulQueueToWriteTo ];
/* Note which index is being written to to ensure all the queues are
used. */
( ulQueueUsedCounter[ ulQueueToWriteTo ] )++;
/* Send to the queue to unblock the task that is waiting for data to
arrive on a queue within the queue set to which this queue belongs. */
if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )
{
/* The send should always pass as an infinite block time was
used. */
xQueueSetTasksStatus = pdFAIL;
}
#if( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
ulTaskTxValue++;
/* If the Tx value has reached the range used by the ISR then set it
back to 0. */
if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )
{
ulTaskTxValue = 0;
}
/* Increase test coverage by occasionally change the priorities of the
two tasks relative to each other. */
prvChangeRelativePriorities();
}
}
/*-----------------------------------------------------------*/
static void prvChangeRelativePriorities( void )
{
static unsigned portBASE_TYPE ulLoops = 0;
static eRelativePriorities ePriorities = eEqualPriority;
/* Occasionally change the task priority relative to the priority of
the receiving task. */
ulLoops++;
if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )
{
ulLoops = 0;
switch( ePriorities )
{
case eEqualPriority:
/* Both tasks are running with medium priority. Now lower the
priority of the receiving task so the Tx task has the higher
relative priority. */
vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );
ePriorities = eTxHigherPriority;
break;
case eTxHigherPriority:
/* The Tx task is running with a higher priority than the Rx
task. Switch the priorities around so the Rx task has the
higher relative priority. */
vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );
vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );
ePriorities = eTxLowerPriority;
break;
case eTxLowerPriority:
/* The Tx task is running with a lower priority than the Rx
task. Make the priorities equal again. */
vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );
ePriorities = eEqualPriority;
/* When both tasks are using a non-idle priority the queue set
tasks will starve idle priority tasks of execution time - so
relax a bit before the next iteration to minimise the impact. */
vTaskDelay( queuesetTX_LOOP_DELAY );
break;
}
}
}
/*-----------------------------------------------------------*/
static void prvQueueSetReceivingTask( void *pvParameters )
{
unsigned long ulReceived;
QueueHandle_t xActivatedQueue;
/* Remove compiler warnings. */
( void ) pvParameters;
/* Create the queues and add them to the queue set before resuming the Tx
task. */
prvSetupTest();
for( ;; )
{
/* Wait for a message to arrive on one of the queues in the set. */
xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );
configASSERT( xActivatedQueue );
if( xActivatedQueue == NULL )
{
/* This should not happen as an infinite delay was used. */
xQueueSetTasksStatus = pdFAIL;
}
else
{
/* Reading from the queue should pass with a zero block time as
this task will only run when something has been posted to a task
in the queue set. */
if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )
{
xQueueSetTasksStatus = pdFAIL;
}
/* Ensure the value received was the value expected. This function
manipulates file scope data and is also called from an ISR, hence
the critical section. */
taskENTER_CRITICAL();
{
prvCheckReceivedValue( ulReceived );
}
taskEXIT_CRITICAL();
}
if( xQueueSetTasksStatus == pdPASS )
{
ulCycleCounter++;
}
}
}
/*-----------------------------------------------------------*/
void vQueueSetAccessQueueSetFromISR( void )
{
static unsigned long ulCallCount = 0;
/* xSetupComplete is set to pdTRUE when the queues have been created and
are available for use. */
if( xSetupComplete == pdTRUE )
{
/* It is intended that this function is called from the tick hook
function, so each call is one tick period apart. */
ulCallCount++;
if( ulCallCount > queuesetISR_TX_PERIOD )
{
ulCallCount = 0;
/* First attempt to read from the queue set. */
prvReceiveFromQueueInSetFromISR();
/* Then write to the queue set. */
prvSendToQueueInSetFromISR();
}
}
}
/*-----------------------------------------------------------*/
static void prvCheckReceivedValue( unsigned long ulReceived )
{
static unsigned long ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
/* Values are received in tasks and interrupts. It is likely that the
receiving task will sometimes get preempted by the receiving interrupt
between reading a value from the queue and calling this function. When
that happens, if the receiving interrupt calls this function the values
will get passed into this function slightly out of order. For that
reason the value passed in is tested against a small range of expected
values, rather than a single absolute value. To make the range testing
easier values in the range limits are ignored. */
/* If the received value is equal to or greater than
queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */
if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )
{
/* The value was sent from the ISR. */
if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )
{
/* The value received is at the lower limit of the expected range.
Don't test it and expect to receive one higher next time. */
}
else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )
{
/* The value received is at the higher limit of the expected range.
Don't test it and expect to wrap soon. */
}
else
{
/* Check the value against its expected value range. */
if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )
{
xQueueSetTasksStatus = pdFAIL;
}
}
configASSERT( xQueueSetTasksStatus );
/* It is expected to receive an incrementing number. */
ulExpectedReceivedFromISR++;
if( ulExpectedReceivedFromISR == 0 )
{
ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
}
}
else
{
/* The value was sent from the Tx task. */
if( ulReceived < queuesetIGNORED_BOUNDARY )
{
/* The value received is at the lower limit of the expected range.
Don't test it, and expect to receive one higher next time. */
}
else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )
{
/* The value received is at the higher limit of the expected range.
Don't test it and expect to wrap soon. */
}
else
{
/* Check the value against its expected value range. */
if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )
{
xQueueSetTasksStatus = pdFAIL;
}
}
configASSERT( xQueueSetTasksStatus );
/* It is expected to receive an incrementing number. */
ulExpectedReceivedFromTask++;
if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )
{
ulExpectedReceivedFromTask = 0;
}
}
}
/*-----------------------------------------------------------*/
static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived )
{
portBASE_TYPE xReturn = pdPASS;
if( ulReceived > ulExpectedReceived )
{
configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )
{
xReturn = pdFALSE;
}
}
else
{
configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )
{
xReturn = pdFALSE;
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
static void prvReceiveFromQueueInSetFromISR( void )
{
QueueSetMemberHandle_t xActivatedQueue;
unsigned long ulReceived;
/* See if any of the queues in the set contain data. */
xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );
if( xActivatedQueue != NULL )
{
/* Reading from the queue for test purposes only. */
if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )
{
/* Data should have been available as the handle was returned from
xQueueSelectFromSetFromISR(). */
xQueueSetTasksStatus = pdFAIL;
}
/* Ensure the value received was the value expected. */
prvCheckReceivedValue( ulReceived );
}
}
/*-----------------------------------------------------------*/
static void prvSendToQueueInSetFromISR( void )
{
static portBASE_TYPE xQueueToWriteTo = 0;
if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulISRTxValue, NULL ) == pdPASS )
{
ulISRTxValue++;
/* If the Tx value has wrapped then set it back to its
initial value. */
if( ulISRTxValue == 0UL )
{
ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
}
/* Use a different queue next time. */
xQueueToWriteTo++;
if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )
{
xQueueToWriteTo = 0;
}
}
}
/*-----------------------------------------------------------*/
static void prvSetupTest( void )
{
portBASE_TYPE x;
unsigned long ulValueToSend = 0;
/* Ensure the queues are created and the queue set configured before the
sending task is unsuspended.
First Create the queue set such that it will be able to hold a message for
every space in every queue in the set. */
xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );
for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
{
/* Create the queue and add it to the set. The queue is just holding
unsigned long value. */
xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( unsigned long ) );
configASSERT( xQueues[ x ] );
if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )
{
xQueueSetTasksStatus = pdFAIL;
}
else
{
/* The queue has now been added to the queue set and cannot be added to
another. */
if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )
{
xQueueSetTasksStatus = pdFAIL;
}
}
}
/* Attempt to remove a queue from a queue set it does not belong
to (NULL being passed as the queue set in this case). */
if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )
{
/* It is not possible to successfully remove a queue from a queue
set it does not belong to. */
xQueueSetTasksStatus = pdFAIL;
}
/* Attempt to remove a queue from the queue set it does belong to. */
if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
{
/* It should be possible to remove the queue from the queue set it
does belong to. */
xQueueSetTasksStatus = pdFAIL;
}
/* Add an item to the queue before attempting to add it back into the
set. */
xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );
if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )
{
/* Should not be able to add a non-empty queue to a set. */
xQueueSetTasksStatus = pdFAIL;
}
/* Remove the item from the queue before adding the queue back into the
set so the dynamic tests can begin. */
xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );
if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
{
/* If the queue was successfully removed from the queue set then it
should be possible to add it back in again. */
xQueueSetTasksStatus = pdFAIL;
}
/* The task that sends to the queues is not running yet, so attempting to
read from the queue set should fail. */
if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )
{
xQueueSetTasksStatus = pdFAIL;
}
/* Resume the task that writes to the queues. */
vTaskResume( xQueueSetSendingTask );
/* Let the ISR access the queues also. */
xSetupComplete = pdTRUE;
}
/*-----------------------------------------------------------*/
static unsigned long prvRand( void )
{
ulNextRand = ( ulNextRand * 1103515245UL ) + 12345UL;
return ( ulNextRand / 65536UL ) % 32768UL;
}
/*-----------------------------------------------------------*/
static void prvSRand( unsigned long ulSeed )
{
ulNextRand = ulSeed;
}
|