[ac7d5ef0] | 1 | /* Clock_init() |
---|
| 2 | * |
---|
| 3 | * This routine initializes the timer on the VIC chip on the CVME961. |
---|
| 4 | * The tick frequency is 1 millisecond. |
---|
| 5 | * |
---|
| 6 | * Input parameters: NONE |
---|
| 7 | * |
---|
| 8 | * Output parameters: NONE |
---|
| 9 | * |
---|
| 10 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * All rights assigned to U.S. Government, 1994. |
---|
| 13 | * |
---|
| 14 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 15 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 16 | * notice must appear in all copies of this file and its derivatives. |
---|
| 17 | * |
---|
| 18 | * $Id$ |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include <stdlib.h> |
---|
| 22 | |
---|
| 23 | #include <bsp.h> |
---|
[3a4ae6c] | 24 | #include <rtems/libio.h> |
---|
| 25 | |
---|
| 26 | #define CLOCK_VECTOR 5 |
---|
[ac7d5ef0] | 27 | |
---|
| 28 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
[7979e35] | 29 | i960_isr_entry Old_ticker; |
---|
[ac7d5ef0] | 30 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
| 31 | /* ticks since initialization */ |
---|
| 32 | |
---|
[3a4ae6c] | 33 | void Clock_exit( void ); |
---|
| 34 | |
---|
| 35 | /* |
---|
| 36 | * These are set by clock driver during its init |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 40 | rtems_device_minor_number rtems_clock_minor; |
---|
[ac7d5ef0] | 41 | |
---|
[3a4ae6c] | 42 | |
---|
| 43 | /* this is later in the file to avoid it being inlined */ |
---|
| 44 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
[ac7d5ef0] | 45 | |
---|
| 46 | void Install_clock( |
---|
| 47 | rtems_isr_entry clock_isr |
---|
| 48 | ) |
---|
| 49 | { |
---|
| 50 | volatile unsigned char *victimer; |
---|
| 51 | |
---|
| 52 | Clock_driver_ticks = 0; |
---|
| 53 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 54 | |
---|
| 55 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
[3a4ae6c] | 56 | Old_ticker = set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
[ac7d5ef0] | 57 | victimer = (volatile unsigned char *) 0xa00000c3; |
---|
| 58 | *victimer = 0x12; |
---|
| 59 | *victimer = 0x92; /* 1000 HZ */ |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
[3a4ae6c] | 63 | void ReInstall_clock( |
---|
| 64 | rtems_isr_entry clock_isr |
---|
| 65 | ) |
---|
| 66 | { |
---|
| 67 | (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 68 | } |
---|
| 69 | |
---|
[ac7d5ef0] | 70 | void Clock_exit() |
---|
| 71 | { |
---|
| 72 | unsigned char *victimer; |
---|
| 73 | |
---|
| 74 | if ( BSP_Configuration.ticks_per_timeslice ) { |
---|
| 75 | victimer = (unsigned char *) 0xa00000c3; |
---|
| 76 | *victimer = 0x12; |
---|
| 77 | i960_mask_intr( 5 ); |
---|
| 78 | /* do not restore old vector */ |
---|
| 79 | } |
---|
| 80 | } |
---|
[3a4ae6c] | 81 | |
---|
| 82 | rtems_device_driver Clock_initialize( |
---|
| 83 | rtems_device_major_number major, |
---|
| 84 | rtems_device_minor_number minor, |
---|
| 85 | void *pargp |
---|
| 86 | ) |
---|
| 87 | { |
---|
| 88 | Install_clock( Clock_isr ); |
---|
| 89 | |
---|
| 90 | atexit( Clock_exit ); |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | * make major/minor avail to others such as shared memory driver |
---|
| 94 | */ |
---|
| 95 | |
---|
| 96 | rtems_clock_major = major; |
---|
| 97 | rtems_clock_minor = minor; |
---|
| 98 | |
---|
| 99 | return RTEMS_SUCCESSFUL; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | rtems_device_driver Clock_control( |
---|
| 103 | rtems_device_major_number major, |
---|
| 104 | rtems_device_minor_number minor, |
---|
| 105 | void *pargp |
---|
| 106 | ) |
---|
| 107 | { |
---|
| 108 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 109 | |
---|
| 110 | if (args == 0) |
---|
| 111 | goto done; |
---|
| 112 | |
---|
| 113 | /* |
---|
| 114 | * This is hokey, but until we get a defined interface |
---|
| 115 | * to do this, it will just be this simple... |
---|
| 116 | */ |
---|
| 117 | |
---|
| 118 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 119 | { |
---|
| 120 | Clock_isr(CLOCK_VECTOR); |
---|
| 121 | } |
---|
| 122 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 123 | { |
---|
| 124 | ReInstall_clock(args->buffer); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | done: |
---|
| 128 | return RTEMS_SUCCESSFUL; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | rtems_isr Clock_isr( |
---|
| 132 | rtems_vector_number vector |
---|
| 133 | ) |
---|
| 134 | { |
---|
| 135 | /* enable_tracing(); */ |
---|
| 136 | Clock_driver_ticks += 1; |
---|
| 137 | if ( Clock_isrs == 1 ) { |
---|
| 138 | rtems_clock_tick(); |
---|
| 139 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 140 | } |
---|
| 141 | else |
---|
| 142 | Clock_isrs -= 1; |
---|
| 143 | i960_clear_intr( 5 ); |
---|
| 144 | } |
---|
| 145 | |
---|