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