]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LM3Sxxxx_IAR_Keil/timertest.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / CORTEX_LM3Sxxxx_IAR_Keil / timertest.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /* High speed timer test as described in main.c. */\r
50 \r
51 /* Scheduler includes. */\r
52 #include "FreeRTOS.h"\r
53 \r
54 /* Library includes. */\r
55 #include "hw_ints.h"\r
56 #include "hw_memmap.h"\r
57 #include "hw_types.h"\r
58 #include "interrupt.h"\r
59 #include "sysctl.h"\r
60 #include "lmi_timer.h"\r
61 #include "hw_timer.h"\r
62 \r
63 /* The set frequency of the interrupt.  Deviations from this are measured as\r
64 the jitter. */\r
65 #define timerINTERRUPT_FREQUENCY                ( 20000UL )\r
66 \r
67 /* The expected time between each of the timer interrupts - if the jitter was\r
68 zero. */\r
69 #define timerEXPECTED_DIFFERENCE_VALUE  ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )\r
70 \r
71 /* The highest available interrupt priority. */\r
72 #define timerHIGHEST_PRIORITY                   ( 0 )\r
73 \r
74 /* Misc defines. */\r
75 #define timerMAX_32BIT_VALUE                    ( 0xffffffffUL )\r
76 #define timerTIMER_1_COUNT_VALUE                ( * ( ( volatile unsigned long * ) ( ( unsigned portLONG ) TIMER1_BASE + 0x48UL ) ) )\r
77 \r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /* Interrupt handler in which the jitter is measured. */\r
81 void Timer0IntHandler( void );\r
82 \r
83 /* Stores the value of the maximum recorded jitter between interrupts. */\r
84 volatile unsigned portLONG ulMaxJitter = 0;\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 void vSetupHighFrequencyTimer( void )\r
89 {\r
90 unsigned long ulFrequency;\r
91 \r
92         /* Timer zero is used to generate the interrupts, and timer 1 is used\r
93         to measure the jitter. */\r
94         SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 );\r
95     SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER1 );\r
96     TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );\r
97     TimerConfigure( TIMER1_BASE, TIMER_CFG_32_BIT_PER );\r
98         \r
99         /* Set the timer interrupt to be above the kernel - highest. */\r
100         IntPrioritySet( INT_TIMER0A, timerHIGHEST_PRIORITY );\r
101 \r
102         /* Just used to measure time. */\r
103     TimerLoadSet(TIMER1_BASE, TIMER_A, timerMAX_32BIT_VALUE );\r
104         \r
105         /* Ensure interrupts do not start until the scheduler is running. */\r
106         portDISABLE_INTERRUPTS();\r
107         \r
108         /* The rate at which the timer will interrupt. */\r
109         ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;    \r
110     TimerLoadSet( TIMER0_BASE, TIMER_A, ulFrequency );\r
111     IntEnable( INT_TIMER0A );\r
112     TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT );\r
113 \r
114         /* Enable both timers. */       \r
115     TimerEnable( TIMER0_BASE, TIMER_A );\r
116     TimerEnable( TIMER1_BASE, TIMER_A );\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 void Timer0IntHandler( void )\r
121 {\r
122 unsigned portLONG ulDifference;\r
123 volatile unsigned portLONG ulCurrentCount;\r
124 static unsigned portLONG ulMaxDifference = 0, ulLastCount = 0;\r
125 \r
126         /* We use the timer 1 counter value to measure the clock cycles between\r
127         the timer 0 interrupts. */\r
128         ulCurrentCount = timerTIMER_1_COUNT_VALUE;\r
129 \r
130         TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );\r
131 \r
132         if( ulCurrentCount < ulLastCount )\r
133         {       \r
134                 /* How many times has timer 1 counted since the last interrupt? */\r
135                 ulDifference =  ulLastCount - ulCurrentCount;\r
136         \r
137                 /* Is this the largest difference we have measured yet? */\r
138                 if( ulDifference > ulMaxDifference )\r
139                 {\r
140                         ulMaxDifference = ulDifference;\r
141                         ulMaxJitter = ulMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;\r
142                 }\r
143         }\r
144         \r
145         ulLastCount = ulCurrentCount;\r
146 }\r
147 \r
148 \r
149 \r
150 \r
151 \r
152 \r
153 \r