2 FreeRTOS.org V5.1.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 * This file defines one of the more complex set of demo/test tasks. They are
\r
52 * designed to stress test the queue implementation though pseudo simultaneous
\r
53 * multiple reads and multiple writes from both tasks of varying priority and
\r
54 * interrupts. The interrupts are prioritised such to ensure that nesting
\r
55 * occurs (for those ports that support it).
\r
57 * The test ensures that, while being accessed from three tasks and two
\r
58 * interrupts, all the data sent to the queues is also received from
\r
59 * the same queue, and that no duplicate items are either sent or received.
\r
60 * The tests also ensure that a low priority task is never able to successfully
\r
61 * read from or write to a queue when a task of higher priority is attempting
\r
62 * the same operation.
\r
65 /* Standard includes. */
\r
68 /* SafeRTOS includes. */
\r
69 #include "FreeRTOS.h"
\r
73 /* Demo app includes. */
\r
74 #include "IntQueue.h"
\r
75 #include "IntQueueTimer.h"
\r
77 /* Priorities used by test tasks. */
\r
78 #define intqHIGHER_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
79 #define intqLOWER_PRIORITY ( tskIDLE_PRIORITY )
\r
81 /* The number of values to send/receive before checking that all values were
\r
82 processed as expected. */
\r
83 #define intqNUM_VALUES_TO_LOG ( 200 )
\r
84 #define intqSHORT_DELAY ( 75 )
\r
86 /* The value by which the value being sent to or received from a queue should
\r
87 increment past intqNUM_VALUES_TO_LOG before we check that all values have been
\r
88 sent/received correctly. This is done to ensure that all tasks and interrupts
\r
89 accessing the queue have completed their accesses with the
\r
90 intqNUM_VALUES_TO_LOG range. */
\r
91 #define intqVALUE_OVERRUN ( 50 )
\r
93 /* The delay used by the polling task. A short delay is used for code
\r
95 #define intqONE_TICK_DELAY ( 1 )
\r
97 /* Each task and interrupt is given a unique identifier. This value is used to
\r
98 identify which task sent or received each value. The identifier is also used
\r
99 to distinguish between two tasks that are running the same task function. */
\r
100 #define intqHIGH_PRIORITY_TASK1 ( ( unsigned portBASE_TYPE ) 1 )
\r
101 #define intqHIGH_PRIORITY_TASK2 ( ( unsigned portBASE_TYPE ) 2 )
\r
102 #define intqLOW_PRIORITY_TASK ( ( unsigned portBASE_TYPE ) 3 )
\r
103 #define intqFIRST_INTERRUPT ( ( unsigned portBASE_TYPE ) 4 )
\r
104 #define intqSECOND_INTERRUPT ( ( unsigned portBASE_TYPE ) 5 )
\r
105 #define intqQUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 10 )
\r
107 /* At least intqMIN_ACCEPTABLE_TASK_COUNT values should be sent to/received
\r
108 from each queue by each task, otherwise an error is detected. */
\r
109 #define intqMIN_ACCEPTABLE_TASK_COUNT ( 5 )
\r
111 /* Send the next value to the queue that is normally empty. This is called
\r
112 from within the interrupts. */
\r
113 #define timerNORMALLY_EMPTY_TX() \
\r
114 if( xQueueIsQueueFullFromISR( xNormallyEmptyQueue ) != pdTRUE ) \
\r
116 unsigned portBASE_TYPE uxSavedInterruptStatus; \
\r
117 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
\r
119 uxValueForNormallyEmptyQueue++; \
\r
120 xQueueSendFromISR( xNormallyEmptyQueue, ( void * ) &uxValueForNormallyEmptyQueue, &xHigherPriorityTaskWoken ); \
\r
122 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
\r
125 /* Send the next value to the queue that is normally full. This is called
\r
126 from within the interrupts. */
\r
127 #define timerNORMALLY_FULL_TX() \
\r
128 if( xQueueIsQueueFullFromISR( xNormallyFullQueue ) != pdTRUE ) \
\r
130 unsigned portBASE_TYPE uxSavedInterruptStatus; \
\r
131 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
\r
133 uxValueForNormallyFullQueue++; \
\r
134 xQueueSendFromISR( xNormallyFullQueue, ( void * ) &uxValueForNormallyFullQueue, &xHigherPriorityTaskWoken ); \
\r
136 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
\r
139 /* Receive a value from the normally empty queue. This is called from within
\r
141 #define timerNORMALLY_EMPTY_RX() \
\r
142 if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
\r
144 prvQueueAccessLogError( __LINE__ ); \
\r
148 prvRecordValue_NormallyEmpty( uxRxedValue, intqSECOND_INTERRUPT ); \
\r
151 /* Receive a value from the normally full queue. This is called from within
\r
153 #define timerNORMALLY_FULL_RX() \
\r
154 if( xQueueReceiveFromISR( xNormallyFullQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) == pdPASS ) \
\r
156 prvRecordValue_NormallyFull( uxRxedValue, intqSECOND_INTERRUPT ); \
\r
160 /*-----------------------------------------------------------*/
\r
162 /* The two queues used by the test. */
\r
163 static xQueueHandle xNormallyEmptyQueue, xNormallyFullQueue;
\r
165 /* Variables used to detect a stall in one of the tasks. */
\r
166 static unsigned portBASE_TYPE uxHighPriorityLoops1 = 0, uxHighPriorityLoops2 = 0, uxLowPriorityLoops1 = 0, uxLowPriorityLoops2 = 0;
\r
168 /* Any unexpected behaviour sets xErrorStatus to fail and log the line that
\r
169 caused the error in xErrorLine. */
\r
170 static portBASE_TYPE xErrorStatus = pdPASS;
\r
171 static unsigned portBASE_TYPE xErrorLine = ( unsigned portBASE_TYPE ) 0;
\r
173 /* Used for sequencing between tasks. */
\r
174 static portBASE_TYPE xWasSuspended = pdFALSE;
\r
176 /* The values that are sent to the queues. An incremented value is sent each
\r
177 time to each queue. */
\r
178 volatile unsigned portBASE_TYPE uxValueForNormallyEmptyQueue = 0, uxValueForNormallyFullQueue = 0;
\r
180 /* A handle to some of the tasks is required so they can be suspended/resumed. */
\r
181 xTaskHandle xHighPriorityNormallyEmptyTask1, xHighPriorityNormallyEmptyTask2, xHighPriorityNormallyFullTask1, xHighPriorityNormallyFullTask2;
\r
183 /* When a value is received in a queue the value is ticked off in the array
\r
184 the array position of the value is set to a the identifier of the task or
\r
185 interrupt that accessed the queue. This way missing or duplicate values can be
\r
187 static unsigned portCHAR ucNormallyEmptyReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
\r
188 static unsigned portCHAR ucNormallyFullReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
\r
190 /* The test tasks themselves. */
\r
191 static void prvLowerPriorityNormallyEmptyTask( void *pvParameters );
\r
192 static void prvLowerPriorityNormallyFullTask( void *pvParameters );
\r
193 static void prvHigherPriorityNormallyEmptyTask( void *pvParameters );
\r
194 static void prv1stHigherPriorityNormallyFullTask( void *pvParameters );
\r
195 static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters );
\r
197 /* Used to mark the positions within the ucNormallyEmptyReceivedValues and
\r
198 ucNormallyFullReceivedValues arrays, while checking for duplicates. */
\r
199 static void prvRecordValue_NormallyEmpty( unsigned portBASE_TYPE uxValue, unsigned portBASE_TYPE uxSource );
\r
200 static void prvRecordValue_NormallyFull( unsigned portBASE_TYPE uxValue, unsigned portBASE_TYPE uxSource );
\r
202 /* Logs the line on which an error occurred. */
\r
203 static void prvQueueAccessLogError( unsigned portBASE_TYPE uxLine );
\r
205 /*-----------------------------------------------------------*/
\r
207 void vStartInterruptQueueTasks( void )
\r
209 /* Start the test tasks. */
\r
210 xTaskCreate( prvHigherPriorityNormallyEmptyTask, ( signed portCHAR * ) "H1QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask1 );
\r
211 xTaskCreate( prvHigherPriorityNormallyEmptyTask, ( signed portCHAR * ) "H2QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask2 );
\r
212 xTaskCreate( prvLowerPriorityNormallyEmptyTask, ( signed portCHAR * ) "LQRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
\r
213 xTaskCreate( prv1stHigherPriorityNormallyFullTask, ( signed portCHAR * ) "H1QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask1 );
\r
214 xTaskCreate( prv2ndHigherPriorityNormallyFullTask, ( signed portCHAR * ) "H1QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask2 );
\r
215 xTaskCreate( prvLowerPriorityNormallyFullTask, ( signed portCHAR * ) "LQRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
\r
217 /* Create the queues that are accessed by multiple tasks and multiple
\r
219 xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
\r
220 xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
\r
222 /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
\r
223 in use. The queue registry is provided as a means for kernel aware
\r
224 debuggers to locate queues and has no purpose if a kernel aware debugger
\r
225 is not being used. The call to vQueueAddToRegistry() will be removed
\r
226 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
\r
227 defined to be less than 1. */
\r
228 vQueueAddToRegistry( xNormallyFullQueue, ( signed portCHAR * ) "NormallyFull" );
\r
229 vQueueAddToRegistry( xNormallyEmptyQueue, ( signed portCHAR * ) "NormallyEmpty" );
\r
231 /*-----------------------------------------------------------*/
\r
233 static void prvRecordValue_NormallyFull( unsigned portBASE_TYPE uxValue, unsigned portBASE_TYPE uxSource )
\r
235 if( uxValue < intqNUM_VALUES_TO_LOG )
\r
237 /* We don't expect to receive the same value twice, so if the value
\r
238 has already been marked as received an error has occurred. */
\r
239 if( ucNormallyFullReceivedValues[ uxValue ] != 0x00 )
\r
241 prvQueueAccessLogError( __LINE__ );
\r
244 /* Log that this value has been received. */
\r
245 ucNormallyFullReceivedValues[ uxValue ] = uxSource;
\r
248 /*-----------------------------------------------------------*/
\r
250 static void prvRecordValue_NormallyEmpty( unsigned portBASE_TYPE uxValue, unsigned portBASE_TYPE uxSource )
\r
252 if( uxValue < intqNUM_VALUES_TO_LOG )
\r
254 /* We don't expect to receive the same value twice, so if the value
\r
255 has already been marked as received an error has occurred. */
\r
256 if( ucNormallyEmptyReceivedValues[ uxValue ] != 0x00 )
\r
258 prvQueueAccessLogError( __LINE__ );
\r
261 /* Log that this value has been received. */
\r
262 ucNormallyEmptyReceivedValues[ uxValue ] = uxSource;
\r
265 /*-----------------------------------------------------------*/
\r
267 static void prvQueueAccessLogError( unsigned portBASE_TYPE uxLine )
\r
269 /* Latch the line number that caused the error. */
\r
270 xErrorLine = uxLine;
\r
271 xErrorStatus = pdFAIL;
\r
273 /*-----------------------------------------------------------*/
\r
275 static void prvHigherPriorityNormallyEmptyTask( void *pvParameters )
\r
277 unsigned portBASE_TYPE uxRxed, ux, uxTask1, uxTask2, uxErrorCount1 = 0, uxErrorCount2 = 0;
\r
279 /* The timer should not be started until after the scheduler has started.
\r
280 More than one task is running this code so we check the parameter value
\r
281 to determine which task should start the timer. */
\r
282 if( ( unsigned portBASE_TYPE ) pvParameters == intqHIGH_PRIORITY_TASK1 )
\r
284 vInitialiseTimerForIntQueueTest();
\r
289 /* Block waiting to receive a value from the normally empty queue.
\r
290 Interrupts will write to the queue so we should receive a value. */
\r
291 if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqSHORT_DELAY ) != pdPASS )
\r
293 prvQueueAccessLogError( __LINE__ );
\r
297 /* Note which value was received so we can check all expected
\r
298 values are received and no values are duplicated. */
\r
299 prvRecordValue_NormallyEmpty( uxRxed, ( unsigned portBASE_TYPE ) pvParameters );
\r
302 /* Ensure the other task running this code gets a chance to execute. */
\r
305 if( ( unsigned portBASE_TYPE ) pvParameters == intqHIGH_PRIORITY_TASK1 )
\r
307 /* Have we received all the expected values? */
\r
308 if( uxValueForNormallyEmptyQueue > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
\r
310 vTaskSuspend( xHighPriorityNormallyEmptyTask2 );
\r
315 /* Loop through the array, checking that both tasks have
\r
316 placed values into the array, and that no values are missing.
\r
317 Start at 1 as we expect position 0 to be unused. */
\r
318 for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
\r
320 if( ucNormallyEmptyReceivedValues[ ux ] == 0 )
\r
322 /* A value is missing. */
\r
323 prvQueueAccessLogError( __LINE__ );
\r
327 if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK1 )
\r
329 /* Value was placed into the array by task 1. */
\r
332 else if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK2 )
\r
334 /* Value was placed into the array by task 2. */
\r
340 if( uxTask1 < intqMIN_ACCEPTABLE_TASK_COUNT )
\r
342 /* Only task 2 seemed to log any values. */
\r
344 if( uxErrorCount1 > 2 )
\r
346 prvQueueAccessLogError( __LINE__ );
\r
354 if( uxTask2 < intqMIN_ACCEPTABLE_TASK_COUNT )
\r
356 /* Only task 1 seemed to log any values. */
\r
358 if( uxErrorCount2 > 2 )
\r
360 prvQueueAccessLogError( __LINE__ );
\r
368 /* Clear the array again, ready to start a new cycle. */
\r
369 memset( ucNormallyEmptyReceivedValues, 0x00, sizeof( ucNormallyEmptyReceivedValues ) );
\r
371 uxHighPriorityLoops1++;
\r
372 uxValueForNormallyEmptyQueue = 0;
\r
374 /* Suspend ourselves, allowing the lower priority task to
\r
375 actually receive something from the queue. Until now it
\r
376 will have been prevented from doing so by the higher
\r
377 priority tasks. The lower priority task will resume us
\r
378 if it receives something. We will then resume the other
\r
379 higher priority task. */
\r
380 vTaskSuspend( NULL );
\r
381 vTaskResume( xHighPriorityNormallyEmptyTask2 );
\r
386 /*-----------------------------------------------------------*/
\r
388 static void prvLowerPriorityNormallyEmptyTask( void *pvParameters )
\r
390 unsigned portBASE_TYPE uxValue, uxRxed;
\r
391 portBASE_TYPE xQueueStatus;
\r
393 /* The parameters are not being used so avoid compiler warnings. */
\r
394 ( void ) pvParameters;
\r
398 if( ( xQueueStatus = xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqONE_TICK_DELAY ) ) != errQUEUE_EMPTY )
\r
400 /* We should only obtain a value when the high priority task is
\r
402 if( xTaskIsTaskSuspended( xHighPriorityNormallyEmptyTask1 ) == pdFALSE )
\r
404 prvQueueAccessLogError( __LINE__ );
\r
407 prvRecordValue_NormallyEmpty( uxRxed, intqLOW_PRIORITY_TASK );
\r
409 /* Wake the higher priority task again. */
\r
410 vTaskResume( xHighPriorityNormallyEmptyTask1 );
\r
411 uxLowPriorityLoops1++;
\r
415 /* Raise our priority while we send so we can preempt the higher
\r
416 priority task, and ensure we get the Tx value into the queue. */
\r
417 vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
\r
419 portENTER_CRITICAL();
\r
421 uxValueForNormallyEmptyQueue++;
\r
422 uxValue = uxValueForNormallyEmptyQueue;
\r
424 portEXIT_CRITICAL();
\r
426 if( xQueueSend( xNormallyEmptyQueue, &uxValue, portMAX_DELAY ) != pdPASS )
\r
428 prvQueueAccessLogError( __LINE__ );
\r
431 vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
\r
435 /*-----------------------------------------------------------*/
\r
437 static void prv1stHigherPriorityNormallyFullTask( void *pvParameters )
\r
439 unsigned portBASE_TYPE uxValueToTx, ux;
\r
440 portBASE_TYPE xQueueStatus;
\r
442 /* The parameters are not being used so avoid compiler warnings. */
\r
443 ( void ) pvParameters;
\r
445 /* Make sure the queue starts full or near full. >> 1 as there are two
\r
446 high priority tasks. */
\r
447 for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
\r
449 portENTER_CRITICAL();
\r
451 uxValueForNormallyFullQueue++;
\r
452 uxValueToTx = uxValueForNormallyFullQueue;
\r
454 portEXIT_CRITICAL();
\r
456 xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
\r
461 portENTER_CRITICAL();
\r
463 uxValueForNormallyFullQueue++;
\r
464 uxValueToTx = uxValueForNormallyFullQueue;
\r
466 portEXIT_CRITICAL();
\r
468 if( ( xQueueStatus = xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) ) != pdPASS )
\r
470 /* intqHIGH_PRIORITY_TASK2 is never suspended so we would not
\r
471 expect it to ever time out. */
\r
472 prvQueueAccessLogError( __LINE__ );
\r
475 /* Allow the other task running this code to run. */
\r
478 /* Have all the expected values been sent to the queue? */
\r
479 if( uxValueToTx > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
\r
481 /* Make sure the other high priority task completes its send of
\r
482 any values below intqNUM_VALUE_TO_LOG. */
\r
483 vTaskDelay( intqSHORT_DELAY );
\r
485 vTaskSuspend( xHighPriorityNormallyFullTask2 );
\r
487 if( xWasSuspended == pdTRUE )
\r
489 /* We would have expected the other high priority task to have
\r
490 set this back to false by now. */
\r
491 prvQueueAccessLogError( __LINE__ );
\r
494 /* Set the suspended flag so an error is not logged if the other
\r
495 task recognises a time out when it is unsuspended. */
\r
496 xWasSuspended = pdTRUE;
\r
498 /* Start at 1 as we expect position 0 to be unused. */
\r
499 for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
\r
501 if( ucNormallyFullReceivedValues[ ux ] == 0 )
\r
503 /* A value was missing. */
\r
504 prvQueueAccessLogError( __LINE__ );
\r
508 /* Reset the array ready for the next cycle. */
\r
509 memset( ucNormallyFullReceivedValues, 0x00, sizeof( ucNormallyFullReceivedValues ) );
\r
511 uxHighPriorityLoops2++;
\r
512 uxValueForNormallyFullQueue = 0;
\r
514 /* Suspend ourselves, allowing the lower priority task to
\r
515 actually receive something from the queue. Until now it
\r
516 will have been prevented from doing so by the higher
\r
517 priority tasks. The lower priority task will resume us
\r
518 if it receives something. We will then resume the other
\r
519 higher priority task. */
\r
520 vTaskSuspend( NULL );
\r
521 vTaskResume( xHighPriorityNormallyFullTask2 );
\r
525 /*-----------------------------------------------------------*/
\r
527 static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters )
\r
529 unsigned portBASE_TYPE uxValueToTx, ux;
\r
530 portBASE_TYPE xQueueStatus;
\r
532 /* The parameters are not being used so avoid compiler warnings. */
\r
533 ( void ) pvParameters;
\r
535 /* Make sure the queue starts full or near full. >> 1 as there are two
\r
536 high priority tasks. */
\r
537 for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
\r
539 portENTER_CRITICAL();
\r
541 uxValueForNormallyFullQueue++;
\r
542 uxValueToTx = uxValueForNormallyFullQueue;
\r
544 portEXIT_CRITICAL();
\r
546 xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
\r
551 portENTER_CRITICAL();
\r
553 uxValueForNormallyFullQueue++;
\r
554 uxValueToTx = uxValueForNormallyFullQueue;
\r
556 portEXIT_CRITICAL();
\r
558 if( ( xQueueStatus = xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) ) != pdPASS )
\r
560 if( xWasSuspended != pdTRUE )
\r
562 /* It is ok to time out if the task has been suspended. */
\r
563 prvQueueAccessLogError( __LINE__ );
\r
567 xWasSuspended = pdFALSE;
\r
572 /*-----------------------------------------------------------*/
\r
574 static void prvLowerPriorityNormallyFullTask( void *pvParameters )
\r
576 unsigned portBASE_TYPE uxValue, uxTxed = 9999;
\r
577 portBASE_TYPE xQueueStatus;
\r
579 /* The parameters are not being used so avoid compiler warnings. */
\r
580 ( void ) pvParameters;
\r
584 if( ( xQueueStatus = xQueueSend( xNormallyFullQueue, &uxTxed, intqONE_TICK_DELAY ) ) != errQUEUE_FULL )
\r
586 /* We would only expect to succeed when the higher priority task
\r
588 if( xTaskIsTaskSuspended( xHighPriorityNormallyFullTask1 ) == pdFALSE )
\r
590 prvQueueAccessLogError( __LINE__ );
\r
593 vTaskResume( xHighPriorityNormallyFullTask1 );
\r
594 uxLowPriorityLoops2++;
\r
598 /* Raise our priority while we receive so we can preempt the higher
\r
599 priority task, and ensure we get the value from the queue. */
\r
600 vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
\r
602 if( xQueueReceive( xNormallyFullQueue, &uxValue, portMAX_DELAY ) != pdPASS )
\r
604 prvQueueAccessLogError( __LINE__ );
\r
608 prvRecordValue_NormallyFull( uxValue, intqLOW_PRIORITY_TASK );
\r
611 vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
\r
615 /*-----------------------------------------------------------*/
\r
617 portBASE_TYPE xFirstTimerHandler( void )
\r
619 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE, uxRxedValue;
\r
620 static unsigned portBASE_TYPE uxNextOperation = 0;
\r
622 /* Called from a timer interrupt. Perform various read and write
\r
623 accesses on the queues. */
\r
627 if( uxNextOperation & ( unsigned portBASE_TYPE ) 0x01 )
\r
629 timerNORMALLY_EMPTY_TX();
\r
630 timerNORMALLY_EMPTY_TX();
\r
631 timerNORMALLY_EMPTY_TX();
\r
635 timerNORMALLY_FULL_RX();
\r
636 timerNORMALLY_FULL_RX();
\r
637 timerNORMALLY_FULL_RX();
\r
640 return xHigherPriorityTaskWoken;
\r
642 /*-----------------------------------------------------------*/
\r
644 portBASE_TYPE xSecondTimerHandler( void )
\r
646 unsigned portBASE_TYPE uxRxedValue;
\r
647 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
648 static unsigned portBASE_TYPE uxNextOperation = 0;
\r
650 /* Called from a timer interrupt. Perform various read and write
\r
651 accesses on the queues. */
\r
655 if( uxNextOperation & ( unsigned portBASE_TYPE ) 0x01 )
\r
657 timerNORMALLY_EMPTY_TX();
\r
658 timerNORMALLY_EMPTY_TX();
\r
660 timerNORMALLY_EMPTY_RX();
\r
661 timerNORMALLY_EMPTY_RX();
\r
665 timerNORMALLY_FULL_RX();
\r
666 timerNORMALLY_FULL_TX();
\r
667 timerNORMALLY_FULL_TX();
\r
668 timerNORMALLY_FULL_TX();
\r
669 timerNORMALLY_FULL_TX();
\r
672 return xHigherPriorityTaskWoken;
\r
674 /*-----------------------------------------------------------*/
\r
677 portBASE_TYPE xAreIntQueueTasksStillRunning( void )
\r
679 static unsigned portBASE_TYPE uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, uxLastLowPriorityLoops1 = 0, uxLastLowPriorityLoops2 = 0;
\r
681 /* xErrorStatus can be set outside of this function. This function just
\r
682 checks that all the tasks are still cycling. */
\r
684 if( uxHighPriorityLoops1 == uxLastHighPriorityLoops1 )
\r
686 /* The high priority 1 task has stalled. */
\r
687 prvQueueAccessLogError( __LINE__ );
\r
690 uxLastHighPriorityLoops1 = uxHighPriorityLoops1;
\r
692 if( uxHighPriorityLoops2 == uxLastHighPriorityLoops2 )
\r
694 /* The high priority 2 task has stalled. */
\r
695 prvQueueAccessLogError( __LINE__ );
\r
698 uxLastHighPriorityLoops2 = uxHighPriorityLoops2;
\r
700 if( uxLowPriorityLoops1 == uxLastLowPriorityLoops1 )
\r
702 /* The low priority 1 task has stalled. */
\r
703 prvQueueAccessLogError( __LINE__ );
\r
706 uxLastLowPriorityLoops1 = uxLowPriorityLoops1;
\r
708 if( uxLowPriorityLoops2 == uxLastLowPriorityLoops2 )
\r
710 /* The low priority 2 task has stalled. */
\r
711 prvQueueAccessLogError( __LINE__ );
\r
714 uxLastLowPriorityLoops2 = uxLowPriorityLoops2;
\r
716 return xErrorStatus;
\r