[ac7d5ef0] | 1 | /* Clock_init() |
---|
| 2 | * |
---|
| 3 | * This routine initializes the Tick Timer 2 on the MVME162 board. |
---|
| 4 | * The tick frequency is 1 millisecond. |
---|
| 5 | * |
---|
| 6 | * Input parameters: NONE |
---|
| 7 | * |
---|
| 8 | * Output parameters: NONE |
---|
| 9 | * |
---|
[08311cc3] | 10 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[f4fe0092] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 16 | * |
---|
| 17 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
| 18 | * EISCAT Scientific Association. M.Savitski |
---|
| 19 | * |
---|
| 20 | * This material is a part of the MVME162 Board Support Package |
---|
| 21 | * for the RTEMS executive. Its licensing policies are those of the |
---|
| 22 | * RTEMS above. |
---|
| 23 | * |
---|
| 24 | * $Id$ |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | |
---|
| 29 | #include <bsp.h> |
---|
[3a4ae6c] | 30 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 31 | |
---|
| 32 | #define MS_COUNT 1000 /* T2's countdown constant (1 ms) */ |
---|
[c6fb8e90] | 33 | #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ |
---|
[ac7d5ef0] | 34 | |
---|
[c6fb8e90] | 35 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
| 36 | volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ |
---|
[ac7d5ef0] | 37 | rtems_isr_entry Old_ticker; |
---|
| 38 | |
---|
[3a4ae6c] | 39 | void Clock_exit( void ); |
---|
| 40 | |
---|
| 41 | #define CLOCK_VECTOR (VBR0 * 0x10 + 0x9) |
---|
| 42 | /* |
---|
| 43 | * These are set by clock driver during its init |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 47 | rtems_device_minor_number rtems_clock_minor; |
---|
| 48 | |
---|
[ac7d5ef0] | 49 | |
---|
[3a4ae6c] | 50 | /* |
---|
| 51 | * ISR Handler |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | rtems_isr Clock_isr(rtems_vector_number vector) |
---|
[ac7d5ef0] | 55 | { |
---|
[3a4ae6c] | 56 | Clock_driver_ticks += 1; |
---|
| 57 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
| 58 | lcsr->intr_clear |= 0x02000000; |
---|
[ac7d5ef0] | 59 | |
---|
[3a4ae6c] | 60 | if ( Clock_isrs == 1 ) { |
---|
| 61 | rtems_clock_tick(); |
---|
| 62 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | Clock_isrs -= 1; |
---|
[ac7d5ef0] | 66 | } |
---|
| 67 | |
---|
[c6fb8e90] | 68 | void Install_clock(rtems_isr_entry clock_isr ) |
---|
[ac7d5ef0] | 69 | { |
---|
| 70 | |
---|
| 71 | Clock_driver_ticks = 0; |
---|
| 72 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 73 | |
---|
[0dd1d44] | 74 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 75 | lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ |
---|
| 76 | lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ |
---|
| 77 | lcsr->timer_cmp_2 = MS_COUNT; |
---|
| 78 | lcsr->timer_cnt_2 = 0; /* clear counter */ |
---|
| 79 | lcsr->board_ctl |= 0x700; /* increment, reset-on-compare, and */ |
---|
| 80 | /* clear-overflow-cnt */ |
---|
[ac7d5ef0] | 81 | |
---|
[0dd1d44] | 82 | lcsr->intr_level[0] |= CLOCK_INT_LEVEL * 0x10; /* set int level */ |
---|
| 83 | lcsr->intr_ena |= 0x02000000; /* enable tick timer 2 interrupt */ |
---|
[ac7d5ef0] | 84 | |
---|
[0dd1d44] | 85 | atexit( Clock_exit ); |
---|
[3a4ae6c] | 86 | } |
---|
[ac7d5ef0] | 87 | |
---|
| 88 | void Clock_exit( void ) |
---|
| 89 | { |
---|
| 90 | /* Dummy for now. See other m68k BSP's for code examples */ |
---|
| 91 | } |
---|
[3a4ae6c] | 92 | |
---|
| 93 | rtems_device_driver Clock_initialize( |
---|
| 94 | rtems_device_major_number major, |
---|
| 95 | rtems_device_minor_number minor, |
---|
| 96 | void *pargp |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | Install_clock( Clock_isr ); |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * make major/minor avail to others such as shared memory driver |
---|
| 103 | */ |
---|
| 104 | |
---|
| 105 | rtems_clock_major = major; |
---|
| 106 | rtems_clock_minor = minor; |
---|
| 107 | |
---|
| 108 | return RTEMS_SUCCESSFUL; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | rtems_device_driver Clock_control( |
---|
| 112 | rtems_device_major_number major, |
---|
| 113 | rtems_device_minor_number minor, |
---|
| 114 | void *pargp |
---|
| 115 | ) |
---|
| 116 | { |
---|
[9700578] | 117 | rtems_unsigned32 isrlevel; |
---|
[3a4ae6c] | 118 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 119 | |
---|
| 120 | if (args == 0) |
---|
| 121 | goto done; |
---|
| 122 | |
---|
| 123 | /* |
---|
| 124 | * This is hokey, but until we get a defined interface |
---|
| 125 | * to do this, it will just be this simple... |
---|
| 126 | */ |
---|
| 127 | |
---|
| 128 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 129 | { |
---|
| 130 | Clock_isr(CLOCK_VECTOR); |
---|
| 131 | } |
---|
| 132 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 133 | { |
---|
[9700578] | 134 | rtems_interrupt_disable( isrlevel ); |
---|
| 135 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
| 136 | rtems_interrupt_enable( isrlevel ); |
---|
[3a4ae6c] | 137 | } |
---|
| 138 | |
---|
| 139 | done: |
---|
| 140 | return RTEMS_SUCCESSFUL; |
---|
| 141 | } |
---|
| 142 | |
---|