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