1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initializes the DP8570A periodic interrupt on the |
---|
4 | * efi68k board. The tick frequency is 1 millisecond. |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * All rights assigned to U.S. Government, 1994. |
---|
13 | * |
---|
14 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
15 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
16 | * notice must appear in all copies of this file and its derivatives. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <stdlib.h> |
---|
22 | #include <bsp.h> |
---|
23 | #include <rtems/libio.h> |
---|
24 | |
---|
25 | #define CLOCK_VECTOR (TCP_ISR_LEVEL+24) |
---|
26 | |
---|
27 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
28 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
29 | /* ticks since initialization */ |
---|
30 | rtems_isr_entry Old_ticker; |
---|
31 | |
---|
32 | void Clock_exit( void ); |
---|
33 | |
---|
34 | /* |
---|
35 | * These are set by clock driver during its init |
---|
36 | */ |
---|
37 | |
---|
38 | rtems_device_major_number rtems_clock_major = ~0; |
---|
39 | rtems_device_minor_number rtems_clock_minor; |
---|
40 | |
---|
41 | |
---|
42 | void per_interrupt(void) |
---|
43 | { |
---|
44 | Clock_driver_ticks += 1; |
---|
45 | |
---|
46 | *MSR = PER; |
---|
47 | |
---|
48 | if ( Clock_isrs == 1 ) { |
---|
49 | rtems_clock_tick(); |
---|
50 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
51 | } |
---|
52 | else |
---|
53 | Clock_isrs -= 1; |
---|
54 | } |
---|
55 | |
---|
56 | rtems_isr Clock_isr( |
---|
57 | rtems_vector_number vector |
---|
58 | ) |
---|
59 | { |
---|
60 | unsigned char entry_msr, msr; |
---|
61 | |
---|
62 | entry_msr = *MSR; |
---|
63 | *MSR = 0; |
---|
64 | while ( (msr=*MSR) & INT ) |
---|
65 | /* test enabled interrupt bits */ |
---|
66 | if (msr & PER) |
---|
67 | per_interrupt(); |
---|
68 | else if (msr & T0) { |
---|
69 | *MSR = T0; /* reset interrupt */ |
---|
70 | Timer_interrupts++; /* inc wrap around counter */ |
---|
71 | } |
---|
72 | else |
---|
73 | /* there has been an error if we reach this point */ |
---|
74 | /* default action: reset all the interrupts */ |
---|
75 | *MSR = ( PER | AL | T0 | T1 ); |
---|
76 | *MSR = entry_msr & (RS | PS); |
---|
77 | } |
---|
78 | |
---|
79 | void Install_clock( |
---|
80 | rtems_isr_entry clock_isr |
---|
81 | ) |
---|
82 | { |
---|
83 | Clock_driver_ticks = 0; |
---|
84 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
85 | |
---|
86 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
87 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
88 | |
---|
89 | *MSR = RS; /* enable 1mS interrupts */ |
---|
90 | *ICR0 |= OME; |
---|
91 | |
---|
92 | atexit( Clock_exit ); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | void ReInstall_clock( |
---|
97 | rtems_isr_entry clock_isr |
---|
98 | ) |
---|
99 | { |
---|
100 | rtems_unsigned32 isrlevel = 0 ; |
---|
101 | |
---|
102 | rtems_interrupt_disable( isrlevel ); |
---|
103 | (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
104 | rtems_interrupt_enable( isrlevel ); |
---|
105 | } |
---|
106 | |
---|
107 | void Clock_exit( void ) |
---|
108 | { |
---|
109 | |
---|
110 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
111 | |
---|
112 | /* shutdown periodic interrupt */ |
---|
113 | *MSR = RS; |
---|
114 | *ICR0 &= 0xc0; |
---|
115 | /* do not restore old vector */ |
---|
116 | |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | rtems_device_driver Clock_initialize( |
---|
121 | rtems_device_major_number major, |
---|
122 | rtems_device_minor_number minor, |
---|
123 | void *pargp |
---|
124 | ) |
---|
125 | { |
---|
126 | Install_clock( Clock_isr ); |
---|
127 | |
---|
128 | /* |
---|
129 | * make major/minor avail to others such as shared memory driver |
---|
130 | */ |
---|
131 | |
---|
132 | rtems_clock_major = major; |
---|
133 | rtems_clock_minor = minor; |
---|
134 | |
---|
135 | return RTEMS_SUCCESSFUL; |
---|
136 | } |
---|
137 | |
---|
138 | rtems_device_driver Clock_control( |
---|
139 | rtems_device_major_number major, |
---|
140 | rtems_device_minor_number minor, |
---|
141 | void *pargp |
---|
142 | ) |
---|
143 | { |
---|
144 | rtems_libio_ioctl_args_t *args = pargp; |
---|
145 | |
---|
146 | if (args == 0) |
---|
147 | goto done; |
---|
148 | |
---|
149 | /* |
---|
150 | * This is hokey, but until we get a defined interface |
---|
151 | * to do this, it will just be this simple... |
---|
152 | */ |
---|
153 | |
---|
154 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
155 | { |
---|
156 | Clock_isr(CLOCK_VECTOR); |
---|
157 | } |
---|
158 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
159 | { |
---|
160 | ReInstall_clock(args->buffer); |
---|
161 | } |
---|
162 | |
---|
163 | done: |
---|
164 | return RTEMS_SUCCESSFUL; |
---|
165 | } |
---|