source: rtems/c/src/lib/libbsp/m68k/mvme167/timer/timer.c @ 26c17377

4.115
Last change on this file since 26c17377 was 26c17377, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/09/11 at 12:15:54

2011-02-09 Ralf Corsépius <ralf.corsepius@…>

  • timer/timer.c: Include <rtems/btimer.h>. Fix benchmark_timer_read() definition.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing Test Suite.
4 *  Each measured time period is demarcated by calls to benchmark_timer_initialize() and
5 *  benchmark_timer_read().  benchmark_timer_read() usually returns the number of microseconds
6 *  since benchmark_timer_initialize() exitted.
7 *
8 *  These functions are prototyped in rtems/c/src/lib/include/timerdrv.h and
9 *  must be implemented as part of the BSP.
10 *
11 *  This port does not allow the application to select which timer on the
12 *  MVME167 to use for the timer, nor does it allow the application to
13 *  configure the timer. The timer uses the VMEchip2 Tick Timer #1. This timer
14 *  is distinct from the clock, which uses Tick Timer #2 in the VMEchip2.
15 *
16 *  All page references are to the MVME166/MVME167/MVME187 Single Board
17 *  Computer Programmer's Reference Guide (MVME187PG/D2) with the April 1993
18 *  supplements/addenda (MVME187PG/D2A1).
19 *
20 *  COPYRIGHT (c) 1989-1999.
21 *  On-Line Applications Research Corporation (OAR).
22 *
23 *  The license and distribution terms for this file may be
24 *  found in the file LICENSE in this distribution or at
25 *  http://www.rtems.com/license/LICENSE.
26 *
27 *  Modifications of respective RTEMS file:
28 *  Copyright (c) 1998, National Research Council of Canada
29 *
30 *  $Id$
31 */
32
33#include <rtems.h>
34#include <rtems/btimer.h>
35#include <bsp.h>
36
37/* Periodic tick interval */
38#define TICK_INTERVAL         10000UL     /* T1's countdown constant (10 ms) */
39#define TIMER_INT_LEVEL       6           /* T1's interrupt level */
40#define TIMER_VECTOR (VBR0 * 0x10 + 0x8)  /* T1 is vector $X8 (p. 2-71)*/
41
42/* Number of interrupts since timer was re-initialized */
43uint32_t            Ttimer_val;
44
45/*
46 *  Set to true to return raw value. Normally zero. Depends on being allocated
47 *  in the .bss section and on that section being explicitly zeroed at boot
48 *  time.
49 */
50bool benchmark_timer_find_average_overhead;
51
52rtems_isr_entry timerisr(rtems_vector_number);
53
54/*
55 *  This routine initializes the Tick Timer 1 on the MVME167 board.
56 *
57 *  Input parameters:  NONE
58 *
59 *  Output parameters:  NONE
60 *
61 *  NOTE: This routine may not work if the optimizer is enabled for some
62 *        compilers. The multiple writes may be optimized away.
63 *
64 *        It is important that the timer start/stop overhead be
65 *        determined when porting or modifying this code.
66 *
67 *  THE VMECHIP2 PRESCALER REGISTER IS ASSUMED TO BE SET!
68 *  The prescaler is used by all VMEchip2 timers, including the VMEbus grant
69 *  timeout counter, the DMAC time off timer, the DMAC timer on timer, and the
70 *  VMEbus global timeout timer. The prescaler value is normally set by the
71 *  boot ROM to provide a 1 MHz clock to the timers. For a 25 MHz MVME167, the
72 *  prescaler value should be 0xE7 (page 2-63).
73 */
74void benchmark_timer_initialize(void)
75{
76  (void) set_vector( timerisr, TIMER_VECTOR, 0 );
77
78  Ttimer_val = 0;                       /* clear timer ISR count */
79  lcsr->intr_ena &= 0xFEFFFFFF;         /* disable tick timer 1 interrupt */
80  lcsr->intr_clear |= 0x01000000;       /* clear tick timer 1 interrupt */
81  lcsr->intr_level[0] =                 /* set int level */
82        (lcsr->intr_level[0] & 0xFFFFFFF0) | TIMER_INT_LEVEL;
83  lcsr->timer_cmp_1 = TICK_INTERVAL;    /* period in compare register */
84  lcsr->timer_cnt_1 = 0;                /* clear tick timer 1 counter */
85  lcsr->board_ctl |= 7;                 /* start tick timer 1, reset-on-compare, */
86                                        /*   and clear overflow counter */
87
88  lcsr->intr_ena |= 0x01000000;         /* enable tick timer 1 interrupt */
89  lcsr->vector_base |= MASK_INT;        /* unmask VMEchip2 interrupts */
90}
91
92#define AVG_OVERHEAD      3UL   /* It typically takes 3.0 microseconds */
93                                /* (3 countdowns) to start/stop the timer. */
94#define LEAST_VALID       3UL   /* Don't trust a value lower than this */
95
96/*
97 *  This routine reads the Tick Timer 1 on the MVME167 board.
98 *
99 *  Input parameters:  NONE
100 *
101 *  Output parameters:  time in microseconds
102 *
103 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
104 *  is usually deducted from the number returned.
105 *
106 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
107 *  below this are "noise" and zero is returned.
108 */
109uint32_t benchmark_timer_read(void)
110{
111  uint32_t            total;
112
113  total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1;
114
115  if ( benchmark_timer_find_average_overhead )
116    return total;          /* in one microsecond units */
117
118  if ( total < LEAST_VALID )
119    return 0;            /* below timer resolution */
120
121  return total - AVG_OVERHEAD;
122}
123
124/*
125 *  This routine sets the benchmark_timer_find_average_overhead flag in this
126 *  module.
127 *
128 *  Input parameters:  NONE
129 *
130 *  Output parameters:  time in microseconds
131 */
132void benchmark_timer_disable_subtracting_average_overhead(
133  bool find_flag
134)
135{
136  benchmark_timer_find_average_overhead = find_flag;
137}
Note: See TracBrowser for help on using the repository browser.