source: rtems/c/src/lib/libcpu/m68k/mcf5206/timer/timer.c @ 00717a3

4.104.114.84.95
Last change on this file since 00717a3 was 00717a3, checked in by Joel Sherrill <joel.sherrill@…>, on 10/26/01 at 19:32:40

2001-10-26 Victor V. Vengerov <vvv@…>

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