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