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