2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Tests the use of queue sets.
\r
31 * A receive task creates a number of queues and adds them to a queue set before
\r
32 * blocking on the queue set receive. A transmit task and (optionally) an
\r
33 * interrupt repeatedly unblocks the receive task by sending messages to the
\r
34 * queues in a pseudo random order. The receive task removes the messages from
\r
35 * the queues and flags an error if the received message does not match that
\r
36 * expected. The task sends values in the range 0 to
\r
37 * queuesetINITIAL_ISR_TX_VALUE, and the ISR sends value in the range
\r
38 * queuesetINITIAL_ISR_TX_VALUE to ULONG_MAX.
\r
42 /* Standard includes. */
\r
46 /* Kernel includes. */
\r
47 #include "FreeRTOS.h"
\r
51 /* Demo includes. */
\r
52 #include "QueueSet.h"
\r
54 /* The number of queues that are created and added to the queue set. */
\r
55 #define queuesetNUM_QUEUES_IN_SET 3
\r
57 /* The length of each created queue. */
\r
58 #define queuesetQUEUE_LENGTH 3
\r
60 /* Block times used in this demo. A block time or 0 means "don't block". */
\r
61 #define queuesetSHORT_DELAY 200
\r
62 #define queuesetDONT_BLOCK 0
\r
64 /* Messages are sent in incrementing order from both a task and an interrupt.
\r
65 The task sends values in the range 0 to 0xfffe, and the interrupt sends values
\r
66 in the range of 0xffff to ULONG_MAX. */
\r
67 #define queuesetINITIAL_ISR_TX_VALUE 0xffffUL
\r
69 /* The priorities used in this demo. */
\r
70 #define queuesetLOW_PRIORITY ( tskIDLE_PRIORITY )
\r
71 #define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )
\r
73 /* For test purposes the priority of the sending task is changed after every
\r
74 queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
\r
75 #define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )
\r
77 /* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
\r
78 #define queuesetISR_TX_PERIOD ( 100UL )
\r
80 /* A delay inserted when the Tx task changes its priority to be above the idle
\r
81 task priority to ensure the idle priority tasks get some CPU time before the
\r
82 next iteration of the queue set Tx task. */
\r
83 #define queuesetTX_LOOP_DELAY pdMS_TO_TICKS( ( TickType_t ) 200 )
\r
85 /* The allowable maximum deviation between a received value and the expected
\r
86 received value. A deviation will occur when data is received from a queue
\r
87 inside an ISR in between a task receiving from a queue and the task checking
\r
88 the received value. */
\r
89 #define queuesetALLOWABLE_RX_DEVIATION 3
\r
91 /* Ignore values that are at the boundaries of allowable values to make the
\r
92 testing of limits easier (don't have to deal with wrapping values). */
\r
93 #define queuesetIGNORED_BOUNDARY ( queuesetALLOWABLE_RX_DEVIATION * 2 )
\r
97 eEqualPriority = 0, /* Tx and Rx tasks have the same priority. */
\r
98 eTxHigherPriority, /* The priority of the Tx task is above that of the Rx task. */
\r
99 eTxLowerPriority /* The priority of the Tx task is below that of the Rx task. */
\r
100 } eRelativePriorities;
\r
103 * The task that periodically sends to the queue set.
\r
105 static void prvQueueSetSendingTask( void *pvParameters );
\r
108 * The task that reads from the queue set.
\r
110 static void prvQueueSetReceivingTask( void *pvParameters );
\r
113 * Check the value received from a queue is the expected value. Some values
\r
114 * originate from the send task, some values originate from the ISR, with the
\r
115 * range of the value being used to distinguish between the two message
\r
118 static void prvCheckReceivedValue( uint32_t ulReceived );
\r
121 * For purposes of test coverage, functions that read from and write to a
\r
122 * queue set from an ISR respectively.
\r
124 static void prvReceiveFromQueueInSetFromISR( void );
\r
125 static void prvSendToQueueInSetFromISR( void );
\r
128 * Create the queues and add them to a queue set before resuming the Tx
\r
131 static void prvSetupTest( void );
\r
134 * Checks a value received from a queue falls within the range of expected
\r
137 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived );
\r
140 * Increase test coverage by occasionally change the priorities of the two tasks
\r
141 * relative to each other.
\r
143 static void prvChangeRelativePriorities( void );
\r
146 * Queue overwrites can only be performed on queues of length of one, requiring
\r
147 * a special test function so a queue of length 1 can temporarily be added to a
\r
150 static void prvTestQueueOverwriteWithQueueSet( void );
\r
153 * Local pseudo random number seed and return functions. Used to avoid calls
\r
154 * to the standard library.
\r
156 static size_t prvRand( void );
\r
157 static void prvSRand( size_t uxSeed );
\r
159 /*-----------------------------------------------------------*/
\r
161 /* The queues that are added to the set. */
\r
162 static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
164 /* Counts how many times each queue in the set is used to ensure all the
\r
165 queues are used. */
\r
166 static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
168 /* The handle of the queue set to which the queues are added. */
\r
169 static QueueSetHandle_t xQueueSet;
\r
171 /* If the prvQueueSetReceivingTask() task has not detected any errors then
\r
172 it increments ulCycleCounter on each iteration.
\r
173 xAreQueueSetTasksStillRunning() returns pdPASS if the value of
\r
174 ulCycleCounter has changed between consecutive calls, and pdFALSE if
\r
175 ulCycleCounter has stopped incrementing (indicating an error condition). */
\r
176 static volatile uint32_t ulCycleCounter = 0UL;
\r
178 /* Set to pdFAIL if an error is detected by any queue set task.
\r
179 ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
\r
180 static volatile BaseType_t xQueueSetTasksStatus = pdPASS;
\r
182 /* Just a flag to let the function that writes to a queue from an ISR know that
\r
183 the queues are setup and can be used. */
\r
184 static volatile BaseType_t xSetupComplete = pdFALSE;
\r
186 /* The value sent to the queue from the ISR is file scope so the
\r
187 xAreQueeuSetTasksStillRunning() function can check it is incrementing as
\r
189 static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
\r
191 /* Used by the pseudo random number generator. */
\r
192 static size_t uxNextRand = 0;
\r
194 /* The task handles are stored so their priorities can be changed. */
\r
195 TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;
\r
197 /*-----------------------------------------------------------*/
\r
199 void vStartQueueSetTasks( void )
\r
201 /* Create the tasks. */
\r
202 xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );
\r
204 if( xQueueSetSendingTask != NULL )
\r
206 xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );
\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
\r
210 the suspended state before the scheduler has started. It is resumed by
\r
211 the receiving task after the receiving task has created the queues and
\r
212 added the queues to the queue set. */
\r
213 vTaskSuspend( xQueueSetSendingTask );
\r
216 /*-----------------------------------------------------------*/
\r
218 BaseType_t xAreQueueSetTasksStillRunning( void )
\r
220 static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;
\r
221 static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
\r
222 BaseType_t xReturn = pdPASS, x;
\r
224 if( ulLastCycleCounter == ulCycleCounter )
\r
226 /* The cycle counter is no longer being incremented. Either one of the
\r
227 tasks is stalled or an error has been detected. */
\r
231 ulLastCycleCounter = ulCycleCounter;
\r
233 /* Ensure that all the queues in the set have been used. This ensures the
\r
234 test is working as intended and guards against the rand() in the Tx task
\r
235 missing some values. */
\r
236 for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
\r
238 if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )
\r
243 ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];
\r
246 /* Check the global status flag. */
\r
247 if( xQueueSetTasksStatus != pdPASS )
\r
252 /* Check that the ISR is still sending values to the queues too. */
\r
253 if( ulISRTxValue == ulLastISRTxValue )
\r
259 ulLastISRTxValue = ulISRTxValue;
\r
264 /*-----------------------------------------------------------*/
\r
266 static void prvQueueSetSendingTask( void *pvParameters )
\r
268 uint32_t ulTaskTxValue = 0;
\r
269 size_t uxQueueToWriteTo;
\r
270 QueueHandle_t xQueueInUse;
\r
272 /* Remove compiler warning about the unused parameter. */
\r
273 ( void ) pvParameters;
\r
275 /* Seed mini pseudo random number generator. */
\r
276 prvSRand( ( size_t ) &ulTaskTxValue );
\r
280 /* Generate the index for the queue to which a value is to be sent. */
\r
281 uxQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
\r
282 xQueueInUse = xQueues[ uxQueueToWriteTo ];
\r
284 /* Note which index is being written to to ensure all the queues are
\r
286 ( ulQueueUsedCounter[ uxQueueToWriteTo ] )++;
\r
288 /* Send to the queue to unblock the task that is waiting for data to
\r
289 arrive on a queue within the queue set to which this queue belongs. */
\r
290 if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )
\r
292 /* The send should always pass as an infinite block time was
\r
294 xQueueSetTasksStatus = pdFAIL;
\r
297 #if( configUSE_PREEMPTION == 0 )
\r
303 /* If the Tx value has reached the range used by the ISR then set it
\r
305 if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )
\r
310 /* Increase test coverage by occasionally change the priorities of the
\r
311 two tasks relative to each other. */
\r
312 prvChangeRelativePriorities();
\r
315 /*-----------------------------------------------------------*/
\r
317 static void prvChangeRelativePriorities( void )
\r
319 static UBaseType_t ulLoops = 0;
\r
320 static eRelativePriorities ePriorities = eEqualPriority;
\r
322 /* Occasionally change the task priority relative to the priority of
\r
323 the receiving task. */
\r
325 if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )
\r
329 switch( ePriorities )
\r
331 case eEqualPriority:
\r
332 /* Both tasks are running with medium priority. Now lower the
\r
333 priority of the receiving task so the Tx task has the higher
\r
334 relative priority. */
\r
335 vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );
\r
336 ePriorities = eTxHigherPriority;
\r
339 case eTxHigherPriority:
\r
340 /* The Tx task is running with a higher priority than the Rx
\r
341 task. Switch the priorities around so the Rx task has the
\r
342 higher relative priority. */
\r
343 vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );
\r
344 vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );
\r
345 ePriorities = eTxLowerPriority;
\r
348 case eTxLowerPriority:
\r
349 /* The Tx task is running with a lower priority than the Rx
\r
350 task. Make the priorities equal again. */
\r
351 vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );
\r
352 ePriorities = eEqualPriority;
\r
354 /* When both tasks are using a non-idle priority the queue set
\r
355 tasks will starve idle priority tasks of execution time - so
\r
356 relax a bit before the next iteration to minimise the impact. */
\r
357 vTaskDelay( queuesetTX_LOOP_DELAY );
\r
363 /*-----------------------------------------------------------*/
\r
365 static void prvQueueSetReceivingTask( void *pvParameters )
\r
367 uint32_t ulReceived;
\r
368 QueueHandle_t xActivatedQueue;
\r
369 TickType_t xBlockTime;
\r
371 /* Remove compiler warnings. */
\r
372 ( void ) pvParameters;
\r
374 /* Create the queues and add them to the queue set before resuming the Tx
\r
380 /* For test coverage reasons, the block time is dependent on the
\r
381 priority of this task - which changes during the test. When the task
\r
382 is at the idle priority it polls the queue set. */
\r
383 if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )
\r
389 xBlockTime = portMAX_DELAY;
\r
392 /* Wait for a message to arrive on one of the queues in the set. */
\r
393 xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );
\r
395 if( xActivatedQueue == NULL )
\r
397 if( xBlockTime != 0 )
\r
399 /* This should not happen as an infinite delay was used. */
\r
400 xQueueSetTasksStatus = pdFAIL;
\r
405 /* Reading from the queue should pass with a zero block time as
\r
406 this task will only run when something has been posted to a task
\r
407 in the queue set. */
\r
408 if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )
\r
410 xQueueSetTasksStatus = pdFAIL;
\r
413 /* Ensure the value received was the value expected. This function
\r
414 manipulates file scope data and is also called from an ISR, hence
\r
415 the critical section. */
\r
416 taskENTER_CRITICAL();
\r
418 prvCheckReceivedValue( ulReceived );
\r
420 taskEXIT_CRITICAL();
\r
422 if( xQueueSetTasksStatus == pdPASS )
\r
429 /*-----------------------------------------------------------*/
\r
431 void vQueueSetAccessQueueSetFromISR( void )
\r
433 static uint32_t ulCallCount = 0;
\r
435 /* xSetupComplete is set to pdTRUE when the queues have been created and
\r
436 are available for use. */
\r
437 if( xSetupComplete == pdTRUE )
\r
439 /* It is intended that this function is called from the tick hook
\r
440 function, so each call is one tick period apart. */
\r
442 if( ulCallCount > queuesetISR_TX_PERIOD )
\r
446 /* First attempt to read from the queue set. */
\r
447 prvReceiveFromQueueInSetFromISR();
\r
449 /* Then write to the queue set. */
\r
450 prvSendToQueueInSetFromISR();
\r
454 /*-----------------------------------------------------------*/
\r
456 static void prvCheckReceivedValue( uint32_t ulReceived )
\r
458 static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
\r
460 /* Values are received in tasks and interrupts. It is likely that the
\r
461 receiving task will sometimes get preempted by the receiving interrupt
\r
462 between reading a value from the queue and calling this function. When
\r
463 that happens, if the receiving interrupt calls this function the values
\r
464 will get passed into this function slightly out of order. For that
\r
465 reason the value passed in is tested against a small range of expected
\r
466 values, rather than a single absolute value. To make the range testing
\r
467 easier values in the range limits are ignored. */
\r
469 /* If the received value is equal to or greater than
\r
470 queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */
\r
471 if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )
\r
473 /* The value was sent from the ISR. */
\r
474 if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )
\r
476 /* The value received is at the lower limit of the expected range.
\r
477 Don't test it and expect to receive one higher next time. */
\r
479 else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )
\r
481 /* The value received is at the higher limit of the expected range.
\r
482 Don't test it and expect to wrap soon. */
\r
486 /* Check the value against its expected value range. */
\r
487 if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )
\r
489 xQueueSetTasksStatus = pdFAIL;
\r
493 configASSERT( xQueueSetTasksStatus );
\r
495 /* It is expected to receive an incrementing number. */
\r
496 ulExpectedReceivedFromISR++;
\r
497 if( ulExpectedReceivedFromISR == 0 )
\r
499 ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
\r
504 /* The value was sent from the Tx task. */
\r
505 if( ulReceived < queuesetIGNORED_BOUNDARY )
\r
507 /* The value received is at the lower limit of the expected range.
\r
508 Don't test it, and expect to receive one higher next time. */
\r
510 else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )
\r
512 /* The value received is at the higher limit of the expected range.
\r
513 Don't test it and expect to wrap soon. */
\r
517 /* Check the value against its expected value range. */
\r
518 if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )
\r
520 xQueueSetTasksStatus = pdFAIL;
\r
524 configASSERT( xQueueSetTasksStatus );
\r
526 /* It is expected to receive an incrementing number. */
\r
527 ulExpectedReceivedFromTask++;
\r
528 if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )
\r
530 ulExpectedReceivedFromTask = 0;
\r
534 /*-----------------------------------------------------------*/
\r
536 static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived )
\r
538 BaseType_t xReturn = pdPASS;
\r
540 if( ulReceived > ulExpectedReceived )
\r
542 configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
\r
543 if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )
\r
550 configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
\r
551 if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )
\r
559 /*-----------------------------------------------------------*/
\r
561 static void prvReceiveFromQueueInSetFromISR( void )
\r
563 QueueSetMemberHandle_t xActivatedQueue;
\r
564 uint32_t ulReceived;
\r
566 /* See if any of the queues in the set contain data. */
\r
567 xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );
\r
569 if( xActivatedQueue != NULL )
\r
571 /* Reading from the queue for test purposes only. */
\r
572 if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )
\r
574 /* Data should have been available as the handle was returned from
\r
575 xQueueSelectFromSetFromISR(). */
\r
576 xQueueSetTasksStatus = pdFAIL;
\r
579 /* Ensure the value received was the value expected. */
\r
580 prvCheckReceivedValue( ulReceived );
\r
583 /*-----------------------------------------------------------*/
\r
585 static void prvSendToQueueInSetFromISR( void )
\r
587 static BaseType_t xQueueToWriteTo = 0;
\r
588 uint32_t ulTxValueSnapshot = ulISRTxValue;
\r
590 if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulTxValueSnapshot, NULL ) == pdPASS )
\r
594 /* If the Tx value has wrapped then set it back to its initial value. */
\r
595 if( ulISRTxValue == 0UL )
\r
597 ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
\r
600 /* Use a different queue next time. */
\r
602 if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )
\r
604 xQueueToWriteTo = 0;
\r
608 /*-----------------------------------------------------------*/
\r
610 static void prvTestQueueOverwriteWithQueueSet( void )
\r
612 uint32_t ulValueToSend = 0, ulValueReceived = 0;
\r
613 QueueHandle_t xQueueHandle = NULL, xReceivedHandle = NULL;
\r
614 const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
\r
616 /* Create a queue that has a length of one - a requirement in order to call
\r
617 xQueueOverwrite. This will get deleted again when this test completes. */
\r
618 xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
\r
620 if( xQueueHandle != NULL )
\r
622 xQueueAddToSet( xQueueHandle, xQueueSet );
\r
624 /* Add an item to the queue then ensure the queue set correctly
\r
625 indicates that one item is available, and that that item is indeed the
\r
626 queue written to. */
\r
627 xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
\r
628 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
\r
630 /* Expected one item in the queue set. */
\r
631 xQueueSetTasksStatus = pdFAIL;
\r
633 xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
\r
634 if( xReceivedHandle != xQueueHandle )
\r
636 /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
\r
637 held in the queue set. */
\r
638 xQueueSetTasksStatus = pdFAIL;
\r
641 /* Now overwrite the value in the queue and ensure the queue set state
\r
642 doesn't change as the number of items in the queues within the set have
\r
645 xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
\r
646 if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
\r
648 /* Still expected one item in the queue set. */
\r
649 xQueueSetTasksStatus = pdFAIL;
\r
651 xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
\r
652 if( xReceivedHandle != xQueueHandle )
\r
654 /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
\r
655 held in the queue set. */
\r
656 xQueueSetTasksStatus = pdFAIL;
\r
659 /* Also ensure the value received from the queue is the overwritten
\r
660 value, not the value originally written. */
\r
661 xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );
\r
662 if( ulValueReceived != ulValueToSend )
\r
664 /* Unexpected value recevied from the queue. */
\r
665 xQueueSetTasksStatus = pdFAIL;
\r
669 xQueueRemoveFromSet( xQueueHandle, xQueueSet );
\r
670 vQueueDelete( xQueueHandle );
\r
673 /*-----------------------------------------------------------*/
\r
675 static void prvSetupTest( void )
\r
678 uint32_t ulValueToSend = 0;
\r
680 /* Ensure the queues are created and the queue set configured before the
\r
681 sending task is unsuspended.
\r
683 First Create the queue set such that it will be able to hold a message for
\r
684 every space in every queue in the set. */
\r
685 xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );
\r
687 for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
\r
689 /* Create the queue and add it to the set. The queue is just holding
\r
691 xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );
\r
692 configASSERT( xQueues[ x ] );
\r
693 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )
\r
695 xQueueSetTasksStatus = pdFAIL;
\r
699 /* The queue has now been added to the queue set and cannot be added to
\r
701 if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )
\r
703 xQueueSetTasksStatus = pdFAIL;
\r
708 /* Attempt to remove a queue from a queue set it does not belong
\r
709 to (NULL being passed as the queue set in this case). */
\r
710 if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )
\r
712 /* It is not possible to successfully remove a queue from a queue
\r
713 set it does not belong to. */
\r
714 xQueueSetTasksStatus = pdFAIL;
\r
717 /* Attempt to remove a queue from the queue set it does belong to. */
\r
718 if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
\r
720 /* It should be possible to remove the queue from the queue set it
\r
722 xQueueSetTasksStatus = pdFAIL;
\r
725 /* Add an item to the queue before attempting to add it back into the
\r
727 xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );
\r
728 if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )
\r
730 /* Should not be able to add a non-empty queue to a set. */
\r
731 xQueueSetTasksStatus = pdFAIL;
\r
734 /* Remove the item from the queue before adding the queue back into the
\r
735 set so the dynamic tests can begin. */
\r
736 xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );
\r
737 if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
\r
739 /* If the queue was successfully removed from the queue set then it
\r
740 should be possible to add it back in again. */
\r
741 xQueueSetTasksStatus = pdFAIL;
\r
744 /* The task that sends to the queues is not running yet, so attempting to
\r
745 read from the queue set should fail. */
\r
746 if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )
\r
748 xQueueSetTasksStatus = pdFAIL;
\r
751 /* Testing the behaviour of queue sets when a queue overwrite operation is
\r
752 performed on a set member requires a special test as overwrites can only
\r
753 be performed on queues that have a length of 1. */
\r
754 prvTestQueueOverwriteWithQueueSet();
\r
756 /* Resume the task that writes to the queues. */
\r
757 vTaskResume( xQueueSetSendingTask );
\r
759 /* Let the ISR access the queues also. */
\r
760 xSetupComplete = pdTRUE;
\r
762 /*-----------------------------------------------------------*/
\r
764 static size_t prvRand( void )
\r
766 uxNextRand = ( uxNextRand * ( size_t ) 1103515245 ) + ( size_t ) 12345;
\r
767 return ( uxNextRand / ( size_t ) 65536 ) % ( size_t ) 32768;
\r
769 /*-----------------------------------------------------------*/
\r
771 static void prvSRand( size_t uxSeed )
\r
773 uxNextRand = uxSeed;
\r