]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/AltQTest.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / Common / Minimal / AltQTest.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \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
12 \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
19 \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
24 \r
25     ***************************************************************************\r
26      *                                                                       *\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
31      *                                                                       *\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
36      *                                                                       *\r
37     ***************************************************************************\r
38 \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
42 \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
46 \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
51 \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
55 \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
58 \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
62 \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
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 \r
71 /* \r
72  * This file implements the same demo and test as GenQTest.c, but uses the \r
73  * light weight API in place of the fully featured API.\r
74  *\r
75  * See the comments at the top of GenQTest.c for a description.\r
76  */\r
77 \r
78 \r
79 #include <stdlib.h>\r
80 \r
81 /* Scheduler include files. */\r
82 #include "FreeRTOS.h"\r
83 #include "task.h"\r
84 #include "queue.h"\r
85 #include "semphr.h"\r
86 \r
87 /* Demo program include files. */\r
88 #include "AltQTest.h"\r
89 \r
90 #define genqQUEUE_LENGTH                ( 5 )\r
91 #define genqNO_BLOCK                    ( 0 )\r
92 \r
93 #define genqMUTEX_LOW_PRIORITY          ( tskIDLE_PRIORITY )\r
94 #define genqMUTEX_TEST_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
95 #define genqMUTEX_MEDIUM_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
96 #define genqMUTEX_HIGH_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /*\r
101  * Tests the behaviour of the xQueueAltSendToFront() and xQueueAltSendToBack()\r
102  * macros by using both to fill a queue, then reading from the queue to\r
103  * check the resultant queue order is as expected.  Queue data is also\r
104  * peeked.\r
105  */\r
106 static void prvSendFrontAndBackTest( void *pvParameters );\r
107 \r
108 /*\r
109  * The following three tasks are used to demonstrate the mutex behaviour.\r
110  * Each task is given a different priority to demonstrate the priority\r
111  * inheritance mechanism.\r
112  *\r
113  * The low priority task obtains a mutex.  After this a high priority task\r
114  * attempts to obtain the same mutex, causing its priority to be inherited\r
115  * by the low priority task.  The task with the inherited high priority then\r
116  * resumes a medium priority task to ensure it is not blocked by the medium\r
117  * priority task while it holds the inherited high priority.  Once the mutex\r
118  * is returned the task with the inherited priority returns to its original\r
119  * low priority, and is therefore immediately preempted by first the high\r
120  * priority task and then the medium prioroity task before it can continue.\r
121  */\r
122 static void prvLowPriorityMutexTask( void *pvParameters );\r
123 static void prvMediumPriorityMutexTask( void *pvParameters );\r
124 static void prvHighPriorityMutexTask( void *pvParameters );\r
125 \r
126 /*-----------------------------------------------------------*/\r
127 \r
128 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
129 detected in any of the tasks. */\r
130 static BaseType_t xErrorDetected = pdFALSE;\r
131 \r
132 /* Counters that are incremented on each cycle of a test.  This is used to\r
133 detect a stalled task - a test that is no longer running. */\r
134 static volatile uint32_t ulLoopCounter = 0;\r
135 static volatile uint32_t ulLoopCounter2 = 0;\r
136 \r
137 /* The variable that is guarded by the mutex in the mutex demo tasks. */\r
138 static volatile uint32_t ulGuardedVariable = 0;\r
139 \r
140 /* Handles used in the mutext test to suspend and resume the high and medium\r
141 priority mutex test tasks. */\r
142 static TaskHandle_t xHighPriorityMutexTask, xMediumPriorityMutexTask;\r
143 \r
144 /*-----------------------------------------------------------*/\r
145 \r
146 void vStartAltGenericQueueTasks( UBaseType_t uxPriority )\r
147 {\r
148 QueueHandle_t xQueue;\r
149 SemaphoreHandle_t xMutex;\r
150 \r
151         /* Create the queue that we are going to use for the\r
152         prvSendFrontAndBackTest demo. */\r
153         xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );\r
154 \r
155         /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
156         in use.  The queue registry is provided as a means for kernel aware \r
157         debuggers to locate queues and has no purpose if a kernel aware debugger\r
158         is not being used.  The call to vQueueAddToRegistry() will be removed\r
159         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
160         defined to be less than 1. */\r
161         vQueueAddToRegistry( xQueue, "Alt_Gen_Test_Queue" );\r
162 \r
163         /* Create the demo task and pass it the queue just created.  We are\r
164         passing the queue handle by value so it does not matter that it is\r
165         declared on the stack here. */\r
166         xTaskCreate( prvSendFrontAndBackTest, "FGenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );\r
167 \r
168         /* Create the mutex used by the prvMutexTest task. */\r
169         xMutex = xSemaphoreCreateMutex();\r
170 \r
171         /* vQueueAddToRegistry() adds the mutex to the registry, if one is\r
172         in use.  The registry is provided as a means for kernel aware \r
173         debuggers to locate mutex and has no purpose if a kernel aware debugger\r
174         is not being used.  The call to vQueueAddToRegistry() will be removed\r
175         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
176         defined to be less than 1. */\r
177         vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Alt_Q_Mutex" );\r
178 \r
179         /* Create the mutex demo tasks and pass it the mutex just created.  We are\r
180         passing the mutex handle by value so it does not matter that it is declared\r
181         on the stack here. */\r
182         xTaskCreate( prvLowPriorityMutexTask, "FMuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );\r
183         xTaskCreate( prvMediumPriorityMutexTask, "FMuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );\r
184         xTaskCreate( prvHighPriorityMutexTask, "FMuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvSendFrontAndBackTest( void *pvParameters )\r
189 {\r
190 uint32_t ulData, ulData2;\r
191 QueueHandle_t xQueue;\r
192 \r
193         #ifdef USE_STDIO\r
194         void vPrintDisplayMessage( const char * const * ppcMessageToSend );\r
195         \r
196                 const char * const pcTaskStartMsg = "Alt queue SendToFront/SendToBack/Peek test started.\r\n";\r
197 \r
198                 /* Queue a message for printing to say the task has started. */\r
199                 vPrintDisplayMessage( &pcTaskStartMsg );\r
200         #endif\r
201 \r
202         xQueue = ( QueueHandle_t ) pvParameters;\r
203 \r
204         for( ;; )\r
205         {\r
206                 /* The queue is empty, so sending an item to the back of the queue\r
207                 should have the same efect as sending it to the front of the queue.\r
208 \r
209                 First send to the front and check everything is as expected. */\r
210                 xQueueAltSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
211 \r
212                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
213                 {\r
214                         xErrorDetected = pdTRUE;\r
215                 }\r
216 \r
217                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
218                 {\r
219                         xErrorDetected = pdTRUE;\r
220                 }\r
221 \r
222                 /* The data we sent to the queue should equal the data we just received\r
223                 from the queue. */\r
224                 if( ulLoopCounter != ulData )\r
225                 {\r
226                         xErrorDetected = pdTRUE;\r
227                 }\r
228 \r
229                 /* Then do the same, sending the data to the back, checking everything\r
230                 is as expected. */\r
231                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
232                 {\r
233                         xErrorDetected = pdTRUE;\r
234                 }\r
235 \r
236                 xQueueAltSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
237 \r
238                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
239                 {\r
240                         xErrorDetected = pdTRUE;\r
241                 }\r
242 \r
243                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
244                 {\r
245                         xErrorDetected = pdTRUE;\r
246                 }\r
247 \r
248                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
249                 {\r
250                         xErrorDetected = pdTRUE;\r
251                 }\r
252 \r
253                 /* The data we sent to the queue should equal the data we just received\r
254                 from the queue. */\r
255                 if( ulLoopCounter != ulData )\r
256                 {\r
257                         xErrorDetected = pdTRUE;\r
258                 }\r
259 \r
260                 #if configUSE_PREEMPTION == 0\r
261                         taskYIELD();\r
262                 #endif\r
263 \r
264 \r
265 \r
266                 /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */\r
267                 for( ulData = 2; ulData < 5; ulData++ )\r
268                 {\r
269                         xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
270                 }\r
271 \r
272                 /* Now the order in the queue should be 2, 3, 4, with 2 being the first\r
273                 thing to be read out.  Now add 1 then 0 to the front of the queue. */\r
274                 if( uxQueueMessagesWaiting( xQueue ) != 3 )\r
275                 {\r
276                         xErrorDetected = pdTRUE;\r
277                 }\r
278                 ulData = 1;\r
279                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
280                 ulData = 0;\r
281                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
282 \r
283                 /* Now the queue should be full, and when we read the data out we\r
284                 should receive 0, 1, 2, 3, 4. */\r
285                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
286                 {\r
287                         xErrorDetected = pdTRUE;\r
288                 }\r
289 \r
290                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
291                 {\r
292                         xErrorDetected = pdTRUE;\r
293                 }\r
294 \r
295                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
296                 {\r
297                         xErrorDetected = pdTRUE;\r
298                 }\r
299 \r
300                 #if configUSE_PREEMPTION == 0\r
301                         taskYIELD();\r
302                 #endif\r
303 \r
304                 /* Check the data we read out is in the expected order. */\r
305                 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )\r
306                 {\r
307                         /* Try peeking the data first. */\r
308                         if( xQueueAltPeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
309                         {\r
310                                 xErrorDetected = pdTRUE;\r
311                         }\r
312 \r
313                         if( ulData != ulData2 )\r
314                         {\r
315                                 xErrorDetected = pdTRUE;\r
316                         }\r
317                         \r
318 \r
319                         /* Now try receiving the data for real.  The value should be the\r
320                         same.  Clobber the value first so we know we really received it. */\r
321                         ulData2 = ~ulData2;\r
322                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
323                         {\r
324                                 xErrorDetected = pdTRUE;\r
325                         }\r
326 \r
327                         if( ulData != ulData2 )\r
328                         {\r
329                                 xErrorDetected = pdTRUE;\r
330                         }\r
331                 }\r
332 \r
333                 /* The queue should now be empty again. */\r
334                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
335                 {\r
336                         xErrorDetected = pdTRUE;\r
337                 }\r
338 \r
339                 #if configUSE_PREEMPTION == 0\r
340                         taskYIELD();\r
341                 #endif\r
342 \r
343 \r
344                 /* Our queue is empty once more, add 10, 11 to the back. */\r
345                 ulData = 10;\r
346                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
347                 {\r
348                         xErrorDetected = pdTRUE;\r
349                 }\r
350                 ulData = 11;\r
351                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
352                 {\r
353                         xErrorDetected = pdTRUE;\r
354                 }\r
355 \r
356                 if( uxQueueMessagesWaiting( xQueue ) != 2 )\r
357                 {\r
358                         xErrorDetected = pdTRUE;\r
359                 }\r
360 \r
361                 /* Now we should have 10, 11 in the queue.  Add 7, 8, 9 to the\r
362                 front. */\r
363                 for( ulData = 9; ulData >= 7; ulData-- )\r
364                 {\r
365                         if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
366                         {\r
367                                 xErrorDetected = pdTRUE;\r
368                         }\r
369                 }\r
370 \r
371                 /* Now check that the queue is full, and that receiving data provides\r
372                 the expected sequence of 7, 8, 9, 10, 11. */\r
373                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
374                 {\r
375                         xErrorDetected = pdTRUE;\r
376                 }\r
377 \r
378                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
379                 {\r
380                         xErrorDetected = pdTRUE;\r
381                 }\r
382 \r
383                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
384                 {\r
385                         xErrorDetected = pdTRUE;\r
386                 }\r
387 \r
388                 #if configUSE_PREEMPTION == 0\r
389                         taskYIELD();\r
390                 #endif\r
391 \r
392                 /* Check the data we read out is in the expected order. */\r
393                 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )\r
394                 {\r
395                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
396                         {\r
397                                 xErrorDetected = pdTRUE;\r
398                         }\r
399 \r
400                         if( ulData != ulData2 )\r
401                         {\r
402                                 xErrorDetected = pdTRUE;\r
403                         }\r
404                 }\r
405 \r
406                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
407                 {\r
408                         xErrorDetected = pdTRUE;\r
409                 }\r
410 \r
411                 ulLoopCounter++;\r
412         }\r
413 }\r
414 /*-----------------------------------------------------------*/\r
415 \r
416 static void prvLowPriorityMutexTask( void *pvParameters )\r
417 {\r
418 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;\r
419 \r
420         #ifdef USE_STDIO\r
421         void vPrintDisplayMessage( const char * const * ppcMessageToSend );\r
422         \r
423                 const char * const pcTaskStartMsg = "Fast mutex with priority inheritance test started.\r\n";\r
424 \r
425                 /* Queue a message for printing to say the task has started. */\r
426                 vPrintDisplayMessage( &pcTaskStartMsg );\r
427         #endif\r
428 \r
429         ( void ) pvParameters;\r
430 \r
431 \r
432         for( ;; )\r
433         {\r
434                 /* Take the mutex.  It should be available now. */\r
435                 if( xSemaphoreAltTake( xMutex, genqNO_BLOCK ) != pdPASS )\r
436                 {\r
437                         xErrorDetected = pdTRUE;\r
438                 }\r
439 \r
440                 /* Set our guarded variable to a known start value. */\r
441                 ulGuardedVariable = 0;\r
442 \r
443                 /* Our priority should be as per that assigned when the task was\r
444                 created. */\r
445                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )\r
446                 {\r
447                         xErrorDetected = pdTRUE;\r
448                 }\r
449 \r
450                 /* Now unsuspend the high priority task.  This will attempt to take the\r
451                 mutex, and block when it finds it cannot obtain it. */\r
452                 vTaskResume( xHighPriorityMutexTask );\r
453 \r
454                 /* We should now have inherited the prioritoy of the high priority task,\r
455                 as by now it will have attempted to get the mutex. */\r
456                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
457                 {\r
458                         xErrorDetected = pdTRUE;\r
459                 }\r
460 \r
461                 /* We can attempt to set our priority to the test priority - between the\r
462                 idle priority and the medium/high test priorities, but our actual\r
463                 prioroity should remain at the high priority. */\r
464                 vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );\r
465                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
466                 {\r
467                         xErrorDetected = pdTRUE;\r
468                 }\r
469 \r
470                 /* Now unsuspend the medium priority task.  This should not run as our\r
471                 inherited priority is above that of the medium priority task. */\r
472                 vTaskResume( xMediumPriorityMutexTask );\r
473 \r
474                 /* If the did run then it will have incremented our guarded variable. */\r
475                 if( ulGuardedVariable != 0 )\r
476                 {\r
477                         xErrorDetected = pdTRUE;\r
478                 }\r
479 \r
480                 /* When we give back the semaphore our priority should be disinherited\r
481                 back to the priority to which we attempted to set ourselves.  This means\r
482                 that when the high priority task next blocks, the medium priority task\r
483                 should execute and increment the guarded variable.   When we next run\r
484                 both the high and medium priority tasks will have been suspended again. */\r
485                 if( xSemaphoreAltGive( xMutex ) != pdPASS )\r
486                 {\r
487                         xErrorDetected = pdTRUE;\r
488                 }\r
489 \r
490                 /* Check that the guarded variable did indeed increment... */\r
491                 if( ulGuardedVariable != 1 )\r
492                 {\r
493                         xErrorDetected = pdTRUE;\r
494                 }\r
495 \r
496                 /* ... and that our priority has been disinherited to\r
497                 genqMUTEX_TEST_PRIORITY. */\r
498                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )\r
499                 {\r
500                         xErrorDetected = pdTRUE;\r
501                 }\r
502 \r
503                 /* Set our priority back to our original priority ready for the next\r
504                 loop around this test. */\r
505                 vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );\r
506 \r
507                 /* Just to show we are still running. */\r
508                 ulLoopCounter2++;\r
509 \r
510                 #if configUSE_PREEMPTION == 0\r
511                         taskYIELD();\r
512                 #endif          \r
513         }\r
514 }\r
515 /*-----------------------------------------------------------*/\r
516 \r
517 static void prvMediumPriorityMutexTask( void *pvParameters )\r
518 {\r
519         ( void ) pvParameters;\r
520 \r
521         for( ;; )\r
522         {\r
523                 /* The medium priority task starts by suspending itself.  The low\r
524                 priority task will unsuspend this task when required. */\r
525                 vTaskSuspend( NULL );\r
526 \r
527                 /* When this task unsuspends all it does is increment the guarded\r
528                 variable, this is so the low priority task knows that it has\r
529                 executed. */\r
530                 ulGuardedVariable++;\r
531         }\r
532 }\r
533 /*-----------------------------------------------------------*/\r
534 \r
535 static void prvHighPriorityMutexTask( void *pvParameters )\r
536 {\r
537 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;\r
538 \r
539         ( void ) pvParameters;\r
540 \r
541         for( ;; )\r
542         {\r
543                 /* The high priority task starts by suspending itself.  The low\r
544                 priority task will unsuspend this task when required. */\r
545                 vTaskSuspend( NULL );\r
546 \r
547                 /* When this task unsuspends all it does is attempt to obtain\r
548                 the mutex.  It should find the mutex is not available so a\r
549                 block time is specified. */\r
550                 if( xSemaphoreAltTake( xMutex, portMAX_DELAY ) != pdPASS )\r
551                 {\r
552                         xErrorDetected = pdTRUE;\r
553                 }\r
554 \r
555                 /* When we eventually obtain the mutex we just give it back then\r
556                 return to suspend ready for the next test. */\r
557                 if( xSemaphoreAltGive( xMutex ) != pdPASS )\r
558                 {\r
559                         xErrorDetected = pdTRUE;\r
560                 }               \r
561         }\r
562 }\r
563 /*-----------------------------------------------------------*/\r
564 \r
565 /* This is called to check that all the created tasks are still running. */\r
566 BaseType_t xAreAltGenericQueueTasksStillRunning( void )\r
567 {\r
568 static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;\r
569 \r
570         /* If the demo task is still running then we expect the loopcounters to\r
571         have incremented since this function was last called. */\r
572         if( ulLastLoopCounter == ulLoopCounter )\r
573         {\r
574                 xErrorDetected = pdTRUE;\r
575         }\r
576 \r
577         if( ulLastLoopCounter2 == ulLoopCounter2 )\r
578         {\r
579                 xErrorDetected = pdTRUE;\r
580         }\r
581 \r
582         ulLastLoopCounter = ulLoopCounter;\r
583         ulLastLoopCounter2 = ulLoopCounter2;    \r
584 \r
585         /* Errors detected in the task itself will have latched xErrorDetected\r
586         to true. */\r
587 \r
588         return !xErrorDetected;\r
589 }\r
590 \r
591 \r