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

4.104.114.84.95
Last change on this file since 0074691 was 0074691, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 31, 1997 at 10:13:29 PM

Merged very large and much appreciated patch from Chris Johns
<cjohns@…>. This patch includes the ods68302 bsp,
the RTEMS++ class library, and the rtems++ test.

  • 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-1997.
13 *  On-Line Applications Research Corporation (OAR).
14 *  Copyright assigned to U.S. Government, 1994.
15 *
16 *  The license and distribution terms for this file may in
17 *  the file LICENSE in this distribution or at
18 *  http://www.OARcorp.com/rtems/license.html.
19 *
20 *  $Id$
21 */
22
23
24#include <rtems.h>
25#include <bsp.h>
26#include "m68302.h"
27
28
29#define TMR2_VAL 0x071b /* Timer mode register
30                         * (section 3.5.2.1 in 68302 manual)
31                         * 15-8: "7"    prescaler divide by 8 (x+1)
32                         *  7-6: 00     dis. intr. on capture event
33                         *    5:  0     active-low pulse
34                         *    4:  1     intr. on reaching reference
35                         *    3:  1     restart counter on reference
36                         *  2-1: 01     master clock input source
37                         *    0:  1     enable timer
38                         */
39#define TRR2_VAL 2000   /* Timer reference register
40                         * (section 3.5.2.2 in 68302 manual)
41                         * 2000 ticks @ (16MHz/1)/8 = 1-ms count
42                         */
43
44rtems_unsigned32 Timer_interrupts;
45
46rtems_boolean Timer_driver_Find_average_overhead;
47
48rtems_isr timerisr();
49
50void Timer_initialize( void )
51{
52    m302.reg.tmr2 = 0;                  /* disable timer */
53
54    Timer_interrupts = 0;               /* clear timer ISR count */
55
56    m302.reg.trr2 = TRR2_VAL;           /* set timer reference register */
57    m302.reg.tmr2 = TMR2_VAL;           /* set timer mode register */
58    m302.reg.imr |= RBIT_IMR_TIMER2;    /* set 68302 int-mask to allow ints */
59}
60
61/*
62 *  The following controls the behavior of Read_timer().
63 *
64 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
65 *
66 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
67 *  is usually deducted from the number returned.
68 *
69 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
70 *  below this are "noise" and zero is returned.
71 */
72
73#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
74                             /* (Y countdowns) to start/stop the timer. */
75                             /* This value is in microseconds. */
76#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
77
78/*
79 * Return timer value in 1/2-microsecond units
80 */
81int Read_timer( void )
82{
83  rtems_unsigned16 clicks;
84  rtems_unsigned32 total;
85
86  /*
87   *  Read the timer and see how many clicks it has been since counter
88   *  rolled over.
89   */
90
91  clicks = m302.reg.tcn2;
92
93  /*
94   *  Total is calculated by taking into account the number of timer overflow
95   *  interrupts since the timer was initialized and clicks since the last
96   *  interrupts.
97   */
98
99  total = (Timer_interrupts * TRR2_VAL) + clicks;
100
101  if ( Timer_driver_Find_average_overhead == 1 )
102    return total;          /* in XXX microsecond units */
103
104  if ( total < LEAST_VALID )
105    return 0;            /* below timer resolution */
106
107  /*
108   *  Convert 1/2-microsecond count into microseconds
109   */
110
111  return (total - AVG_OVERHEAD) >> 1;
112}
113
114
115/*
116 *  Empty function call used in loops to measure basic cost of looping
117 *  in Timing Test Suite.
118 */
119
120rtems_status_code Empty_function(void)
121{
122    return RTEMS_SUCCESSFUL;
123}
124
125void Set_find_average_overhead(
126  rtems_boolean find_flag
127)
128{
129  Timer_driver_Find_average_overhead = find_flag;
130}
Note: See TracBrowser for help on using the repository browser.