source: rtems/c/src/lib/libbsp/m68k/idp/timer/timer.c @ c3db3251

4.104.114.84.9
Last change on this file since c3db3251 was c3db3251, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:51:54 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, startup/bspstart.c, timer/timer.c, timer/timerisr.S: URL for license changed.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*  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.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 */
27
28
29#include <rtems.h>
30#include <bsp.h>
31#include <motorola/mc68230.h>
32
33#define TIMER_VECTOR 0x4D
34
35int Ttimer_val;
36rtems_boolean Timer_driver_Find_average_overhead;
37
38rtems_isr timerisr();
39
40void 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
68int 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
109rtems_status_code Empty_function( void )
110{
111  return RTEMS_SUCCESSFUL;
112}
113
114void Set_find_average_overhead(
115  rtems_boolean find_flag
116)
117{
118  Timer_driver_Find_average_overhead = find_flag;
119}
Note: See TracBrowser for help on using the repository browser.