]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/AltQTest.c
97103366265c0642f7615c52a556f08f9e6e6c66
[freertos] / FreeRTOS / Demo / Common / Minimal / AltQTest.c
1 /*\r
2     FreeRTOS V7.6.0 - Copyright (C) 2013 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 \r
67 /* \r
68  * This file implements the same demo and test as GenQTest.c, but uses the \r
69  * light weight API in place of the fully featured API.\r
70  *\r
71  * See the comments at the top of GenQTest.c for a description.\r
72  */\r
73 \r
74 \r
75 #include <stdlib.h>\r
76 \r
77 /* Scheduler include files. */\r
78 #include "FreeRTOS.h"\r
79 #include "task.h"\r
80 #include "queue.h"\r
81 #include "semphr.h"\r
82 \r
83 /* Demo program include files. */\r
84 #include "AltQTest.h"\r
85 \r
86 #define genqQUEUE_LENGTH                ( 5 )\r
87 #define genqNO_BLOCK                    ( 0 )\r
88 \r
89 #define genqMUTEX_LOW_PRIORITY          ( tskIDLE_PRIORITY )\r
90 #define genqMUTEX_TEST_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
91 #define genqMUTEX_MEDIUM_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
92 #define genqMUTEX_HIGH_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
93 \r
94 /*-----------------------------------------------------------*/\r
95 \r
96 /*\r
97  * Tests the behaviour of the xQueueAltSendToFront() and xQueueAltSendToBack()\r
98  * macros by using both to fill a queue, then reading from the queue to\r
99  * check the resultant queue order is as expected.  Queue data is also\r
100  * peeked.\r
101  */\r
102 static void prvSendFrontAndBackTest( void *pvParameters );\r
103 \r
104 /*\r
105  * The following three tasks are used to demonstrate the mutex behaviour.\r
106  * Each task is given a different priority to demonstrate the priority\r
107  * inheritance mechanism.\r
108  *\r
109  * The low priority task obtains a mutex.  After this a high priority task\r
110  * attempts to obtain the same mutex, causing its priority to be inherited\r
111  * by the low priority task.  The task with the inherited high priority then\r
112  * resumes a medium priority task to ensure it is not blocked by the medium\r
113  * priority task while it holds the inherited high priority.  Once the mutex\r
114  * is returned the task with the inherited priority returns to its original\r
115  * low priority, and is therefore immediately preempted by first the high\r
116  * priority task and then the medium prioroity task before it can continue.\r
117  */\r
118 static void prvLowPriorityMutexTask( void *pvParameters );\r
119 static void prvMediumPriorityMutexTask( void *pvParameters );\r
120 static void prvHighPriorityMutexTask( void *pvParameters );\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
125 detected in any of the tasks. */\r
126 static portBASE_TYPE xErrorDetected = pdFALSE;\r
127 \r
128 /* Counters that are incremented on each cycle of a test.  This is used to\r
129 detect a stalled task - a test that is no longer running. */\r
130 static volatile unsigned portLONG ulLoopCounter = 0;\r
131 static volatile unsigned portLONG ulLoopCounter2 = 0;\r
132 \r
133 /* The variable that is guarded by the mutex in the mutex demo tasks. */\r
134 static volatile unsigned portLONG ulGuardedVariable = 0;\r
135 \r
136 /* Handles used in the mutext test to suspend and resume the high and medium\r
137 priority mutex test tasks. */\r
138 static xTaskHandle xHighPriorityMutexTask, xMediumPriorityMutexTask;\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 \r
142 void vStartAltGenericQueueTasks( unsigned portBASE_TYPE uxPriority )\r
143 {\r
144 xQueueHandle xQueue;\r
145 xSemaphoreHandle xMutex;\r
146 \r
147         /* Create the queue that we are going to use for the\r
148         prvSendFrontAndBackTest demo. */\r
149         xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );\r
150 \r
151         /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
152         in use.  The queue registry is provided as a means for kernel aware \r
153         debuggers to locate queues and has no purpose if a kernel aware debugger\r
154         is not being used.  The call to vQueueAddToRegistry() will be removed\r
155         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
156         defined to be less than 1. */\r
157         vQueueAddToRegistry( xQueue, ( signed portCHAR * ) "Alt_Gen_Test_Queue" );\r
158 \r
159         /* Create the demo task and pass it the queue just created.  We are\r
160         passing the queue handle by value so it does not matter that it is\r
161         declared on the stack here. */\r
162         xTaskCreate( prvSendFrontAndBackTest, ( signed portCHAR * ) "FGenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );\r
163 \r
164         /* Create the mutex used by the prvMutexTest task. */\r
165         xMutex = xSemaphoreCreateMutex();\r
166 \r
167         /* vQueueAddToRegistry() adds the mutex to the registry, if one is\r
168         in use.  The registry is provided as a means for kernel aware \r
169         debuggers to locate mutex and has no purpose if a kernel aware debugger\r
170         is not being used.  The call to vQueueAddToRegistry() will be removed\r
171         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
172         defined to be less than 1. */\r
173         vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Alt_Q_Mutex" );\r
174 \r
175         /* Create the mutex demo tasks and pass it the mutex just created.  We are\r
176         passing the mutex handle by value so it does not matter that it is declared\r
177         on the stack here. */\r
178         xTaskCreate( prvLowPriorityMutexTask, ( signed portCHAR * ) "FMuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );\r
179         xTaskCreate( prvMediumPriorityMutexTask, ( signed portCHAR * ) "FMuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );\r
180         xTaskCreate( prvHighPriorityMutexTask, ( signed portCHAR * ) "FMuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 static void prvSendFrontAndBackTest( void *pvParameters )\r
185 {\r
186 unsigned portLONG ulData, ulData2;\r
187 xQueueHandle xQueue;\r
188 \r
189         #ifdef USE_STDIO\r
190         void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
191         \r
192                 const portCHAR * const pcTaskStartMsg = "Alt queue SendToFront/SendToBack/Peek test started.\r\n";\r
193 \r
194                 /* Queue a message for printing to say the task has started. */\r
195                 vPrintDisplayMessage( &pcTaskStartMsg );\r
196         #endif\r
197 \r
198         xQueue = ( xQueueHandle ) pvParameters;\r
199 \r
200         for( ;; )\r
201         {\r
202                 /* The queue is empty, so sending an item to the back of the queue\r
203                 should have the same efect as sending it to the front of the queue.\r
204 \r
205                 First send to the front and check everything is as expected. */\r
206                 xQueueAltSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
207 \r
208                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
209                 {\r
210                         xErrorDetected = pdTRUE;\r
211                 }\r
212 \r
213                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
214                 {\r
215                         xErrorDetected = pdTRUE;\r
216                 }\r
217 \r
218                 /* The data we sent to the queue should equal the data we just received\r
219                 from the queue. */\r
220                 if( ulLoopCounter != ulData )\r
221                 {\r
222                         xErrorDetected = pdTRUE;\r
223                 }\r
224 \r
225                 /* Then do the same, sending the data to the back, checking everything\r
226                 is as expected. */\r
227                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
228                 {\r
229                         xErrorDetected = pdTRUE;\r
230                 }\r
231 \r
232                 xQueueAltSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
233 \r
234                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
235                 {\r
236                         xErrorDetected = pdTRUE;\r
237                 }\r
238 \r
239                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
240                 {\r
241                         xErrorDetected = pdTRUE;\r
242                 }\r
243 \r
244                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
245                 {\r
246                         xErrorDetected = pdTRUE;\r
247                 }\r
248 \r
249                 /* The data we sent to the queue should equal the data we just received\r
250                 from the queue. */\r
251                 if( ulLoopCounter != ulData )\r
252                 {\r
253                         xErrorDetected = pdTRUE;\r
254                 }\r
255 \r
256                 #if configUSE_PREEMPTION == 0\r
257                         taskYIELD();\r
258                 #endif\r
259 \r
260 \r
261 \r
262                 /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */\r
263                 for( ulData = 2; ulData < 5; ulData++ )\r
264                 {\r
265                         xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
266                 }\r
267 \r
268                 /* Now the order in the queue should be 2, 3, 4, with 2 being the first\r
269                 thing to be read out.  Now add 1 then 0 to the front of the queue. */\r
270                 if( uxQueueMessagesWaiting( xQueue ) != 3 )\r
271                 {\r
272                         xErrorDetected = pdTRUE;\r
273                 }\r
274                 ulData = 1;\r
275                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
276                 ulData = 0;\r
277                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
278 \r
279                 /* Now the queue should be full, and when we read the data out we\r
280                 should receive 0, 1, 2, 3, 4. */\r
281                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
282                 {\r
283                         xErrorDetected = pdTRUE;\r
284                 }\r
285 \r
286                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
287                 {\r
288                         xErrorDetected = pdTRUE;\r
289                 }\r
290 \r
291                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
292                 {\r
293                         xErrorDetected = pdTRUE;\r
294                 }\r
295 \r
296                 #if configUSE_PREEMPTION == 0\r
297                         taskYIELD();\r
298                 #endif\r
299 \r
300                 /* Check the data we read out is in the expected order. */\r
301                 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )\r
302                 {\r
303                         /* Try peeking the data first. */\r
304                         if( xQueueAltPeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
305                         {\r
306                                 xErrorDetected = pdTRUE;\r
307                         }\r
308 \r
309                         if( ulData != ulData2 )\r
310                         {\r
311                                 xErrorDetected = pdTRUE;\r
312                         }\r
313                         \r
314 \r
315                         /* Now try receiving the data for real.  The value should be the\r
316                         same.  Clobber the value first so we know we really received it. */\r
317                         ulData2 = ~ulData2;\r
318                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
319                         {\r
320                                 xErrorDetected = pdTRUE;\r
321                         }\r
322 \r
323                         if( ulData != ulData2 )\r
324                         {\r
325                                 xErrorDetected = pdTRUE;\r
326                         }\r
327                 }\r
328 \r
329                 /* The queue should now be empty again. */\r
330                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
331                 {\r
332                         xErrorDetected = pdTRUE;\r
333                 }\r
334 \r
335                 #if configUSE_PREEMPTION == 0\r
336                         taskYIELD();\r
337                 #endif\r
338 \r
339 \r
340                 /* Our queue is empty once more, add 10, 11 to the back. */\r
341                 ulData = 10;\r
342                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
343                 {\r
344                         xErrorDetected = pdTRUE;\r
345                 }\r
346                 ulData = 11;\r
347                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
348                 {\r
349                         xErrorDetected = pdTRUE;\r
350                 }\r
351 \r
352                 if( uxQueueMessagesWaiting( xQueue ) != 2 )\r
353                 {\r
354                         xErrorDetected = pdTRUE;\r
355                 }\r
356 \r
357                 /* Now we should have 10, 11 in the queue.  Add 7, 8, 9 to the\r
358                 front. */\r
359                 for( ulData = 9; ulData >= 7; ulData-- )\r
360                 {\r
361                         if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
362                         {\r
363                                 xErrorDetected = pdTRUE;\r
364                         }\r
365                 }\r
366 \r
367                 /* Now check that the queue is full, and that receiving data provides\r
368                 the expected sequence of 7, 8, 9, 10, 11. */\r
369                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
370                 {\r
371                         xErrorDetected = pdTRUE;\r
372                 }\r
373 \r
374                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
375                 {\r
376                         xErrorDetected = pdTRUE;\r
377                 }\r
378 \r
379                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
380                 {\r
381                         xErrorDetected = pdTRUE;\r
382                 }\r
383 \r
384                 #if configUSE_PREEMPTION == 0\r
385                         taskYIELD();\r
386                 #endif\r
387 \r
388                 /* Check the data we read out is in the expected order. */\r
389                 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )\r
390                 {\r
391                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
392                         {\r
393                                 xErrorDetected = pdTRUE;\r
394                         }\r
395 \r
396                         if( ulData != ulData2 )\r
397                         {\r
398                                 xErrorDetected = pdTRUE;\r
399                         }\r
400                 }\r
401 \r
402                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
403                 {\r
404                         xErrorDetected = pdTRUE;\r
405                 }\r
406 \r
407                 ulLoopCounter++;\r
408         }\r
409 }\r
410 /*-----------------------------------------------------------*/\r
411 \r
412 static void prvLowPriorityMutexTask( void *pvParameters )\r
413 {\r
414 xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;\r
415 \r
416         #ifdef USE_STDIO\r
417         void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
418         \r
419                 const portCHAR * const pcTaskStartMsg = "Fast mutex with priority inheritance test started.\r\n";\r
420 \r
421                 /* Queue a message for printing to say the task has started. */\r
422                 vPrintDisplayMessage( &pcTaskStartMsg );\r
423         #endif\r
424 \r
425         ( void ) pvParameters;\r
426 \r
427 \r
428         for( ;; )\r
429         {\r
430                 /* Take the mutex.  It should be available now. */\r
431                 if( xSemaphoreAltTake( 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( xSemaphoreAltGive( 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         ( void ) 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( xSemaphoreAltTake( 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( xSemaphoreAltGive( 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 xAreAltGenericQueueTasksStillRunning( 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