OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3Sxxxx_Rowley/] [timertest.c] - Blame information for rev 728

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/* High speed timer test as described in main.c. */
55
 
56
/* Scheduler includes. */
57
#include "FreeRTOS.h"
58
 
59
/* Library includes. */
60
#include "hw_ints.h"
61
#include "hw_memmap.h"
62
#include "hw_types.h"
63
#include "interrupt.h"
64
#include "sysctl.h"
65
#include "lmi_timer.h"
66
 
67
/* The set frequency of the interrupt.  Deviations from this are measured as
68
the jitter. */
69
#define timerINTERRUPT_FREQUENCY                ( 20000UL )
70
 
71
/* The expected time between each of the timer interrupts - if the jitter was
72
zero. */
73
#define timerEXPECTED_DIFFERENCE_VALUE  ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )
74
 
75
/* The highest available interrupt priority. */
76
#define timerHIGHEST_PRIORITY                   ( 0 )
77
 
78
/* Misc defines. */
79
#define timerMAX_32BIT_VALUE                    ( 0xffffffffUL )
80
#define timerTIMER_1_COUNT_VALUE                ( * ( ( unsigned long * ) ( TIMER1_BASE + 0x48 ) ) )
81
 
82
/*-----------------------------------------------------------*/
83
 
84
/* Interrupt handler in which the jitter is measured. */
85
void Timer0IntHandler( void );
86
 
87
/* Stores the value of the maximum recorded jitter between interrupts. */
88
volatile unsigned long ulMaxJitter = 0UL;
89
 
90
/* Counts the total number of times that the high frequency timer has 'ticked'.
91
This value is used by the run time stats function to work out what percentage
92
of CPU time each task is taking. */
93
volatile unsigned long ulHighFrequencyTimerTicks = 0UL;
94
/*-----------------------------------------------------------*/
95
 
96
void vSetupHighFrequencyTimer( void )
97
{
98
unsigned long ulFrequency;
99
 
100
        /* Timer zero is used to generate the interrupts, and timer 1 is used
101
        to measure the jitter. */
102
        SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER0 );
103
    SysCtlPeripheralEnable( SYSCTL_PERIPH_TIMER1 );
104
    TimerConfigure( TIMER0_BASE, TIMER_CFG_32_BIT_PER );
105
    TimerConfigure( TIMER1_BASE, TIMER_CFG_32_BIT_PER );
106
 
107
        /* Set the timer interrupt to be above the kernel - highest. */
108
        IntPrioritySet( INT_TIMER0A, timerHIGHEST_PRIORITY );
109
 
110
        /* Just used to measure time. */
111
    TimerLoadSet(TIMER1_BASE, TIMER_A, timerMAX_32BIT_VALUE );
112
 
113
        /* Ensure interrupts do not start until the scheduler is running. */
114
        portDISABLE_INTERRUPTS();
115
 
116
        /* The rate at which the timer will interrupt. */
117
        ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;
118
    TimerLoadSet( TIMER0_BASE, TIMER_A, ulFrequency );
119
    IntEnable( INT_TIMER0A );
120
    TimerIntEnable( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
121
 
122
        /* Enable both timers. */
123
    TimerEnable( TIMER0_BASE, TIMER_A );
124
    TimerEnable( TIMER1_BASE, TIMER_A );
125
}
126
/*-----------------------------------------------------------*/
127
 
128
void Timer0IntHandler( void )
129
{
130
unsigned long ulDifference;
131
volatile unsigned long ulCurrentCount;
132
static unsigned long ulMaxDifference = 0, ulLastCount = 0;
133
 
134
        /* We use the timer 1 counter value to measure the clock cycles between
135
        the timer 0 interrupts. */
136
        ulCurrentCount = timerTIMER_1_COUNT_VALUE;
137
 
138
        TimerIntClear( TIMER0_BASE, TIMER_TIMA_TIMEOUT );
139
 
140
        if( ulCurrentCount < ulLastCount )
141
        {
142
                /* How many times has timer 1 counted since the last interrupt? */
143
                ulDifference =  ulLastCount - ulCurrentCount;
144
 
145
                /* Is this the largest difference we have measured yet? */
146
                if( ulDifference > ulMaxDifference )
147
                {
148
                        ulMaxDifference = ulDifference;
149
                        ulMaxJitter = ulMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
150
                }
151
        }
152
 
153
        ulLastCount = ulCurrentCount;
154
 
155
        /* Keep a count of the total number of 20KHz ticks.  This is used by the
156
        run time stats functionality to calculate how much CPU time is used by
157
        each task. */
158
        ulHighFrequencyTimerTicks++;
159
}
160
 
161
 
162
 
163
 
164
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.