]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Full/dynamic.c
8abfb4992076d10b7b0c46bca13ee8d30036a110
[freertos] / FreeRTOS / Demo / Common / Full / dynamic.c
1 /*\r
2     FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 /**\r
66  * The first test creates three tasks - two counter tasks (one continuous count \r
67  * and one limited count) and one controller.  A "count" variable is shared \r
68  * between all three tasks.  The two counter tasks should never be in a "ready" \r
69  * state at the same time.  The controller task runs at the same priority as \r
70  * the continuous count task, and at a lower priority than the limited count \r
71  * task.\r
72  *\r
73  * One counter task loops indefinitely, incrementing the shared count variable\r
74  * on each iteration.  To ensure it has exclusive access to the variable it\r
75  * raises it's priority above that of the controller task before each \r
76  * increment, lowering it again to it's original priority before starting the\r
77  * next iteration.\r
78  *\r
79  * The other counter task increments the shared count variable on each\r
80  * iteration of it's loop until the count has reached a limit of 0xff - at\r
81  * which point it suspends itself.  It will not start a new loop until the \r
82  * controller task has made it "ready" again by calling vTaskResume ().  \r
83  * This second counter task operates at a higher priority than controller \r
84  * task so does not need to worry about mutual exclusion of the counter \r
85  * variable.\r
86  *\r
87  * The controller task is in two sections.  The first section controls and\r
88  * monitors the continuous count task.  When this section is operational the \r
89  * limited count task is suspended.  Likewise, the second section controls \r
90  * and monitors the limited count task.  When this section is operational the \r
91  * continuous count task is suspended.\r
92  *\r
93  * In the first section the controller task first takes a copy of the shared\r
94  * count variable.  To ensure mutual exclusion on the count variable it\r
95  * suspends the continuous count task, resuming it again when the copy has been\r
96  * taken.  The controller task then sleeps for a fixed period - during which\r
97  * the continuous count task will execute and increment the shared variable.\r
98  * When the controller task wakes it checks that the continuous count task\r
99  * has executed by comparing the copy of the shared variable with its current\r
100  * value.  This time, to ensure mutual exclusion, the scheduler itself is \r
101  * suspended with a call to vTaskSuspendAll ().  This is for demonstration \r
102  * purposes only and is not a recommended technique due to its inefficiency.\r
103  *\r
104  * After a fixed number of iterations the controller task suspends the \r
105  * continuous count task, and moves on to its second section.\r
106  *\r
107  * At the start of the second section the shared variable is cleared to zero.\r
108  * The limited count task is then woken from it's suspension by a call to\r
109  * vTaskResume ().  As this counter task operates at a higher priority than\r
110  * the controller task the controller task should not run again until the\r
111  * shared variable has been counted up to the limited value causing the counter\r
112  * task to suspend itself.  The next line after vTaskResume () is therefore\r
113  * a check on the shared variable to ensure everything is as expected.\r
114  *\r
115  *\r
116  * The second test consists of a couple of very simple tasks that post onto a \r
117  * queue while the scheduler is suspended.  This test was added to test parts\r
118  * of the scheduler not exercised by the first test.\r
119  *\r
120  *\r
121  * The final set of two tasks implements a third test.  This simply raises the\r
122  * priority of a task while the scheduler is suspended.  Again this test was\r
123  * added to exercise parts of the code not covered by the first test.\r
124  *\r
125  * \page Priorities dynamic.c\r
126  * \ingroup DemoFiles\r
127  * <HR>\r
128  */\r
129 \r
130 /*\r
131 Changes from V2.0.0\r
132 \r
133         + Delay periods are now specified using variables and constants of\r
134           portTickType rather than unsigned long.\r
135         + Added a second, simple test that uses the functions \r
136           vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().\r
137 \r
138 Changes from V3.1.1\r
139 \r
140         + Added a third simple test that uses the vTaskPrioritySet() function\r
141           while the scheduler is suspended.\r
142         + Modified the controller task slightly to test the calling of \r
143           vTaskResumeAll() while the scheduler is suspended.\r
144 */\r
145 \r
146 #include <stdlib.h>\r
147 \r
148 /* Scheduler include files. */\r
149 #include "FreeRTOS.h"\r
150 #include "task.h"\r
151 #include "semphr.h"\r
152 \r
153 /* Demo app include files. */\r
154 #include "dynamic.h"\r
155 #include "print.h"\r
156 \r
157 /* Function that implements the "limited count" task as described above. */\r
158 static void vLimitedIncrementTask( void * pvParameters );\r
159 \r
160 /* Function that implements the "continuous count" task as described above. */\r
161 static void vContinuousIncrementTask( void * pvParameters );\r
162 \r
163 /* Function that implements the controller task as described above. */\r
164 static void vCounterControlTask( void * pvParameters );\r
165 \r
166 /* The simple test functions that check sending and receiving while the\r
167 scheduler is suspended. */\r
168 static void vQueueReceiveWhenSuspendedTask( void *pvParameters );\r
169 static void vQueueSendWhenSuspendedTask( void *pvParameters );\r
170 \r
171 /* The simple test functions that check raising and lowering of task priorities\r
172 while the scheduler is suspended. */\r
173 static void prvChangePriorityWhenSuspendedTask( void *pvParameters );\r
174 static void prvChangePriorityHelperTask( void *pvParameters );\r
175 \r
176 \r
177 /* Demo task specific constants. */\r
178 #define priSTACK_SIZE                           ( ( unsigned short ) configMINIMAL_STACK_SIZE )\r
179 #define priSLEEP_TIME                           ( ( portTickType ) 50 )\r
180 #define priLOOPS                                        ( 5 )\r
181 #define priMAX_COUNT                            ( ( unsigned long ) 0xff )\r
182 #define priNO_BLOCK                                     ( ( portTickType ) 0 )\r
183 #define priSUSPENDED_QUEUE_LENGTH       ( 1 )\r
184 \r
185 /*-----------------------------------------------------------*/\r
186 \r
187 /* Handles to the two counter tasks.  These could be passed in as parameters\r
188 to the controller task to prevent them having to be file scope. */\r
189 static xTaskHandle xContinuousIncrementHandle, xLimitedIncrementHandle, xChangePriorityWhenSuspendedHandle;\r
190 \r
191 /* The shared counter variable.  This is passed in as a parameter to the two \r
192 counter variables for demonstration purposes. */\r
193 static unsigned long ulCounter;\r
194 \r
195 /* Variable used in a similar way by the test that checks the raising and\r
196 lowering of task priorities while the scheduler is suspended. */\r
197 static unsigned long ulPrioritySetCounter;\r
198 \r
199 /* Variables used to check that the tasks are still operating without error.\r
200 Each complete iteration of the controller task increments this variable\r
201 provided no errors have been found.  The variable maintaining the same value\r
202 is therefore indication of an error. */\r
203 static unsigned short usCheckVariable = ( unsigned short ) 0;\r
204 static portBASE_TYPE xSuspendedQueueSendError = pdFALSE;\r
205 static portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;\r
206 static portBASE_TYPE xPriorityRaiseWhenSuspendedError = pdFALSE;\r
207 \r
208 /* Queue used by the second test. */\r
209 xQueueHandle xSuspendedTestQueue;\r
210 \r
211 /*-----------------------------------------------------------*/\r
212 /*\r
213  * Start the seven tasks as described at the top of the file.\r
214  * Note that the limited count task is given a higher priority.\r
215  */\r
216 void vStartDynamicPriorityTasks( void )\r
217 {\r
218         xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );\r
219         xTaskCreate( vContinuousIncrementTask, "CONT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );\r
220         xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );\r
221         xTaskCreate( vCounterControlTask, "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
222         xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_SEND", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
223         xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RECV", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
224         xTaskCreate( prvChangePriorityWhenSuspendedTask, "1st_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );\r
225         xTaskCreate( prvChangePriorityHelperTask, "2nd_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xChangePriorityWhenSuspendedHandle );\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 /*\r
230  * Just loops around incrementing the shared variable until the limit has been\r
231  * reached.  Once the limit has been reached it suspends itself. \r
232  */\r
233 static void vLimitedIncrementTask( void * pvParameters )\r
234 {\r
235 unsigned long *pulCounter;\r
236 \r
237         /* Take a pointer to the shared variable from the parameters passed into\r
238         the task. */\r
239         pulCounter = ( unsigned long * ) pvParameters;\r
240 \r
241         /* This will run before the control task, so the first thing it does is\r
242         suspend - the control task will resume it when ready. */\r
243         vTaskSuspend( NULL );\r
244 \r
245         for( ;; )\r
246         {\r
247                 /* Just count up to a value then suspend. */\r
248                 ( *pulCounter )++;      \r
249                 \r
250                 if( *pulCounter >= priMAX_COUNT )\r
251                 {\r
252                         vTaskSuspend( NULL );\r
253                 }       \r
254         }\r
255 }\r
256 /*-----------------------------------------------------------*/\r
257 \r
258 /*\r
259  * Just keep counting the shared variable up.  The control task will suspend\r
260  * this task when it wants.\r
261  */\r
262 static void vContinuousIncrementTask( void * pvParameters )\r
263 {\r
264 unsigned long *pulCounter;\r
265 unsigned portBASE_TYPE uxOurPriority;\r
266 \r
267         /* Take a pointer to the shared variable from the parameters passed into\r
268         the task. */\r
269         pulCounter = ( unsigned long * ) pvParameters;\r
270 \r
271         /* Query our priority so we can raise it when exclusive access to the \r
272         shared variable is required. */\r
273         uxOurPriority = uxTaskPriorityGet( NULL );\r
274 \r
275         for( ;; )\r
276         {\r
277                 /* Raise our priority above the controller task to ensure a context\r
278                 switch does not occur while we are accessing this variable. */\r
279                 vTaskPrioritySet( NULL, uxOurPriority + 1 );\r
280                         ( *pulCounter )++;              \r
281                 vTaskPrioritySet( NULL, uxOurPriority );\r
282 \r
283                 #if configUSE_PREEMPTION == 0\r
284                         taskYIELD();\r
285                 #endif\r
286         }\r
287 }\r
288 /*-----------------------------------------------------------*/\r
289 \r
290 /*\r
291  * Controller task as described above.\r
292  */\r
293 static void vCounterControlTask( void * pvParameters )\r
294 {\r
295 unsigned long ulLastCounter;\r
296 short sLoops;\r
297 short sError = pdFALSE;\r
298 const char * const pcTaskStartMsg = "Priority manipulation tasks started.\r\n";\r
299 const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";\r
300 \r
301         /* Just to stop warning messages. */\r
302         ( void ) pvParameters;\r
303 \r
304         /* Queue a message for printing to say the task has started. */\r
305         vPrintDisplayMessage( &pcTaskStartMsg );\r
306 \r
307         for( ;; )\r
308         {\r
309                 /* Start with the counter at zero. */\r
310                 ulCounter = ( unsigned long ) 0;\r
311 \r
312                 /* First section : */\r
313 \r
314                 /* Check the continuous count task is running. */\r
315                 for( sLoops = 0; sLoops < priLOOPS; sLoops++ )\r
316                 {\r
317                         /* Suspend the continuous count task so we can take a mirror of the\r
318                         shared variable without risk of corruption. */\r
319                         vTaskSuspend( xContinuousIncrementHandle );\r
320                                 ulLastCounter = ulCounter;\r
321                         vTaskResume( xContinuousIncrementHandle );\r
322                         \r
323                         /* Now delay to ensure the other task has processor time. */\r
324                         vTaskDelay( priSLEEP_TIME );\r
325 \r
326                         /* Check the shared variable again.  This time to ensure mutual \r
327                         exclusion the whole scheduler will be locked.  This is just for\r
328                         demo purposes! */\r
329                         vTaskSuspendAll();\r
330                         {\r
331                                 if( ulLastCounter == ulCounter )\r
332                                 {\r
333                                         /* The shared variable has not changed.  There is a problem\r
334                                         with the continuous count task so flag an error. */\r
335                                         sError = pdTRUE;\r
336                                         xTaskResumeAll();\r
337                                                 vPrintDisplayMessage( &pcTaskFailMsg );\r
338                                         vTaskSuspendAll();\r
339                                 }\r
340                         }\r
341                         xTaskResumeAll();\r
342                 }\r
343 \r
344 \r
345                 /* Second section: */\r
346 \r
347                 /* Suspend the continuous counter task so it stops accessing the shared variable. */\r
348                 vTaskSuspend( xContinuousIncrementHandle );\r
349 \r
350                 /* Reset the variable. */\r
351                 ulCounter = ( unsigned long ) 0;\r
352 \r
353                 /* Resume the limited count task which has a higher priority than us.\r
354                 We should therefore not return from this call until the limited count\r
355                 task has suspended itself with a known value in the counter variable. \r
356                 The scheduler suspension is not necessary but is included for test\r
357                 purposes. */\r
358                 vTaskSuspendAll();\r
359                         vTaskResume( xLimitedIncrementHandle );\r
360                 xTaskResumeAll();\r
361 \r
362                 /* Does the counter variable have the expected value? */\r
363                 if( ulCounter != priMAX_COUNT )\r
364                 {\r
365                         sError = pdTRUE;\r
366                         vPrintDisplayMessage( &pcTaskFailMsg );\r
367                 }\r
368 \r
369                 if( sError == pdFALSE )\r
370                 {\r
371                         /* If no errors have occurred then increment the check variable. */\r
372                         portENTER_CRITICAL();\r
373                                 usCheckVariable++;\r
374                         portEXIT_CRITICAL();\r
375                 }\r
376 \r
377                 #if configUSE_PREEMPTION == 0\r
378                         taskYIELD();\r
379                 #endif\r
380 \r
381                 /* Resume the continuous count task and do it all again. */\r
382                 vTaskResume( xContinuousIncrementHandle );\r
383         }\r
384 }\r
385 /*-----------------------------------------------------------*/\r
386 \r
387 static void vQueueSendWhenSuspendedTask( void *pvParameters )\r
388 {\r
389 static unsigned long ulValueToSend = ( unsigned long ) 0;\r
390 const char * const pcTaskStartMsg = "Queue send while suspended task started.\r\n";\r
391 const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";\r
392 \r
393         /* Just to stop warning messages. */\r
394         ( void ) pvParameters;\r
395 \r
396         /* Queue a message for printing to say the task has started. */\r
397         vPrintDisplayMessage( &pcTaskStartMsg );\r
398 \r
399         for( ;; )\r
400         {\r
401                 vTaskSuspendAll();\r
402                 {\r
403                         /* We must not block while the scheduler is suspended! */\r
404                         if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )\r
405                         {\r
406                                 if( xSuspendedQueueSendError == pdFALSE )\r
407                                 {\r
408                                         xTaskResumeAll();\r
409                                                 vPrintDisplayMessage( &pcTaskFailMsg );\r
410                                         vTaskSuspendAll();\r
411                                 }\r
412 \r
413                                 xSuspendedQueueSendError = pdTRUE;\r
414                         }\r
415                 }\r
416                 xTaskResumeAll();\r
417 \r
418                 vTaskDelay( priSLEEP_TIME );\r
419 \r
420                 ++ulValueToSend;\r
421         }\r
422 }\r
423 /*-----------------------------------------------------------*/\r
424 \r
425 static void vQueueReceiveWhenSuspendedTask( void *pvParameters )\r
426 {\r
427 static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;\r
428 const char * const pcTaskStartMsg = "Queue receive while suspended task started.\r\n";\r
429 const char * const pcTaskFailMsg = "Queue receive while suspended failed.\r\n";\r
430 portBASE_TYPE xGotValue;\r
431 \r
432         /* Just to stop warning messages. */\r
433         ( void ) pvParameters;\r
434 \r
435         /* Queue a message for printing to say the task has started. */\r
436         vPrintDisplayMessage( &pcTaskStartMsg );\r
437 \r
438         for( ;; )\r
439         {\r
440                 do\r
441                 {\r
442                         /* Suspending the scheduler here is fairly pointless and \r
443                         undesirable for a normal application.  It is done here purely\r
444                         to test the scheduler.  The inner xTaskResumeAll() should\r
445                         never return pdTRUE as the scheduler is still locked by the\r
446                         outer call. */\r
447                         vTaskSuspendAll();\r
448                         {\r
449                                 vTaskSuspendAll();\r
450                                 {\r
451                                         xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );\r
452                                 }\r
453                                 if( xTaskResumeAll() )\r
454                                 {\r
455                                         xSuspendedQueueReceiveError = pdTRUE;\r
456                                 }\r
457                         }\r
458                         xTaskResumeAll();\r
459 \r
460                         #if configUSE_PREEMPTION == 0\r
461                                 taskYIELD();\r
462                         #endif\r
463 \r
464                 } while( xGotValue == pdFALSE );\r
465 \r
466                 if( ulReceivedValue != ulExpectedValue )\r
467                 {\r
468                         if( xSuspendedQueueReceiveError == pdFALSE )\r
469                         {\r
470                                 vPrintDisplayMessage( &pcTaskFailMsg );\r
471                         }\r
472                         xSuspendedQueueReceiveError = pdTRUE;\r
473                 }\r
474 \r
475                 ++ulExpectedValue;\r
476         }\r
477 }\r
478 /*-----------------------------------------------------------*/\r
479 \r
480 static void prvChangePriorityWhenSuspendedTask( void *pvParameters )\r
481 {\r
482 const char * const pcTaskStartMsg = "Priority change when suspended task started.\r\n";\r
483 const char * const pcTaskFailMsg = "Priority change when suspended task failed.\r\n";\r
484 \r
485         /* Just to stop warning messages. */\r
486         ( void ) pvParameters;\r
487 \r
488         /* Queue a message for printing to say the task has started. */\r
489         vPrintDisplayMessage( &pcTaskStartMsg );        \r
490         \r
491         for( ;; )\r
492         {\r
493                 /* Start with the counter at 0 so we know what the counter should be\r
494                 when we check it next. */\r
495                 ulPrioritySetCounter = ( unsigned long ) 0;\r
496 \r
497                 /* Resume the helper task.  At this time it has a priority lower than\r
498                 ours so no context switch should occur. */\r
499                 vTaskResume( xChangePriorityWhenSuspendedHandle );\r
500 \r
501                 /* Check to ensure the task just resumed has not executed. */\r
502                 portENTER_CRITICAL();\r
503                 {\r
504                         if( ulPrioritySetCounter != ( unsigned long ) 0 )\r
505                         {\r
506                                 xPriorityRaiseWhenSuspendedError = pdTRUE;\r
507                                 vPrintDisplayMessage( &pcTaskFailMsg );\r
508                         }\r
509                 }\r
510                 portEXIT_CRITICAL();\r
511 \r
512                 /* Now try raising the priority while the scheduler is suspended. */\r
513                 vTaskSuspendAll();\r
514                 {\r
515                         vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, ( configMAX_PRIORITIES - 1 ) );\r
516 \r
517                         /* Again, even though the helper task has a priority greater than \r
518                         ours, it should not have executed yet because the scheduler is\r
519                         suspended. */\r
520                         portENTER_CRITICAL();\r
521                         {\r
522                                 if( ulPrioritySetCounter != ( unsigned long ) 0 )\r
523                                 {\r
524                                         xPriorityRaiseWhenSuspendedError = pdTRUE;\r
525                                         vPrintDisplayMessage( &pcTaskFailMsg );\r
526                                 }\r
527                         }\r
528                         portEXIT_CRITICAL();\r
529                 }\r
530                 xTaskResumeAll();\r
531                 \r
532                 /* Now the scheduler has been resumed the helper task should \r
533                 immediately preempt us and execute.  When it executes it will increment\r
534                 the ulPrioritySetCounter exactly once before suspending itself.\r
535 \r
536                 We should now always find the counter set to 1. */\r
537                 portENTER_CRITICAL();\r
538                 {\r
539                         if( ulPrioritySetCounter != ( unsigned long ) 1 )\r
540                         {\r
541                                 xPriorityRaiseWhenSuspendedError = pdTRUE;\r
542                                 vPrintDisplayMessage( &pcTaskFailMsg );\r
543                         }\r
544                 }\r
545                 portEXIT_CRITICAL();\r
546 \r
547                 /* Delay until we try this again. */            \r
548                 vTaskDelay( priSLEEP_TIME * 2 );\r
549                 \r
550                 /* Set the priority of the helper task back ready for the next \r
551                 execution of this task. */\r
552                 vTaskSuspendAll();\r
553                         vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );                               \r
554                 xTaskResumeAll();                               \r
555         }\r
556 }\r
557 /*-----------------------------------------------------------*/\r
558 \r
559 static void prvChangePriorityHelperTask( void *pvParameters )\r
560 {\r
561         /* Just to stop warning messages. */\r
562         ( void ) pvParameters;\r
563 \r
564         for( ;; )\r
565         {\r
566                 /* This is the helper task for prvChangePriorityWhenSuspendedTask().\r
567                 It has it's priority raised and lowered.  When it runs it simply \r
568                 increments the counter then suspends itself again.  This allows\r
569                 prvChangePriorityWhenSuspendedTask() to know how many times it has\r
570                 executed. */\r
571                 ulPrioritySetCounter++;\r
572                 vTaskSuspend( NULL );\r
573         }\r
574 }\r
575 /*-----------------------------------------------------------*/\r
576 \r
577 /* Called to check that all the created tasks are still running without error. */\r
578 portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )\r
579 {\r
580 /* Keep a history of the check variables so we know if it has been incremented \r
581 since the last call. */\r
582 static unsigned short usLastTaskCheck = ( unsigned short ) 0;\r
583 portBASE_TYPE xReturn = pdTRUE;\r
584 \r
585         /* Check the tasks are still running by ensuring the check variable\r
586         is still incrementing. */\r
587 \r
588         if( usCheckVariable == usLastTaskCheck )\r
589         {\r
590                 /* The check has not incremented so an error exists. */\r
591                 xReturn = pdFALSE;\r
592         }\r
593 \r
594         if( xSuspendedQueueSendError == pdTRUE )\r
595         {\r
596                 xReturn = pdFALSE;\r
597         }\r
598 \r
599         if( xSuspendedQueueReceiveError == pdTRUE )\r
600         {\r
601                 xReturn = pdFALSE;\r
602         }\r
603 \r
604         if( xPriorityRaiseWhenSuspendedError == pdTRUE )\r
605         {\r
606                 xReturn = pdFALSE;\r
607         }\r
608 \r
609         usLastTaskCheck = usCheckVariable;\r
610         return xReturn;\r
611 }\r
612 \r
613 \r
614 \r
615 \r