1 | /* |
---|
2 | * Clock Tick Device Driver |
---|
3 | * |
---|
4 | * This routine utilizes the Decrementer Register common to the PPC family. |
---|
5 | * |
---|
6 | * The tick frequency is directly programmed to the configured number of |
---|
7 | * microseconds per tick. |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1997. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may in |
---|
13 | * the file LICENSE in this distribution or at |
---|
14 | * http://www.OARcorp.com/rtems/license.html. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #include <stdlib.h> |
---|
20 | |
---|
21 | #include <bsp.h> |
---|
22 | #include <rtems/libio.h> |
---|
23 | |
---|
24 | extern rtems_cpu_table Cpu_table; |
---|
25 | |
---|
26 | /* |
---|
27 | * The Real Time Clock Counter Timer uses this trap type. |
---|
28 | */ |
---|
29 | |
---|
30 | #define CLOCK_VECTOR PPC_IRQ_DECREMENTER |
---|
31 | |
---|
32 | /* |
---|
33 | * Clock ticks since initialization |
---|
34 | */ |
---|
35 | |
---|
36 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
37 | |
---|
38 | /* |
---|
39 | * This is the value programmed into the count down timer. |
---|
40 | */ |
---|
41 | |
---|
42 | rtems_unsigned32 Clock_Decrementer_value; |
---|
43 | |
---|
44 | /* |
---|
45 | * This is the value of the old isr routine. |
---|
46 | */ |
---|
47 | rtems_isr_entry Old_ticker; |
---|
48 | |
---|
49 | |
---|
50 | void Clock_exit( void ); |
---|
51 | |
---|
52 | /* |
---|
53 | * These are set by clock driver during its init |
---|
54 | */ |
---|
55 | |
---|
56 | rtems_device_major_number rtems_clock_major = ~0; |
---|
57 | rtems_device_minor_number rtems_clock_minor; |
---|
58 | |
---|
59 | /*PAGE |
---|
60 | * |
---|
61 | * Clock_isr |
---|
62 | * |
---|
63 | * This is the clock tick interrupt handler. |
---|
64 | * |
---|
65 | * Input parameters: |
---|
66 | * vector - vector number |
---|
67 | * |
---|
68 | * Output parameters: NONE |
---|
69 | * |
---|
70 | * Return values: NONE |
---|
71 | * |
---|
72 | */ |
---|
73 | |
---|
74 | rtems_isr Clock_isr( |
---|
75 | rtems_vector_number vector, |
---|
76 | CPU_Interrupt_frame *frame |
---|
77 | ) |
---|
78 | { |
---|
79 | /* |
---|
80 | * Set the decrementer. |
---|
81 | */ |
---|
82 | |
---|
83 | PPC_Set_decrementer( Clock_Decrementer_value ); |
---|
84 | |
---|
85 | /* |
---|
86 | * The driver has seen another tick. |
---|
87 | */ |
---|
88 | |
---|
89 | Clock_driver_ticks += 1; |
---|
90 | |
---|
91 | /* |
---|
92 | * Real Time Clock counter/timer is set to automatically reload. |
---|
93 | */ |
---|
94 | |
---|
95 | rtems_clock_tick(); |
---|
96 | } |
---|
97 | |
---|
98 | /*PAGE |
---|
99 | * |
---|
100 | * Install_clock |
---|
101 | * |
---|
102 | * This routine actually performs the hardware initialization for the clock. |
---|
103 | * |
---|
104 | * Input parameters: |
---|
105 | * clock_isr - clock interrupt service routine entry point |
---|
106 | * |
---|
107 | * Output parameters: NONE |
---|
108 | * |
---|
109 | * Return values: NONE |
---|
110 | * |
---|
111 | */ |
---|
112 | |
---|
113 | extern int CLOCK_SPEED; |
---|
114 | |
---|
115 | void Install_clock( |
---|
116 | rtems_isr_entry clock_isr |
---|
117 | ) |
---|
118 | { |
---|
119 | Clock_driver_ticks = 0; |
---|
120 | |
---|
121 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
122 | |
---|
123 | PPC_Set_decrementer( Clock_Decrementer_value ); |
---|
124 | |
---|
125 | atexit( Clock_exit ); |
---|
126 | } |
---|
127 | |
---|
128 | /*PAGE |
---|
129 | * |
---|
130 | * Clock_exit |
---|
131 | * |
---|
132 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
133 | * disabling the clock's counter. |
---|
134 | * |
---|
135 | * Input parameters: NONE |
---|
136 | * |
---|
137 | * Output parameters: NONE |
---|
138 | * |
---|
139 | * Return values: NONE |
---|
140 | * |
---|
141 | */ |
---|
142 | |
---|
143 | void Clock_exit( void ) |
---|
144 | { |
---|
145 | /* nothing to do */; |
---|
146 | |
---|
147 | /* do not restore old vector */ |
---|
148 | } |
---|
149 | |
---|
150 | /*PAGE |
---|
151 | * |
---|
152 | * Clock_initialize |
---|
153 | * |
---|
154 | * This routine initializes the clock driver. |
---|
155 | * |
---|
156 | * Input parameters: |
---|
157 | * major - clock device major number |
---|
158 | * minor - clock device minor number |
---|
159 | * parg - pointer to optional device driver arguments |
---|
160 | * |
---|
161 | * Output parameters: NONE |
---|
162 | * |
---|
163 | * Return values: |
---|
164 | * rtems_device_driver status code |
---|
165 | */ |
---|
166 | |
---|
167 | rtems_device_driver Clock_initialize( |
---|
168 | rtems_device_major_number major, |
---|
169 | rtems_device_minor_number minor, |
---|
170 | void *pargp |
---|
171 | ) |
---|
172 | { |
---|
173 | Clock_Decrementer_value = Cpu_table.clicks_per_usec * |
---|
174 | BSP_Configuration.microseconds_per_tick; |
---|
175 | |
---|
176 | Install_clock( Clock_isr ); |
---|
177 | |
---|
178 | /* |
---|
179 | * make major/minor avail to others such as shared memory driver |
---|
180 | */ |
---|
181 | |
---|
182 | rtems_clock_major = major; |
---|
183 | rtems_clock_minor = minor; |
---|
184 | |
---|
185 | return RTEMS_SUCCESSFUL; |
---|
186 | } |
---|
187 | |
---|
188 | /* PAGE |
---|
189 | * |
---|
190 | * Clock_control |
---|
191 | * |
---|
192 | * This routine is the clock device driver control entry point. |
---|
193 | * |
---|
194 | * Input parameters: |
---|
195 | * major - clock device major number |
---|
196 | * minor - clock device minor number |
---|
197 | * parg - pointer to optional device driver arguments |
---|
198 | * |
---|
199 | * Output parameters: NONE |
---|
200 | * |
---|
201 | * Return values: |
---|
202 | * rtems_device_driver status code |
---|
203 | */ |
---|
204 | |
---|
205 | rtems_device_driver Clock_control( |
---|
206 | rtems_device_major_number major, |
---|
207 | rtems_device_minor_number minor, |
---|
208 | void *pargp |
---|
209 | ) |
---|
210 | { |
---|
211 | rtems_unsigned32 isrlevel; |
---|
212 | rtems_libio_ioctl_args_t *args = pargp; |
---|
213 | |
---|
214 | if (args == 0) |
---|
215 | goto done; |
---|
216 | |
---|
217 | /* |
---|
218 | * This is hokey, but until we get a defined interface |
---|
219 | * to do this, it will just be this simple... |
---|
220 | */ |
---|
221 | |
---|
222 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
223 | { |
---|
224 | Clock_isr( CLOCK_VECTOR, pargp ); |
---|
225 | } |
---|
226 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
227 | { |
---|
228 | rtems_interrupt_disable( isrlevel ); |
---|
229 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
230 | rtems_interrupt_enable( isrlevel ); |
---|
231 | } |
---|
232 | |
---|
233 | done: |
---|
234 | return RTEMS_SUCCESSFUL; |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | |
---|