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