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