[ac7d5ef0] | 1 | /* Clock_init() |
---|
| 2 | * |
---|
| 3 | * This routine initializes the Z80386 1 on the MVME136 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 |
---|
[9980062] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <stdlib.h> |
---|
[3a4ae6c] | 21 | |
---|
[ac7d5ef0] | 22 | #include <bsp.h> |
---|
[3a4ae6c] | 23 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 24 | |
---|
[0f458a3] | 25 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
| 26 | volatile uint32_t Clock_driver_ticks; |
---|
[ac7d5ef0] | 27 | /* ticks since initialization */ |
---|
| 28 | rtems_isr_entry Old_ticker; |
---|
| 29 | |
---|
[3a4ae6c] | 30 | void Clock_exit( void ); |
---|
[ac7d5ef0] | 31 | |
---|
[3a4ae6c] | 32 | #define CLOCK_VECTOR TIMER_VECTOR |
---|
| 33 | |
---|
| 34 | /* |
---|
| 35 | * These are set by clock driver during its init |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 39 | rtems_device_minor_number rtems_clock_minor; |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | * ISR Handler |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | rtems_isr Clock_isr( |
---|
| 46 | rtems_vector_number vector |
---|
[ac7d5ef0] | 47 | ) |
---|
| 48 | { |
---|
[3a4ae6c] | 49 | Clock_driver_ticks += 1; |
---|
[ac7d5ef0] | 50 | |
---|
[3a4ae6c] | 51 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xE2 ); |
---|
| 52 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x22 ); |
---|
| 53 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 ); |
---|
| 54 | |
---|
| 55 | if ( Clock_isrs == 1 ) { |
---|
| 56 | rtems_clock_tick(); |
---|
| 57 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | Clock_isrs -= 1; |
---|
[ac7d5ef0] | 61 | } |
---|
| 62 | |
---|
| 63 | void Install_clock( |
---|
| 64 | rtems_isr_entry clock_isr |
---|
| 65 | ) |
---|
| 66 | { |
---|
[0f458a3] | 67 | uint8_t data; |
---|
[ac7d5ef0] | 68 | |
---|
| 69 | Clock_driver_ticks = 0; |
---|
| 70 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 71 | |
---|
[0dd1d44] | 72 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 73 | |
---|
| 74 | Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 ); |
---|
| 75 | Z8x36_READ ( TIMER, MASTER_INTR, data ); |
---|
| 76 | Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x7E) ); |
---|
| 77 | Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x04 ); |
---|
| 78 | Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0xCE ); |
---|
| 79 | Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x83 ); |
---|
| 80 | Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, CLOCK_VECTOR ); |
---|
| 81 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 ); |
---|
| 82 | Z8x36_READ ( TIMER, MASTER_INTR, data ); |
---|
| 83 | Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 ); |
---|
| 84 | |
---|
| 85 | /* |
---|
| 86 | * ACC_IC54 - interrupt 5 will be vectored and mapped to level 6 |
---|
| 87 | */ |
---|
| 88 | |
---|
[0f458a3] | 89 | data = (*(uint8_t*)0x0D00000B); |
---|
| 90 | (*(uint8_t*)0x0D00000B) = (data & 0x7F) | 0x60; |
---|
[0dd1d44] | 91 | |
---|
| 92 | Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 ); |
---|
| 93 | |
---|
| 94 | atexit( Clock_exit ); |
---|
[ac7d5ef0] | 95 | } |
---|
| 96 | |
---|
| 97 | void Clock_exit( void ) |
---|
| 98 | { |
---|
[0f458a3] | 99 | uint8_t data; |
---|
[ac7d5ef0] | 100 | |
---|
[0dd1d44] | 101 | Z8x36_READ ( TIMER, MASTER_INTR, data ); |
---|
| 102 | Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) ); |
---|
| 103 | /* do not restore old vector */ |
---|
[ac7d5ef0] | 104 | } |
---|
[3a4ae6c] | 105 | |
---|
| 106 | rtems_device_driver Clock_initialize( |
---|
| 107 | rtems_device_major_number major, |
---|
| 108 | rtems_device_minor_number minor, |
---|
| 109 | void *pargp |
---|
| 110 | ) |
---|
| 111 | { |
---|
| 112 | Install_clock( Clock_isr ); |
---|
| 113 | |
---|
| 114 | /* |
---|
| 115 | * make major/minor avail to others such as shared memory driver |
---|
| 116 | */ |
---|
| 117 | |
---|
| 118 | rtems_clock_major = major; |
---|
| 119 | rtems_clock_minor = minor; |
---|
| 120 | |
---|
| 121 | return RTEMS_SUCCESSFUL; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | rtems_device_driver Clock_control( |
---|
| 125 | rtems_device_major_number major, |
---|
| 126 | rtems_device_minor_number minor, |
---|
| 127 | void *pargp |
---|
| 128 | ) |
---|
| 129 | { |
---|
[0f458a3] | 130 | uint32_t isrlevel; |
---|
[3a4ae6c] | 131 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 132 | |
---|
| 133 | if (args == 0) |
---|
| 134 | goto done; |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | * This is hokey, but until we get a defined interface |
---|
| 138 | * to do this, it will just be this simple... |
---|
| 139 | */ |
---|
| 140 | |
---|
| 141 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 142 | { |
---|
| 143 | Clock_isr(CLOCK_VECTOR); |
---|
| 144 | } |
---|
| 145 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 146 | { |
---|
[9700578] | 147 | rtems_interrupt_disable( isrlevel ); |
---|
| 148 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
| 149 | rtems_interrupt_enable( isrlevel ); |
---|
[3a4ae6c] | 150 | } |
---|
| 151 | |
---|
| 152 | done: |
---|
| 153 | return RTEMS_SUCCESSFUL; |
---|
| 154 | } |
---|
| 155 | |
---|