OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [ods68302/] [timer/] [timer.c] - Blame information for rev 173

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.