source: rtems/c/src/lib/libcpu/m68k/mcf5206/timer/timer.c @ 7a53dc9

4.104.114.84.95
Last change on this file since 7a53dc9 was 57e9580f, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:53:02 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/mcfuart.c, include/mcf5206e.h, include/mcfmbus.h, include/mcfuart.h, mbus/mcfmbus.c, timer/timer.c, timer/timerisr.S: URL for license changed.
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 *  Timer Init
3 *
4 *  This module initializes TIMER 2 for on the MCF5206E 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 *
17 *  The license and distribution terms for this file may be
18 *  found in the file LICENSE in this distribution or at
19 *
20 *  http://www.rtems.com/license/LICENSE.
21 *
22 *  $Id$
23 */
24
25#include <rtems.h>
26#include <bsp.h>
27#include "mcf5206/mcf5206e.h"
28
29#define TRR2_VAL 65530 
30
31rtems_unsigned32 Timer_interrupts;
32
33rtems_boolean Timer_driver_Find_average_overhead;
34
35/* External assembler interrupt handler routine */
36extern rtems_isr timerisr(rtems_vector_number vector);
37
38
39/* Timer_initialize --
40 *     Initialize timer 2 for accurate time measurement.
41 *
42 * PARAMETERS:
43 *     none
44 *
45 * RETURNS:
46 *     none
47 */
48void
49Timer_initialize(void)
50{
51    /* Catch timer2 interrupts */
52    set_vector(timerisr, BSP_INTVEC_TIMER2, 0);
53   
54    /* Initialize interrupts for timer2 */
55    *MCF5206E_ICR(MBAR, MCF5206E_INTR_TIMER_2) =
56        MCF5206E_ICR_AVEC |
57        ((BSP_INTLVL_TIMER2 << MCF5206E_ICR_IL_S) & MCF5206E_ICR_IL) |
58        ((BSP_INTPRIO_TIMER2 << MCF5206E_ICR_IP_S) & MCF5206E_ICR_IP);
59       
60    /* Enable interrupts from timer2 */
61    *MCF5206E_IMR(MBAR) &= ~MCF5206E_INTR_BIT(MCF5206E_INTR_TIMER_2);
62   
63    /* Reset Timer */
64    *MCF5206E_TMR(MBAR, 2) = MCF5206E_TMR_RST;
65    *MCF5206E_TMR(MBAR, 2) = MCF5206E_TMR_ICLK_STOP;
66    *MCF5206E_TMR(MBAR, 2) = MCF5206E_TMR_RST;
67    *MCF5206E_TCN(MBAR, 2) = 0; /* Zero timer counter */
68    Timer_interrupts = 0; /* Clear timer ISR counter */
69    *MCF5206E_TER(MBAR, 2) = MCF5206E_TER_REF | MCF5206E_TER_CAP; /*clr pend*/
70    *MCF5206E_TRR(MBAR, 2) = TRR2_VAL - 1;
71    *MCF5206E_TMR(MBAR, 2) =
72        (((BSP_SYSTEM_FREQUENCY / 1000000) << MCF5206E_TMR_PS_S) &
73          MCF5206E_TMR_PS) |
74        MCF5206E_TMR_CE_NONE | MCF5206E_TMR_ORI | MCF5206E_TMR_FRR |
75        MCF5206E_TMR_RST;
76    *MCF5206E_TMR(MBAR, 2) |= MCF5206E_TMR_ICLK_MSCLK;
77}
78
79/*
80 *  The following controls the behavior of Read_timer().
81 *
82 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
83 *
84 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
85 *  is usually deducted from the number returned.
86 *
87 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
88 *  below this are "noise" and zero is returned.
89 */
90
91#define AVG_OVERHEAD      0  /* It typically takes 2.0 microseconds */
92                             /* (Y countdowns) to start/stop the timer. */
93                             /* This value is in microseconds. */
94#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
95
96/* Read_timer --
97 *     Read timer value in microsecond units since timer start.
98 *
99 * PARAMETERS:
100 *     none
101 *
102 * RETURNS:
103 *     number of microseconds since timer has been started
104 */
105int
106Read_timer( void )
107{
108    rtems_unsigned16 clicks;
109    rtems_unsigned32 total;
110
111    /*
112     *  Read the timer and see how many clicks it has been since counter
113     *  rolled over.
114     */
115    clicks = *MCF5206E_TCN(MBAR, 2);
116 
117    /* Stop Timer... */
118    *MCF5206E_TMR(MBAR, 2) = MCF5206E_TMR_ICLK_STOP |
119                             MCF5206E_TMR_RST;
120
121    /*
122     *  Total is calculated by taking into account the number of timer
123     *  overflow interrupts since the timer was initialized and clicks
124     *  since the last interrupts.
125     */
126
127    total = (Timer_interrupts * TRR2_VAL) + clicks;
128
129    if ( Timer_driver_Find_average_overhead == 1 )
130        return total;          /* in XXX microsecond units */
131
132    if ( total < LEAST_VALID )
133        return 0;            /* below timer resolution */
134
135    /*
136     *  Return the count in microseconds
137     */
138    return (total - AVG_OVERHEAD);
139}
140
141
142/* Empty_function --
143 *     Empty function call used in loops to measure basic cost of looping
144 *     in Timing Test Suite.
145 *
146 * PARAMETERS:
147 *     none
148 *
149 * RETURNS:
150 *     RTEMS_SUCCESSFUL
151 */
152rtems_status_code
153Empty_function(void)
154{
155    return RTEMS_SUCCESSFUL;
156}
157
158/* Set_find_average_overhead --
159 *     This routine is invoked by the "Check Timer" (tmck) test in the
160 *     RTEMS Timing Test Suite. It makes the Read_timer routine not
161 *     subtract the overhead required to initialize and read the benchmark
162 *     timer.
163 *
164 * PARAMETERS:
165 *     find_flag - boolean flag, TRUE if overhead must not be subtracted.
166 *
167 * RETURNS:
168 *     none
169 */
170void
171Set_find_average_overhead(rtems_boolean find_flag)
172{
173  Timer_driver_Find_average_overhead = find_flag;
174}
Note: See TracBrowser for help on using the repository browser.