]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/GenQTest.c
Prepare for V7.3.0 release.
[freertos] / FreeRTOS / Demo / Common / Minimal / GenQTest.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32     >>>NOTE<<< The modification to the GPL is included to allow you to\r
33     distribute a combined work that includes FreeRTOS without being obliged to\r
34     provide the source code for proprietary components outside of the FreeRTOS\r
35     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
36     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
37     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
38     more details. You should have received a copy of the GNU General Public\r
39     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
40     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
41     by writing to Richard Barry, contact details for whom are available on the\r
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \r
62     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
63     the code with commercial support, indemnification, and middleware, under \r
64     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
65     provide a safety engineered and independently SIL3 certified version under \r
66     the SafeRTOS brand: http://www.SafeRTOS.com.\r
67 */\r
68 \r
69 \r
70 /* \r
71  * Tests the extra queue functionality introduced in FreeRTOS.org V4.5.0 - \r
72  * including xQueueSendToFront(), xQueueSendToBack(), xQueuePeek() and \r
73  * mutex behaviour. \r
74  *\r
75  * See the comments above the prvSendFrontAndBackTest() and \r
76  * prvLowPriorityMutexTask() prototypes below for more information.\r
77  */\r
78 \r
79 \r
80 #include <stdlib.h>\r
81 \r
82 /* Scheduler include files. */\r
83 #include "FreeRTOS.h"\r
84 #include "task.h"\r
85 #include "queue.h"\r
86 #include "semphr.h"\r
87 \r
88 /* Demo program include files. */\r
89 #include "GenQTest.h"\r
90 \r
91 #define genqQUEUE_LENGTH                ( 5 )\r
92 #define genqNO_BLOCK                    ( 0 )\r
93 \r
94 #define genqMUTEX_LOW_PRIORITY          ( tskIDLE_PRIORITY )\r
95 #define genqMUTEX_TEST_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
96 #define genqMUTEX_MEDIUM_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
97 #define genqMUTEX_HIGH_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
98 \r
99 /*-----------------------------------------------------------*/\r
100 \r
101 /*\r
102  * Tests the behaviour of the xQueueSendToFront() and xQueueSendToBack()\r
103  * macros by using both to fill a queue, then reading from the queue to\r
104  * check the resultant queue order is as expected.  Queue data is also\r
105  * peeked.\r
106  */\r
107 static void prvSendFrontAndBackTest( void *pvParameters );\r
108 \r
109 /*\r
110  * The following three tasks are used to demonstrate the mutex behaviour.\r
111  * Each task is given a different priority to demonstrate the priority\r
112  * inheritance mechanism.\r
113  *\r
114  * The low priority task obtains a mutex.  After this a high priority task\r
115  * attempts to obtain the same mutex, causing its priority to be inherited\r
116  * by the low priority task.  The task with the inherited high priority then\r
117  * resumes a medium priority task to ensure it is not blocked by the medium\r
118  * priority task while it holds the inherited high priority.  Once the mutex\r
119  * is returned the task with the inherited priority returns to its original\r
120  * low priority, and is therefore immediately preempted by first the high\r
121  * priority task and then the medium prioroity task before it can continue.\r
122  */\r
123 static void prvLowPriorityMutexTask( void *pvParameters );\r
124 static void prvMediumPriorityMutexTask( void *pvParameters );\r
125 static void prvHighPriorityMutexTask( void *pvParameters );\r
126 \r
127 /*-----------------------------------------------------------*/\r
128 \r
129 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
130 detected in any of the tasks. */\r
131 static portBASE_TYPE xErrorDetected = pdFALSE;\r
132 \r
133 /* Counters that are incremented on each cycle of a test.  This is used to\r
134 detect a stalled task - a test that is no longer running. */\r
135 static volatile unsigned portLONG ulLoopCounter = 0;\r
136 static volatile unsigned portLONG ulLoopCounter2 = 0;\r
137 \r
138 /* The variable that is guarded by the mutex in the mutex demo tasks. */\r
139 static volatile unsigned portLONG ulGuardedVariable = 0;\r
140 \r
141 /* Handles used in the mutext test to suspend and resume the high and medium\r
142 priority mutex test tasks. */\r
143 static xTaskHandle xHighPriorityMutexTask, xMediumPriorityMutexTask;\r
144 \r
145 /*-----------------------------------------------------------*/\r
146 \r
147 void vStartGenericQueueTasks( unsigned portBASE_TYPE uxPriority )\r
148 {\r
149 xQueueHandle xQueue;\r
150 xSemaphoreHandle xMutex;\r
151 \r
152         /* Create the queue that we are going to use for the\r
153         prvSendFrontAndBackTest demo. */\r
154         xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );\r
155 \r
156         /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
157         in use.  The queue registry is provided as a means for kernel aware \r
158         debuggers to locate queues and has no purpose if a kernel aware debugger\r
159         is not being used.  The call to vQueueAddToRegistry() will be removed\r
160         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
161         defined to be less than 1. */\r
162         vQueueAddToRegistry( xQueue, ( signed portCHAR * ) "Gen_Queue_Test" );\r
163 \r
164         /* Create the demo task and pass it the queue just created.  We are\r
165         passing the queue handle by value so it does not matter that it is\r
166         declared on the stack here. */\r
167         xTaskCreate( prvSendFrontAndBackTest, ( signed portCHAR * )"GenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );\r
168 \r
169         /* Create the mutex used by the prvMutexTest task. */\r
170         xMutex = xSemaphoreCreateMutex();\r
171 \r
172         /* vQueueAddToRegistry() adds the mutex to the registry, if one is\r
173         in use.  The registry is provided as a means for kernel aware \r
174         debuggers to locate mutexes and has no purpose if a kernel aware debugger\r
175         is not being used.  The call to vQueueAddToRegistry() will be removed\r
176         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
177         defined to be less than 1. */\r
178         vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Gen_Queue_Mutex" );\r
179 \r
180         /* Create the mutex demo tasks and pass it the mutex just created.  We are\r
181         passing the mutex handle by value so it does not matter that it is declared\r
182         on the stack here. */\r
183         xTaskCreate( prvLowPriorityMutexTask, ( signed portCHAR * )"MuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );\r
184         xTaskCreate( prvMediumPriorityMutexTask, ( signed portCHAR * )"MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );\r
185         xTaskCreate( prvHighPriorityMutexTask, ( signed portCHAR * )"MuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 static void prvSendFrontAndBackTest( void *pvParameters )\r
190 {\r
191 unsigned portLONG ulData, ulData2;\r
192 xQueueHandle xQueue;\r
193 \r
194         #ifdef USE_STDIO\r
195         void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
196         \r
197                 const portCHAR * const pcTaskStartMsg = "Queue SendToFront/SendToBack/Peek test started.\r\n";\r
198 \r
199                 /* Queue a message for printing to say the task has started. */\r
200                 vPrintDisplayMessage( &pcTaskStartMsg );\r
201         #endif\r
202 \r
203         xQueue = ( xQueueHandle ) pvParameters;\r
204 \r
205         for( ;; )\r
206         {\r
207                 /* The queue is empty, so sending an item to the back of the queue\r
208                 should have the same efect as sending it to the front of the queue.\r
209 \r
210                 First send to the front and check everything is as expected. */\r
211                 xQueueSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
212 \r
213                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
214                 {\r
215                         xErrorDetected = pdTRUE;\r
216                 }\r
217 \r
218                 if( xQueueReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
219                 {\r
220                         xErrorDetected = pdTRUE;\r
221                 }\r
222 \r
223                 /* The data we sent to the queue should equal the data we just received\r
224                 from the queue. */\r
225                 if( ulLoopCounter != ulData )\r
226                 {\r
227                         xErrorDetected = pdTRUE;\r
228                 }\r
229 \r
230                 /* Then do the same, sending the data to the back, checking everything\r
231                 is as expected. */\r
232                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
233                 {\r
234                         xErrorDetected = pdTRUE;\r
235                 }\r
236 \r
237                 xQueueSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
238 \r
239                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
240                 {\r
241                         xErrorDetected = pdTRUE;\r
242                 }\r
243 \r
244                 if( xQueueReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
245                 {\r
246                         xErrorDetected = pdTRUE;\r
247                 }\r
248 \r
249                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
250                 {\r
251                         xErrorDetected = pdTRUE;\r
252                 }\r
253 \r
254                 /* The data we sent to the queue should equal the data we just received\r
255                 from the queue. */\r
256                 if( ulLoopCounter != ulData )\r
257                 {\r
258                         xErrorDetected = pdTRUE;\r
259                 }\r
260 \r
261                 #if configUSE_PREEMPTION == 0\r
262                         taskYIELD();\r
263                 #endif\r
264 \r
265 \r
266 \r
267                 /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */\r
268                 for( ulData = 2; ulData < 5; ulData++ )\r
269                 {\r
270                         xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
271                 }\r
272 \r
273                 /* Now the order in the queue should be 2, 3, 4, with 2 being the first\r
274                 thing to be read out.  Now add 1 then 0 to the front of the queue. */\r
275                 if( uxQueueMessagesWaiting( xQueue ) != 3 )\r
276                 {\r
277                         xErrorDetected = pdTRUE;\r
278                 }\r
279                 ulData = 1;\r
280                 xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
281                 ulData = 0;\r
282                 xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
283 \r
284                 /* Now the queue should be full, and when we read the data out we\r
285                 should receive 0, 1, 2, 3, 4. */\r
286                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
287                 {\r
288                         xErrorDetected = pdTRUE;\r
289                 }\r
290 \r
291                 if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
292                 {\r
293                         xErrorDetected = pdTRUE;\r
294                 }\r
295 \r
296                 if( xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
297                 {\r
298                         xErrorDetected = pdTRUE;\r
299                 }\r
300 \r
301                 #if configUSE_PREEMPTION == 0\r
302                         taskYIELD();\r
303                 #endif\r
304 \r
305                 /* Check the data we read out is in the expected order. */\r
306                 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )\r
307                 {\r
308                         /* Try peeking the data first. */\r
309                         if( xQueuePeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
310                         {\r
311                                 xErrorDetected = pdTRUE;\r
312                         }\r
313 \r
314                         if( ulData != ulData2 )\r
315                         {\r
316                                 xErrorDetected = pdTRUE;\r
317                         }\r
318                         \r
319 \r
320                         /* Now try receiving the data for real.  The value should be the\r
321                         same.  Clobber the value first so we know we really received it. */\r
322                         ulData2 = ~ulData2;\r
323                         if( xQueueReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
324                         {\r
325                                 xErrorDetected = pdTRUE;\r
326                         }\r
327 \r
328                         if( ulData != ulData2 )\r
329                         {\r
330                                 xErrorDetected = pdTRUE;\r
331                         }\r
332                 }\r
333 \r
334                 /* The queue should now be empty again. */\r
335                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
336                 {\r
337                         xErrorDetected = pdTRUE;\r
338                 }\r
339 \r
340                 #if configUSE_PREEMPTION == 0\r
341                         taskYIELD();\r
342                 #endif\r
343 \r
344 \r
345                 /* Our queue is empty once more, add 10, 11 to the back. */\r
346                 ulData = 10;\r
347                 if( xQueueSend( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
348                 {\r
349                         xErrorDetected = pdTRUE;\r
350                 }\r
351                 ulData = 11;\r
352                 if( xQueueSend( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
353                 {\r
354                         xErrorDetected = pdTRUE;\r
355                 }\r
356 \r
357                 if( uxQueueMessagesWaiting( xQueue ) != 2 )\r
358                 {\r
359                         xErrorDetected = pdTRUE;\r
360                 }\r
361 \r
362                 /* Now we should have 10, 11 in the queue.  Add 7, 8, 9 to the\r
363                 front. */\r
364                 for( ulData = 9; ulData >= 7; ulData-- )\r
365                 {\r
366                         if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
367                         {\r
368                                 xErrorDetected = pdTRUE;\r
369                         }\r
370                 }\r
371 \r
372                 /* Now check that the queue is full, and that receiving data provides\r
373                 the expected sequence of 7, 8, 9, 10, 11. */\r
374                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
375                 {\r
376                         xErrorDetected = pdTRUE;\r
377                 }\r
378 \r
379                 if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
380                 {\r
381                         xErrorDetected = pdTRUE;\r
382                 }\r
383 \r
384                 if( xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
385                 {\r
386                         xErrorDetected = pdTRUE;\r
387                 }\r
388 \r
389                 #if configUSE_PREEMPTION == 0\r
390                         taskYIELD();\r
391                 #endif\r
392 \r
393                 /* Check the data we read out is in the expected order. */\r
394                 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )\r
395                 {\r
396                         if( xQueueReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
397                         {\r
398                                 xErrorDetected = pdTRUE;\r
399                         }\r
400 \r
401                         if( ulData != ulData2 )\r
402                         {\r
403                                 xErrorDetected = pdTRUE;\r
404                         }\r
405                 }\r
406 \r
407                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
408                 {\r
409                         xErrorDetected = pdTRUE;\r
410                 }\r
411 \r
412                 ulLoopCounter++;\r
413         }\r
414 }\r
415 /*-----------------------------------------------------------*/\r
416 \r
417 static void prvLowPriorityMutexTask( void *pvParameters )\r
418 {\r
419 xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;\r
420 \r
421         #ifdef USE_STDIO\r
422         void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
423         \r
424                 const portCHAR * const pcTaskStartMsg = "Mutex with priority inheritance test started.\r\n";\r
425 \r
426                 /* Queue a message for printing to say the task has started. */\r
427                 vPrintDisplayMessage( &pcTaskStartMsg );\r
428         #endif\r
429 \r
430         for( ;; )\r
431         {\r
432                 /* Take the mutex.  It should be available now. */\r
433                 if( xSemaphoreTake( xMutex, genqNO_BLOCK ) != pdPASS )\r
434                 {\r
435                         xErrorDetected = pdTRUE;\r
436                 }\r
437 \r
438                 /* Set our guarded variable to a known start value. */\r
439                 ulGuardedVariable = 0;\r
440 \r
441                 /* Our priority should be as per that assigned when the task was\r
442                 created. */\r
443                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )\r
444                 {\r
445                         xErrorDetected = pdTRUE;\r
446                 }\r
447 \r
448                 /* Now unsuspend the high priority task.  This will attempt to take the\r
449                 mutex, and block when it finds it cannot obtain it. */\r
450                 vTaskResume( xHighPriorityMutexTask );\r
451 \r
452                 /* We should now have inherited the prioritoy of the high priority task,\r
453                 as by now it will have attempted to get the mutex. */\r
454                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
455                 {\r
456                         xErrorDetected = pdTRUE;\r
457                 }\r
458 \r
459                 /* We can attempt to set our priority to the test priority - between the\r
460                 idle priority and the medium/high test priorities, but our actual\r
461                 prioroity should remain at the high priority. */\r
462                 vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );\r
463                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
464                 {\r
465                         xErrorDetected = pdTRUE;\r
466                 }\r
467 \r
468                 /* Now unsuspend the medium priority task.  This should not run as our\r
469                 inherited priority is above that of the medium priority task. */\r
470                 vTaskResume( xMediumPriorityMutexTask );\r
471 \r
472                 /* If the did run then it will have incremented our guarded variable. */\r
473                 if( ulGuardedVariable != 0 )\r
474                 {\r
475                         xErrorDetected = pdTRUE;\r
476                 }\r
477 \r
478                 /* When we give back the semaphore our priority should be disinherited\r
479                 back to the priority to which we attempted to set ourselves.  This means\r
480                 that when the high priority task next blocks, the medium priority task\r
481                 should execute and increment the guarded variable.   When we next run\r
482                 both the high and medium priority tasks will have been suspended again. */\r
483                 if( xSemaphoreGive( xMutex ) != pdPASS )\r
484                 {\r
485                         xErrorDetected = pdTRUE;\r
486                 }\r
487 \r
488                 /* Check that the guarded variable did indeed increment... */\r
489                 if( ulGuardedVariable != 1 )\r
490                 {\r
491                         xErrorDetected = pdTRUE;\r
492                 }\r
493 \r
494                 /* ... and that our priority has been disinherited to\r
495                 genqMUTEX_TEST_PRIORITY. */\r
496                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )\r
497                 {\r
498                         xErrorDetected = pdTRUE;\r
499                 }\r
500 \r
501                 /* Set our priority back to our original priority ready for the next\r
502                 loop around this test. */\r
503                 vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );\r
504 \r
505                 /* Just to show we are still running. */\r
506                 ulLoopCounter2++;\r
507 \r
508                 #if configUSE_PREEMPTION == 0\r
509                         taskYIELD();\r
510                 #endif          \r
511         }\r
512 }\r
513 /*-----------------------------------------------------------*/\r
514 \r
515 static void prvMediumPriorityMutexTask( void *pvParameters )\r
516 {\r
517         ( void ) pvParameters;\r
518 \r
519         for( ;; )\r
520         {\r
521                 /* The medium priority task starts by suspending itself.  The low\r
522                 priority task will unsuspend this task when required. */\r
523                 vTaskSuspend( NULL );\r
524 \r
525                 /* When this task unsuspends all it does is increment the guarded\r
526                 variable, this is so the low priority task knows that it has\r
527                 executed. */\r
528                 ulGuardedVariable++;\r
529         }\r
530 }\r
531 /*-----------------------------------------------------------*/\r
532 \r
533 static void prvHighPriorityMutexTask( void *pvParameters )\r
534 {\r
535 xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;\r
536 \r
537         for( ;; )\r
538         {\r
539                 /* The high priority task starts by suspending itself.  The low\r
540                 priority task will unsuspend this task when required. */\r
541                 vTaskSuspend( NULL );\r
542 \r
543                 /* When this task unsuspends all it does is attempt to obtain\r
544                 the mutex.  It should find the mutex is not available so a\r
545                 block time is specified. */\r
546                 if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )\r
547                 {\r
548                         xErrorDetected = pdTRUE;\r
549                 }\r
550 \r
551                 /* When we eventually obtain the mutex we just give it back then\r
552                 return to suspend ready for the next test. */\r
553                 if( xSemaphoreGive( xMutex ) != pdPASS )\r
554                 {\r
555                         xErrorDetected = pdTRUE;\r
556                 }               \r
557         }\r
558 }\r
559 /*-----------------------------------------------------------*/\r
560 \r
561 /* This is called to check that all the created tasks are still running. */\r
562 portBASE_TYPE xAreGenericQueueTasksStillRunning( void )\r
563 {\r
564 static unsigned portLONG ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;\r
565 \r
566         /* If the demo task is still running then we expect the loopcounters to\r
567         have incremented since this function was last called. */\r
568         if( ulLastLoopCounter == ulLoopCounter )\r
569         {\r
570                 xErrorDetected = pdTRUE;\r
571         }\r
572 \r
573         if( ulLastLoopCounter2 == ulLoopCounter2 )\r
574         {\r
575                 xErrorDetected = pdTRUE;\r
576         }\r
577 \r
578         ulLastLoopCounter = ulLoopCounter;\r
579         ulLastLoopCounter2 = ulLoopCounter2;    \r
580 \r
581         /* Errors detected in the task itself will have latched xErrorDetected\r
582         to true. */\r
583 \r
584         return !xErrorDetected;\r
585 }\r
586 \r
587 \r