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