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