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