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 | * |
---|
12 | * COPYRIGHT (c) 1989-1999. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
18 | * |
---|
19 | * $Id$ |
---|
20 | */ |
---|
21 | #define TMR0 0xF040 |
---|
22 | #define TMR1 0xF041 |
---|
23 | #define TMR2 0xF042 |
---|
24 | #define TMRCON 0xF043 |
---|
25 | #define TMRCFG 0xF834 |
---|
26 | |
---|
27 | #include <bsp.h> |
---|
28 | #include <bsp/irq.h> |
---|
29 | |
---|
30 | #include <stdlib.h> |
---|
31 | |
---|
32 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
33 | static uint32_t Clock_initial_isr_value; |
---|
34 | |
---|
35 | volatile uint32_t Clock_driver_ticks; |
---|
36 | |
---|
37 | void Clock_exit( void ); |
---|
38 | |
---|
39 | /* |
---|
40 | * These are set by clock driver during its init |
---|
41 | */ |
---|
42 | |
---|
43 | rtems_device_major_number rtems_clock_major = ~0; |
---|
44 | rtems_device_major_number rtems_clock_minor = 0; |
---|
45 | |
---|
46 | /* |
---|
47 | * This is the ISR handler. |
---|
48 | */ |
---|
49 | |
---|
50 | void Clock_isr() |
---|
51 | { |
---|
52 | /* enable_tracing(); */ |
---|
53 | Clock_driver_ticks += 1; |
---|
54 | if ( Clock_isrs == 1 ) { |
---|
55 | rtems_clock_tick(); |
---|
56 | Clock_isrs = Clock_initial_isr_value; /* rtems_configuration_get_microseconds_per_tick() / 1000;*/ |
---|
57 | } |
---|
58 | else |
---|
59 | Clock_isrs -= 1; |
---|
60 | } |
---|
61 | |
---|
62 | void ClockOff(const rtems_irq_connect_data* unused) |
---|
63 | { |
---|
64 | outport_byte ( TMRCFG , 0x80 ); /* disable the counter timer */ |
---|
65 | } |
---|
66 | |
---|
67 | void ClockOn(const rtems_irq_connect_data* unused) |
---|
68 | { |
---|
69 | outport_byte ( TMRCFG , 0x00 ); /* enable the counter timer */ |
---|
70 | } |
---|
71 | |
---|
72 | int ClockIsOn(const rtems_irq_connect_data* unused) |
---|
73 | { |
---|
74 | return ((i8259s_cache & 0x1) == 0); |
---|
75 | } |
---|
76 | |
---|
77 | static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER, |
---|
78 | Clock_isr, |
---|
79 | 0, |
---|
80 | ClockOn, |
---|
81 | ClockOff, |
---|
82 | ClockIsOn}; |
---|
83 | |
---|
84 | rtems_device_driver Clock_initialize( |
---|
85 | rtems_device_major_number major, |
---|
86 | rtems_device_minor_number minor, |
---|
87 | void *pargp |
---|
88 | ) |
---|
89 | { |
---|
90 | unsigned timer_counter_init_value; |
---|
91 | unsigned char clock_lsb, clock_msb; |
---|
92 | |
---|
93 | Clock_driver_ticks = 0; |
---|
94 | |
---|
95 | Clock_isrs = |
---|
96 | Clock_initial_isr_value = |
---|
97 | rtems_configuration_get_microseconds_per_tick() / 1000; /* ticks per clock_isr */ |
---|
98 | |
---|
99 | /* |
---|
100 | * configure the counter timer ( should be based on microsecs/tick ) |
---|
101 | * NB. The divisor(Clock_isrs) resolves the is the same number that appears in confdefs.h |
---|
102 | * when setting the microseconds_per_tick value. |
---|
103 | */ |
---|
104 | ClockOff ( &clockIrqData ); |
---|
105 | |
---|
106 | timer_counter_init_value = rtems_configuration_get_microseconds_per_tick() / Clock_isrs; |
---|
107 | clock_lsb = (unsigned char)timer_counter_init_value; |
---|
108 | clock_msb = timer_counter_init_value >> 8; |
---|
109 | |
---|
110 | outport_byte ( TMRCON , 0x34 ); |
---|
111 | outport_byte ( TMR0 , clock_lsb ); /* load LSB first */ |
---|
112 | outport_byte ( TMR0 , clock_msb ); /* then MSB */ |
---|
113 | |
---|
114 | if (!BSP_install_rtems_irq_handler (&clockIrqData)) { |
---|
115 | printk("Unable to initialize system clock\n"); |
---|
116 | rtems_fatal_error_occurred(1); |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * make major/minor avail to others such as shared memory driver |
---|
121 | */ |
---|
122 | |
---|
123 | rtems_clock_major = major; |
---|
124 | rtems_clock_minor = minor; |
---|
125 | |
---|
126 | return RTEMS_SUCCESSFUL; |
---|
127 | } |
---|
128 | |
---|
129 | void Clock_exit() |
---|
130 | { |
---|
131 | ClockOff(&clockIrqData); |
---|
132 | BSP_remove_rtems_irq_handler (&clockIrqData); |
---|
133 | } |
---|