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