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