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, 1990, 1991, 1992, 1993, 1994. |
---|
19 | * On-Line Applications Research Corporation (OAR). |
---|
20 | * All rights assigned to U.S. Government, 1994. |
---|
21 | * |
---|
22 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
23 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
24 | * notice must appear in all copies of this file and its derivatives. |
---|
25 | * |
---|
26 | * $Id$ |
---|
27 | */ |
---|
28 | |
---|
29 | |
---|
30 | #include "rtems.h" |
---|
31 | #include "cpu.h" |
---|
32 | #include "bsp.h" |
---|
33 | #include "mc68230.h" |
---|
34 | |
---|
35 | #define TIMER_VECTOR 0x4D |
---|
36 | |
---|
37 | int Ttimer_val; |
---|
38 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
39 | |
---|
40 | rtems_isr timerisr(); |
---|
41 | |
---|
42 | void Timer_initialize() |
---|
43 | { |
---|
44 | (void) set_vector( timerisr, TIMER_VECTOR, 0 ); /* install ISR */ |
---|
45 | |
---|
46 | Ttimer_val = 0; /* clear timer ISR count */ |
---|
47 | |
---|
48 | /* some PI/T initialization stuff here */ |
---|
49 | /* Set up the interrupt vector on the MC68230 chip: |
---|
50 | TIVR = TIMER_VECTOR; */ |
---|
51 | MC68230_WRITE (TIVR, TIMER_VECTOR); |
---|
52 | |
---|
53 | /* Set CPRH through CPRL to maximum count to reduce interrupt overhead |
---|
54 | CPRH = 0xFF; |
---|
55 | CPRM = 0xFF; |
---|
56 | CPRL = 0xFF; */ |
---|
57 | MC68230_WRITE (CPRH, 0xFF); |
---|
58 | MC68230_WRITE (CPRM, 0xFF); |
---|
59 | MC68230_WRITE (CPRL, 0xFF); |
---|
60 | |
---|
61 | /* Enable timer and use it as an external periodic interrupt generator |
---|
62 | TCR = 0xA1; */ |
---|
63 | MC68230_WRITE (TCR, 0xA1); |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | #define AVG_OVERHEAD 9 /* may not be right -- do this later */ |
---|
68 | #define LEAST_VALID 10 /* Don't trust a value lower than this */ |
---|
69 | |
---|
70 | int Read_timer() |
---|
71 | { |
---|
72 | rtems_unsigned8 data; |
---|
73 | rtems_unsigned8 msb, osb, lsb; |
---|
74 | rtems_unsigned32 remaining, total; |
---|
75 | |
---|
76 | /* Disable timer so that timer can be read |
---|
77 | data = TCR; |
---|
78 | TCR = (data & 0xFE); */ |
---|
79 | MC68230_READ (TCR, data); |
---|
80 | MC68230_WRITE (TCR, (data & 0xFE)); |
---|
81 | |
---|
82 | /* Read the counter value |
---|
83 | msb = CNTRH; |
---|
84 | osb = CNTRM; |
---|
85 | lsb = CNTRL; */ |
---|
86 | MC68230_READ (CNTRH, msb); |
---|
87 | MC68230_READ (CNTRM, osb); |
---|
88 | MC68230_READ (CNTRL, lsb); |
---|
89 | |
---|
90 | /* Calculate the time so far */ |
---|
91 | remaining = 0x1000000 - ((msb << 16) + (osb << 8) + lsb); |
---|
92 | total = (Ttimer_val * 0x1000000) + remaining; |
---|
93 | |
---|
94 | /* Enable timer so that timer can continue |
---|
95 | TCR = 0xA1; */ |
---|
96 | MC68230_WRITE (TCR, 0xA1); |
---|
97 | |
---|
98 | /* do not restore old vector */ |
---|
99 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
100 | return total; /* in countdown units */ |
---|
101 | |
---|
102 | if ( total < LEAST_VALID ) |
---|
103 | return 0; /* below timer resolution */ |
---|
104 | |
---|
105 | /* Clocked at 6.5 Mhz */ |
---|
106 | /* Avoid floating point problems, be lazy, and return the total minus |
---|
107 | the average overhead */ |
---|
108 | return (total - AVG_OVERHEAD); |
---|
109 | } |
---|
110 | |
---|
111 | rtems_status_code Empty_function( void ) |
---|
112 | { |
---|
113 | return RTEMS_SUCCESSFUL; |
---|
114 | } |
---|
115 | |
---|
116 | void Set_find_average_overhead( |
---|
117 | rtems_boolean find_flag |
---|
118 | ) |
---|
119 | { |
---|
120 | Timer_driver_Find_average_overhead = find_flag; |
---|
121 | } |
---|