source: rtems/c/src/lib/libbsp/m68k/mvme167/timer/timer.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

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