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