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

Subversion Repositories openrisc_me

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  Timer_init()
2
 *
3
 *  This routine initializes a timer in efi68k's DP8570A TCP
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:03 chris Exp $
20
 */
21
 
22
 
23
#include <bsp.h>
24
 
25
rtems_boolean Timer_driver_Find_average_overhead;
26
 
27
extern rtems_isr Clock_isr();
28
 
29
void Timer_initialize( void )
30
{
31
  /* stop counter */
32
  *MSR = 0;
33
  *T0CR = 0;
34
 
35
  /*
36
   * Make sure isr is installed
37
   */
38
 
39
  set_vector( Clock_isr, TCP_ISR_LEVEL+24, 1);
40
 
41
  /* clear timer ISR count */
42
  Timer_interrupts = 0;
43
 
44
  /* load count (count down timer) */
45
  *MSR = 0;
46
  *T0_MSB = 0xff;
47
  *T0_LSB = 0xff;
48
 
49
  /* clear old interrupts */
50
  *MSR = T0;
51
 
52
  /* enable timer 0 interrupt */
53
  *MSR = RS;
54
  *ICR0 |= T0E;
55
 
56
  /*
57
     TSS = 1        starts the timer (timer resets on start)
58
     M1/0 = 0/1     rate generator
59
     C2/1/0 = 0/0/0 external clock (8MHz) (1/8 usec resolution)
60
     RD = 0         read data (latchs count)
61
     CHG = 0        hold
62
   */
63
  *MSR = 0;
64
  *T0CR = (TSS | M0);
65
}
66
 
67
/*
68
 *  The following controls the behavior of Read_timer().
69
 *
70
 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
71
 *
72
 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
73
 *  is usually deducted from the number returned.
74
 *
75
 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
76
 *  below this are "noise" and zero is returned.
77
 */
78
 
79
#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
80
                             /* (Y countdowns) to start/stop the timer. */
81
                             /* This value is in microseconds. */
82
#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
83
 
84
/*
85
 * Return timer value in 1/2-microsecond units
86
 */
87
int Read_timer( void )
88
{
89
  rtems_unsigned16 clicks;
90
  rtems_unsigned32 total;
91
  rtems_unsigned32 msb, lsb;
92
 
93
 
94
  /*
95
   *  Read the timer and see how many clicks it has been since counter
96
   *  rolled over.
97
   */
98
 
99
  *MSR = 0;
100
  *T0CR |= RD;
101
  /* must read MSB first */
102
  msb = *T0_MSB;
103
  lsb = *T0_LSB;
104
  clicks = 0xffff - ((msb << 8) | lsb);
105
 
106
  /*
107
   *  Total is calculated by taking into account the number of timer overflow
108
   *  interrupts since the timer was initialized and clicks since the last
109
   *  interrupts.
110
   */
111
 
112
  total = (Timer_interrupts * 0x10000 + clicks + 4)/8; /* in micoseconds */
113
  /*                                            ^^^ round to nearest int */
114
 
115
  if ( Timer_driver_Find_average_overhead == 1 )
116
    return total;          /* in XXX microsecond units */
117
 
118
  if ( total < LEAST_VALID )
119
    return 0;            /* below timer resolution */
120
 
121
  return (total - AVG_OVERHEAD);
122
}
123
 
124
 
125
/*
126
 *  Empty function call used in loops to measure basic cost of looping
127
 *  in Timing Test Suite.
128
 */
129
 
130
rtems_status_code Empty_function(void)
131
{
132
    return RTEMS_SUCCESSFUL;
133
}
134
 
135
void Set_find_average_overhead(
136
  rtems_boolean find_flag
137
)
138
{
139
  Timer_driver_Find_average_overhead = find_flag;
140
}

powered by: WebSVN 2.1.0

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