2 FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Tests the use of queue sets.
\r
73 * A receive task creates a number of queues and adds them to a queue set before
\r
74 * blocking on the queue set receive. A transmit task and (optionally) an
\r
75 * interrupt repeatedly unblocks the receive task by sending messages to the
\r
76 * queues in a pseudo random order. The receive task removes the messages from
\r
77 * the queues and flags an error if the received message does not match that
\r
78 * expected. The task sends values in the range 0 to
\r
79 * queuesetINITIAL_ISR_TX_VALUE, and the ISR sends value in the range
\r
80 * queuesetINITIAL_ISR_TX_VALUE to ULONG_MAX.
\r
84 /* Standard includes. */
\r
88 /* Kernel includes. */
\r
89 #include "FreeRTOS.h"
\r
93 /* Demo includes. */
\r
94 #include "QueueSet.h"
\r
96 /* The number of queues that are created and added to the queue set. */
\r
97 #define queuesetNUM_QUEUES_IN_SET 3
\r
99 /* The length of each created queue. */
\r
100 #define queuesetQUEUE_LENGTH 3
\r
102 /* Block times used in this demo. A block time or 0 means "don't block". */
\r
103 #define queuesetSHORT_DELAY 200
\r
104 #define queuesetDONT_BLOCK 0
\r
106 /* Messages are sent in incrementing order from both a task and an interrupt.
\r
107 The task sends values in the range 0 to 0xfffe, and the interrupt sends values
\r
108 in the range of 0xffff to ULONG_MAX. */
\r
109 #define queuesetINITIAL_ISR_TX_VALUE 0xffffUL
\r
111 /* The priorities used in this demo. */
\r
112 #define queuesetLOW_PRIORITY ( tskIDLE_PRIORITY )
\r
113 #define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )
\r
115 /* For test purposes the priority of the sending task is changed after every
\r
116 queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
\r
117 #define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )
\r
119 /* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
\r
120 #define queuesetISR_TX_PERIOD ( 100UL )
\r
122 /* A delay inserted when the Tx task changes its priority to be above the idle
\r
123 task priority to ensure the idle priority tasks get some CPU time before the
\r
124 next iteration of the queue set Tx task. */
\r
125 #define queuesetTX_LOOP_DELAY ( 200 / portTICK_PERIOD_MS )
\r
127 /* The allowable maximum deviation between a received value and the expected
\r
128 received value. A deviation will occur when data is received from a queue
\r
129 inside an ISR in between a task receiving from a queue and the task checking
\r
130 the received value. */
\r
131 #define queuesetALLOWABLE_RX_DEVIATION 3
\r
133 /* Ignore values that are at the boundaries of allowable values to make the
\r
134 testing of limits easier (don't have to deal with wrapping values). */
\r
135 #define queuesetIGNORED_BOUNDARY ( queuesetALLOWABLE_RX_DEVIATION * 2 )
\r
139 eEqualPriority = 0, /* Tx and Rx tasks have the same priority. */
\r
140 eTxHigherPriority, /* The priority of the Tx task is above that of the Rx task. */
\r
141 eTxLowerPriority /* The priority of the Tx task is below that of the Rx task. */
\r
142 } eRelativePriorities;
\r
145 * The task that periodically sends to the queue set.
\r
147 static void prvQueueSetSendingTask( void *pvParameters );
\r
150 * The task that reads from the queue set.
\r
152 static void prvQueueSetReceivingTask( void *pvParameters );
\r
155 * Check the value received from a queue is the expected value. Some values
\r
156 * originate from the send task, some values originate from the ISR, with the
\r
157 * range of the value being used to distinguish between the two message
\r
160 static void prvCheckReceivedValue( uint32_t ulReceived );
\r
163 * For purposes of test coverage, functions that read from and write to a
\r
164 * queue set from an ISR respectively.
\r
166 static void prvReceiveFromQueueInSetFromISR( void );
\r
167 static void prvSendToQueueInSetFromISR( void );
\r
170 * Create the queues and add them to a queue set before resuming the Tx
\r
173 static void prvSetupTest( void );
\r
176 * Checks a value received from a queue falls within the range of expected
\r
179 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived );
\r
182 * Increase test coverage by occasionally change the priorities of the two tasks
\r
183 * relative to each other. */
\r
184 static void prvChangeRelativePriorities( void );
\r
187 * Local pseudo random number seed and return functions. Used to avoid calls
\r
188 * to the standard library.
\r
190 static uint32_t prvRand( void );
\r
191 static void prvSRand( uint32_t ulSeed );
\r
193 /*-----------------------------------------------------------*/
\r
195 /* The queues that are added to the set. */
\r
196 static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
198 /* Counts how many times each queue in the set is used to ensure all the
\r
199 queues are used. */
\r
200 static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
202 /* The handle of the queue set to which the queues are added. */
\r
203 static QueueSetHandle_t xQueueSet;
\r
205 /* If the prvQueueSetReceivingTask() task has not detected any errors then
\r
206 it increments ulCycleCounter on each iteration.
\r
207 xAreQueueSetTasksStillRunning() returns pdPASS if the value of
\r
208 ulCycleCounter has changed between consecutive calls, and pdFALSE if
\r
209 ulCycleCounter has stopped incrementing (indicating an error condition). */
\r
210 static volatile uint32_t ulCycleCounter = 0UL;
\r
212 /* Set to pdFAIL if an error is detected by any queue set task.
\r
213 ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
\r
214 static volatile BaseType_t xQueueSetTasksStatus = pdPASS;
\r
216 /* Just a flag to let the function that writes to a queue from an ISR know that
\r
217 the queues are setup and can be used. */
\r
218 static volatile BaseType_t xSetupComplete = pdFALSE;
\r
220 /* The value sent to the queue from the ISR is file scope so the
\r
221 xAreQueeuSetTasksStillRunning() function can check it is incrementing as
\r
223 static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
\r
225 /* Used by the pseudo random number generator. */
\r
226 static uint32_t ulNextRand = 0;
\r
228 /* The task handles are stored so their priorities can be changed. */
\r
229 TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;
\r
231 /*-----------------------------------------------------------*/
\r
233 void vStartQueueSetTasks( void )
\r
235 /* Create the tasks. */
\r
236 xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );
\r
237 xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );
\r
239 /* It is important that the sending task does not attempt to write to a
\r
240 queue before the queue has been created. It is therefore placed into the
\r
241 suspended state before the scheduler has started. It is resumed by the
\r
242 receiving task after the receiving task has created the queues and added the
\r
243 queues to the queue set. */
\r
244 vTaskSuspend( xQueueSetSendingTask );
\r
246 /*-----------------------------------------------------------*/
\r
248 BaseType_t xAreQueueSetTasksStillRunning( void )
\r
250 static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;
\r
251 static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
252 BaseType_t xReturn = pdPASS, x;
\r
254 if( ulLastCycleCounter == ulCycleCounter )
\r
256 /* The cycle counter is no longer being incremented. Either one of the
\r
257 tasks is stalled or an error has been detected. */
\r
261 ulLastCycleCounter = ulCycleCounter;
\r
263 /* Ensure that all the queues in the set have been used. This ensures the
\r
264 test is working as intended and guards against the rand() in the Tx task
\r
265 missing some values. */
\r
266 for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
\r
268 if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )
\r
273 ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];
\r
276 /* Check the global status flag. */
\r
277 if( xQueueSetTasksStatus != pdPASS )
\r
282 /* Check that the ISR is still sending values to the queues too. */
\r
283 if( ulISRTxValue == ulLastISRTxValue )
\r
289 ulLastISRTxValue = ulISRTxValue;
\r
294 /*-----------------------------------------------------------*/
\r
296 static void prvQueueSetSendingTask( void *pvParameters )
\r
298 uint32_t ulTaskTxValue = 0, ulQueueToWriteTo;
\r
299 QueueHandle_t xQueueInUse;
\r
301 /* Remove compiler warning about the unused parameter. */
\r
302 ( void ) pvParameters;
\r
304 /* Seed mini pseudo random number generator. */
\r
305 prvSRand( ( uint32_t ) &ulTaskTxValue );
\r
309 /* Generate the index for the queue to which a value is to be sent. */
\r
310 ulQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
\r
311 xQueueInUse = xQueues[ ulQueueToWriteTo ];
\r
313 /* Note which index is being written to to ensure all the queues are
\r
315 ( ulQueueUsedCounter[ ulQueueToWriteTo ] )++;
\r
317 /* Send to the queue to unblock the task that is waiting for data to
\r
318 arrive on a queue within the queue set to which this queue belongs. */
\r
319 if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )
\r
321 /* The send should always pass as an infinite block time was
\r
323 xQueueSetTasksStatus = pdFAIL;
\r
326 #if( configUSE_PREEMPTION == 0 )
\r
332 /* If the Tx value has reached the range used by the ISR then set it
\r
334 if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )
\r
339 /* Increase test coverage by occasionally change the priorities of the
\r
340 two tasks relative to each other. */
\r
341 prvChangeRelativePriorities();
\r
344 /*-----------------------------------------------------------*/
\r
346 static void prvChangeRelativePriorities( void )
\r
348 static UBaseType_t ulLoops = 0;
\r
349 static eRelativePriorities ePriorities = eEqualPriority;
\r
351 /* Occasionally change the task priority relative to the priority of
\r
352 the receiving task. */
\r
354 if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )
\r
358 switch( ePriorities )
\r
360 case eEqualPriority:
\r
361 /* Both tasks are running with medium priority. Now lower the
\r
362 priority of the receiving task so the Tx task has the higher
\r
363 relative priority. */
\r
364 vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );
\r
365 ePriorities = eTxHigherPriority;
\r
368 case eTxHigherPriority:
\r
369 /* The Tx task is running with a higher priority than the Rx
\r
370 task. Switch the priorities around so the Rx task has the
\r
371 higher relative priority. */
\r
372 vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );
\r
373 vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );
\r
374 ePriorities = eTxLowerPriority;
\r
377 case eTxLowerPriority:
\r
378 /* The Tx task is running with a lower priority than the Rx
\r
379 task. Make the priorities equal again. */
\r
380 vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );
\r
381 ePriorities = eEqualPriority;
\r
383 /* When both tasks are using a non-idle priority the queue set
\r
384 tasks will starve idle priority tasks of execution time - so
\r
385 relax a bit before the next iteration to minimise the impact. */
\r
386 vTaskDelay( queuesetTX_LOOP_DELAY );
\r
392 /*-----------------------------------------------------------*/
\r
394 static void prvQueueSetReceivingTask( void *pvParameters )
\r
396 uint32_t ulReceived;
\r
397 QueueHandle_t xActivatedQueue;
\r
398 TickType_t xBlockTime;
\r
400 /* Remove compiler warnings. */
\r
401 ( void ) pvParameters;
\r
403 /* Create the queues and add them to the queue set before resuming the Tx
\r
409 /* For test coverage reasons, the block time is dependent on the
\r
410 priority of this task - which changes during the test. When the task
\r
411 is at the idle priority it polls the queue set. */
\r
412 if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )
\r
418 xBlockTime = portMAX_DELAY;
\r
421 /* Wait for a message to arrive on one of the queues in the set. */
\r
422 xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );
\r
424 if( xActivatedQueue == NULL )
\r
426 if( xBlockTime != 0 )
\r
428 /* This should not happen as an infinite delay was used. */
\r
429 xQueueSetTasksStatus = pdFAIL;
\r
434 /* Reading from the queue should pass with a zero block time as
\r
435 this task will only run when something has been posted to a task
\r
436 in the queue set. */
\r
437 if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )
\r
439 xQueueSetTasksStatus = pdFAIL;
\r
442 /* Ensure the value received was the value expected. This function
\r
443 manipulates file scope data and is also called from an ISR, hence
\r
444 the critical section. */
\r
445 taskENTER_CRITICAL();
\r
447 prvCheckReceivedValue( ulReceived );
\r
449 taskEXIT_CRITICAL();
\r
451 if( xQueueSetTasksStatus == pdPASS )
\r
458 /*-----------------------------------------------------------*/
\r
460 void vQueueSetAccessQueueSetFromISR( void )
\r
462 static uint32_t ulCallCount = 0;
\r
464 /* xSetupComplete is set to pdTRUE when the queues have been created and
\r
465 are available for use. */
\r
466 if( xSetupComplete == pdTRUE )
\r
468 /* It is intended that this function is called from the tick hook
\r
469 function, so each call is one tick period apart. */
\r
471 if( ulCallCount > queuesetISR_TX_PERIOD )
\r
475 /* First attempt to read from the queue set. */
\r
476 prvReceiveFromQueueInSetFromISR();
\r
478 /* Then write to the queue set. */
\r
479 prvSendToQueueInSetFromISR();
\r
483 /*-----------------------------------------------------------*/
\r
485 static void prvCheckReceivedValue( uint32_t ulReceived )
\r
487 static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
\r
489 /* Values are received in tasks and interrupts. It is likely that the
\r
490 receiving task will sometimes get preempted by the receiving interrupt
\r
491 between reading a value from the queue and calling this function. When
\r
492 that happens, if the receiving interrupt calls this function the values
\r
493 will get passed into this function slightly out of order. For that
\r
494 reason the value passed in is tested against a small range of expected
\r
495 values, rather than a single absolute value. To make the range testing
\r
496 easier values in the range limits are ignored. */
\r
498 /* If the received value is equal to or greater than
\r
499 queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */
\r
500 if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )
\r
502 /* The value was sent from the ISR. */
\r
503 if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )
\r
505 /* The value received is at the lower limit of the expected range.
\r
506 Don't test it and expect to receive one higher next time. */
\r
508 else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )
\r
510 /* The value received is at the higher limit of the expected range.
\r
511 Don't test it and expect to wrap soon. */
\r
515 /* Check the value against its expected value range. */
\r
516 if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )
\r
518 xQueueSetTasksStatus = pdFAIL;
\r
522 configASSERT( xQueueSetTasksStatus );
\r
524 /* It is expected to receive an incrementing number. */
\r
525 ulExpectedReceivedFromISR++;
\r
526 if( ulExpectedReceivedFromISR == 0 )
\r
528 ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
\r
533 /* The value was sent from the Tx task. */
\r
534 if( ulReceived < queuesetIGNORED_BOUNDARY )
\r
536 /* The value received is at the lower limit of the expected range.
\r
537 Don't test it, and expect to receive one higher next time. */
\r
539 else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )
\r
541 /* The value received is at the higher limit of the expected range.
\r
542 Don't test it and expect to wrap soon. */
\r
546 /* Check the value against its expected value range. */
\r
547 if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )
\r
549 xQueueSetTasksStatus = pdFAIL;
\r
553 configASSERT( xQueueSetTasksStatus );
\r
555 /* It is expected to receive an incrementing number. */
\r
556 ulExpectedReceivedFromTask++;
\r
557 if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )
\r
559 ulExpectedReceivedFromTask = 0;
\r
563 /*-----------------------------------------------------------*/
\r
565 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived )
\r
567 BaseType_t xReturn = pdPASS;
\r
569 if( ulReceived > ulExpectedReceived )
\r
571 configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
\r
572 if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )
\r
579 configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
\r
580 if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )
\r
588 /*-----------------------------------------------------------*/
\r
590 static void prvReceiveFromQueueInSetFromISR( void )
\r
592 QueueSetMemberHandle_t xActivatedQueue;
\r
593 uint32_t ulReceived;
\r
595 /* See if any of the queues in the set contain data. */
\r
596 xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );
\r
598 if( xActivatedQueue != NULL )
\r
600 /* Reading from the queue for test purposes only. */
\r
601 if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )
\r
603 /* Data should have been available as the handle was returned from
\r
604 xQueueSelectFromSetFromISR(). */
\r
605 xQueueSetTasksStatus = pdFAIL;
\r
608 /* Ensure the value received was the value expected. */
\r
609 prvCheckReceivedValue( ulReceived );
\r
612 /*-----------------------------------------------------------*/
\r
614 static void prvSendToQueueInSetFromISR( void )
\r
616 static BaseType_t xQueueToWriteTo = 0;
\r
618 if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulISRTxValue, NULL ) == pdPASS )
\r
622 /* If the Tx value has wrapped then set it back to its initial value. */
\r
623 if( ulISRTxValue == 0UL )
\r
625 ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
\r
628 /* Use a different queue next time. */
\r
630 if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )
\r
632 xQueueToWriteTo = 0;
\r
636 /*-----------------------------------------------------------*/
\r
638 static void prvSetupTest( void )
\r
641 uint32_t ulValueToSend = 0;
\r
643 /* Ensure the queues are created and the queue set configured before the
\r
644 sending task is unsuspended.
\r
646 First Create the queue set such that it will be able to hold a message for
\r
647 every space in every queue in the set. */
\r
648 xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );
\r
650 for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
\r
652 /* Create the queue and add it to the set. The queue is just holding
\r
654 xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );
\r
655 configASSERT( xQueues[ x ] );
\r
656 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )
\r
658 xQueueSetTasksStatus = pdFAIL;
\r
662 /* The queue has now been added to the queue set and cannot be added to
\r
664 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )
\r
666 xQueueSetTasksStatus = pdFAIL;
\r
671 /* Attempt to remove a queue from a queue set it does not belong
\r
672 to (NULL being passed as the queue set in this case). */
\r
673 if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )
\r
675 /* It is not possible to successfully remove a queue from a queue
\r
676 set it does not belong to. */
\r
677 xQueueSetTasksStatus = pdFAIL;
\r
680 /* Attempt to remove a queue from the queue set it does belong to. */
\r
681 if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
\r
683 /* It should be possible to remove the queue from the queue set it
\r
685 xQueueSetTasksStatus = pdFAIL;
\r
688 /* Add an item to the queue before attempting to add it back into the
\r
690 xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );
\r
691 if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )
\r
693 /* Should not be able to add a non-empty queue to a set. */
\r
694 xQueueSetTasksStatus = pdFAIL;
\r
697 /* Remove the item from the queue before adding the queue back into the
\r
698 set so the dynamic tests can begin. */
\r
699 xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );
\r
700 if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
\r
702 /* If the queue was successfully removed from the queue set then it
\r
703 should be possible to add it back in again. */
\r
704 xQueueSetTasksStatus = pdFAIL;
\r
707 /* The task that sends to the queues is not running yet, so attempting to
\r
708 read from the queue set should fail. */
\r
709 if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )
\r
711 xQueueSetTasksStatus = pdFAIL;
\r
714 /* Resume the task that writes to the queues. */
\r
715 vTaskResume( xQueueSetSendingTask );
\r
717 /* Let the ISR access the queues also. */
\r
718 xSetupComplete = pdTRUE;
\r
720 /*-----------------------------------------------------------*/
\r
722 static uint32_t prvRand( void )
\r
724 ulNextRand = ( ulNextRand * 1103515245UL ) + 12345UL;
\r
725 return ( ulNextRand / 65536UL ) % 32768UL;
\r
727 /*-----------------------------------------------------------*/
\r
729 static void prvSRand( uint32_t ulSeed )
\r
731 ulNextRand = ulSeed;
\r