1 | |
---|
2 | /* ckinit.c |
---|
3 | * |
---|
4 | * This file contains the clock driver initialization for the Hurricane BSP. |
---|
5 | * |
---|
6 | * Author: Craig Lebakken <craigl@transition.com> |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
9 | * |
---|
10 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
11 | * without any express or implied warranty: |
---|
12 | * permission to use, copy, modify, and distribute this file |
---|
13 | * for any purpose is hereby granted without fee, provided that |
---|
14 | * the above copyright notice and this notice appears in all |
---|
15 | * copies, and that the name of Transition Networks not be used in |
---|
16 | * advertising or publicity pertaining to distribution of the |
---|
17 | * software without specific, written prior permission. |
---|
18 | * Transition Networks makes no representations about the suitability |
---|
19 | * of this software for any purpose. |
---|
20 | * |
---|
21 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/clock/ckinit.c: |
---|
22 | * |
---|
23 | * COPYRIGHT (c) 1989-1999. |
---|
24 | * On-Line Applications Research Corporation (OAR). |
---|
25 | * |
---|
26 | * The license and distribution terms for this file may be |
---|
27 | * found in the file LICENSE in this distribution or at |
---|
28 | * http://www.rtems.com/license/LICENSE. |
---|
29 | * |
---|
30 | * $Id$ |
---|
31 | */ |
---|
32 | |
---|
33 | /* |
---|
34 | * Rather than deleting this, it is commented out to (hopefully) help |
---|
35 | * the submitter send updates. |
---|
36 | * |
---|
37 | * static char _sccsid[] = "@(#)ckinit.c 08/20/96 1.3\n"; |
---|
38 | */ |
---|
39 | |
---|
40 | |
---|
41 | #include <stdlib.h> |
---|
42 | |
---|
43 | #include <rtems.h> |
---|
44 | #include <rtems/libio.h> |
---|
45 | |
---|
46 | extern uint32_t bsp_clicks_per_microsecond; |
---|
47 | |
---|
48 | #define EXT_INT1 0x800 /* external interrupt 5 */ |
---|
49 | |
---|
50 | #include "clock.h" |
---|
51 | |
---|
52 | /* to avoid including the bsp */ |
---|
53 | mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int ); |
---|
54 | |
---|
55 | void USC_isr( void ); |
---|
56 | void reset_wdt(void); |
---|
57 | void enable_wdi(void); |
---|
58 | void init_hbt(void); |
---|
59 | void enable_hbi(void); |
---|
60 | void disable_hbi(void); |
---|
61 | |
---|
62 | void Clock_exit( void ); |
---|
63 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
64 | |
---|
65 | |
---|
66 | /* |
---|
67 | * The interrupt vector number associated with the clock tick device |
---|
68 | * driver. |
---|
69 | */ |
---|
70 | |
---|
71 | #define CLOCK_VECTOR_MASK EXT_INT1 |
---|
72 | #define CLOCK_VECTOR MIPS_INTERRUPT_BASE + 0x3 |
---|
73 | |
---|
74 | /* |
---|
75 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
76 | * number of clock ticks since the driver was initialized. |
---|
77 | */ |
---|
78 | |
---|
79 | volatile uint32_t Clock_driver_ticks; |
---|
80 | |
---|
81 | /* |
---|
82 | * Clock_isrs is the number of clock ISRs until the next invocation of |
---|
83 | * the RTEMS clock tick routine. The clock tick device driver |
---|
84 | * gets an interrupt once a millisecond and counts down until the |
---|
85 | * length of time between the user configured microseconds per tick |
---|
86 | * has passed. |
---|
87 | */ |
---|
88 | |
---|
89 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
90 | |
---|
91 | /* |
---|
92 | * These are set by clock driver during its init |
---|
93 | */ |
---|
94 | |
---|
95 | rtems_device_major_number rtems_clock_major = ~0; |
---|
96 | rtems_device_minor_number rtems_clock_minor; |
---|
97 | |
---|
98 | /* |
---|
99 | * The previous ISR on this clock tick interrupt vector. |
---|
100 | */ |
---|
101 | |
---|
102 | rtems_isr_entry Old_ticker; |
---|
103 | |
---|
104 | void Clock_exit( void ); |
---|
105 | |
---|
106 | static uint32_t mips_timer_rate = 0; |
---|
107 | |
---|
108 | /* |
---|
109 | * Isr Handler |
---|
110 | */ |
---|
111 | |
---|
112 | rtems_isr Clock_isr( |
---|
113 | rtems_vector_number vector |
---|
114 | ) |
---|
115 | { |
---|
116 | /* |
---|
117 | * bump the number of clock driver ticks since initialization |
---|
118 | * |
---|
119 | * determine if it is time to announce the passing of tick as configured |
---|
120 | * to RTEMS through the rtems_clock_tick directive |
---|
121 | * |
---|
122 | * perform any timer dependent tasks |
---|
123 | */ |
---|
124 | |
---|
125 | reset_wdt(); /* Reset hardware watchdog timer */ |
---|
126 | |
---|
127 | Clock_driver_ticks += 1; |
---|
128 | |
---|
129 | rtems_clock_tick(); |
---|
130 | } |
---|
131 | |
---|
132 | /* User callback shell (set from Clock_Control) */ |
---|
133 | static void (*user_callback)(void); |
---|
134 | |
---|
135 | rtems_isr User_Clock_isr( |
---|
136 | rtems_vector_number vector |
---|
137 | ) |
---|
138 | { |
---|
139 | if (user_callback) |
---|
140 | user_callback(); |
---|
141 | } |
---|
142 | |
---|
143 | /* |
---|
144 | * Install_clock |
---|
145 | * |
---|
146 | * Install a clock tick handleR and reprograms the chip. This |
---|
147 | * is used to initially establish the clock tick. |
---|
148 | */ |
---|
149 | |
---|
150 | void Install_clock( |
---|
151 | rtems_isr_entry clock_isr |
---|
152 | ) |
---|
153 | { |
---|
154 | /* |
---|
155 | * Initialize the clock tick device driver variables |
---|
156 | */ |
---|
157 | |
---|
158 | Clock_driver_ticks = 0; |
---|
159 | Clock_isrs = rtems_configuration_get_milliseconds_per_tick(); |
---|
160 | |
---|
161 | mips_timer_rate = rtems_configuration_get_microseconds_per_tick() * |
---|
162 | bsp_clicks_per_microsecond; |
---|
163 | |
---|
164 | /* |
---|
165 | * Hardware specific initialize goes here |
---|
166 | */ |
---|
167 | |
---|
168 | /* Set up USC heartbeat timer to generate interrupts */ |
---|
169 | disable_hbi(); /* Disable heartbeat interrupt in USC */ |
---|
170 | |
---|
171 | /* Install interrupt handler */ |
---|
172 | Old_ticker = (rtems_isr_entry) set_vector( USC_isr, CLOCK_VECTOR, 1 ); |
---|
173 | |
---|
174 | init_hbt(); /* Initialize heartbeat timer */ |
---|
175 | |
---|
176 | reset_wdt(); /* Reset watchdog timer */ |
---|
177 | |
---|
178 | enable_wdi(); /* Enable watchdog interrupt in USC */ |
---|
179 | |
---|
180 | enable_hbi(); /* Enable heartbeat interrupt in USC */ |
---|
181 | |
---|
182 | /* Enable USC interrupt in MIPS processor */ |
---|
183 | mips_enable_in_interrupt_mask(CLOCK_VECTOR_MASK); |
---|
184 | |
---|
185 | /* |
---|
186 | * Schedule the clock cleanup routine to execute if the application exits. |
---|
187 | */ |
---|
188 | |
---|
189 | atexit( Clock_exit ); |
---|
190 | } |
---|
191 | |
---|
192 | /* |
---|
193 | * Clean up before the application exits |
---|
194 | */ |
---|
195 | |
---|
196 | void Clock_exit( void ) |
---|
197 | { |
---|
198 | /* mips: turn off the timer interrupts */ |
---|
199 | mips_disable_in_interrupt_mask(~CLOCK_VECTOR_MASK); |
---|
200 | } |
---|
201 | |
---|
202 | /* |
---|
203 | * Clock_initialize |
---|
204 | * |
---|
205 | * Device driver entry point for clock tick driver initialization. |
---|
206 | */ |
---|
207 | |
---|
208 | rtems_device_driver Clock_initialize( |
---|
209 | rtems_device_major_number major, |
---|
210 | rtems_device_minor_number minor, |
---|
211 | void *pargp |
---|
212 | ) |
---|
213 | { |
---|
214 | Install_clock( Clock_isr ); |
---|
215 | |
---|
216 | /* |
---|
217 | * make major/minor avail to others such as shared memory driver |
---|
218 | */ |
---|
219 | |
---|
220 | rtems_clock_major = major; |
---|
221 | rtems_clock_minor = minor; |
---|
222 | |
---|
223 | return RTEMS_SUCCESSFUL; |
---|
224 | } |
---|
225 | |
---|