[752cd8f] | 1 | /* Clock_initialize |
---|
| 2 | * |
---|
| 3 | * This routine initializes the Timer/Counter on the Intel |
---|
| 4 | * 386ex evaluation board. |
---|
| 5 | * |
---|
| 6 | * The tick frequency is 1 millisecond. |
---|
| 7 | * |
---|
| 8 | * Input parameters: NONE |
---|
| 9 | * |
---|
| 10 | * Output parameters: NONE |
---|
| 11 | * |
---|
[08311cc3] | 12 | * COPYRIGHT (c) 1989-1999. |
---|
[752cd8f] | 13 | * On-Line Applications Research Corporation (OAR). |
---|
| 14 | * |
---|
[98e4ebf5] | 15 | * The license and distribution terms for this file may be |
---|
| 16 | * found in the file LICENSE in this distribution or at |
---|
[6ff7e2c] | 17 | * http://www.rtems.com/license/LICENSE. |
---|
[752cd8f] | 18 | * |
---|
| 19 | * $Id$ |
---|
| 20 | */ |
---|
[04bc5d9] | 21 | #define TMR0 0xF040 |
---|
| 22 | #define TMR1 0xF041 |
---|
| 23 | #define TMR2 0xF042 |
---|
| 24 | #define TMRCON 0xF043 |
---|
| 25 | #define TMRCFG 0xF834 |
---|
[752cd8f] | 26 | |
---|
| 27 | #include <bsp.h> |
---|
[bd8c8b2a] | 28 | #include <irq.h> |
---|
[39cafa5] | 29 | |
---|
| 30 | #include <rtems/libio.h> |
---|
| 31 | |
---|
[752cd8f] | 32 | #include <stdlib.h> |
---|
| 33 | |
---|
| 34 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
[479c86dd] | 35 | static rtems_unsigned32 Clock_initial_isr_value; |
---|
[39cafa5] | 36 | |
---|
| 37 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
| 38 | |
---|
| 39 | void Clock_exit( void ); |
---|
[752cd8f] | 40 | |
---|
[39cafa5] | 41 | /* |
---|
| 42 | * These are set by clock driver during its init |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 46 | rtems_device_major_number rtems_clock_minor = 0; |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * This is the ISR handler. |
---|
| 50 | */ |
---|
| 51 | |
---|
[bd8c8b2a] | 52 | void Clock_isr() |
---|
[752cd8f] | 53 | { |
---|
[39cafa5] | 54 | /* enable_tracing(); */ |
---|
| 55 | Clock_driver_ticks += 1; |
---|
| 56 | if ( Clock_isrs == 1 ) { |
---|
| 57 | rtems_clock_tick(); |
---|
[479c86dd] | 58 | Clock_isrs = Clock_initial_isr_value; /* BSP_Configuration.microseconds_per_tick / 1000;*/ |
---|
[39cafa5] | 59 | } |
---|
| 60 | else |
---|
| 61 | Clock_isrs -= 1; |
---|
[752cd8f] | 62 | } |
---|
| 63 | |
---|
[bd8c8b2a] | 64 | void ClockOff(const rtems_irq_connect_data* unused) |
---|
[752cd8f] | 65 | { |
---|
[479c86dd] | 66 | outport_byte ( TMRCFG , 0x80 ); /* disable the counter timer */ |
---|
[bd8c8b2a] | 67 | } |
---|
[752cd8f] | 68 | |
---|
[bd8c8b2a] | 69 | void ClockOn(const rtems_irq_connect_data* unused) |
---|
| 70 | { |
---|
[479c86dd] | 71 | outport_byte ( TMRCFG , 0x00 ); /* enable the counter timer */ |
---|
[752cd8f] | 72 | } |
---|
| 73 | |
---|
[bd8c8b2a] | 74 | int ClockIsOn(const rtems_irq_connect_data* unused) |
---|
[752cd8f] | 75 | { |
---|
[bd8c8b2a] | 76 | return ((i8259s_cache & 0x1) == 0); |
---|
[752cd8f] | 77 | } |
---|
| 78 | |
---|
[0ebbf66] | 79 | static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER, |
---|
[bd8c8b2a] | 80 | Clock_isr, |
---|
| 81 | ClockOn, |
---|
| 82 | ClockOff, |
---|
| 83 | ClockIsOn}; |
---|
[39cafa5] | 84 | |
---|
[1cf2df40] | 85 | |
---|
[39cafa5] | 86 | rtems_device_driver Clock_initialize( |
---|
| 87 | rtems_device_major_number major, |
---|
| 88 | rtems_device_minor_number minor, |
---|
| 89 | void *pargp |
---|
| 90 | ) |
---|
| 91 | { |
---|
[479c86dd] | 92 | unsigned timer_counter_init_value; |
---|
| 93 | unsigned char clock_lsb, clock_msb; |
---|
| 94 | |
---|
[bd8c8b2a] | 95 | Clock_driver_ticks = 0; |
---|
[479c86dd] | 96 | |
---|
[1cf2df40] | 97 | Clock_isrs = |
---|
| 98 | Clock_initial_isr_value = |
---|
| 99 | BSP_Configuration.microseconds_per_tick / 1000; /* ticks per clock_isr */ |
---|
[479c86dd] | 100 | |
---|
| 101 | /* |
---|
| 102 | * configure the counter timer ( should be based on microsecs/tick ) |
---|
| 103 | * NB. The divisor(Clock_isrs) resolves the is the same number that appears in confdefs.h |
---|
| 104 | * when setting the microseconds_per_tick value. |
---|
| 105 | */ |
---|
| 106 | ClockOff ( &clockIrqData ); |
---|
| 107 | |
---|
| 108 | timer_counter_init_value = BSP_Configuration.microseconds_per_tick / Clock_isrs; |
---|
| 109 | clock_lsb = (unsigned char)timer_counter_init_value; |
---|
| 110 | clock_msb = timer_counter_init_value >> 8; |
---|
| 111 | |
---|
| 112 | outport_byte ( TMRCON , 0x34 ); |
---|
| 113 | outport_byte ( TMR0 , clock_lsb ); /* load LSB first */ |
---|
| 114 | outport_byte ( TMR0 , clock_msb ); /* then MSB */ |
---|
| 115 | |
---|
[0ebbf66] | 116 | if (!BSP_install_rtems_irq_handler (&clockIrqData)) { |
---|
[bd8c8b2a] | 117 | printk("Unable to initialize system clock\n"); |
---|
| 118 | rtems_fatal_error_occurred(1); |
---|
| 119 | } |
---|
[479c86dd] | 120 | |
---|
[39cafa5] | 121 | /* |
---|
| 122 | * make major/minor avail to others such as shared memory driver |
---|
| 123 | */ |
---|
| 124 | |
---|
| 125 | rtems_clock_major = major; |
---|
| 126 | rtems_clock_minor = minor; |
---|
| 127 | |
---|
| 128 | return RTEMS_SUCCESSFUL; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | rtems_device_driver Clock_control( |
---|
| 132 | rtems_device_major_number major, |
---|
| 133 | rtems_device_minor_number minor, |
---|
| 134 | void *pargp |
---|
| 135 | ) |
---|
| 136 | { |
---|
| 137 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 138 | |
---|
| 139 | if (args == 0) |
---|
| 140 | goto done; |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * This is hokey, but until we get a defined interface |
---|
| 144 | * to do this, it will just be this simple... |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 148 | { |
---|
[bd8c8b2a] | 149 | Clock_isr(); |
---|
[39cafa5] | 150 | } |
---|
| 151 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 152 | { |
---|
[0ebbf66] | 153 | if (!BSP_install_rtems_irq_handler (&clockIrqData)) { |
---|
[bd8c8b2a] | 154 | printk("Error installing clock interrupt handler!\n"); |
---|
| 155 | rtems_fatal_error_occurred(1); |
---|
| 156 | } |
---|
[04bc5d9] | 157 | #ifdef DEBUG |
---|
| 158 | else |
---|
| 159 | printk("Clock installed AGAIN\n"); |
---|
| 160 | #endif |
---|
[39cafa5] | 161 | } |
---|
| 162 | |
---|
| 163 | done: |
---|
| 164 | return RTEMS_SUCCESSFUL; |
---|
| 165 | } |
---|
| 166 | |
---|
[bd8c8b2a] | 167 | void Clock_exit() |
---|
| 168 | { |
---|
[04bc5d9] | 169 | ClockOff(&clockIrqData); |
---|
[0ebbf66] | 170 | BSP_remove_rtems_irq_handler (&clockIrqData); |
---|
[bd8c8b2a] | 171 | } |
---|