]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LM3Sxxxx_IAR_Keil/timertest.c
Add queue registry so the IAR plug-in can be tested.
[freertos] / Demo / CORTEX_LM3Sxxxx_IAR_Keil / timertest.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 /* High speed timer test as described in main.c. */\r
53 \r
54 /* Scheduler includes. */\r
55 #include "FreeRTOS.h"\r
56 \r
57 /* Library includes. */\r
58 #include "hw_ints.h"\r
59 #include "hw_memmap.h"\r
60 #include "hw_types.h"\r
61 #include "interrupt.h"\r
62 #include "sysctl.h"\r
63 #include "lmi_timer.h"\r
64 #include "hw_timer.h"\r
65 \r
66 /* The set frequency of the interrupt.  Deviations from this are measured as\r
67 the jitter. */\r
68 #define timerINTERRUPT_FREQUENCY                ( 20000UL )\r
69 \r
70 /* The expected time between each of the timer interrupts - if the jitter was\r
71 zero. */\r
72 #define timerEXPECTED_DIFFERENCE_VALUE  ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )\r
73 \r
74 /* The highest available interrupt priority. */\r
75 #define timerHIGHEST_PRIORITY                   ( 0 )\r
76 \r
77 /* Misc defines. */\r
78 #define timerMAX_32BIT_VALUE                    ( 0xffffffffUL )\r
79 #define timerTIMER_1_COUNT_VALUE                ( * ( ( volatile unsigned long * ) ( ( unsigned portLONG ) TIMER1_BASE + 0x48UL ) ) )\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 /* Interrupt handler in which the jitter is measured. */\r
84 void Timer0IntHandler( void );\r
85 \r
86 /* Stores the value of the maximum recorded jitter between interrupts. */\r
87 volatile unsigned portLONG ulMaxJitter = 0;\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 void vSetupHighFrequencyTimer( void )\r
92 {\r
93 unsigned long ulFrequency;\r
94 \r
95         /* Timer zero is used to generate the interrupts, and timer 1 is used\r
96         to measure the jitter. */\r
97         SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 );\r
98     SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER1 );\r
99     TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );\r
100     TimerConfigure( TIMER1_BASE, TIMER_CFG_32_BIT_PER );\r
101         \r
102         /* Set the timer interrupt to be above the kernel - highest. */\r
103         IntPrioritySet( INT_TIMER0A, timerHIGHEST_PRIORITY );\r
104 \r
105         /* Just used to measure time. */\r
106     TimerLoadSet(TIMER1_BASE, TIMER_A, timerMAX_32BIT_VALUE );\r
107         \r
108         /* Ensure interrupts do not start until the scheduler is running. */\r
109         portDISABLE_INTERRUPTS();\r
110         \r
111         /* The rate at which the timer will interrupt. */\r
112         ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;    \r
113     TimerLoadSet( TIMER0_BASE, TIMER_A, ulFrequency );\r
114     IntEnable( INT_TIMER0A );\r
115     TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT );\r
116 \r
117         /* Enable both timers. */       \r
118     TimerEnable( TIMER0_BASE, TIMER_A );\r
119     TimerEnable( TIMER1_BASE, TIMER_A );\r
120 }\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 void Timer0IntHandler( void )\r
124 {\r
125 unsigned portLONG ulDifference;\r
126 volatile unsigned portLONG ulCurrentCount;\r
127 static unsigned portLONG ulMaxDifference = 0, ulLastCount = 0;\r
128 \r
129         /* We use the timer 1 counter value to measure the clock cycles between\r
130         the timer 0 interrupts. */\r
131         ulCurrentCount = timerTIMER_1_COUNT_VALUE;\r
132 \r
133         TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );\r
134 \r
135         if( ulCurrentCount < ulLastCount )\r
136         {       \r
137                 /* How many times has timer 1 counted since the last interrupt? */\r
138                 ulDifference =  ulLastCount - ulCurrentCount;\r
139         \r
140                 /* Is this the largest difference we have measured yet? */\r
141                 if( ulDifference > ulMaxDifference )\r
142                 {\r
143                         ulMaxDifference = ulDifference;\r
144                         ulMaxJitter = ulMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;\r
145                 }\r
146         }\r
147         \r
148         ulLastCount = ulCurrentCount;\r
149 }\r
150 \r
151 \r
152 \r
153 \r
154 \r
155 \r
156 \r