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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 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 "stm32f10x_lib.h"
61
#include "stm32f10x_tim.h"
62
#include "stm32f10x_map.h"
63
 
64
/* The set frequency of the interrupt.  Deviations from this are measured as
65
the jitter. */
66
#define timerINTERRUPT_FREQUENCY                ( ( unsigned short ) 20000 )
67
 
68
/* The expected time between each of the timer interrupts - if the jitter was
69
zero. */
70
#define timerEXPECTED_DIFFERENCE_VALUE  ( configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY )
71
 
72
/* The highest available interrupt priority. */
73
#define timerHIGHEST_PRIORITY                   ( 0 )
74
 
75
/* Misc defines. */
76
#define timerMAX_32BIT_VALUE                    ( 0xffffffffUL )
77
#define timerTIMER_1_COUNT_VALUE                ( * ( ( unsigned long * ) ( TIMER1_BASE + 0x48 ) ) )
78
 
79
/* The number of interrupts to pass before we start looking at the jitter. */
80
#define timerSETTLE_TIME                        5
81
 
82
/*-----------------------------------------------------------*/
83
 
84
/*
85
 * Configures the two timers used to perform the test.
86
 */
87
void vSetupHighFrequencyTimer( void );
88
 
89
/* Stores the value of the maximum recorded jitter between interrupts. */
90
volatile unsigned short usMaxJitter = 0;
91
 
92
/* Variable that counts at 20KHz to provide the time base for the run time
93
stats. */
94
unsigned long ulRunTimeStatsClock = 0UL;
95
 
96
/*-----------------------------------------------------------*/
97
 
98
void vSetupHighFrequencyTimer( void )
99
{
100
unsigned long ulFrequency;
101
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
102
NVIC_InitTypeDef NVIC_InitStructure;
103
 
104
 
105
        /* Enable timer clocks */
106
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, ENABLE );
107
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
108
 
109
        /* Initialise data. */
110
        TIM_DeInit( TIM2 );
111
        TIM_DeInit( TIM3 );
112
        TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
113
 
114
        /* Time base configuration for timer 2 - which generates the interrupts. */
115
        ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;
116
        TIM_TimeBaseStructure.TIM_Period = ( unsigned short ) ( ulFrequency & 0xffffUL );
117
        TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
118
        TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
119
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
120
        TIM_TimeBaseInit( TIM2, &TIM_TimeBaseStructure );
121
        TIM_ARRPreloadConfig( TIM2, ENABLE );
122
 
123
 
124
        /* Configuration for timer 3 which is used as a high resolution time
125
        measurement. */
126
        TIM_TimeBaseStructure.TIM_Period = ( unsigned short ) 0xffff;
127
        TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
128
        TIM_ARRPreloadConfig( TIM3, ENABLE );
129
 
130
        /* Enable TIM2 IT.  TIM3 does not generate an interrupt. */
131
        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
132
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
133
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = timerHIGHEST_PRIORITY;
134
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
135
        NVIC_Init( &NVIC_InitStructure );
136
        TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE );
137
 
138
        /* Finally, enable both timers. */
139
        TIM_Cmd( TIM2, ENABLE );
140
        TIM_Cmd( TIM3, ENABLE );
141
}
142
/*-----------------------------------------------------------*/
143
 
144
void TIM2_IRQHandler( void )
145
{
146
static unsigned short usLastCount = 0, usSettleCount = 0, usMaxDifference = 0;
147
unsigned short usThisCount, usDifference;
148
 
149
        /* Capture the free running timer 3 value as we enter the interrupt. */
150
        usThisCount = TIM3->CNT;
151
 
152
        if( usSettleCount >= timerSETTLE_TIME )
153
        {
154
                /* What is the difference between the timer value in this interrupt
155
                and the value from the last interrupt. */
156
                usDifference = usThisCount - usLastCount;
157
 
158
                /* Store the difference in the timer values if it is larger than the
159
                currently stored largest value.  The difference over and above the
160
                expected difference will give the 'jitter' in the processing of these
161
                interrupts. */
162
                if( usDifference > usMaxDifference )
163
                {
164
                        usMaxDifference = usDifference;
165
                        usMaxJitter = usMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
166
                }
167
        }
168
        else
169
        {
170
                /* Don't bother storing any values for the first couple of
171
                interrupts. */
172
                usSettleCount++;
173
        }
174
 
175
        /* Remember what the timer value was this time through, so we can calculate
176
        the difference the next time through. */
177
        usLastCount = usThisCount;
178
 
179
        /* Keep a count of the number of interrupts as a time base for the run time
180
        stats collection. */
181
        ulRunTimeStatsClock++;
182
 
183
    TIM_ClearITPendingBit( TIM2, TIM_IT_Update );
184
}
185
 
186
 
187
 
188
 
189
 
190
 
191
 
192
 

powered by: WebSVN 2.1.0

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