2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
53 /* High speed timer test as described in main.c. */
\r
55 /* Scheduler includes. */
\r
56 #include "FreeRTOS.h"
\r
58 /* Library includes. */
\r
59 #include "hw_ints.h"
\r
60 #include "hw_memmap.h"
\r
61 #include "hw_types.h"
\r
62 #include "interrupt.h"
\r
64 #include "lmi_timer.h"
\r
65 #include "hw_timer.h"
\r
67 /* The set frequency of the interrupt. Deviations from this are measured as
\r
69 #define timerINTERRUPT_FREQUENCY ( 20000UL )
\r
71 /* The expected time between each of the timer interrupts - if the jitter was
\r
73 #define timerEXPECTED_DIFFERENCE_VALUE ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )
\r
75 /* The highest available interrupt priority. */
\r
76 #define timerHIGHEST_PRIORITY ( 0 )
\r
79 #define timerMAX_32BIT_VALUE ( 0xffffffffUL )
\r
80 #define timerTIMER_1_COUNT_VALUE ( * ( ( volatile unsigned long * ) ( ( unsigned portLONG ) TIMER1_BASE + 0x48UL ) ) )
\r
82 /*-----------------------------------------------------------*/
\r
84 /* Interrupt handler in which the jitter is measured. */
\r
85 void Timer0IntHandler( void );
\r
87 /* Stores the value of the maximum recorded jitter between interrupts. */
\r
88 volatile unsigned portLONG ulMaxJitter = 0;
\r
90 /*-----------------------------------------------------------*/
\r
92 void vSetupHighFrequencyTimer( void )
\r
94 unsigned long ulFrequency;
\r
96 /* Timer zero is used to generate the interrupts, and timer 1 is used
\r
97 to measure the jitter. */
\r
98 SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 );
\r
99 SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER1 );
\r
100 TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );
\r
101 TimerConfigure( TIMER1_BASE, TIMER_CFG_32_BIT_PER );
\r
103 /* Set the timer interrupt to be above the kernel - highest. */
\r
104 IntPrioritySet( INT_TIMER0A, timerHIGHEST_PRIORITY );
\r
106 /* Just used to measure time. */
\r
107 TimerLoadSet(TIMER1_BASE, TIMER_A, timerMAX_32BIT_VALUE );
\r
109 /* Ensure interrupts do not start until the scheduler is running. */
\r
110 portDISABLE_INTERRUPTS();
\r
112 /* The rate at which the timer will interrupt. */
\r
113 ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;
\r
114 TimerLoadSet( TIMER0_BASE, TIMER_A, ulFrequency );
\r
115 IntEnable( INT_TIMER0A );
\r
116 TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
\r
118 /* Enable both timers. */
\r
119 TimerEnable( TIMER0_BASE, TIMER_A );
\r
120 TimerEnable( TIMER1_BASE, TIMER_A );
\r
122 /*-----------------------------------------------------------*/
\r
124 void Timer0IntHandler( void )
\r
126 unsigned portLONG ulDifference;
\r
127 volatile unsigned portLONG ulCurrentCount;
\r
128 static unsigned portLONG ulMaxDifference = 0, ulLastCount = 0;
\r
130 /* We use the timer 1 counter value to measure the clock cycles between
\r
131 the timer 0 interrupts. */
\r
132 ulCurrentCount = timerTIMER_1_COUNT_VALUE;
\r
134 TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
\r
136 if( ulCurrentCount < ulLastCount )
\r
138 /* How many times has timer 1 counted since the last interrupt? */
\r
139 ulDifference = ulLastCount - ulCurrentCount;
\r
141 /* Is this the largest difference we have measured yet? */
\r
142 if( ulDifference > ulMaxDifference )
\r
144 ulMaxDifference = ulDifference;
\r
145 ulMaxJitter = ulMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
\r
149 ulLastCount = ulCurrentCount;
\r