source: rtems/c/src/lib/libbsp/m68k/ods68302/timer/timer.c @ 290da88f

4.104.115
Last change on this file since 290da88f was 290da88f, checked in by Joel Sherrill <joel.sherrill@…>, on 09/30/08 at 16:27:16

2008-09-30 Joel Sherrill <joel.sherrill@…>

  • timer/timer.c: Eliminate uses of old benchmark timer names.
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *
3 *  This routine initializes TIMER 2 for an MC68302.
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#include <rtems.h>
16#include <bsp.h>
17#include <rtems/m68k/m68302.h>
18
19#define TMR2_VAL 0x071b /* Timer mode register
20                         * (section 3.5.2.1 in 68302 manual)
21                         * 15-8: "7"    prescaler divide by 8 (x+1)
22                         *  7-6: 00     dis. intr. on capture event
23                         *    5:  0     active-low pulse
24                         *    4:  1     intr. on reaching reference
25                         *    3:  1     restart counter on reference
26                         *  2-1: 01     master clock input source
27                         *    0:  1     enable timer
28                         */
29#define TRR2_VAL 2000   /* Timer reference register
30                         * (section 3.5.2.2 in 68302 manual)
31                         * 2000 ticks @ (16MHz/1)/8 = 1-ms count
32                         */
33
34uint32_t         Timer_interrupts;
35
36bool benchmark_timer_find_average_overhead;
37
38rtems_isr timerisr(void);
39
40void benchmark_timer_initialize( void )
41{
42    m302.reg.tmr2 = 0;                  /* disable timer */
43
44    Timer_interrupts = 0;               /* clear timer ISR count */
45
46    m302.reg.trr2 = TRR2_VAL;           /* set timer reference register */
47    m302.reg.tmr2 = TMR2_VAL;           /* set timer mode register */
48    m302.reg.imr |= RBIT_IMR_TIMER2;    /* set 68302 int-mask to allow ints */
49}
50
51/*
52 *  The following controls the behavior of benchmark_timer_read().
53 *
54 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
55 *
56 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
57 *  is usually deducted from the number returned.
58 *
59 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
60 *  below this are "noise" and zero is returned.
61 */
62
63#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
64                             /* (Y countdowns) to start/stop the timer. */
65                             /* This value is in microseconds. */
66#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
67
68/*
69 * Return timer value in 1/2-microsecond units
70 */
71int benchmark_timer_read( void )
72{
73  uint16_t         clicks;
74  uint32_t         total;
75
76  /*
77   *  Read the timer and see how many clicks it has been since counter
78   *  rolled over.
79   */
80
81  clicks = m302.reg.tcn2;
82
83  /*
84   *  Total is calculated by taking into account the number of timer overflow
85   *  interrupts since the timer was initialized and clicks since the last
86   *  interrupts.
87   */
88
89  total = (Timer_interrupts * TRR2_VAL) + clicks;
90
91  if ( benchmark_timer_find_average_overhead == true )
92    return total;          /* in XXX microsecond units */
93
94  if ( total < LEAST_VALID )
95    return 0;            /* below timer resolution */
96
97  /*
98   *  Convert 1/2-microsecond count into microseconds
99   */
100
101  return (total - AVG_OVERHEAD) >> 1;
102}
103
104void benchmark_timer_disable_subtracting_average_overhead(
105  bool find_flag
106)
107{
108  benchmark_timer_find_average_overhead = find_flag;
109}
Note: See TracBrowser for help on using the repository browser.