1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "h/types.h"
27#include "h/fddi.h"
28#include "h/smc.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#define HWT_MAX (65000)
54
55void hwt_start(struct s_smc *smc, u_long time)
56{
57 u_short cnt ;
58
59 if (time > HWT_MAX)
60 time = HWT_MAX ;
61
62 smc->hw.t_start = time ;
63 smc->hw.t_stop = 0L ;
64
65 cnt = (u_short)time ;
66
67
68
69
70 if (!cnt)
71 cnt++ ;
72
73 outpd(ADDR(B2_TI_INI), (u_long) cnt * 200) ;
74 outpw(ADDR(B2_TI_CRTL), TIM_START) ;
75
76 smc->hw.timer_activ = TRUE ;
77}
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93void hwt_stop(struct s_smc *smc)
94{
95 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
96 outpw(ADDR(B2_TI_CRTL), TIM_CL_IRQ) ;
97
98 smc->hw.timer_activ = FALSE ;
99}
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115void hwt_init(struct s_smc *smc)
116{
117 smc->hw.t_start = 0 ;
118 smc->hw.t_stop = 0 ;
119 smc->hw.timer_activ = FALSE ;
120
121 hwt_restart(smc) ;
122}
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138void hwt_restart(struct s_smc *smc)
139{
140 hwt_stop(smc) ;
141}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156u_long hwt_read(struct s_smc *smc)
157{
158 u_short tr ;
159 u_long is ;
160
161 if (smc->hw.timer_activ) {
162 hwt_stop(smc) ;
163 tr = (u_short)((inpd(ADDR(B2_TI_VAL))/200) & 0xffff) ;
164
165 is = GET_ISR() ;
166
167 if ((tr > smc->hw.t_start) || (is & IS_TIMINT)) {
168 hwt_restart(smc) ;
169 smc->hw.t_stop = smc->hw.t_start ;
170 }
171 else
172 smc->hw.t_stop = smc->hw.t_start - tr ;
173 }
174 return smc->hw.t_stop;
175}
176
177#ifdef PCI
178
179
180
181
182
183
184
185
186
187
188
189
190
191u_long hwt_quick_read(struct s_smc *smc)
192{
193 u_long interval ;
194 u_long time ;
195
196 interval = inpd(ADDR(B2_TI_INI)) ;
197 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
198 time = inpd(ADDR(B2_TI_VAL)) ;
199 outpd(ADDR(B2_TI_INI),time) ;
200 outpw(ADDR(B2_TI_CRTL), TIM_START) ;
201 outpd(ADDR(B2_TI_INI),interval) ;
202
203 return time;
204}
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219void hwt_wait_time(struct s_smc *smc, u_long start, long int duration)
220{
221 long diff ;
222 long interval ;
223 int wrapped ;
224
225
226
227
228 if (smc->hw.timer_activ == FALSE ||
229 hwt_quick_read(smc) == hwt_quick_read(smc)) {
230 return ;
231 }
232
233 interval = inpd(ADDR(B2_TI_INI)) ;
234 if (interval > duration) {
235 do {
236 diff = (long)(start - hwt_quick_read(smc)) ;
237 if (diff < 0) {
238 diff += interval ;
239 }
240 } while (diff <= duration) ;
241 }
242 else {
243 diff = interval ;
244 wrapped = 0 ;
245 do {
246 if (!wrapped) {
247 if (hwt_quick_read(smc) >= start) {
248 diff += interval ;
249 wrapped = 1 ;
250 }
251 }
252 else {
253 if (hwt_quick_read(smc) < start) {
254 wrapped = 0 ;
255 }
256 }
257 } while (diff <= duration) ;
258 }
259}
260#endif
261
262