1 | /* Clock_init() |
---|
2 | * |
---|
3 | * This routine initializes the i960RP onboard timer |
---|
4 | * The tick frequency is 1 millisecond; assuming 33MHz core |
---|
5 | * |
---|
6 | * Input parameters: NONE |
---|
7 | * |
---|
8 | * Output parameters: NONE |
---|
9 | * |
---|
10 | * COPYRIGHT (c) 1989-1997. |
---|
11 | * RAMiX Inc 1999 |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may in |
---|
15 | * the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <rtems/libio.h> |
---|
25 | |
---|
26 | #define CLOCK_VECTOR 0x92 |
---|
27 | |
---|
28 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
29 | rtems_unsigned32 Reload_Clock_isrs; |
---|
30 | |
---|
31 | i960_isr_entry Old_ticker; |
---|
32 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
33 | /* ticks since initialization */ |
---|
34 | unsigned int clock_isr_global[16]; /* place to store global regs */ |
---|
35 | |
---|
36 | void Clock_exit( void ); |
---|
37 | |
---|
38 | /* |
---|
39 | * These are set by clock driver during its init |
---|
40 | */ |
---|
41 | |
---|
42 | rtems_device_major_number rtems_clock_major = ~0; |
---|
43 | rtems_device_minor_number rtems_clock_minor; |
---|
44 | |
---|
45 | /* this is later in the file to avoid it being inlined */ |
---|
46 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
47 | |
---|
48 | void Install_clock( |
---|
49 | rtems_isr_entry clock_isr |
---|
50 | ) |
---|
51 | { |
---|
52 | volatile unsigned int *tmr0 = (unsigned int *) TMR0_ADDR; |
---|
53 | volatile unsigned int *trr0 = (unsigned int *) TRR0_ADDR; |
---|
54 | volatile unsigned int *tcr0 = (unsigned int *) TCR0_ADDR; |
---|
55 | volatile unsigned int *icon = (unsigned int *) ICON_ADDR; |
---|
56 | volatile unsigned int *imap2 = (unsigned int *) IMAP2_ADDR; |
---|
57 | volatile unsigned int *ipnd = (unsigned int *) IPND_ADDR; |
---|
58 | volatile unsigned int *imsk = (unsigned int *) IMSK_ADDR; |
---|
59 | void clockHandler(); |
---|
60 | |
---|
61 | |
---|
62 | Clock_driver_ticks = 0; |
---|
63 | Reload_Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
64 | Clock_isrs = Reload_Clock_isrs; |
---|
65 | |
---|
66 | #define BUS_CLOCK_1 0 |
---|
67 | #define TMR_WRITE_CNTL 8 |
---|
68 | #define TMR_AUTO_RELOAD 4 |
---|
69 | #define TMR_ENABLE 2 |
---|
70 | #define TMR_TERM_CNT_STAT 1 |
---|
71 | |
---|
72 | Old_ticker = set_vector( (((unsigned int) clock_isr) | 0x2), CLOCK_VECTOR, 1 ); |
---|
73 | |
---|
74 | /* initialize the i960RP timer 0 here */ |
---|
75 | |
---|
76 | /* set the timer countdown (Assume 33MHz operation) */ |
---|
77 | *trr0 = 30 * BSP_Configuration.microseconds_per_tick ; |
---|
78 | *tcr0 = 30 * BSP_Configuration.microseconds_per_tick ; |
---|
79 | /* |
---|
80 | kkprintf("Load the timers with %x\n", 30 * BSP_Configuration.microseconds_per_tick / Reload_Clock_isrs); |
---|
81 | */ |
---|
82 | |
---|
83 | *tmr0 = BUS_CLOCK_1 | TMR_AUTO_RELOAD | TMR_ENABLE; |
---|
84 | /* Unmask the interrupts */ |
---|
85 | *ipnd &= ~(1 << 12); |
---|
86 | *imsk |= 1 << 12; |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | void Clock_exit() |
---|
91 | { |
---|
92 | volatile unsigned int *tmr0 = (unsigned int *) TMR0_ADDR; |
---|
93 | |
---|
94 | /* shut down the timer */ |
---|
95 | *tmr0 = *tmr0 & ~TMR_ENABLE; |
---|
96 | |
---|
97 | i960_mask_intr( 12 ); |
---|
98 | /* do not restore old vector */ |
---|
99 | } |
---|
100 | |
---|
101 | rtems_device_driver Clock_initialize( |
---|
102 | rtems_device_major_number major, |
---|
103 | rtems_device_minor_number minor, |
---|
104 | void *pargp |
---|
105 | ) |
---|
106 | { |
---|
107 | Install_clock( Clock_isr ); |
---|
108 | |
---|
109 | atexit( Clock_exit ); |
---|
110 | |
---|
111 | /* |
---|
112 | * make major/minor avail to others such as shared memory driver |
---|
113 | */ |
---|
114 | |
---|
115 | rtems_clock_major = major; |
---|
116 | rtems_clock_minor = minor; |
---|
117 | |
---|
118 | return RTEMS_SUCCESSFUL; |
---|
119 | } |
---|
120 | |
---|
121 | rtems_device_driver Clock_control( |
---|
122 | rtems_device_major_number major, |
---|
123 | rtems_device_minor_number minor, |
---|
124 | void *pargp |
---|
125 | ) |
---|
126 | { |
---|
127 | rtems_unsigned32 isrlevel; |
---|
128 | rtems_libio_ioctl_args_t *args = pargp; |
---|
129 | |
---|
130 | if (args == 0) |
---|
131 | goto done; |
---|
132 | |
---|
133 | /* |
---|
134 | * This is hokey, but until we get a defined interface |
---|
135 | * to do this, it will just be this simple... |
---|
136 | */ |
---|
137 | |
---|
138 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
139 | { |
---|
140 | Clock_isr(CLOCK_VECTOR); |
---|
141 | } |
---|
142 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
143 | { |
---|
144 | rtems_interrupt_disable( isrlevel ); |
---|
145 | (void) set_tmr_vector( args->buffer, CLOCK_VECTOR, 0 ); |
---|
146 | rtems_interrupt_enable( isrlevel ); |
---|
147 | } |
---|
148 | |
---|
149 | done: |
---|
150 | return RTEMS_SUCCESSFUL; |
---|
151 | } |
---|
152 | |
---|
153 | rtems_isr Clock_isr( |
---|
154 | rtems_vector_number vector |
---|
155 | ) |
---|
156 | { |
---|
157 | /* enable_tracing(); */ |
---|
158 | #ifdef NOTMB |
---|
159 | if ( Clock_isrs == 1 ) { |
---|
160 | rtems_clock_tick(); |
---|
161 | Clock_isrs = Reload_Clock_isrs; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | Clock_isrs -= 1; |
---|
166 | } |
---|
167 | #else |
---|
168 | *(int *)(0xfed00000) += 1; |
---|
169 | rtems_clock_tick(); |
---|
170 | #endif |
---|
171 | |
---|
172 | i960_clear_intr( 12 ); |
---|
173 | } |
---|
174 | |
---|