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 | /* |
---|
20 | * Clock ticks since initialization |
---|
21 | */ |
---|
22 | |
---|
23 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
24 | |
---|
25 | rtems_isr_entry Old_ticker; |
---|
26 | |
---|
27 | void Clock_exit( void ); |
---|
28 | |
---|
29 | /* |
---|
30 | * These are set by clock driver during its init |
---|
31 | */ |
---|
32 | |
---|
33 | rtems_device_major_number rtems_clock_major = ~0; |
---|
34 | rtems_device_minor_number rtems_clock_minor; |
---|
35 | |
---|
36 | /* |
---|
37 | * Clock_isr |
---|
38 | * |
---|
39 | * This is the clock tick interrupt handler. |
---|
40 | * |
---|
41 | * Input parameters: |
---|
42 | * vector - vector number |
---|
43 | * |
---|
44 | * Output parameters: NONE |
---|
45 | * |
---|
46 | * Return values: NONE |
---|
47 | * |
---|
48 | */ |
---|
49 | |
---|
50 | rtems_isr Clock_isr( |
---|
51 | rtems_vector_number vector |
---|
52 | ) |
---|
53 | { |
---|
54 | /* |
---|
55 | * Do the hardware specific per-tick action. |
---|
56 | */ |
---|
57 | |
---|
58 | Clock_driver_support_at_tick(); |
---|
59 | |
---|
60 | /* |
---|
61 | * The driver has seen another tick. |
---|
62 | */ |
---|
63 | |
---|
64 | Clock_driver_ticks += 1; |
---|
65 | |
---|
66 | /* |
---|
67 | * Real Time Clock counter/timer is set to automatically reload. |
---|
68 | */ |
---|
69 | |
---|
70 | #ifndef CLOCK_DRIVER_ISRS_ARE_ONE_MILLISECOND |
---|
71 | rtems_clock_tick(); |
---|
72 | #else |
---|
73 | #error "Clock driver shell: Does not currently support counting mseconds." |
---|
74 | #endif |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * Install_clock |
---|
79 | * |
---|
80 | * This routine actually performs the hardware initialization for the clock. |
---|
81 | * |
---|
82 | * Input parameters: |
---|
83 | * clock_isr - clock interrupt service routine entry point |
---|
84 | * |
---|
85 | * Output parameters: NONE |
---|
86 | * |
---|
87 | * Return values: NONE |
---|
88 | * |
---|
89 | */ |
---|
90 | |
---|
91 | extern int CLOCK_SPEED; |
---|
92 | |
---|
93 | void Install_clock( |
---|
94 | rtems_isr_entry clock_isr |
---|
95 | ) |
---|
96 | { |
---|
97 | Clock_driver_ticks = 0; |
---|
98 | |
---|
99 | /* |
---|
100 | * Install vector |
---|
101 | */ |
---|
102 | |
---|
103 | Clock_driver_support_install_isr( clock_isr, Old_ticker ); |
---|
104 | |
---|
105 | /* |
---|
106 | * Now initialize the hardware that is the source of the tick ISR. |
---|
107 | */ |
---|
108 | |
---|
109 | Clock_driver_support_initialize_hardware(); |
---|
110 | |
---|
111 | atexit( Clock_exit ); |
---|
112 | } |
---|
113 | |
---|
114 | /* |
---|
115 | * Clock_exit |
---|
116 | * |
---|
117 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
118 | * disabling the clock's counter. |
---|
119 | * |
---|
120 | * Input parameters: NONE |
---|
121 | * |
---|
122 | * Output parameters: NONE |
---|
123 | * |
---|
124 | * Return values: NONE |
---|
125 | * |
---|
126 | */ |
---|
127 | |
---|
128 | void Clock_exit( void ) |
---|
129 | { |
---|
130 | Clock_driver_support_shutdown_hardware(); |
---|
131 | |
---|
132 | /* do not restore old vector */ |
---|
133 | } |
---|
134 | |
---|
135 | /* |
---|
136 | * Clock_initialize |
---|
137 | * |
---|
138 | * This routine initializes the clock driver. |
---|
139 | * |
---|
140 | * Input parameters: |
---|
141 | * major - clock device major number |
---|
142 | * minor - clock device minor number |
---|
143 | * parg - pointer to optional device driver arguments |
---|
144 | * |
---|
145 | * Output parameters: NONE |
---|
146 | * |
---|
147 | * Return values: |
---|
148 | * rtems_device_driver status code |
---|
149 | */ |
---|
150 | |
---|
151 | rtems_device_driver Clock_initialize( |
---|
152 | rtems_device_major_number major, |
---|
153 | rtems_device_minor_number minor, |
---|
154 | void *pargp |
---|
155 | ) |
---|
156 | { |
---|
157 | Install_clock( Clock_isr ); |
---|
158 | |
---|
159 | /* |
---|
160 | * make major/minor avail to others such as shared memory driver |
---|
161 | */ |
---|
162 | |
---|
163 | rtems_clock_major = major; |
---|
164 | rtems_clock_minor = minor; |
---|
165 | |
---|
166 | return RTEMS_SUCCESSFUL; |
---|
167 | } |
---|
168 | |
---|
169 | /* |
---|
170 | * Clock_control |
---|
171 | * |
---|
172 | * This routine is the clock device driver control entry point. |
---|
173 | * |
---|
174 | * Input parameters: |
---|
175 | * major - clock device major number |
---|
176 | * minor - clock device minor number |
---|
177 | * parg - pointer to optional device driver arguments |
---|
178 | * |
---|
179 | * Output parameters: NONE |
---|
180 | * |
---|
181 | * Return values: |
---|
182 | * rtems_device_driver status code |
---|
183 | */ |
---|
184 | |
---|
185 | rtems_device_driver Clock_control( |
---|
186 | rtems_device_major_number major, |
---|
187 | rtems_device_minor_number minor, |
---|
188 | void *pargp |
---|
189 | ) |
---|
190 | { |
---|
191 | rtems_unsigned32 isrlevel; |
---|
192 | rtems_libio_ioctl_args_t *args = pargp; |
---|
193 | rtems_isr_entry ignored_ticker; |
---|
194 | |
---|
195 | if (args == 0) |
---|
196 | goto done; |
---|
197 | |
---|
198 | /* |
---|
199 | * This is hokey, but until we get a defined interface |
---|
200 | * to do this, it will just be this simple... |
---|
201 | */ |
---|
202 | |
---|
203 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
204 | { |
---|
205 | |
---|
206 | Clock_isr(CLOCK_VECTOR); |
---|
207 | } |
---|
208 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
209 | { |
---|
210 | rtems_interrupt_disable( isrlevel ); |
---|
211 | Clock_driver_support_install_isr( args->buffer, ignored_ticker ); |
---|
212 | rtems_interrupt_enable( isrlevel ); |
---|
213 | } |
---|
214 | |
---|
215 | done: |
---|
216 | return RTEMS_SUCCESSFUL; |
---|
217 | } |
---|