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