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