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