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