]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/QueueSet.c
18d8ed7893332fe1611c0ae76d9340b19e8be4ae
[freertos] / FreeRTOS / Demo / Common / Minimal / QueueSet.c
1 /*\r
2     FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not itcan be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /*\r
76  * Tests the use of queue sets.\r
77  *\r
78  * A receive task creates a number of queues and adds them to a queue set before\r
79  * blocking on the queue set receive.  A transmit task and (optionally) an\r
80  * interrupt repeatedly unblocks the receive task by sending messages to the\r
81  * queues in a pseudo random order.  The receive task removes the messages from\r
82  * the queues and flags an error if the received message does not match that\r
83  * expected.  The task sends values in the range 0 to\r
84  * queuesetINITIAL_ISR_TX_VALUE, and the ISR sends value in the range\r
85  * queuesetINITIAL_ISR_TX_VALUE to ULONG_MAX.\r
86  */\r
87 \r
88 /* Standard includes. */\r
89 #include <stdlib.h>\r
90 #include <limits.h>\r
91 \r
92 /* Kernel includes. */\r
93 #include "FreeRTOS.h"\r
94 #include "task.h"\r
95 #include "queue.h"\r
96 \r
97 /* Demo includes. */\r
98 #include "QueueSet.h"\r
99 \r
100 /* The number of queues that are created and added to the queue set. */\r
101 #define queuesetNUM_QUEUES_IN_SET 3\r
102 \r
103 /* The length of each created queue. */\r
104 #define queuesetQUEUE_LENGTH    3\r
105 \r
106 /* Block times used in this demo.  A block time or 0 means "don't block". */\r
107 #define queuesetSHORT_DELAY     200\r
108 #define queuesetDONT_BLOCK 0\r
109 \r
110 /* Messages are sent in incrementing order from both a task and an interrupt.\r
111 The task sends values in the range 0 to 0xfffe, and the interrupt sends values\r
112 in the range of 0xffff to ULONG_MAX. */\r
113 #define queuesetINITIAL_ISR_TX_VALUE 0xffffUL\r
114 \r
115 /* The priorities used in this demo. */\r
116 #define queuesetLOW_PRIORITY    ( tskIDLE_PRIORITY )\r
117 #define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )\r
118 #define queuesetHIGH_PRIORITY   ( queuesetMEDIUM_PRIORITY + 1 )\r
119 \r
120 /* For test purposes the priority of the sending task is changed after every\r
121 queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */\r
122 #define queuesetPRIORITY_CHANGE_LOOPS   100UL\r
123 \r
124 /* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */\r
125 #define queuesetISR_TX_PERIOD   ( 100UL )\r
126 \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
132 \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
136 \r
137 /*\r
138  * The task that periodically sends to the queue set.\r
139  */\r
140 static void prvQueueSetSendingTask( void *pvParameters );\r
141 \r
142 /*\r
143  * The task that reads from the queue set.\r
144  */\r
145 static void prvQueueSetReceivingTask( void *pvParameters );\r
146 \r
147 /*\r
148  * Check the value received from a queue is the expected value.  Some values\r
149  * originate from the send task, some values originate from the ISR, with the\r
150  * range of the value being used to distinguish between the two message\r
151  * sources.\r
152  */\r
153 static void prvCheckReceivedValue( unsigned long ulReceived );\r
154 \r
155 /*\r
156  * For purposes of test coverage, functions that read from and write to a\r
157  * queue set from an ISR respectively.\r
158  */\r
159 static void prvReceiveFromQueueInSetFromISR( void );\r
160 static void prvSendToQueueInSetFromISR( void );\r
161 \r
162 /*\r
163  * Create the queues and add them to a queue set before resuming the Tx\r
164  * task.\r
165  */\r
166 static void prvSetupTest( xTaskHandle xQueueSetSendingTask );\r
167 \r
168 /*\r
169  * Checks a value received from a queue falls within the range of expected\r
170  * values.\r
171  */\r
172 static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived );\r
173 \r
174 /*-----------------------------------------------------------*/\r
175 \r
176 /* The queues that are added to the set. */\r
177 static xQueueHandle xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
178 \r
179 /* Counts how many times each queue in the set is used to ensure all the\r
180 queues are used. */\r
181 static unsigned long ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
182 \r
183 /* The handle of the queue set to which the queues are added. */\r
184 static xQueueSetHandle xQueueSet;\r
185 \r
186 /* If the prvQueueSetReceivingTask() task has not detected any errors then\r
187 it increments ulCycleCounter on each iteration.\r
188 xAreQueueSetTasksStillRunning() returns pdPASS if the value of\r
189 ulCycleCounter has changed between consecutive calls, and pdFALSE if\r
190 ulCycleCounter has stopped incrementing (indicating an error condition). */\r
191 static volatile unsigned long ulCycleCounter = 0UL;\r
192 \r
193 /* Set to pdFAIL if an error is detected by any queue set task.\r
194 ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */\r
195 static volatile portBASE_TYPE xQueueSetTasksStatus = pdPASS;\r
196 \r
197 /* Just a flag to let the function that writes to a queue from an ISR know that\r
198 the queues are setup and can be used. */\r
199 static volatile portBASE_TYPE xSetupComplete = pdFALSE;\r
200 \r
201 /* The value sent to the queue from the ISR is file scope so the\r
202 xAreQueeuSetTasksStillRunning() function can check it is incrementing as\r
203 expected. */\r
204 static volatile unsigned long ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
205 \r
206 /*-----------------------------------------------------------*/\r
207 \r
208 void vStartQueueSetTasks( void )\r
209 {\r
210 xTaskHandle xQueueSetSendingTask;\r
211 \r
212         /* Create the two queues.  The handle of the sending task is passed into\r
213         the receiving task using the task parameter.  The receiving task uses the\r
214         handle to resume the sending task after it has created the queues. */\r
215         xTaskCreate( prvQueueSetSendingTask, ( signed char * ) "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );\r
216         xTaskCreate( prvQueueSetReceivingTask, ( signed char * ) "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, NULL );\r
217 \r
218         /* It is important that the sending task does not attempt to write to a\r
219         queue before the queue has been created.  It is therefore placed into the\r
220         suspended state before the scheduler has started.  It is resumed by the\r
221         receiving task after the receiving task has created the queues and added the\r
222         queues to the queue set. */\r
223         vTaskSuspend( xQueueSetSendingTask );\r
224 }\r
225 /*-----------------------------------------------------------*/\r
226 \r
227 portBASE_TYPE xAreQueueSetTasksStillRunning( void )\r
228 {\r
229 static unsigned long ulLastCycleCounter, ulLastISRTxValue = 0;\r
230 static unsigned long ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
231 portBASE_TYPE xReturn = pdPASS, x;\r
232 \r
233         if( ulLastCycleCounter == ulCycleCounter )\r
234         {\r
235                 /* The cycle counter is no longer being incremented.  Either one of the\r
236                 tasks is stalled or an error has been detected. */\r
237                 xReturn = pdFAIL;\r
238         }\r
239 \r
240         ulLastCycleCounter = ulCycleCounter;\r
241 \r
242         /* Ensure that all the queues in the set have been used.  This ensures the\r
243         test is working as intended and guards against the rand() in the Tx task\r
244         missing some values. */\r
245         for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )\r
246         {\r
247                 if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )\r
248                 {\r
249                         xReturn = pdFAIL;\r
250                 }\r
251 \r
252                 ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];\r
253         }\r
254 \r
255         /* Check the global status flag. */\r
256         if( xQueueSetTasksStatus != pdPASS )\r
257         {\r
258                 xReturn = pdFAIL;\r
259         }\r
260 \r
261         /* Check that the ISR is still sending values to the queues too. */\r
262         if( ulISRTxValue == ulLastISRTxValue )\r
263         {\r
264                 xReturn = pdFAIL;\r
265         }\r
266         else\r
267         {\r
268                 ulLastISRTxValue = ulISRTxValue;\r
269         }\r
270 \r
271         return xReturn;\r
272 }\r
273 /*-----------------------------------------------------------*/\r
274 \r
275 static void prvQueueSetSendingTask( void *pvParameters )\r
276 {\r
277 unsigned long ulTaskTxValue = 0;\r
278 portBASE_TYPE xQueueToWriteTo;\r
279 xQueueHandle xQueueInUse;\r
280 unsigned portBASE_TYPE uxPriority = queuesetMEDIUM_PRIORITY, ulLoops = 0;\r
281 \r
282         /* Remove compiler warning about the unused parameter. */\r
283         ( void ) pvParameters;\r
284 \r
285         srand( ( unsigned int ) &ulTaskTxValue );\r
286 \r
287         for( ;; )\r
288         {\r
289                 /* Generate the index for the queue to which a value is to be sent. */\r
290                 xQueueToWriteTo = rand() % queuesetNUM_QUEUES_IN_SET;\r
291                 xQueueInUse = xQueues[ xQueueToWriteTo ];\r
292 \r
293                 /* Note which index is being written to to ensure all the queues are\r
294                 used. */\r
295                 ( ulQueueUsedCounter[ xQueueToWriteTo ] )++;\r
296 \r
297                 /* Send to the queue to unblock the task that is waiting for data to\r
298                 arrive on a queue within the queue set to which this queue belongs. */\r
299                 if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )\r
300                 {\r
301                         /* The send should always pass as an infinite block time was\r
302                         used. */\r
303                         xQueueSetTasksStatus = pdFAIL;\r
304                 }\r
305 \r
306                 ulTaskTxValue++;\r
307 \r
308                 /* If the Tx value has reached the range used by the ISR then set it\r
309                 back to 0. */\r
310                 if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )\r
311                 {\r
312                         ulTaskTxValue = 0;\r
313                 }\r
314 \r
315                 /* Occasionally change the task priority relative to the priority of\r
316                 the receiving task. */\r
317                 ulLoops++;\r
318                 if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )\r
319                 {\r
320                         ulLoops = 0;\r
321                         uxPriority++;\r
322                         if( uxPriority > queuesetHIGH_PRIORITY )\r
323                         {\r
324                                 uxPriority = queuesetLOW_PRIORITY;\r
325                         }\r
326 \r
327                         vTaskPrioritySet( NULL, uxPriority );\r
328                 }\r
329         }\r
330 }\r
331 /*-----------------------------------------------------------*/\r
332 \r
333 static void prvQueueSetReceivingTask( void *pvParameters )\r
334 {\r
335 unsigned long ulReceived;\r
336 xQueueHandle xActivatedQueue;\r
337 xTaskHandle xQueueSetSendingTask;\r
338 \r
339         /* The handle to the sending task is passed in using the task parameter. */\r
340         xQueueSetSendingTask = ( xTaskHandle ) pvParameters;\r
341 \r
342         /* Create the queues and add them to the queue set before resuming the Tx\r
343         task. */\r
344         prvSetupTest( xQueueSetSendingTask );\r
345 \r
346         for( ;; )\r
347         {\r
348                 /* Wait for a message to arrive on one of the queues in the set. */\r
349                 xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );\r
350                 configASSERT( xActivatedQueue );\r
351 \r
352                 if( xActivatedQueue == NULL )\r
353                 {\r
354                         /* This should not happen as an infinite delay was used. */\r
355                         xQueueSetTasksStatus = pdFAIL;\r
356                 }\r
357                 else\r
358                 {\r
359                         /* Reading from the queue should pass with a zero block time as\r
360                         this task will only run when something has been posted to a task\r
361                         in the queue set. */\r
362                         if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )\r
363                         {\r
364                                 xQueueSetTasksStatus = pdFAIL;\r
365                         }\r
366 \r
367                         /* Ensure the value received was the value expected.  This function\r
368                         manipulates file scope data and is also called from an ISR, hence\r
369                         the critical section. */\r
370                         taskENTER_CRITICAL();\r
371                         {\r
372                                 prvCheckReceivedValue( ulReceived );\r
373                         }\r
374                         taskEXIT_CRITICAL();\r
375                 }\r
376 \r
377                 if( xQueueSetTasksStatus == pdPASS )\r
378                 {\r
379                         ulCycleCounter++;\r
380                 }\r
381         }\r
382 }\r
383 /*-----------------------------------------------------------*/\r
384 \r
385 void vQueueSetAccessQueueSetFromISR( void )\r
386 {\r
387 static unsigned long ulCallCount = 0;\r
388 \r
389         /* xSetupComplete is set to pdTRUE when the queues have been created and\r
390         are available for use. */\r
391         if( xSetupComplete == pdTRUE )\r
392         {\r
393                 /* It is intended that this function is called from the tick hook\r
394                 function, so each call is one tick period apart. */\r
395                 ulCallCount++;\r
396                 if( ulCallCount > queuesetISR_TX_PERIOD )\r
397                 {\r
398                         ulCallCount = 0;\r
399 \r
400                         /* First attempt to read from the queue set. */\r
401                         prvReceiveFromQueueInSetFromISR();\r
402 \r
403                         /* Then write to the queue set. */\r
404                         prvSendToQueueInSetFromISR();\r
405                 }\r
406         }\r
407 }\r
408 /*-----------------------------------------------------------*/\r
409 \r
410 static void prvCheckReceivedValue( unsigned long ulReceived )\r
411 {\r
412 static unsigned long ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
413 \r
414         /* Values are received in tasks and interrupts.  It is likely that the\r
415         receiving task will sometimes get preempted by the receiving interrupt\r
416         between reading a value from the queue and calling this function.  When\r
417         that happens, if the receiving interrupt calls this function the values\r
418         will get passed into this function slightly out of order.  For that\r
419         reason the value passed in is tested against a small range of expected\r
420         values, rather than a single absolute value.  To make the range testing\r
421         easier values in the range limits are ignored. */\r
422 \r
423         /* If the received value is equal to or greater than\r
424         queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */\r
425         if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )\r
426         {\r
427                 /* The value was sent from the ISR. */\r
428                 if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )\r
429                 {\r
430                         /* The value received is at the lower limit of the expected range.\r
431                         Don't test it and expect to receive one higher next time. */\r
432                         ulExpectedReceivedFromISR++;\r
433                 }\r
434                 else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )\r
435                 {\r
436                         /* The value received is at the higher limit of the expected range.\r
437                         Don't test it and expect to wrap soon. */\r
438                         ulExpectedReceivedFromISR++;\r
439                         if( ulExpectedReceivedFromISR == 0 )\r
440                         {\r
441                                 ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
442                         }\r
443                 }\r
444                 else\r
445                 {\r
446                         /* Check the value against its expected value range. */\r
447                         if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )\r
448                         {\r
449                                 xQueueSetTasksStatus = pdFAIL;\r
450                         }\r
451                         else\r
452                         {\r
453                                 /* It is expected to receive an incrementing value. */\r
454                                 ulExpectedReceivedFromISR++;\r
455                         }\r
456                 }\r
457         }\r
458         else\r
459         {\r
460                 /* The value was sent from the Tx task. */\r
461                 if( ulReceived < queuesetIGNORED_BOUNDARY )\r
462                 {\r
463                         /* The value received is at the lower limit of the expected range.\r
464                         Don't test it, and expect to receive one higher next time. */\r
465                         ulExpectedReceivedFromTask++;\r
466                 }\r
467                 else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )\r
468                 {\r
469                         /* The value received is at the higher limit of the expected range.\r
470                         Don't test it and expect to wrap soon. */\r
471                         ulExpectedReceivedFromTask++;\r
472                         if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )\r
473                         {\r
474                                 ulExpectedReceivedFromTask = 0;\r
475                         }\r
476                 }\r
477                 else\r
478                 {\r
479                         /* Check the value against its expected value range. */\r
480                         if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )\r
481                         {\r
482                                 xQueueSetTasksStatus = pdFAIL;\r
483                         }\r
484                         else\r
485                         {\r
486                                 /* It is expected to receive an incrementing value. */\r
487                                 ulExpectedReceivedFromTask++;\r
488                         }\r
489                 }\r
490         }\r
491 }\r
492 /*-----------------------------------------------------------*/\r
493 \r
494 static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived )\r
495 {\r
496 portBASE_TYPE xReturn = pdPASS;\r
497 \r
498         if( ulReceived > ulExpectedReceived )\r
499         {\r
500                 configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );\r
501                 if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )\r
502                 {\r
503                         xReturn = pdFALSE;\r
504                 }\r
505         }\r
506         else\r
507         {\r
508                 configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );\r
509                 if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )\r
510                 {\r
511                         xReturn = pdFALSE;\r
512                 }\r
513         }\r
514 \r
515         return xReturn;\r
516 }\r
517 /*-----------------------------------------------------------*/\r
518 \r
519 static void prvReceiveFromQueueInSetFromISR( void )\r
520 {\r
521 xQueueSetMemberHandle xActivatedQueue;\r
522 unsigned long ulReceived;\r
523 \r
524         /* See if any of the queues in the set contain data. */\r
525         xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );\r
526 \r
527         if( xActivatedQueue != NULL )\r
528         {\r
529                 /* Reading from the queue for test purposes only. */\r
530                 if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )\r
531                 {\r
532                         /* Data should have been available as the handle was returned from\r
533                         xQueueSelectFromSetFromISR(). */\r
534                         xQueueSetTasksStatus = pdFAIL;\r
535                 }\r
536 \r
537                 /* Ensure the value received was the value expected. */\r
538                 prvCheckReceivedValue( ulReceived );\r
539         }\r
540 }\r
541 /*-----------------------------------------------------------*/\r
542 \r
543 static void prvSendToQueueInSetFromISR( void )\r
544 {\r
545 static portBASE_TYPE xQueueToWriteTo = 0;\r
546 \r
547         if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulISRTxValue, NULL ) == pdPASS )\r
548         {\r
549                 ulISRTxValue++;\r
550 \r
551                 /* If the Tx value has wrapped then set it back to its\r
552                 initial value. */\r
553                 if( ulISRTxValue == 0UL )\r
554                 {\r
555                         ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
556                 }\r
557 \r
558                 /* Use a different queue next time. */\r
559                 xQueueToWriteTo++;\r
560                 if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )\r
561                 {\r
562                         xQueueToWriteTo = 0;\r
563                 }\r
564         }\r
565 }\r
566 /*-----------------------------------------------------------*/\r
567 \r
568 static void prvSetupTest( xTaskHandle xQueueSetSendingTask )\r
569 {\r
570 portBASE_TYPE x;\r
571 \r
572         /* Ensure the queues are created and the queue set configured before the\r
573         sending task is unsuspended.\r
574 \r
575         First Create the queue set such that it will be able to hold a message for\r
576         every space in every queue in the set. */\r
577         xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );\r
578 \r
579         for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )\r
580         {\r
581                 /* Create the queue and add it to the set.  The queue is just holding\r
582                 unsigned long value. */\r
583                 xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( unsigned long ) );\r
584                 configASSERT( xQueues[ x ] );\r
585                 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )\r
586                 {\r
587                         xQueueSetTasksStatus = pdFAIL;\r
588                 }\r
589                 else\r
590                 {\r
591                         /* The queue has now been added to the queue set and cannot be added to\r
592                         another. */\r
593                         if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )\r
594                         {\r
595                                 xQueueSetTasksStatus = pdFAIL;\r
596                         }\r
597                 }\r
598         }\r
599 \r
600         /* Attempt to remove a queue from a queue set it does not belong\r
601         to (NULL being passed as the queue set in this case). */\r
602         if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )\r
603         {\r
604                 /* It is not possible to successfully remove a queue from a queue\r
605                 set it does not belong to. */\r
606                 xQueueSetTasksStatus = pdFAIL;\r
607         }\r
608 \r
609         /* Attempt to remove a queue from the queue set it does belong to. */\r
610         if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )\r
611         {\r
612                 /* It should be possible to remove the queue from the queue set it\r
613                 does belong to. */\r
614                 xQueueSetTasksStatus = pdFAIL;\r
615         }\r
616 \r
617         /* Add the queue back again before starting the dynamic tests. */\r
618         if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )\r
619         {\r
620                 /* If the queue was successfully removed from the queue set then it\r
621                 should be possible to add it back in again. */\r
622                 xQueueSetTasksStatus = pdFAIL;\r
623         }\r
624 \r
625         /* The task that sends to the queues is not running yet, so attempting to\r
626         read from the queue set should fail. */\r
627         if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )\r
628         {\r
629                 xQueueSetTasksStatus = pdFAIL;\r
630         }\r
631 \r
632         /* Resume the task that writes to the queues. */\r
633         vTaskResume( xQueueSetSendingTask );\r
634 \r
635         /* Let the ISR access the queues also. */\r
636         xSetupComplete = pdTRUE;\r
637 }\r