source: rtems/c/src/lib/libbsp/m68k/gen68302/timer/timer.c @ 0ccb2bb

4.104.114.95
Last change on this file since 0ccb2bb was 0ccb2bb, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/08 at 15:54:43

2008-08-31 Joel Sherrill <joel.sherrill@…>

  • timer/timer.c, timer/timerisr.S: Rename timer driver methods to follow RTEMS programming conventions.
  • Property mode set to 100644
File size: 3.3 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
43rtems_boolean benchmark_timerfind_average_overhead;
44
45rtems_isr timerisr(void);
46
47void benchmark_timerinitialize( 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_timerread().
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_timerread( 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_timerfind_average_overhead == 1 )
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
111/*
112 *  Empty function call used in loops to measure basic cost of looping
113 *  in Timing Test Suite.
114 */
115
116rtems_status_code benchmark_timerempty_function(void)
117{
118    return RTEMS_SUCCESSFUL;
119}
120
121void benchmark_timerdisable_subtracting_average_overhead(
122  rtems_boolean find_flag
123)
124{
125  benchmark_timerfind_average_overhead = find_flag;
126}
Note: See TracBrowser for help on using the repository browser.