]> git.sur5r.net Git - freertos/blob - Demo/SuperH_SH7216_Renesas/RTOSDemo/main.c
Tidy up SuperH port a bit ready for release.
[freertos] / Demo / SuperH_SH7216_Renesas / RTOSDemo / main.c
1 /*\r
2     FreeRTOS V6.0.2 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public \r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it \r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 \r
55 \r
56 /*\r
57  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
58  * documentation provides more details of the standard demo application tasks,\r
59  * which provide no particular functionality but do provide a good example of\r
60  * how to use the FreeRTOS API.  In addition to the standard demo tasks, the \r
61  * following tasks and tests are defined and/or created within this file:\r
62  *\r
63  * Webserver ("uIP") task - This serves a number of dynamically generated WEB\r
64  * pages to a standard WEB browser.  The IP and MAC addresses are configured by\r
65  * constants defined at the bottom of FreeRTOSConfig.h.  Use either a standard\r
66  * Ethernet cable to connect through a hug, or a cross over (point to point)\r
67  * cable to connect directly.  Ensure the IP address used is compatible with the\r
68  * IP address of the machine running the browser - the easiest way to achieve\r
69  * this is to ensure the first three octets of the IP addresses are the same.\r
70  *\r
71  * "Reg test" tasks - These fill the registers with known values, then check\r
72  * that each register still contains its expected value.  Each task uses\r
73  * different values.  The tasks run with very low priority so get preempted very\r
74  * frequently.  A register containing an unexpected value is indicative of an\r
75  * error in the context switching mechanism.  Both standard and floating point\r
76  * registers are checked.  The nature of the reg test tasks necessitates that\r
77  * they are written in assembly code.  They are defined in regtest.src.\r
78  *\r
79  * "math" tasks - These are a set of 8 tasks that perform various double\r
80  * precision floating point calculations in order to check that the tasks \r
81  * floating point registers are being correctly saved and restored during\r
82  * context switches.  The math tasks are defined in flop.c.\r
83  *\r
84  * "Check" task - This only executes every five seconds but has a high priority\r
85  * to ensure it gets processor time.  Its main function is to check that all the\r
86  * standard demo tasks are still operational.  While no errors have been\r
87  * discovered the check task will toggle an LED every 5 seconds - the toggle\r
88  * rate increasing to 500ms being a visual indication that at least one task has\r
89  * reported unexpected behaviour.\r
90  *\r
91  * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
92  * tasks are executing as expected and no errors have been reported in any \r
93  * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
94  * has reported unexpected behaviour.\r
95  * \r
96  * *NOTE 2* This file and flop.c both demonstrate the use of \r
97  * xPortUsesFloatingPoint() which informs the kernel that a task should maintain\r
98  * a floating point context.\r
99  *\r
100  * *NOTE 3* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
101  * the application set up a timer to generate the tick interrupt.  In this\r
102  * example a compare match timer is used for this purpose.  \r
103  * vApplicationTickHook() is used to clear the timer interrupt and relies on\r
104  * configUSE_TICK_HOOK being set to 1 in FreeRTOSConfig.h.\r
105  *\r
106  * *NOTE 4* The traceTASK_SWITCHED_IN and traceTASK_SWITCHED_OUT trace hooks\r
107  * are used to save and restore the floating point context respectively for\r
108  * those tasks that require it (those for which xPortUsesFloatingPoint() has\r
109  * been called).\r
110  * \r
111  * *NOTE 5* Any interrupt that can cause a context switch requires an asm \r
112  * wrapper and must be assigned an interrupt priority of \r
113  * portKERNEL_INTERRUPT_PRIORITY.\r
114  *\r
115  * *NOTE 6* vSetupClockForRunTimeStats() is called by the kernel (via the \r
116  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()) macro to configure an MTU channel\r
117  * to produce a time base that is used to log how much processor time each task\r
118  * is consuming.  The MTU is used to generate a high(ish) frequency interrupt,\r
119  * and so also provides an example of how interrupts that don't make use of the\r
120  * FreeRTOS kernel can be assigned a priority above any priority used by the\r
121  * kernel itself.\r
122  */\r
123 \r
124 /* Kernel includes. */\r
125 #include "FreeRTOS.h"\r
126 #include "task.h"\r
127 \r
128 /* Demo application includes. */\r
129 #include "BlockQ.h"\r
130 #include "death.h"\r
131 #include "integer.h"\r
132 #include "blocktim.h"\r
133 #include "flash.h"\r
134 #include "partest.h"\r
135 #include "semtest.h"\r
136 #include "PollQ.h"\r
137 #include "GenQTest.h"\r
138 #include "QPeek.h"\r
139 #include "recmutex.h"\r
140 #include "flop.h"\r
141 \r
142 /* Constants required to configure the hardware. */\r
143 #define mainFRQCR_VALUE                                         ( 0x0303 )      /* Input = 12.5MHz, I Clock = 200MHz, B Clock = 50MHz, P Clock = 50MHz */\r
144 \r
145 /* Task priorities. */\r
146 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 1 )\r
147 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
148 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
149 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
150 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
151 #define mainFLASH_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 1 )\r
152 #define mainuIP_TASK_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
153 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
154 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
155 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
156 \r
157 /* The WEB server uses string handling functions, which in turn use a bit more\r
158 stack than most of the other tasks. */\r
159 #define mainuIP_STACK_SIZE                                      ( configMINIMAL_STACK_SIZE * 3 )\r
160 \r
161 /* The LED toggled by the check task. */\r
162 #define mainCHECK_LED                                           ( 5 )\r
163 \r
164 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
165 without error. */\r
166 #define mainNO_ERROR_CYCLE_TIME                         ( 5000 / portTICK_RATE_MS )\r
167 \r
168 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
169 by at least one task. */\r
170 #define mainERROR_CYCLE_TIME                            ( 200 / portTICK_RATE_MS )\r
171 \r
172 /*\r
173  * vApplicationMallocFailedHook() will only be called if\r
174  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
175  * function that will execute if a call to pvPortMalloc() fails.\r
176  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
177  * semaphore is created.  It is also called by various parts of the demo\r
178  * application.  \r
179  */\r
180 void vApplicationMallocFailedHook( void );\r
181 \r
182 /*\r
183  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
184  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
185  * of the idle task.  It is essential that code added to this hook function\r
186  * never attempts to block in any way (for example, call xQueueReceive() with\r
187  * a block time specified).  If the application makes use of the vTaskDelete()\r
188  * API function (as this demo application does) then it is also important that\r
189  * vApplicationIdleHook() is permitted to return to its calling function because\r
190  * it is the responsibility of the idle task to clean up memory allocated by the\r
191  * kernel to any task that has since been deleted.\r
192  */\r
193 void vApplicationIdleHook( void );\r
194 \r
195 /*\r
196  * Just sets up clocks, ports, etc. used by the demo application.\r
197  */\r
198 static void prvSetupHardware( void );\r
199 \r
200 /*\r
201  * The check task as described at the top of this file.\r
202  */\r
203 static void prvCheckTask( void *pvParameters );\r
204 \r
205 /*\r
206  * The reg test tasks as described at the top of this file.\r
207  */\r
208 extern void vRegTest1Task( void *pvParameters );\r
209 extern void vRegTest2Task( void *pvParameters );\r
210 \r
211 /*\r
212  * Contains the implementation of the WEB server.\r
213  */\r
214 extern void vuIP_Task( void *pvParameters );\r
215 \r
216 /*\r
217  * The interrupt handler for the MTU - which is used to maintain the time base\r
218  * used by the run time stats.\r
219  */\r
220 #pragma interrupt MTU_Match\r
221 void MTU_Match( void );\r
222 \r
223 /*-----------------------------------------------------------*/\r
224 \r
225 /* Variables that are incremented on each iteration of the reg test tasks - \r
226 provided the tasks have not reported any errors.  The check task inspects these\r
227 variables to ensure they are still incrementing as expected. */\r
228 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
229 \r
230 /* The status message that is displayed at the bottom of the "task stats" WEB\r
231 page, which is served by the uIP task. */\r
232 const char *pcStatusMessage = "All tasks executing without error.";\r
233 \r
234 /* The time use for the run time stats. */\r
235 unsigned long ulRunTime = 0UL;\r
236 \r
237 /*-----------------------------------------------------------*/\r
238 \r
239 /*\r
240  * Creates the majority of the demo application tasks before starting the\r
241  * scheduler.\r
242  */\r
243 void main(void)\r
244 {\r
245 xTaskHandle xCreatedTask;\r
246 \r
247         prvSetupHardware();\r
248 \r
249         /* Start the reg test tasks which test the context switching mechanism. */\r
250         xTaskCreate( vRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xCreatedTask );\r
251         xPortUsesFloatingPoint( xCreatedTask );\r
252         \r
253         xTaskCreate( vRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xCreatedTask );\r
254         xPortUsesFloatingPoint( xCreatedTask );\r
255 \r
256         xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
257 \r
258         /* Start the check task as described at the top of this file. */\r
259         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
260 \r
261         /* Start the standard demo tasks.  These don't perform any particular useful\r
262         functionality, other than to demonstrate the FreeRTOS API being used. */\r
263         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
264         vCreateBlockTimeTasks();\r
265     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
266     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
267     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
268     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
269         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
270     vStartQueuePeekTasks();\r
271         vStartRecursiveMutexTasks();\r
272         \r
273         /* Start the math tasks as described at the top of this file. */\r
274         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
275 \r
276         /* The suicide tasks must be created last as they need to know how many\r
277         tasks were running prior to their creation in order to ascertain whether\r
278         or not the correct/expected number of tasks are running at any given time. */\r
279     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
280 \r
281         /* Start the tasks running. */\r
282         vTaskStartScheduler();\r
283 \r
284         /* Will only get here if there was insufficient heap memory to create the idle\r
285     task.  Increase the configTOTAL_HEAP_SIZE setting in FreeRTOSConfig.h. */\r
286         for( ;; );\r
287 }\r
288 /*-----------------------------------------------------------*/\r
289 \r
290 static void prvCheckTask( void *pvParameter )\r
291 {\r
292 portTickType xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;\r
293 unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
294 \r
295         /* Just to remove compiler warning. */\r
296         ( void ) pvParameter;\r
297 \r
298         /* Initialise xNextWakeTime - this only needs to be done once. */\r
299         xNextWakeTime = xTaskGetTickCount();\r
300 \r
301         for( ;; )\r
302         {\r
303                 /* Place this task in the blocked state until it is time to run again. */\r
304                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
305                 \r
306                 /* Inspect all the other tasks to ensure none have experienced any errors. */\r
307                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
308                 {\r
309                         /* Increase the rate at which this task cycles, which will increase the\r
310                         rate at which mainCHECK_LED flashes to give visual feedback that an error\r
311                         has occurred. */\r
312                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
313                         pcStatusMessage = "Error in GenQ test.";\r
314                 }\r
315                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
316                 {\r
317                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
318                         pcStatusMessage = "Error in Queue Peek test.";\r
319                 }\r
320                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
321                 {\r
322                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
323                         pcStatusMessage = "Error in Blocking Queue test.";\r
324                 }\r
325                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
326                 {\r
327                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
328                         pcStatusMessage = "Error in BlockTim test.";\r
329                 }\r
330             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
331             {\r
332                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
333                         pcStatusMessage = "Error in Semaphore test.";\r
334             }\r
335             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
336             {\r
337                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
338                         pcStatusMessage = "Error in Polling Queue test.";\r
339             }\r
340             else if( xIsCreateTaskStillRunning() != pdTRUE )\r
341             {\r
342                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
343                         pcStatusMessage = "Error in Create test.";\r
344             }\r
345             else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
346             {\r
347                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
348                         pcStatusMessage = "Error in integer Math test.";\r
349             }\r
350             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
351             {\r
352                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
353                         pcStatusMessage = "Error in recursive mutex test.";\r
354             }\r
355                 else if( xAreMathsTaskStillRunning() != pdTRUE )\r
356                 {\r
357                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
358                         pcStatusMessage = "Error in floating point Math test.";\r
359                 }\r
360 \r
361                 /* Check the reg test tasks are still cycling.  They will stop incrementing\r
362                 their loop counters if they encounter an error. */\r
363                 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
364                 {\r
365                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
366                         pcStatusMessage = "Error in RegTest.";\r
367                 }\r
368 \r
369                 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
370                 {\r
371                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
372                         pcStatusMessage = "Error in RegTest.";\r
373                 }\r
374                 \r
375                 ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
376                 ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
377                 \r
378                 /* Toggle the check LED to give an indication of the system status.  If the\r
379                 LED toggles every 5 seconds then everything is ok.  A faster toggle indicates\r
380                 an error. */\r
381                 vParTestToggleLED( mainCHECK_LED );\r
382         }\r
383 }\r
384 /*-----------------------------------------------------------*/\r
385 \r
386 void vApplicationMallocFailedHook( void )\r
387 {\r
388         /* A call to vPortMalloc() failed, probably during the creation of a task,\r
389         queue or semaphore.  Inspect pxCurrentTCB to find which task is currently\r
390         executing. */\r
391         for( ;; );\r
392 }\r
393 /*-----------------------------------------------------------*/\r
394 \r
395 void vApplicationIdleHook( void )\r
396 {\r
397         /* Code can be added to the idle task here.  This function must *NOT* attempt\r
398         to block.  Also, if the application uses the vTaskDelete() API function then\r
399         this function must return regularly to ensure the idle task gets a chance to\r
400         clean up the memory used by deleted tasks. */\r
401 }\r
402 /*-----------------------------------------------------------*/\r
403 \r
404 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
405 {\r
406         /* Just to remove compiler warnings.  This function will only actually\r
407         get called if configCHECK_FOR_STACK_OVERFLOW is set to a non zero value.\r
408         By default this demo does not use the stack overflow checking functionality\r
409         as the SuperH will normally execute an exception if the stack overflows. */\r
410         ( void ) pxTask;\r
411         ( void ) pcTaskName;\r
412         \r
413         taskDISABLE_INTERRUPTS();\r
414         for( ;; );\r
415 }\r
416 /*-----------------------------------------------------------*/\r
417 \r
418 static void prvSetupHardware( void )\r
419 {\r
420 volatile unsigned long ul;\r
421 \r
422         /* Set the CPU and peripheral clocks. */\r
423         CPG.FRQCR.WORD = mainFRQCR_VALUE;\r
424         \r
425         /* Wait for the clock to settle. */\r
426         for( ul = 0; ul < 99; ul++ )\r
427         {\r
428                 nop();\r
429         }\r
430 \r
431         /* Initialise the ports used to toggle LEDs. */\r
432         vParTestInitialise();   \r
433 }\r
434 /*-----------------------------------------------------------*/\r
435 \r
436 void vApplicationSetupTimerInterrupt( void )\r
437 {\r
438 /* The peripheral clock is divided by 32 before feeding the compare match\r
439 peripheral (CMT). */\r
440 const unsigned long ulCompareMatch = ( configPERIPHERAL_CLOCK_HZ / ( configTICK_RATE_HZ * 32 ) ) + 1;\r
441 \r
442         /* Configure a timer to create the RTOS tick interrupt.  This example uses\r
443         the compare match timer, but the multi function timer or possible even the\r
444         watchdog timer could also be used.  Ensure vPortTickInterrupt() is installed\r
445         as the interrupt handler for whichever peripheral is used. */\r
446         \r
447         /* Turn the CMT on. */\r
448         STB.CR4.BIT._CMT = 0;\r
449         \r
450         /* Set the compare match value for the required tick frequency. */\r
451         CMT0.CMCOR = ( unsigned short ) ulCompareMatch;\r
452         \r
453         /* Divide the peripheral clock by 32. */\r
454         CMT0.CMCSR.BIT.CKS = 0x01;\r
455         \r
456         /* Set the CMT interrupt priority - the interrupt priority must be\r
457         configKERNEL_INTERRUPT_PRIORITY no matter which peripheral is used to generate\r
458         the tick interrupt. */\r
459         INTC.IPR08.BIT._CMT0 = portKERNEL_INTERRUPT_PRIORITY;\r
460         \r
461         /* Clear the interrupt flag. */\r
462         CMT0.CMCSR.BIT.CMF = 0;\r
463         \r
464         /* Enable the compare match interrupt. */\r
465         CMT0.CMCSR.BIT.CMIE = 0x01;\r
466         \r
467         /* Start the timer. */\r
468         CMT.CMSTR.BIT.STR0 = 0x01;\r
469 }\r
470 /*-----------------------------------------------------------*/\r
471 \r
472 void vApplicationTickHook( void )\r
473 {\r
474         /* Clear the tick inerrupt.  This is called from an interrupt context. */\r
475         CMT0.CMCSR.BIT.CMF = 0;\r
476 }\r
477 /*-----------------------------------------------------------*/\r
478 \r
479 void vSetupClockForRunTimeStats( void )\r
480 {\r
481         /* Configure an MTU channel to generate a periodic interrupt that is used\r
482         as the run time stats time base.  The run time stats keep a track of how\r
483         much processing time each task is using. */\r
484 \r
485         /* Turn the MTU2 on. */\r
486         STB.CR3.BIT._MTU2 = 0;\r
487                 \r
488         /* Clear counter on compare match A. */\r
489         MTU20.TCR.BIT.CCLR = 0x01;\r
490         \r
491         /* Compare match value to give very approximately 10 interrupts per \r
492         millisecond. */\r
493         MTU20.TGRA = 5000;\r
494         \r
495         /* Ensure the interrupt is clear. */\r
496         MTU20.TSR.BIT.TGFA = 0;\r
497                 \r
498         /* Enable the compare match interrupt. */\r
499         MTU20.TIER.BIT.TGIEA = 0x01;    \r
500         \r
501         /* Set the interrupt priority. */\r
502         INTC.IPR09.BIT._MTU20G = portKERNEL_INTERRUPT_PRIORITY + 1;\r
503         \r
504         /* Start the count. */\r
505         MTU2.TSTR.BIT.CST0 = 1;\r
506 }\r
507 /*-----------------------------------------------------------*/\r
508 \r
509 void MTU_Match( void )\r
510 {\r
511 volatile unsigned char ucStatus;\r
512 \r
513         /* Increment the run time stats time base. */\r
514         ulRunTime++;\r
515 \r
516         /* Clear the interrupt. */\r
517         ucStatus = MTU20.TSR.BYTE;\r
518         MTU20.TSR.BIT.TGFA = 0;\r
519 }\r
520 /*-----------------------------------------------------------*/\r
521 \r
522 char *pcGetTaskStatusMessage( void )\r
523 {\r
524         /* Not bothered about a critical section here.  This just returns a string\r
525         that is displaed on the "Task Stats" WEB page served by this demo. */\r
526         return pcStatusMessage;\r
527 }\r
528 /*-----------------------------------------------------------*/\r