2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 * Tests the extra queue functionality introduced in FreeRTOS.org V4.5.0 -
\r
73 * including xQueueSendToFront(), xQueueSendToBack(), xQueuePeek() and
\r
76 * See the comments above the prvSendFrontAndBackTest() and
\r
77 * prvLowPriorityMutexTask() prototypes below for more information.
\r
83 /* Scheduler include files. */
\r
84 #include "FreeRTOS.h"
\r
89 /* Demo program include files. */
\r
90 #include "GenQTest.h"
\r
92 #define genqQUEUE_LENGTH ( 5 )
\r
93 #define intsemNO_BLOCK ( 0 )
\r
95 #define genqMUTEX_LOW_PRIORITY ( tskIDLE_PRIORITY )
\r
96 #define genqMUTEX_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
97 #define genqMUTEX_MEDIUM_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
98 #define genqMUTEX_HIGH_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
100 /*-----------------------------------------------------------*/
\r
103 * Tests the behaviour of the xQueueSendToFront() and xQueueSendToBack()
\r
104 * macros by using both to fill a queue, then reading from the queue to
\r
105 * check the resultant queue order is as expected. Queue data is also
\r
108 static void prvSendFrontAndBackTest( void *pvParameters );
\r
111 * The following three tasks are used to demonstrate the mutex behaviour.
\r
112 * Each task is given a different priority to demonstrate the priority
\r
113 * inheritance mechanism.
\r
115 * The low priority task obtains a mutex. After this a high priority task
\r
116 * attempts to obtain the same mutex, causing its priority to be inherited
\r
117 * by the low priority task. The task with the inherited high priority then
\r
118 * resumes a medium priority task to ensure it is not blocked by the medium
\r
119 * priority task while it holds the inherited high priority. Once the mutex
\r
120 * is returned the task with the inherited priority returns to its original
\r
121 * low priority, and is therefore immediately preempted by first the high
\r
122 * priority task and then the medium prioroity task before it can continue.
\r
124 static void prvLowPriorityMutexTask( void *pvParameters );
\r
125 static void prvMediumPriorityMutexTask( void *pvParameters );
\r
126 static void prvHighPriorityMutexTask( void *pvParameters );
\r
128 /*-----------------------------------------------------------*/
\r
130 /* Flag that will be latched to pdTRUE should any unexpected behaviour be
\r
131 detected in any of the tasks. */
\r
132 static volatile BaseType_t xErrorDetected = pdFALSE;
\r
134 /* Counters that are incremented on each cycle of a test. This is used to
\r
135 detect a stalled task - a test that is no longer running. */
\r
136 static volatile uint32_t ulLoopCounter = 0;
\r
137 static volatile uint32_t ulLoopCounter2 = 0;
\r
139 /* The variable that is guarded by the mutex in the mutex demo tasks. */
\r
140 static volatile uint32_t ulGuardedVariable = 0;
\r
142 /* Handles used in the mutext test to suspend and resume the high and medium
\r
143 priority mutex test tasks. */
\r
144 static TaskHandle_t xHighPriorityMutexTask, xMediumPriorityMutexTask;
\r
146 /*-----------------------------------------------------------*/
\r
148 void vStartGenericQueueTasks( UBaseType_t uxPriority )
\r
150 QueueHandle_t xQueue;
\r
151 SemaphoreHandle_t xMutex;
\r
154 /* Create the queue that we are going to use for the
\r
155 prvSendFrontAndBackTest demo. */
\r
156 xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );
\r
158 /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
\r
159 in use. The queue registry is provided as a means for kernel aware
\r
160 debuggers to locate queues and has no purpose if a kernel aware debugger
\r
161 is not being used. The call to vQueueAddToRegistry() will be removed
\r
162 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
\r
163 defined to be less than 1. */
\r
164 vQueueAddToRegistry( xQueue, "Gen_Queue_Test" );
\r
166 /* Create the demo task and pass it the queue just created. We are
\r
167 passing the queue handle by value so it does not matter that it is
\r
168 declared on the stack here. */
\r
169 xTaskCreate( prvSendFrontAndBackTest, "GenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );
\r
171 /* Create the mutex used by the prvMutexTest task. */
\r
172 xMutex = xSemaphoreCreateMutex();
\r
174 /* vQueueAddToRegistry() adds the mutex to the registry, if one is
\r
175 in use. The registry is provided as a means for kernel aware
\r
176 debuggers to locate mutexes and has no purpose if a kernel aware debugger
\r
177 is not being used. The call to vQueueAddToRegistry() will be removed
\r
178 by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
\r
179 defined to be less than 1. */
\r
180 vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Gen_Queue_Mutex" );
\r
182 /* Create the mutex demo tasks and pass it the mutex just created. We are
\r
183 passing the mutex handle by value so it does not matter that it is declared
\r
184 on the stack here. */
\r
185 xTaskCreate( prvLowPriorityMutexTask, "MuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );
\r
186 xTaskCreate( prvMediumPriorityMutexTask, "MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );
\r
187 xTaskCreate( prvHighPriorityMutexTask, "MuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );
\r
189 /*-----------------------------------------------------------*/
\r
191 static void prvSendFrontAndBackTest( void *pvParameters )
\r
193 uint32_t ulData, ulData2;
\r
194 QueueHandle_t xQueue;
\r
197 void vPrintDisplayMessage( const char * const * ppcMessageToSend );
\r
199 const char * const pcTaskStartMsg = "Queue SendToFront/SendToBack/Peek test started.\r\n";
\r
201 /* Queue a message for printing to say the task has started. */
\r
202 vPrintDisplayMessage( &pcTaskStartMsg );
\r
205 xQueue = ( QueueHandle_t ) pvParameters;
\r
209 /* The queue is empty, so sending an item to the back of the queue
\r
210 should have the same efect as sending it to the front of the queue.
\r
212 First send to the front and check everything is as expected. */
\r
213 xQueueSendToFront( xQueue, ( void * ) &ulLoopCounter, intsemNO_BLOCK );
\r
215 if( uxQueueMessagesWaiting( xQueue ) != 1 )
\r
217 xErrorDetected = pdTRUE;
\r
220 if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
\r
222 xErrorDetected = pdTRUE;
\r
225 /* The data we sent to the queue should equal the data we just received
\r
227 if( ulLoopCounter != ulData )
\r
229 xErrorDetected = pdTRUE;
\r
232 /* Then do the same, sending the data to the back, checking everything
\r
234 if( uxQueueMessagesWaiting( xQueue ) != 0 )
\r
236 xErrorDetected = pdTRUE;
\r
239 xQueueSendToBack( xQueue, ( void * ) &ulLoopCounter, intsemNO_BLOCK );
\r
241 if( uxQueueMessagesWaiting( xQueue ) != 1 )
\r
243 xErrorDetected = pdTRUE;
\r
246 if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
\r
248 xErrorDetected = pdTRUE;
\r
251 if( uxQueueMessagesWaiting( xQueue ) != 0 )
\r
253 xErrorDetected = pdTRUE;
\r
256 /* The data we sent to the queue should equal the data we just received
\r
258 if( ulLoopCounter != ulData )
\r
260 xErrorDetected = pdTRUE;
\r
263 #if configUSE_PREEMPTION == 0
\r
269 /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */
\r
270 for( ulData = 2; ulData < 5; ulData++ )
\r
272 xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
\r
275 /* Now the order in the queue should be 2, 3, 4, with 2 being the first
\r
276 thing to be read out. Now add 1 then 0 to the front of the queue. */
\r
277 if( uxQueueMessagesWaiting( xQueue ) != 3 )
\r
279 xErrorDetected = pdTRUE;
\r
282 xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
\r
284 xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
\r
286 /* Now the queue should be full, and when we read the data out we
\r
287 should receive 0, 1, 2, 3, 4. */
\r
288 if( uxQueueMessagesWaiting( xQueue ) != 5 )
\r
290 xErrorDetected = pdTRUE;
\r
293 if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
\r
295 xErrorDetected = pdTRUE;
\r
298 if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
\r
300 xErrorDetected = pdTRUE;
\r
303 #if configUSE_PREEMPTION == 0
\r
307 /* Check the data we read out is in the expected order. */
\r
308 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )
\r
310 /* Try peeking the data first. */
\r
311 if( xQueuePeek( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
\r
313 xErrorDetected = pdTRUE;
\r
316 if( ulData != ulData2 )
\r
318 xErrorDetected = pdTRUE;
\r
322 /* Now try receiving the data for real. The value should be the
\r
323 same. Clobber the value first so we know we really received it. */
\r
324 ulData2 = ~ulData2;
\r
325 if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
\r
327 xErrorDetected = pdTRUE;
\r
330 if( ulData != ulData2 )
\r
332 xErrorDetected = pdTRUE;
\r
336 /* The queue should now be empty again. */
\r
337 if( uxQueueMessagesWaiting( xQueue ) != 0 )
\r
339 xErrorDetected = pdTRUE;
\r
342 #if configUSE_PREEMPTION == 0
\r
347 /* Our queue is empty once more, add 10, 11 to the back. */
\r
349 if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
\r
351 xErrorDetected = pdTRUE;
\r
354 if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
\r
356 xErrorDetected = pdTRUE;
\r
359 if( uxQueueMessagesWaiting( xQueue ) != 2 )
\r
361 xErrorDetected = pdTRUE;
\r
364 /* Now we should have 10, 11 in the queue. Add 7, 8, 9 to the
\r
366 for( ulData = 9; ulData >= 7; ulData-- )
\r
368 if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
\r
370 xErrorDetected = pdTRUE;
\r
374 /* Now check that the queue is full, and that receiving data provides
\r
375 the expected sequence of 7, 8, 9, 10, 11. */
\r
376 if( uxQueueMessagesWaiting( xQueue ) != 5 )
\r
378 xErrorDetected = pdTRUE;
\r
381 if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
\r
383 xErrorDetected = pdTRUE;
\r
386 if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
\r
388 xErrorDetected = pdTRUE;
\r
391 #if configUSE_PREEMPTION == 0
\r
395 /* Check the data we read out is in the expected order. */
\r
396 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )
\r
398 if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
\r
400 xErrorDetected = pdTRUE;
\r
403 if( ulData != ulData2 )
\r
405 xErrorDetected = pdTRUE;
\r
409 if( uxQueueMessagesWaiting( xQueue ) != 0 )
\r
411 xErrorDetected = pdTRUE;
\r
417 /*-----------------------------------------------------------*/
\r
419 static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
\r
421 /* Take the mutex. It should be available now. */
\r
422 if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
\r
424 xErrorDetected = pdTRUE;
\r
427 /* Set the guarded variable to a known start value. */
\r
428 ulGuardedVariable = 0;
\r
430 /* This task's priority should be as per that assigned when the task was
\r
432 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
\r
434 xErrorDetected = pdTRUE;
\r
437 /* Now unsuspend the high priority task. This will attempt to take the
\r
438 mutex, and block when it finds it cannot obtain it. */
\r
439 vTaskResume( xHighPriorityMutexTask );
\r
441 #if configUSE_PREEMPTION == 0
\r
445 /* Ensure the task is reporting its priority as blocked and not
\r
446 suspended (as it would have done in versions up to V7.5.3). */
\r
447 #if( INCLUDE_eTaskGetState == 1 )
\r
449 configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
\r
451 #endif /* INCLUDE_eTaskGetState */
\r
453 /* The priority of the high priority task should now have been inherited
\r
454 as by now it will have attempted to get the mutex. */
\r
455 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
\r
457 xErrorDetected = pdTRUE;
\r
460 /* Attempt to set the priority of this task to the test priority -
\r
461 between the idle priority and the medium/high test priorities, but the
\r
462 actual priority should remain at the high priority. */
\r
463 vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );
\r
464 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
\r
466 xErrorDetected = pdTRUE;
\r
469 /* Now unsuspend the medium priority task. This should not run as the
\r
470 inherited priority of this task is above that of the medium priority
\r
472 vTaskResume( xMediumPriorityMutexTask );
\r
474 /* If the medium priority task did run then it will have incremented the
\r
475 guarded variable. */
\r
476 if( ulGuardedVariable != 0 )
\r
478 xErrorDetected = pdTRUE;
\r
481 /* Take the local mutex too, so two mutexes are now held. */
\r
482 if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
\r
484 xErrorDetected = pdTRUE;
\r
487 /* When the semaphore is given back the priority of this task should not
\r
488 yet be disinherited because the local mutex is still held. This is a
\r
489 simplification to allow FreeRTOS to be integrated with middleware that
\r
490 attempts to hold multiple mutexes without bloating the code with complex
\r
491 algorithms. It is possible that the high priority mutex task will
\r
492 execute as it shares a priority with this task. */
\r
493 if( xSemaphoreGive( xMutex ) != pdPASS )
\r
495 xErrorDetected = pdTRUE;
\r
498 #if configUSE_PREEMPTION == 0
\r
502 /* The guarded variable is only incremented by the medium priority task,
\r
503 which still should not have executed as this task should remain at the
\r
504 higher priority, ensure this is the case. */
\r
505 if( ulGuardedVariable != 0 )
\r
507 xErrorDetected = pdTRUE;
\r
510 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
\r
512 xErrorDetected = pdTRUE;
\r
515 /* Now also give back the local mutex, taking the held count back to 0.
\r
516 This time the priority of this task should be disinherited back to the
\r
517 priority to which it was set while the mutex was held. This means
\r
518 the medium priority task should execute and increment the guarded
\r
519 variable. When this task next runs both the high and medium priority
\r
520 tasks will have been suspended again. */
\r
521 if( xSemaphoreGive( xLocalMutex ) != pdPASS )
\r
523 xErrorDetected = pdTRUE;
\r
526 #if configUSE_PREEMPTION == 0
\r
530 /* Check the guarded variable did indeed increment... */
\r
531 if( ulGuardedVariable != 1 )
\r
533 xErrorDetected = pdTRUE;
\r
536 /* ... and that the priority of this task has been disinherited to
\r
537 genqMUTEX_TEST_PRIORITY. */
\r
538 if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )
\r
540 xErrorDetected = pdTRUE;
\r
543 /* Set the priority of this task back to its original value, ready for
\r
544 the next loop around this test. */
\r
545 vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );
\r
547 /*-----------------------------------------------------------*/
\r
549 static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
\r
551 /* Take the mutex. It should be available now. */
\r
552 if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
\r
554 xErrorDetected = pdTRUE;
\r
557 /* Set the guarded variable to a known start value. */
\r
558 ulGuardedVariable = 0;
\r
560 /* This task's priority should be as per that assigned when the task was
\r
562 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
\r
564 xErrorDetected = pdTRUE;
\r
567 /* Now unsuspend the high priority task. This will attempt to take the
\r
568 mutex, and block when it finds it cannot obtain it. */
\r
569 vTaskResume( xHighPriorityMutexTask );
\r
571 #if configUSE_PREEMPTION == 0
\r
575 /* Ensure the task is reporting its priority as blocked and not
\r
576 suspended (as it would have done in versions up to V7.5.3). */
\r
577 #if( INCLUDE_eTaskGetState == 1 )
\r
579 configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
\r
581 #endif /* INCLUDE_eTaskGetState */
\r
583 /* The priority of the high priority task should now have been inherited
\r
584 as by now it will have attempted to get the mutex. */
\r
585 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
\r
587 xErrorDetected = pdTRUE;
\r
590 /* Now unsuspend the medium priority task. This should not run as the
\r
591 inherited priority of this task is above that of the medium priority
\r
593 vTaskResume( xMediumPriorityMutexTask );
\r
595 /* If the medium priority task did run then it will have incremented the
\r
596 guarded variable. */
\r
597 if( ulGuardedVariable != 0 )
\r
599 xErrorDetected = pdTRUE;
\r
602 /* Take the local mutex too, so two mutexes are now held. */
\r
603 if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
\r
605 xErrorDetected = pdTRUE;
\r
608 /* When the local semaphore is given back the priority of this task should
\r
609 not yet be disinherited because the shared mutex is still held. This is a
\r
610 simplification to allow FreeRTOS to be integrated with middleware that
\r
611 attempts to hold multiple mutexes without bloating the code with complex
\r
612 algorithms. It is possible that the high priority mutex task will
\r
613 execute as it shares a priority with this task. */
\r
614 if( xSemaphoreGive( xLocalMutex ) != pdPASS )
\r
616 xErrorDetected = pdTRUE;
\r
619 #if configUSE_PREEMPTION == 0
\r
623 /* The guarded variable is only incremented by the medium priority task,
\r
624 which still should not have executed as this task should remain at the
\r
625 higher priority, ensure this is the case. */
\r
626 if( ulGuardedVariable != 0 )
\r
628 xErrorDetected = pdTRUE;
\r
631 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
\r
633 xErrorDetected = pdTRUE;
\r
636 /* Now also give back the shared mutex, taking the held count back to 0.
\r
637 This time the priority of this task should be disinherited back to the
\r
638 priority at which it was created. This means the medium priority task
\r
639 should execute and increment the guarded variable. When this task next runs
\r
640 both the high and medium priority tasks will have been suspended again. */
\r
641 if( xSemaphoreGive( xMutex ) != pdPASS )
\r
643 xErrorDetected = pdTRUE;
\r
646 #if configUSE_PREEMPTION == 0
\r
650 /* Check the guarded variable did indeed increment... */
\r
651 if( ulGuardedVariable != 1 )
\r
653 xErrorDetected = pdTRUE;
\r
656 /* ... and that the priority of this task has been disinherited to
\r
657 genqMUTEX_LOW_PRIORITY. */
\r
658 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
\r
660 xErrorDetected = pdTRUE;
\r
663 /*-----------------------------------------------------------*/
\r
665 static void prvLowPriorityMutexTask( void *pvParameters )
\r
667 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
\r
670 void vPrintDisplayMessage( const char * const * ppcMessageToSend );
\r
672 const char * const pcTaskStartMsg = "Mutex with priority inheritance test started.\r\n";
\r
674 /* Queue a message for printing to say the task has started. */
\r
675 vPrintDisplayMessage( &pcTaskStartMsg );
\r
678 /* The local mutex is used to check the 'mutexs held' count. */
\r
679 xLocalMutex = xSemaphoreCreateMutex();
\r
680 configASSERT( xLocalMutex );
\r
684 /* The first tests exercise the priority inheritance when two mutexes
\r
685 are taken then returned in a different order to which they were
\r
687 prvTakeTwoMutexesReturnInDifferentOrder( xMutex, xLocalMutex );
\r
689 /* Just to show this task is still running. */
\r
692 #if configUSE_PREEMPTION == 0
\r
696 /* The second tests exercise the priority inheritance when two mutexes
\r
697 are taken then returned in the same order in which they were taken. */
\r
698 prvTakeTwoMutexesReturnInSameOrder( xMutex, xLocalMutex );
\r
700 /* Just to show this task is still running. */
\r
703 #if configUSE_PREEMPTION == 0
\r
708 /*-----------------------------------------------------------*/
\r
710 static void prvMediumPriorityMutexTask( void *pvParameters )
\r
712 ( void ) pvParameters;
\r
716 /* The medium priority task starts by suspending itself. The low
\r
717 priority task will unsuspend this task when required. */
\r
718 vTaskSuspend( NULL );
\r
720 /* When this task unsuspends all it does is increment the guarded
\r
721 variable, this is so the low priority task knows that it has
\r
723 ulGuardedVariable++;
\r
726 /*-----------------------------------------------------------*/
\r
728 static void prvHighPriorityMutexTask( void *pvParameters )
\r
730 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
\r
734 /* The high priority task starts by suspending itself. The low
\r
735 priority task will unsuspend this task when required. */
\r
736 vTaskSuspend( NULL );
\r
738 /* When this task unsuspends all it does is attempt to obtain
\r
739 the mutex. It should find the mutex is not available so a
\r
740 block time is specified. */
\r
741 if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )
\r
743 xErrorDetected = pdTRUE;
\r
746 /* When the mutex is eventually obtained it is just given back before
\r
747 returning to suspend ready for the next cycle. */
\r
748 if( xSemaphoreGive( xMutex ) != pdPASS )
\r
750 xErrorDetected = pdTRUE;
\r
754 /*-----------------------------------------------------------*/
\r
757 /* This is called to check that all the created tasks are still running. */
\r
758 BaseType_t xAreGenericQueueTasksStillRunning( void )
\r
760 static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
\r
762 /* If the demo task is still running then we expect the loop counters to
\r
763 have incremented since this function was last called. */
\r
764 if( ulLastLoopCounter == ulLoopCounter )
\r
766 xErrorDetected = pdTRUE;
\r
769 if( ulLastLoopCounter2 == ulLoopCounter2 )
\r
771 xErrorDetected = pdTRUE;
\r
774 ulLastLoopCounter = ulLoopCounter;
\r
775 ulLastLoopCounter2 = ulLoopCounter2;
\r
777 /* Errors detected in the task itself will have latched xErrorDetected
\r
780 return ( BaseType_t ) !xErrorDetected;
\r