1 | /* |
---|
2 | * Clock Tick Device Driver Shell |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1999. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.OARcorp.com/rtems/license.html. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdlib.h> |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | |
---|
19 | #if defined(CLOCK_DRIVER_USE_FAST_IDLE) && defined(CLOCK_DRIVER_ISRS_PER_TICK) |
---|
20 | #error "clockdrv_shell.c: fast idle and N ISRs per tick is not supported" |
---|
21 | #endif |
---|
22 | |
---|
23 | /* |
---|
24 | * ISRs until next clock tick |
---|
25 | */ |
---|
26 | |
---|
27 | #ifdef CLOCK_DRIVER_ISRS_PER_TICK |
---|
28 | volatile rtems_unsigned32 Clock_driver_isrs; |
---|
29 | #endif |
---|
30 | |
---|
31 | /* |
---|
32 | * Clock ticks since initialization |
---|
33 | */ |
---|
34 | |
---|
35 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
36 | |
---|
37 | /* |
---|
38 | * ISR formerly installed. |
---|
39 | */ |
---|
40 | |
---|
41 | rtems_isr_entry Old_ticker; |
---|
42 | |
---|
43 | void Clock_exit( void ); |
---|
44 | |
---|
45 | /* |
---|
46 | * Major and minor number. |
---|
47 | */ |
---|
48 | |
---|
49 | rtems_device_major_number rtems_clock_major = ~0; |
---|
50 | rtems_device_minor_number rtems_clock_minor; |
---|
51 | |
---|
52 | /* |
---|
53 | * Clock_isr |
---|
54 | * |
---|
55 | * This is the clock tick interrupt handler. |
---|
56 | * |
---|
57 | * Input parameters: |
---|
58 | * vector - vector number |
---|
59 | * |
---|
60 | * Output parameters: NONE |
---|
61 | * |
---|
62 | * Return values: NONE |
---|
63 | * |
---|
64 | */ |
---|
65 | |
---|
66 | rtems_isr Clock_isr( |
---|
67 | rtems_vector_number vector |
---|
68 | ) |
---|
69 | { |
---|
70 | /* |
---|
71 | * Accurate count of ISRs |
---|
72 | */ |
---|
73 | |
---|
74 | Clock_driver_ticks += 1; |
---|
75 | |
---|
76 | #ifdef CLOCK_DRIVER_USE_FAST_IDLE |
---|
77 | do { |
---|
78 | rtems_clock_tick(); |
---|
79 | } while ( _Thread_Executing == _Thread_Idle && |
---|
80 | _Thread_Heir == _Thread_Executing); |
---|
81 | |
---|
82 | Clock_driver_support_at_tick(); |
---|
83 | return; |
---|
84 | |
---|
85 | #else |
---|
86 | |
---|
87 | /* |
---|
88 | * Do the hardware specific per-tick action. |
---|
89 | * |
---|
90 | * The counter/timer may or may not be set to automatically reload. |
---|
91 | */ |
---|
92 | |
---|
93 | Clock_driver_support_at_tick(); |
---|
94 | |
---|
95 | #ifdef CLOCK_DRIVER_ISRS_PER_TICK |
---|
96 | /* |
---|
97 | * The driver is multiple ISRs per clock tick. |
---|
98 | */ |
---|
99 | |
---|
100 | if ( !Clock_driver_isrs ) { |
---|
101 | |
---|
102 | rtems_clock_tick(); |
---|
103 | |
---|
104 | Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK; |
---|
105 | } |
---|
106 | Clock_driver_isrs--; |
---|
107 | #else |
---|
108 | |
---|
109 | /* |
---|
110 | * The driver is one ISR per clock tick. |
---|
111 | */ |
---|
112 | rtems_clock_tick(); |
---|
113 | #endif |
---|
114 | #endif |
---|
115 | } |
---|
116 | |
---|
117 | /* |
---|
118 | * Install_clock |
---|
119 | * |
---|
120 | * This routine actually performs the hardware initialization for the clock. |
---|
121 | * |
---|
122 | * Input parameters: |
---|
123 | * clock_isr - clock interrupt service routine entry point |
---|
124 | * |
---|
125 | * Output parameters: NONE |
---|
126 | * |
---|
127 | * Return values: NONE |
---|
128 | * |
---|
129 | */ |
---|
130 | |
---|
131 | void Install_clock( |
---|
132 | rtems_isr_entry clock_isr |
---|
133 | ) |
---|
134 | { |
---|
135 | Clock_driver_ticks = 0; |
---|
136 | |
---|
137 | /* |
---|
138 | * Install vector |
---|
139 | */ |
---|
140 | |
---|
141 | Clock_driver_support_install_isr( clock_isr, Old_ticker ); |
---|
142 | |
---|
143 | /* |
---|
144 | * Now initialize the hardware that is the source of the tick ISR. |
---|
145 | */ |
---|
146 | |
---|
147 | Clock_driver_support_initialize_hardware(); |
---|
148 | |
---|
149 | atexit( Clock_exit ); |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | * Clock_exit |
---|
154 | * |
---|
155 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
156 | * disabling the clock's counter. |
---|
157 | * |
---|
158 | * Input parameters: NONE |
---|
159 | * |
---|
160 | * Output parameters: NONE |
---|
161 | * |
---|
162 | * Return values: NONE |
---|
163 | * |
---|
164 | */ |
---|
165 | |
---|
166 | void Clock_exit( void ) |
---|
167 | { |
---|
168 | Clock_driver_support_shutdown_hardware(); |
---|
169 | |
---|
170 | /* do not restore old vector */ |
---|
171 | } |
---|
172 | |
---|
173 | /* |
---|
174 | * Clock_initialize |
---|
175 | * |
---|
176 | * This routine initializes the clock driver. |
---|
177 | * |
---|
178 | * Input parameters: |
---|
179 | * major - clock device major number |
---|
180 | * minor - clock device minor number |
---|
181 | * parg - pointer to optional device driver arguments |
---|
182 | * |
---|
183 | * Output parameters: NONE |
---|
184 | * |
---|
185 | * Return values: |
---|
186 | * rtems_device_driver status code |
---|
187 | */ |
---|
188 | |
---|
189 | rtems_device_driver Clock_initialize( |
---|
190 | rtems_device_major_number major, |
---|
191 | rtems_device_minor_number minor, |
---|
192 | void *pargp |
---|
193 | ) |
---|
194 | { |
---|
195 | Install_clock( Clock_isr ); |
---|
196 | |
---|
197 | /* |
---|
198 | * make major/minor avail to others such as shared memory driver |
---|
199 | */ |
---|
200 | |
---|
201 | rtems_clock_major = major; |
---|
202 | rtems_clock_minor = minor; |
---|
203 | |
---|
204 | /* |
---|
205 | * If we are counting ISRs per tick, then initialize the counter. |
---|
206 | */ |
---|
207 | |
---|
208 | #ifdef CLOCK_DRIVER_ISRS_PER_TICK |
---|
209 | Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK; |
---|
210 | #endif |
---|
211 | |
---|
212 | return RTEMS_SUCCESSFUL; |
---|
213 | } |
---|
214 | |
---|
215 | /* |
---|
216 | * Clock_control |
---|
217 | * |
---|
218 | * This routine is the clock device driver control entry point. |
---|
219 | * |
---|
220 | * Input parameters: |
---|
221 | * major - clock device major number |
---|
222 | * minor - clock device minor number |
---|
223 | * parg - pointer to optional device driver arguments |
---|
224 | * |
---|
225 | * Output parameters: NONE |
---|
226 | * |
---|
227 | * Return values: |
---|
228 | * rtems_device_driver status code |
---|
229 | */ |
---|
230 | |
---|
231 | rtems_device_driver Clock_control( |
---|
232 | rtems_device_major_number major, |
---|
233 | rtems_device_minor_number minor, |
---|
234 | void *pargp |
---|
235 | ) |
---|
236 | { |
---|
237 | rtems_unsigned32 isrlevel; |
---|
238 | rtems_libio_ioctl_args_t *args = pargp; |
---|
239 | rtems_isr_entry ignored_ticker; |
---|
240 | |
---|
241 | if (args == 0) |
---|
242 | goto done; |
---|
243 | |
---|
244 | /* |
---|
245 | * This is hokey, but until we get a defined interface |
---|
246 | * to do this, it will just be this simple... |
---|
247 | */ |
---|
248 | |
---|
249 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
250 | { |
---|
251 | |
---|
252 | Clock_isr(CLOCK_VECTOR); |
---|
253 | } |
---|
254 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
255 | { |
---|
256 | rtems_interrupt_disable( isrlevel ); |
---|
257 | Clock_driver_support_install_isr( args->buffer, ignored_ticker ); |
---|
258 | rtems_interrupt_enable( isrlevel ); |
---|
259 | } |
---|
260 | |
---|
261 | done: |
---|
262 | return RTEMS_SUCCESSFUL; |
---|
263 | } |
---|