2 FreeRTOS.org V4.7.2 - Copyright (C) 2003-2008 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
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
43 /* High speed timer test as described in main.c. */
\r
45 /* Scheduler includes. */
\r
46 #include "FreeRTOS.h"
\r
48 /* Library includes. */
\r
49 #include "hw_ints.h"
\r
50 #include "hw_memmap.h"
\r
51 #include "hw_types.h"
\r
52 #include "interrupt.h"
\r
54 #include "lmi_timer.h"
\r
56 /* The set frequency of the interrupt. Deviations from this are measured as
\r
58 #define timerINTERRUPT_FREQUENCY ( 20000UL )
\r
60 /* The expected time between each of the timer interrupts - if the jitter was
\r
62 #define timerEXPECTED_DIFFERENCE_VALUE ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )
\r
64 /* The highest available interrupt priority. */
\r
65 #define timerHIGHEST_PRIORITY ( 0 )
\r
68 #define timerMAX_32BIT_VALUE ( 0xffffffffUL )
\r
69 #define timerTIMER_1_COUNT_VALUE ( * ( ( unsigned long * ) ( TIMER1_BASE + 0x48 ) ) )
\r
71 /*-----------------------------------------------------------*/
\r
73 /* Interrupt handler in which the jitter is measured. */
\r
74 void Timer0IntHandler( void );
\r
76 /* Stores the value of the maximum recorded jitter between interrupts. */
\r
77 volatile unsigned portLONG ulMaxJitter = 0;
\r
79 /*-----------------------------------------------------------*/
\r
81 void vSetupTimer( void )
\r
83 unsigned long ulFrequency;
\r
85 /* Timer zero is used to generate the interrupts, and timer 1 is used
\r
86 to measure the jitter. */
\r
87 SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 );
\r
88 SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER1 );
\r
89 TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );
\r
90 TimerConfigure( TIMER1_BASE, TIMER_CFG_32_BIT_PER );
\r
92 /* Set the timer interrupt to be above the kernel - highest. */
\r
93 IntPrioritySet( INT_TIMER0A, timerHIGHEST_PRIORITY );
\r
95 /* Just used to measure time. */
\r
96 TimerLoadSet(TIMER1_BASE, TIMER_A, timerMAX_32BIT_VALUE );
\r
98 /* Ensure interrupts do not start until the scheduler is running. */
\r
99 portDISABLE_INTERRUPTS();
\r
101 /* The rate at which the timer will interrupt. */
\r
102 ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;
\r
103 TimerLoadSet( TIMER0_BASE, TIMER_A, ulFrequency );
\r
104 IntEnable( INT_TIMER0A );
\r
105 TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
\r
107 /* Enable both timers. */
\r
108 TimerEnable( TIMER0_BASE, TIMER_A );
\r
109 TimerEnable( TIMER1_BASE, TIMER_A );
\r
111 /*-----------------------------------------------------------*/
\r
113 void Timer0IntHandler( void )
\r
115 unsigned portLONG ulDifference;
\r
116 volatile unsigned portLONG ulCurrentCount;
\r
117 static portLONG ulMaxDifference = 0, ulLastCount = 0;
\r
119 /* We use the timer 1 counter value to measure the clock cycles between
\r
120 the timer 0 interrupts. */
\r
121 ulCurrentCount = timerTIMER_1_COUNT_VALUE;
\r
123 if( ulCurrentCount < ulLastCount )
\r
125 /* How many times has timer 1 counted since the last interrupt? */
\r
126 ulDifference = ulLastCount - ulCurrentCount;
\r
128 /* Is this the largest difference we have measured yet? */
\r
129 if( ulDifference > ulMaxDifference )
\r
131 ulMaxDifference = ulDifference;
\r
132 ulMaxJitter = ulMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
\r
136 ulLastCount = ulCurrentCount;
\r
138 TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
\r