1 | /* ckinit.c |
---|
2 | * |
---|
3 | * This file provides a template for the clock device driver initialization. |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <stdlib.h> |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | #include <bsp.h> |
---|
20 | |
---|
21 | void Clock_exit( void ); |
---|
22 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
23 | |
---|
24 | |
---|
25 | /* |
---|
26 | * The interrupt vector number associated with the clock tick device |
---|
27 | * driver. |
---|
28 | */ |
---|
29 | |
---|
30 | #define CLOCK_VECTOR 4 |
---|
31 | |
---|
32 | /* |
---|
33 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
34 | * number of clock ticks since the driver was initialized. |
---|
35 | */ |
---|
36 | |
---|
37 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
38 | |
---|
39 | /* |
---|
40 | * Clock_isrs is the number of clock ISRs until the next invocation of |
---|
41 | * the RTEMS clock tick routine. The clock tick device driver |
---|
42 | * gets an interrupt once a millisecond and counts down until the |
---|
43 | * length of time between the user configured microseconds per tick |
---|
44 | * has passed. |
---|
45 | */ |
---|
46 | |
---|
47 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
48 | |
---|
49 | /* |
---|
50 | * These are set by clock driver during its init |
---|
51 | */ |
---|
52 | |
---|
53 | rtems_device_major_number rtems_clock_major = ~0; |
---|
54 | rtems_device_minor_number rtems_clock_minor; |
---|
55 | |
---|
56 | /* |
---|
57 | * The previous ISR on this clock tick interrupt vector. |
---|
58 | */ |
---|
59 | |
---|
60 | rtems_isr_entry Old_ticker; |
---|
61 | |
---|
62 | void Clock_exit( void ); |
---|
63 | |
---|
64 | |
---|
65 | /* |
---|
66 | * Isr Handler |
---|
67 | */ |
---|
68 | |
---|
69 | rtems_isr Clock_isr( |
---|
70 | rtems_vector_number vector |
---|
71 | ) |
---|
72 | { |
---|
73 | /* |
---|
74 | * bump the number of clock driver ticks since initialization |
---|
75 | * |
---|
76 | * determine if it is time to announce the passing of tick as configured |
---|
77 | * to RTEMS through the rtems_clock_tick directive |
---|
78 | * |
---|
79 | * perform any timer dependent tasks |
---|
80 | */ |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * Install_clock |
---|
85 | * |
---|
86 | * Install a clock tick handler and reprograms the chip. This |
---|
87 | * is used to initially establish the clock tick. |
---|
88 | */ |
---|
89 | |
---|
90 | void Install_clock( |
---|
91 | rtems_isr_entry clock_isr |
---|
92 | ) |
---|
93 | { |
---|
94 | /* |
---|
95 | * Initialize the clock tick device driver variables |
---|
96 | */ |
---|
97 | |
---|
98 | Clock_driver_ticks = 0; |
---|
99 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
100 | |
---|
101 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
102 | /* |
---|
103 | * Hardware specific initialize goes here |
---|
104 | */ |
---|
105 | |
---|
106 | /* XXX */ |
---|
107 | |
---|
108 | /* |
---|
109 | * Schedule the clock cleanup routine to execute if the application exits. |
---|
110 | */ |
---|
111 | |
---|
112 | atexit( Clock_exit ); |
---|
113 | } |
---|
114 | |
---|
115 | /* |
---|
116 | * Clean up before the application exits |
---|
117 | */ |
---|
118 | |
---|
119 | void Clock_exit( void ) |
---|
120 | { |
---|
121 | /* XXX: turn off the timer interrupts */ |
---|
122 | |
---|
123 | /* XXX: If necessary, restore the old vector */ |
---|
124 | } |
---|
125 | |
---|
126 | /* |
---|
127 | * Clock_initialize |
---|
128 | * |
---|
129 | * Device driver entry point for clock tick driver initialization. |
---|
130 | */ |
---|
131 | |
---|
132 | rtems_device_driver Clock_initialize( |
---|
133 | rtems_device_major_number major, |
---|
134 | rtems_device_minor_number minor, |
---|
135 | void *pargp |
---|
136 | ) |
---|
137 | { |
---|
138 | Install_clock( Clock_isr ); |
---|
139 | |
---|
140 | /* |
---|
141 | * make major/minor avail to others such as shared memory driver |
---|
142 | */ |
---|
143 | |
---|
144 | rtems_clock_major = major; |
---|
145 | rtems_clock_minor = minor; |
---|
146 | |
---|
147 | return RTEMS_SUCCESSFUL; |
---|
148 | } |
---|
149 | |
---|
150 | rtems_device_driver Clock_control( |
---|
151 | rtems_device_major_number major, |
---|
152 | rtems_device_minor_number minor, |
---|
153 | void *pargp |
---|
154 | ) |
---|
155 | { |
---|
156 | rtems_unsigned32 isrlevel; |
---|
157 | rtems_libio_ioctl_args_t *args = pargp; |
---|
158 | |
---|
159 | if (args == 0) |
---|
160 | goto done; |
---|
161 | |
---|
162 | /* |
---|
163 | * This is hokey, but until we get a defined interface |
---|
164 | * to do this, it will just be this simple... |
---|
165 | */ |
---|
166 | |
---|
167 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
168 | { |
---|
169 | Clock_isr(CLOCK_VECTOR); |
---|
170 | } |
---|
171 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
172 | { |
---|
173 | rtems_interrupt_disable( isrlevel ); |
---|
174 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
175 | rtems_interrupt_enable( isrlevel ); |
---|
176 | } |
---|
177 | |
---|
178 | done: |
---|
179 | return RTEMS_SUCCESSFUL; |
---|
180 | } |
---|