[f198c63] | 1 | |
---|
| 2 | /* ckinit.c |
---|
| 3 | * |
---|
| 4 | * This file contains the clock driver initialization for the IDT 4650. |
---|
| 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 | * |
---|
[08311cc3] | 23 | * COPYRIGHT (c) 1989-1999. |
---|
[f198c63] | 24 | * On-Line Applications Research Corporation (OAR). |
---|
| 25 | * |
---|
[98e4ebf5] | 26 | * The license and distribution terms for this file may be |
---|
| 27 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 28 | * http://www.OARcorp.com/rtems/license.html. |
---|
[f198c63] | 29 | * |
---|
[0971cd5] | 30 | * $Id$ |
---|
[f198c63] | 31 | */ |
---|
| 32 | |
---|
[82478528] | 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 | |
---|
[f198c63] | 40 | |
---|
| 41 | #include <stdlib.h> |
---|
| 42 | |
---|
| 43 | #include <rtems.h> |
---|
| 44 | #include <rtems/libio.h> |
---|
| 45 | |
---|
[b944007b] | 46 | #define EXT_INT5 0x8000 /* external interrupt 5 */ |
---|
[f198c63] | 47 | |
---|
| 48 | #include "clock.h" |
---|
| 49 | |
---|
[f817b02] | 50 | /* formerly in the BSP */ |
---|
| 51 | #if 0 |
---|
[f198c63] | 52 | #define CLOCKS_PER_MICROSECOND ( CPU_CLOCK_RATE_MHZ ) /* equivalent to CPU clock speed in MHz */ |
---|
[f817b02] | 53 | #endif |
---|
| 54 | |
---|
| 55 | #define CLOCKS_PER_MICROSECOND \ |
---|
| 56 | rtems_cpu_configuration_get_clicks_per_microsecond() |
---|
| 57 | /* to avoid including the bsp */ |
---|
| 58 | mips_isr_entry set_vector( rtems_isr_entry, rtems_vector_number, int ); |
---|
[f198c63] | 59 | |
---|
| 60 | void Clock_exit( void ); |
---|
| 61 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | * The interrupt vector number associated with the clock tick device |
---|
| 66 | * driver. |
---|
| 67 | */ |
---|
| 68 | |
---|
| 69 | #define CLOCK_VECTOR_MASK EXT_INT5 |
---|
| 70 | #define CLOCK_VECTOR 0x7 |
---|
| 71 | |
---|
| 72 | /* |
---|
| 73 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
| 74 | * number of clock ticks since the driver was initialized. |
---|
| 75 | */ |
---|
| 76 | |
---|
| 77 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
| 78 | |
---|
| 79 | /* |
---|
| 80 | * Clock_isrs is the number of clock ISRs until the next invocation of |
---|
| 81 | * the RTEMS clock tick routine. The clock tick device driver |
---|
| 82 | * gets an interrupt once a millisecond and counts down until the |
---|
| 83 | * length of time between the user configured microseconds per tick |
---|
| 84 | * has passed. |
---|
| 85 | */ |
---|
| 86 | |
---|
| 87 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * These are set by clock driver during its init |
---|
| 91 | */ |
---|
| 92 | |
---|
| 93 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 94 | rtems_device_minor_number rtems_clock_minor; |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * The previous ISR on this clock tick interrupt vector. |
---|
| 98 | */ |
---|
| 99 | |
---|
| 100 | rtems_isr_entry Old_ticker; |
---|
| 101 | |
---|
| 102 | void Clock_exit( void ); |
---|
| 103 | |
---|
| 104 | static unsigned32 mips_timer_rate = 0; |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * Isr Handler |
---|
| 108 | */ |
---|
| 109 | |
---|
| 110 | rtems_isr Clock_isr( |
---|
| 111 | rtems_vector_number vector |
---|
| 112 | ) |
---|
| 113 | { |
---|
| 114 | /* |
---|
| 115 | * bump the number of clock driver ticks since initialization |
---|
| 116 | * |
---|
| 117 | * determine if it is time to announce the passing of tick as configured |
---|
| 118 | * to RTEMS through the rtems_clock_tick directive |
---|
| 119 | * |
---|
| 120 | * perform any timer dependent tasks |
---|
| 121 | */ |
---|
| 122 | |
---|
| 123 | /* refresh the internal CPU timer */ |
---|
| 124 | mips_set_timer( mips_timer_rate ); |
---|
| 125 | |
---|
| 126 | Clock_driver_ticks += 1; |
---|
| 127 | |
---|
| 128 | rtems_clock_tick(); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /* User callback shell (set from Clock_Control) */ |
---|
| 132 | static void (*user_callback)(void); |
---|
| 133 | |
---|
| 134 | rtems_isr User_Clock_isr( |
---|
| 135 | rtems_vector_number vector |
---|
| 136 | ) |
---|
| 137 | { |
---|
| 138 | /* refresh the internal CPU timer */ |
---|
| 139 | mips_set_timer( mips_timer_rate ); |
---|
| 140 | |
---|
| 141 | if (user_callback) |
---|
| 142 | user_callback(); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | * Install_clock |
---|
| 147 | * |
---|
| 148 | * Install a clock tick handleR and reprograms the chip. This |
---|
| 149 | * is used to initially establish the clock tick. |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | void Install_clock( |
---|
| 153 | rtems_isr_entry clock_isr |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | /* |
---|
| 157 | * Initialize the clock tick device driver variables |
---|
| 158 | */ |
---|
| 159 | |
---|
| 160 | Clock_driver_ticks = 0; |
---|
[f817b02] | 161 | Clock_isrs = rtems_configuration_get_milliseconds_per_tick(); |
---|
[f198c63] | 162 | |
---|
| 163 | /* |
---|
| 164 | * If ticks_per_timeslice is configured as non-zero, then the user |
---|
| 165 | * wants a clock tick. |
---|
| 166 | */ |
---|
| 167 | |
---|
[f817b02] | 168 | if ( rtems_configuration_get_ticks_per_timeslice() ) { |
---|
[f198c63] | 169 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 170 | /* |
---|
| 171 | * Hardware specific initialize goes here |
---|
| 172 | */ |
---|
| 173 | |
---|
[f817b02] | 174 | mips_timer_rate = rtems_configuration_get_microseconds_per_tick() * CLOCKS_PER_MICROSECOND; |
---|
[f198c63] | 175 | mips_set_timer( mips_timer_rate ); |
---|
| 176 | enable_int(CLOCK_VECTOR_MASK); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | /* |
---|
| 180 | * Schedule the clock cleanup routine to execute if the application exits. |
---|
| 181 | */ |
---|
| 182 | |
---|
| 183 | atexit( Clock_exit ); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /* |
---|
| 187 | * Clean up before the application exits |
---|
| 188 | */ |
---|
| 189 | |
---|
| 190 | void Clock_exit( void ) |
---|
| 191 | { |
---|
[f817b02] | 192 | if ( rtems_configuration_get_ticks_per_timeslice() ) { |
---|
[f198c63] | 193 | /* mips: turn off the timer interrupts */ |
---|
[86c9eb0] | 194 | disable_int(~CLOCK_VECTOR_MASK); |
---|
[f198c63] | 195 | } |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | * Clock_initialize |
---|
| 200 | * |
---|
| 201 | * Device driver entry point for clock tick driver initialization. |
---|
| 202 | */ |
---|
| 203 | |
---|
| 204 | rtems_device_driver Clock_initialize( |
---|
| 205 | rtems_device_major_number major, |
---|
| 206 | rtems_device_minor_number minor, |
---|
| 207 | void *pargp |
---|
| 208 | ) |
---|
| 209 | { |
---|
| 210 | Install_clock( Clock_isr ); |
---|
| 211 | |
---|
| 212 | /* |
---|
| 213 | * make major/minor avail to others such as shared memory driver |
---|
| 214 | */ |
---|
| 215 | |
---|
| 216 | rtems_clock_major = major; |
---|
| 217 | rtems_clock_minor = minor; |
---|
| 218 | |
---|
| 219 | return RTEMS_SUCCESSFUL; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | rtems_device_driver Clock_control( |
---|
| 223 | rtems_device_major_number major, |
---|
| 224 | rtems_device_minor_number minor, |
---|
| 225 | void *pargp |
---|
| 226 | ) |
---|
| 227 | { |
---|
| 228 | rtems_unsigned32 isrlevel; |
---|
| 229 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 230 | |
---|
| 231 | if (args == 0) |
---|
| 232 | goto done; |
---|
| 233 | |
---|
| 234 | /* |
---|
| 235 | * This is hokey, but until we get a defined interface |
---|
| 236 | * to do this, it will just be this simple... |
---|
| 237 | */ |
---|
| 238 | |
---|
| 239 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 240 | { |
---|
| 241 | Clock_isr(CLOCK_VECTOR); |
---|
| 242 | } |
---|
| 243 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 244 | { |
---|
| 245 | rtems_interrupt_disable( isrlevel ); |
---|
| 246 | user_callback = (void (*)(void))args->buffer; |
---|
| 247 | (void) set_vector( User_Clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 248 | rtems_interrupt_enable( isrlevel ); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | done: |
---|
| 252 | return RTEMS_SUCCESSFUL; |
---|
| 253 | } |
---|