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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F103_Keil/] [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 portSHORT ) 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 vSetupTimerTest( void );
88
 
89
/* Interrupt handler in which the jitter is measured. */
90
void vTimer2IntHandler( void );
91
 
92
/* Stores the value of the maximum recorded jitter between interrupts. */
93
volatile unsigned portSHORT usMaxJitter = 0;
94
 
95
/*-----------------------------------------------------------*/
96
 
97
void vSetupTimerTest( void )
98
{
99
unsigned long ulFrequency;
100
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
101
NVIC_InitTypeDef NVIC_InitStructure;
102
 
103
 
104
        /* Enable timer clocks */
105
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, ENABLE );
106
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
107
 
108
        /* Initialise data. */
109
        TIM_DeInit( TIM2 );
110
        TIM_DeInit( TIM3 );
111
        TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
112
 
113
        /* Time base configuration for timer 2 - which generates the interrupts. */
114
        ulFrequency = configCPU_CLOCK_HZ / timerINTERRUPT_FREQUENCY;
115
        TIM_TimeBaseStructure.TIM_Period = ( unsigned portSHORT ) ( ulFrequency & 0xffffUL );
116
        TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
117
        TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
118
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
119
        TIM_TimeBaseInit( TIM2, &TIM_TimeBaseStructure );
120
        TIM_ARRPreloadConfig( TIM2, ENABLE );
121
 
122
 
123
        /* Configuration for timer 3 which is used as a high resolution time
124
        measurement. */
125
        TIM_TimeBaseStructure.TIM_Period = ( unsigned portSHORT ) 0xffff;
126
        TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
127
        TIM_ARRPreloadConfig( TIM3, ENABLE );
128
 
129
        /* Enable TIM2 IT.  TIM3 does not generate an interrupt. */
130
        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
131
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
132
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = timerHIGHEST_PRIORITY;
133
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
134
        NVIC_Init( &NVIC_InitStructure );
135
        TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE );
136
 
137
        /* Finally, enable both timers. */
138
        TIM_Cmd( TIM2, ENABLE );
139
        TIM_Cmd( TIM3, ENABLE );
140
}
141
/*-----------------------------------------------------------*/
142
 
143
void vTimer2IntHandler( void )
144
{
145
static unsigned portSHORT usLastCount = 0, usSettleCount = 0, usMaxDifference = 0;
146
unsigned portSHORT usThisCount, usDifference;
147
 
148
        /* Capture the free running timer 3 value as we enter the interrupt. */
149
        usThisCount = TIM3->CNT;
150
 
151
        if( usSettleCount >= timerSETTLE_TIME )
152
        {
153
                /* What is the difference between the timer value in this interrupt
154
                and the value from the last interrupt. */
155
                usDifference = usThisCount - usLastCount;
156
 
157
                /* Store the difference in the timer values if it is larger than the
158
                currently stored largest value.  The difference over and above the
159
                expected difference will give the 'jitter' in the processing of these
160
                interrupts. */
161
                if( usDifference > usMaxDifference )
162
                {
163
                        usMaxDifference = usDifference;
164
                        usMaxJitter = usMaxDifference - timerEXPECTED_DIFFERENCE_VALUE;
165
                }
166
        }
167
        else
168
        {
169
                /* Don't bother storing any values for the first couple of
170
                interrupts. */
171
                usSettleCount++;
172
        }
173
 
174
        /* Remember what the timer value was this time through, so we can calculate
175
        the difference the next time through. */
176
        usLastCount = usThisCount;
177
 
178
    TIM_ClearITPendingBit( TIM2, TIM_IT_Update );
179
}
180
 
181
 
182
 
183
 
184
 
185
 
186
 
187
 

powered by: WebSVN 2.1.0

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