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