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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [idp/] [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 the MC68230 timer on the Motorola IDP board.
4
 *
5
 *  Input parameters:  NONE
6
 *
7
 *  Output parameters:  NONE
8
 *
9
 *  NOTE: This routine will not work if the optimizer is enabled
10
 *        for some compilers.  The multiple writes to the MC68230
11
 *        may be optimized away.
12
 *
13
 *        It is important that the timer start/stop overhead be
14
 *        determined when porting or modifying this code.
15
 *
16
 *  Code Modified for the MC68230 by Doug McBride, Colorado Space Grant College
17
 *
18
 *  COPYRIGHT (c) 1989-1999.
19
 *  On-Line Applications Research Corporation (OAR).
20
 *
21
 *  The license and distribution terms for this file may be
22
 *  found in the file LICENSE in this distribution or at
23
 *  http://www.OARcorp.com/rtems/license.html.
24
 *
25
 *  $Id: timer.c,v 1.2 2001-09-27 12:00:12 chris Exp $
26
 */
27
 
28
 
29
#include <rtems.h>
30
#include <bsp.h>
31
#include <motorola/mc68230.h>
32
 
33
#define TIMER_VECTOR 0x4D
34
 
35
int Ttimer_val;
36
rtems_boolean Timer_driver_Find_average_overhead;
37
 
38
rtems_isr timerisr();
39
 
40
void Timer_initialize()
41
{
42
  (void) set_vector( timerisr, TIMER_VECTOR, 0 );  /* install ISR */
43
 
44
  Ttimer_val = 0;                          /* clear timer ISR count */
45
 
46
  /* some PI/T initialization stuff here */
47
  /* Set up the interrupt vector on the MC68230 chip:
48
     TIVR = TIMER_VECTOR; */
49
  MC68230_WRITE (TIVR, TIMER_VECTOR);
50
 
51
  /* Set CPRH through CPRL to maximum count to reduce interrupt overhead
52
      CPRH = 0xFF;
53
      CPRM = 0xFF;
54
      CPRL = 0xFF; */
55
  MC68230_WRITE (CPRH, 0xFF);
56
  MC68230_WRITE (CPRM, 0xFF);
57
  MC68230_WRITE (CPRL, 0xFF);
58
 
59
  /* Enable timer and use it as an external periodic interrupt generator
60
      TCR = 0xA1; */
61
  MC68230_WRITE (TCR, 0xA1);
62
 
63
}
64
 
65
#define AVG_OVERHEAD      9  /* may not be right -- do this later */
66
#define LEAST_VALID       10 /* Don't trust a value lower than this */
67
 
68
int Read_timer()
69
{
70
  rtems_unsigned8 data;
71
  rtems_unsigned8  msb, osb, lsb;
72
  rtems_unsigned32 remaining, total;
73
 
74
  /* Disable timer so that timer can be read
75
        data = TCR;
76
        TCR = (data & 0xFE); */
77
  MC68230_READ (TCR, data);
78
  MC68230_WRITE (TCR, (data & 0xFE));
79
 
80
  /* Read the counter value
81
        msb = CNTRH;
82
        osb = CNTRM;
83
        lsb = CNTRL; */
84
  MC68230_READ (CNTRH, msb);
85
  MC68230_READ (CNTRM, osb);
86
  MC68230_READ (CNTRL, lsb);
87
 
88
  /* Calculate the time so far */
89
  remaining = 0x1000000 - ((msb << 16) + (osb << 8) + lsb);
90
  total = (Ttimer_val * 0x1000000) + remaining;
91
 
92
  /* Enable timer so that timer can continue
93
                TCR = 0xA1; */
94
  MC68230_WRITE (TCR, 0xA1);
95
 
96
  /* do not restore old vector */
97
  if ( Timer_driver_Find_average_overhead == 1 )
98
    return total;          /* in countdown units */
99
 
100
  if ( total < LEAST_VALID )
101
    return 0;            /* below timer resolution */
102
 
103
  /* Clocked at 6.5 Mhz */
104
  /* Avoid floating point problems, be lazy, and return the total minus
105
     the average overhead */
106
  return (total - AVG_OVERHEAD);
107
}
108
 
109
rtems_status_code Empty_function( void )
110
{
111
  return RTEMS_SUCCESSFUL;
112
}
113
 
114
void Set_find_average_overhead(
115
  rtems_boolean find_flag
116
)
117
{
118
  Timer_driver_Find_average_overhead = find_flag;
119
}

powered by: WebSVN 2.1.0

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