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 | * Copyright assigned to U.S. Government, 1994. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may in |
---|
14 | * the file LICENSE in this distribution or at |
---|
15 | * http://www.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * Modified to support the MPC750. |
---|
18 | * Modifications Copyright (c) 1999 Eric Valette valette@crf.canon.fr |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <bsp/irq.h> |
---|
25 | #include <rtems/libio.h> |
---|
26 | #include <stdlib.h> /* for atexit() */ |
---|
27 | #include <assert.h> |
---|
28 | #include <libcpu/cpu.h> |
---|
29 | |
---|
30 | /* |
---|
31 | * Clock ticks since initialization |
---|
32 | */ |
---|
33 | |
---|
34 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
35 | |
---|
36 | /* |
---|
37 | * This is the value programmed into the count down timer. |
---|
38 | */ |
---|
39 | |
---|
40 | rtems_unsigned32 Clock_Decrementer_value; |
---|
41 | |
---|
42 | /* |
---|
43 | * These are set by clock driver during its init |
---|
44 | */ |
---|
45 | |
---|
46 | rtems_device_major_number rtems_clock_major = ~0; |
---|
47 | rtems_device_minor_number rtems_clock_minor; |
---|
48 | |
---|
49 | void clockOff(const rtems_irq_connect_data* unused) |
---|
50 | { |
---|
51 | if (BSP_Configuration.ticks_per_timeslice) { |
---|
52 | /* |
---|
53 | * Nothing to do as we cannot disable all interrupts and |
---|
54 | * the decrementer interrupt enable is MSR_EE |
---|
55 | */ |
---|
56 | } |
---|
57 | } |
---|
58 | static void clockOn(const rtems_irq_connect_data* unused) |
---|
59 | { |
---|
60 | PPC_Set_decrementer( Clock_Decrementer_value ); |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Clock_isr |
---|
65 | * |
---|
66 | * This is the clock tick interrupt handler. |
---|
67 | * |
---|
68 | * Input parameters: |
---|
69 | * vector - vector number |
---|
70 | * |
---|
71 | * Output parameters: NONE |
---|
72 | * |
---|
73 | * Return values: NONE |
---|
74 | * |
---|
75 | */ |
---|
76 | void clockIsr() |
---|
77 | { |
---|
78 | /* |
---|
79 | * The driver has seen another tick. |
---|
80 | */ |
---|
81 | |
---|
82 | PPC_Set_decrementer( Clock_Decrementer_value ); |
---|
83 | |
---|
84 | Clock_driver_ticks += 1; |
---|
85 | |
---|
86 | /* |
---|
87 | * Real Time Clock counter/timer is set to automatically reload. |
---|
88 | */ |
---|
89 | |
---|
90 | rtems_clock_tick(); |
---|
91 | } |
---|
92 | |
---|
93 | int clockIsOn(const rtems_irq_connect_data* unused) |
---|
94 | { |
---|
95 | unsigned32 msr_value; |
---|
96 | |
---|
97 | _CPU_MSR_GET( msr_value ); |
---|
98 | if (msr_value & MSR_EE) return 1; |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | static rtems_irq_connect_data clockIrqData = {BSP_DECREMENTER, |
---|
103 | clockIsr, |
---|
104 | clockOn, |
---|
105 | clockOff, |
---|
106 | clockIsOn}; |
---|
107 | |
---|
108 | |
---|
109 | /* |
---|
110 | * Clock_exit |
---|
111 | * |
---|
112 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
113 | * disabling the clock's counter. |
---|
114 | * |
---|
115 | * Input parameters: NONE |
---|
116 | * |
---|
117 | * Output parameters: NONE |
---|
118 | * |
---|
119 | * Return values: NONE |
---|
120 | * |
---|
121 | */ |
---|
122 | |
---|
123 | void Clock_exit( void ) |
---|
124 | { |
---|
125 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
126 | BSP_remove_rtems_irq_handler (&clockIrqData); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | /* |
---|
131 | * Clock_initialize |
---|
132 | * |
---|
133 | * This routine initializes the clock driver. |
---|
134 | * |
---|
135 | * Input parameters: |
---|
136 | * major - clock device major number |
---|
137 | * minor - clock device minor number |
---|
138 | * parg - pointer to optional device driver arguments |
---|
139 | * |
---|
140 | * Output parameters: NONE |
---|
141 | * |
---|
142 | * Return values: |
---|
143 | * rtems_device_driver status code |
---|
144 | */ |
---|
145 | |
---|
146 | rtems_device_driver Clock_initialize( |
---|
147 | rtems_device_major_number major, |
---|
148 | rtems_device_minor_number minor, |
---|
149 | void *pargp |
---|
150 | ) |
---|
151 | { |
---|
152 | Clock_Decrementer_value = (BSP_bus_frequency/4000)* |
---|
153 | (BSP_Configuration.microseconds_per_tick/1000); |
---|
154 | |
---|
155 | if (!BSP_install_rtems_irq_handler (&clockIrqData)) { |
---|
156 | printk("Unable to initialize system clock\n"); |
---|
157 | rtems_fatal_error_occurred(1); |
---|
158 | } |
---|
159 | /* make major/minor avail to others such as shared memory driver */ |
---|
160 | |
---|
161 | rtems_clock_major = major; |
---|
162 | rtems_clock_minor = minor; |
---|
163 | |
---|
164 | return RTEMS_SUCCESSFUL; |
---|
165 | } /* Clock_initialize */ |
---|
166 | |
---|
167 | /* |
---|
168 | * Clock_control |
---|
169 | * |
---|
170 | * This routine is the clock device driver control entry point. |
---|
171 | * |
---|
172 | * Input parameters: |
---|
173 | * major - clock device major number |
---|
174 | * minor - clock device minor number |
---|
175 | * parg - pointer to optional device driver arguments |
---|
176 | * |
---|
177 | * Output parameters: NONE |
---|
178 | * |
---|
179 | * Return values: |
---|
180 | * rtems_device_driver status code |
---|
181 | */ |
---|
182 | |
---|
183 | rtems_device_driver Clock_control( |
---|
184 | rtems_device_major_number major, |
---|
185 | rtems_device_minor_number minor, |
---|
186 | void *pargp |
---|
187 | ) |
---|
188 | { |
---|
189 | rtems_unsigned32 isrlevel; |
---|
190 | rtems_libio_ioctl_args_t *args = pargp; |
---|
191 | |
---|
192 | if (args == 0) |
---|
193 | goto done; |
---|
194 | |
---|
195 | Clock_Decrementer_value = (BSP_bus_frequency/4000)* |
---|
196 | (BSP_Configuration.microseconds_per_tick/1000); |
---|
197 | |
---|
198 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
199 | clockIsr(); |
---|
200 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
201 | { |
---|
202 | if (!BSP_install_rtems_irq_handler (&clockIrqData)) { |
---|
203 | printk("Error installing clock interrupt handler!\n"); |
---|
204 | rtems_fatal_error_occurred(1); |
---|
205 | } |
---|
206 | } |
---|
207 | done: |
---|
208 | return RTEMS_SUCCESSFUL; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | |
---|
215 | |
---|