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