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