source: rtems/c/src/lib/libcpu/m68k/mcf5272/timer/timer.c @ 3cfd520

4.104.114.84.95
Last change on this file since 3cfd520 was 3cfd520, checked in by Jay Monkman <jtm@…>, on Aug 3, 2004 at 4:59:11 AM

2004-08-02 Jay Monkman <jtm@…>

  • Makefile.am, configure.ac: Added CSB360 BSP
  • mcf5272/.cvsignore, mcf5272/ChangeLog, mcf5272/Makefile.am, mcf5272/clock/.cvsignore, mcf5272/clock/ckinit.c, mcf5272/include/.cvsignore, mcf5272/include/mcf5272.h, mcf5272/timer/.cvsignore, mcf5272/timer/timer.c, mcf5272/timer/timerisr.S: New files.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Timer Init
3 *
4 *  This module initializes TIMER 2 for on the MCF5272 for benchmarks.
5 *
6 *  Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
7 *  Author: Victor V. Vengerov <vvv@oktet.ru>
8 *
9 *  Based on work:
10 *  Author:
11 *    David Fiddes, D.J@fiddes.surfaid.org
12 *    http://www.calm.hw.ac.uk/davidf/coldfire/
13 *
14 *  COPYRIGHT (c) 1989-1998.
15 *  On-Line Applications Research Corporation (OAR).
16 *  Copyright assigned to U.S. Government, 1994.
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *
21 *  http://www.OARcorp.com/rtems/license.html.
22 *
23 *  timer.c,v 1.1 2001/10/26 19:32:40 joel Exp
24 */
25
26#include <rtems.h>
27#include <bsp.h>
28#include <mcf5272/mcf5272.h>
29
30#define TRR2_VAL 65530 
31
32rtems_unsigned32 Timer_interrupts;
33
34rtems_boolean Timer_driver_Find_average_overhead;
35
36/* External assembler interrupt handler routine */
37extern rtems_isr timerisr(rtems_vector_number vector);
38
39
40/* Timer_initialize --
41 *     Initialize timer 2 for accurate time measurement.
42 *
43 * PARAMETERS:
44 *     none
45 *
46 * RETURNS:
47 *     none
48 */
49void
50Timer_initialize(void)
51{
52    unsigned32 icr;
53    /* Catch timer2 interrupts */
54    set_vector(timerisr, BSP_INTVEC_TMR2, 0);
55   
56    /* Reset Timer */
57    g_timer_regs->tmr2 = MCF5272_TMR_RST;
58    g_timer_regs->tmr2 = MCF5272_TMR_CLK_STOP;
59    g_timer_regs->tmr2 = MCF5272_TMR_RST;
60    g_timer_regs->tcn2 = 0;  /* reset counter */
61    Timer_interrupts   = 0;  /* Clear timer ISR counter */
62    g_timer_regs->ter2 = MCF5272_TER_REF | MCF5272_TER_CAP;
63    g_timer_regs->trr2 = TRR2_VAL -1 ;
64
65
66    /* Set Timer 2 prescaler so that it counts in microseconds */
67    g_timer_regs->tmr2 = (
68        (((BSP_SYSTEM_FREQUENCY / 1000000) - 1) << MCF5272_TMR_PS_SHIFT) |
69        MCF5272_TMR_CE_DISABLE                                           |
70        MCF5272_TMR_ORI                                                  |
71        MCF5272_TMR_FRR                                                  |
72        MCF5272_TMR_CLK_MSTR                                             |
73        MCF5272_TMR_RST);
74
75    /* Initialize interrupts for timer2 */
76    icr = g_intctrl_regs->icr1;
77    icr = icr & ~(MCF5272_ICR1_TMR2_MASK | MCF5272_ICR1_TMR2_PI);
78    icr |= (MCF5272_ICR1_TMR2_IPL(BSP_INTLVL_TMR2) | MCF5272_ICR1_TMR2_PI);
79    g_intctrl_regs->icr1 = icr;
80
81}
82
83/*
84 *  The following controls the behavior of Read_timer().
85 *
86 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
87 *
88 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
89 *  is usually deducted from the number returned.
90 *
91 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
92 *  below this are "noise" and zero is returned.
93 */
94
95#define AVG_OVERHEAD      0  /* It typically takes 2.0 microseconds */
96                             /* (Y countdowns) to start/stop the timer. */
97                             /* This value is in microseconds. */
98#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
99
100/* Read_timer --
101 *     Read timer value in microsecond units since timer start.
102 *
103 * PARAMETERS:
104 *     none
105 *
106 * RETURNS:
107 *     number of microseconds since timer has been started
108 */
109int
110Read_timer( void )
111{
112    rtems_unsigned16 clicks;
113    rtems_unsigned32 total;
114
115    /*
116     *  Read the timer and see how many clicks it has been since counter
117     *  rolled over.
118     */
119    clicks = g_timer_regs->tcn2;
120 
121    /* Stop Timer... */
122    g_timer_regs->tmr2 = MCF5272_TMR_CLK_STOP | MCF5272_TMR_RST;
123
124    /*
125     *  Total is calculated by taking into account the number of timer
126     *  overflow interrupts since the timer was initialized and clicks
127     *  since the last interrupts.
128     */
129
130    total = (Timer_interrupts * TRR2_VAL) + clicks;
131
132    if ( Timer_driver_Find_average_overhead == 1 )
133        return total;          /* in XXX microsecond units */
134
135    if ( total < LEAST_VALID )
136        return 0;            /* below timer resolution */
137
138    /*
139     *  Return the count in microseconds
140     */
141    return (total - AVG_OVERHEAD);
142}
143
144
145/* Empty_function --
146 *     Empty function call used in loops to measure basic cost of looping
147 *     in Timing Test Suite.
148 *
149 * PARAMETERS:
150 *     none
151 *
152 * RETURNS:
153 *     RTEMS_SUCCESSFUL
154 */
155rtems_status_code
156Empty_function(void)
157{
158    return RTEMS_SUCCESSFUL;
159}
160
161/* Set_find_average_overhead --
162 *     This routine is invoked by the "Check Timer" (tmck) test in the
163 *     RTEMS Timing Test Suite. It makes the Read_timer routine not
164 *     subtract the overhead required to initialize and read the benchmark
165 *     timer.
166 *
167 * PARAMETERS:
168 *     find_flag - boolean flag, TRUE if overhead must not be subtracted.
169 *
170 * RETURNS:
171 *     none
172 */
173void
174Set_find_average_overhead(rtems_boolean find_flag)
175{
176  Timer_driver_Find_average_overhead = find_flag;
177}
Note: See TracBrowser for help on using the repository browser.