1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
18 * Timer Driver for FBI board (timer chip 82C54)
24 * 28-Jun-1994 sw Edit v1.6.
25 * MCA: Added support for the SK-NET FDDI-FM2 adapter. The
26 * following functions have been added(+) or modified(*):
27 * hwt_start(*), hwt_stop(*), hwt_restart(*), hwt_read(*)
35 static const char ID_sccs[] = "@(#)hwt.c 1.13 97/04/23 (C) SK " ;
39 * Prototypes of local functions.
41 /* 28-Jun-1994 sw - Note: hwt_restart() is also used in module 'drvfbi.c'. */
42 /*static*/ void hwt_restart() ;
44 /************************
48 * Start hardware timer (clock ticks are 16us).
54 * smc - A pointer to the SMT Context structure.
56 * time - The time in units of 16us to load the timer with.
60 ************************/
61 #define HWT_MAX (65000)
63 void hwt_start(smc, time)
72 smc->hw.t_start = time ;
84 * 6.25MHz -> CLK0 : T0 (cnt0 = 16us) -> OUT0
85 * OUT0 -> CLK1 : T1 (cnt1) OUT1 -> ISRA(IS_TIMINT)
87 OUT_82c54_TIMER(3,1<<6 | 3<<4 | 0<<1) ; /* counter 1, mode 0 */
88 OUT_82c54_TIMER(1,cnt & 0xff) ; /* LSB */
89 OUT_82c54_TIMER(1,(cnt>>8) & 0xff) ; /* MSB */
91 * start timer by switching counter 0 to mode 3
92 * T0 resolution 16 us (CLK0=0.16us)
94 OUT_82c54_TIMER(3,0<<6 | 3<<4 | 3<<1) ; /* counter 0, mode 3 */
95 OUT_82c54_TIMER(0,100) ; /* LSB */
96 OUT_82c54_TIMER(0,0) ; /* MSB */
98 outpd(ADDR(B2_TI_INI), (u_long) cnt * 200) ; /* Load timer value. */
99 outpw(ADDR(B2_TI_CRTL), TIM_START) ; /* Start timer. */
101 smc->hw.timer_activ = TRUE ;
104 /************************
108 * Stop hardware timer.
111 * struct s_smc *smc) ;
113 * smc - A pointer to the SMT Context structure.
117 ************************/
122 /* stop counter 0 by switching to mode 0 */
123 OUT_82c54_TIMER(3,0<<6 | 3<<4 | 0<<1) ; /* counter 0, mode 0 */
124 OUT_82c54_TIMER(0,0) ; /* LSB */
125 OUT_82c54_TIMER(0,0) ; /* MSB */
127 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
128 outpw(ADDR(B2_TI_CRTL), TIM_CL_IRQ) ;
131 smc->hw.timer_activ = FALSE ;
134 /************************
138 * Initialize hardware timer.
141 * struct s_smc *smc) ;
143 * smc - A pointer to the SMT Context structure.
147 ************************/
151 smc->hw.t_start = 0 ;
153 smc->hw.timer_activ = FALSE ;
158 /************************
162 * Clear timer interrupt.
165 * struct s_smc *smc) ;
167 * smc - A pointer to the SMT Context structure.
171 ************************/
172 void hwt_restart(smc)
177 OUT_82c54_TIMER(3,1<<6 | 3<<4 | 0<<1) ; /* counter 1, mode 0 */
178 OUT_82c54_TIMER(1,1 ) ; /* LSB */
179 OUT_82c54_TIMER(1,0 ) ; /* MSB */
183 /************************
187 * Stop hardware timer and read time elapsed since last start.
189 * u_long hwt_read(smc) ;
191 * smc - A pointer to the SMT Context structure.
193 * The elapsed time since last start in units of 16us.
195 ************************/
206 if (smc->hw.timer_activ) {
209 OUT_82c54_TIMER(3,1<<6) ; /* latch command */
210 tr = IN_82c54_TIMER(1) & 0xff ;
211 tr += (IN_82c54_TIMER(1) & 0xff)<<8 ;
213 tr = (u_short)((inpd(ADDR(B2_TI_VAL))/200) & 0xffff) ;
216 /* Check if timer expired (or wraparound). */
217 if ((tr > smc->hw.t_start) || (is & IS_TIMINT)) {
219 smc->hw.t_stop = smc->hw.t_start ;
222 smc->hw.t_stop = smc->hw.t_start - tr ;
224 return (smc->hw.t_stop) ;
228 /************************
232 * Stop hardware timer and read timer value and start the timer again.
234 * u_long hwt_read(smc) ;
236 * smc - A pointer to the SMT Context structure.
238 * current timer value in units of 80ns.
240 ************************/
241 u_long hwt_quick_read(smc)
247 interval = inpd(ADDR(B2_TI_INI)) ;
248 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
249 time = inpd(ADDR(B2_TI_VAL)) ;
250 outpd(ADDR(B2_TI_INI),time) ;
251 outpw(ADDR(B2_TI_CRTL), TIM_START) ;
252 outpd(ADDR(B2_TI_INI),interval) ;
257 /************************
259 * hwt_wait_time(smc,start,duration)
261 * This function returnes after the amount of time is elapsed
262 * since the start time.
264 * para start start time
265 * duration time to wait
267 * NOTE: The fuction will return immediately, if the timer is not
269 ************************/
270 void hwt_wait_time(smc,start,duration)
280 * check if timer is running
282 if (smc->hw.timer_activ == FALSE ||
283 hwt_quick_read(smc) == hwt_quick_read(smc)) {
287 interval = inpd(ADDR(B2_TI_INI)) ;
288 if (interval > duration) {
290 diff = (long)(start - hwt_quick_read(smc)) ;
294 } while (diff <= duration) ;
301 if (hwt_quick_read(smc) >= start) {
307 if (hwt_quick_read(smc) < start) {
311 } while (diff <= duration) ;