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