source: rtems/c/src/lib/libbsp/m68k/ods68302/timer/timer.c @ 907bf4b8

4.104.114.95
Last change on this file since 907bf4b8 was 907bf4b8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/05/08 at 08:46:27

Convert to "bool".

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