File: /usr/src/linux/drivers/net/sk98lin/skgehwt.c

1     /******************************************************************************
2      *
3      * Name:	skgehwt.c
4      * Project:	PCI Gigabit Ethernet Adapter
5      * Version:	$Revision: 1.12 $
6      * Date:	$Date: 1998/10/15 15:11:34 $
7      * Purpose:	Hardware Timer.
8      *
9      ******************************************************************************/
10     
11     /******************************************************************************
12      *
13      *	(C)Copyright 1989-1998 SysKonnect,
14      *	a business unit of Schneider & Koch & Co. Datensysteme GmbH.
15      *	All Rights Reserved
16      *
17      *	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SYSKONNECT
18      *	The copyright notice above does not evidence any
19      *	actual or intended publication of such source code.
20      *
21      *	This Module contains Proprietary Information of SysKonnect
22      *	and should be treated as Confidential.
23      *
24      *	The information in this file is provided for the exclusive use of
25      *	the licensees of SysKonnect.
26      *	Such users have the right to use, modify, and incorporate this code
27      *	into products for purposes authorized by the license agreement
28      *	provided they include this notice and the associated copyright notice
29      *	with any such product.
30      *	The information in this file is provided "AS IS" without warranty.
31      *
32      ******************************************************************************/
33     
34     /******************************************************************************
35      *
36      * History:
37      *
38      *	$Log: skgehwt.c,v $
39      *	Revision 1.12  1998/10/15 15:11:34  gklug
40      *	fix: ID_sccs to SysKonnectFileId
41      *	
42      *	Revision 1.11  1998/10/08 15:27:51  gklug
43      *	chg: correction factor is host clock dependent
44      *	
45      *	Revision 1.10  1998/09/15 14:18:31  cgoos
46      *	Changed more BOOLEANs to SK_xxx
47      *
48      *	Revision 1.9  1998/09/15 14:16:06  cgoos
49      *	Changed line 107: FALSE to SK_FALSE
50      *	
51      *	Revision 1.8  1998/08/24 13:04:44  gklug
52      *	fix: typo
53      *	
54      *	Revision 1.7  1998/08/19 09:50:49  gklug
55      *	fix: remove struct keyword from c-code (see CCC) add typedefs
56      *	
57      *	Revision 1.6  1998/08/17 09:59:02  gklug
58      *	fix: typos
59      *	
60      *	Revision 1.5  1998/08/14 07:09:10  gklug
61      *	fix: chg pAc -> pAC
62      *	
63      *	Revision 1.4  1998/08/10 14:14:52  gklug
64      *	rmv: unneccessary SK_ADDR macro
65      *	
66      *	Revision 1.3  1998/08/07 12:53:44  gklug
67      *	fix: first compiled version
68      *	
69      *	Revision 1.2  1998/08/07 09:19:29  gklug
70      *	adapt functions to the C coding conventions
71      *	rmv unneccessary functions.
72      *	
73      *	Revision 1.1  1998/08/05 11:28:36  gklug
74      *	first version: adapted from SMT/FDDI
75      *	
76      *	
77      *	
78      *
79      ******************************************************************************/
80     
81     
82     /*
83     	Event queue and dispatcher
84     */
85     static const char SysKonnectFileId[] =
86     	"$Header: /usr56/projects/ge/schedule/skgehwt.c,v 1.12 1998/10/15 15:11:34 gklug Exp $" ;
87     
88     #include "h/skdrv1st.h"		/* Driver Specific Definitions */
89     #include "h/skdrv2nd.h"		/* Adapter Control- and Driver specific Def. */
90     
91     #ifdef __C2MAN__
92     /*
93     	Hardware Timer function queue management.
94     
95     	General Description:
96     
97      */
98     intro()
99     {}
100     #endif
101     
102     /*
103      * Prototypes of local functions.
104      */
105     #define	SK_HWT_MAX	(65000)
106     
107     /* correction factor */
108     #define	SK_HWT_FAC	(1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
109     
110     /*
111      * Initialize hardware timer.
112      *
113      * Must be called during init level 1.
114      */
115     void	SkHwtInit(
116     SK_AC	*pAC,	/* Adapters context */
117     SK_IOC	Ioc)	/* IoContext */
118     {
119     	pAC->Hwt.TStart = 0 ;
120     	pAC->Hwt.TStop	= 0 ;
121     	pAC->Hwt.TActive = SK_FALSE ;
122     
123     	SkHwtStop(pAC,Ioc) ;
124     }
125     
126     /*
127      *
128      * Start hardware timer (clock ticks are 16us).
129      *
130      */
131     void	SkHwtStart(
132     SK_AC	*pAC,	/* Adapters context */
133     SK_IOC	Ioc,	/* IoContext */
134     SK_U32	Time)	/* Time in units of 16us to load the timer with. */
135     {
136     	SK_U32	Cnt ;
137     
138     	if (Time > SK_HWT_MAX)
139     		Time = SK_HWT_MAX ;
140     
141     	pAC->Hwt.TStart = Time ;
142     	pAC->Hwt.TStop = 0L ;
143     
144     	Cnt = Time ;
145     
146     	/*
147     	 * if time < 16 us
148     	 *	time = 16 us
149     	 */
150     	if (!Cnt) {
151     		Cnt++ ;
152     	}
153     
154     	SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
155     	SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ;	/* Start timer. */
156     
157     	pAC->Hwt.TActive = SK_TRUE ;
158     }
159     
160     /*
161      * Stop hardware timer.
162      * and clear the timer IRQ
163      */
164     void	SkHwtStop(
165     SK_AC	*pAC,	/* Adapters context */
166     SK_IOC	Ioc)	/* IoContext */
167     {
168     	SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
169     	SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
170     
171     	pAC->Hwt.TActive = SK_FALSE ;
172     }
173     
174     
175     /*
176      *	Stop hardware timer and read time elapsed since last start.
177      *
178      * returns
179      *	The elapsed time since last start in units of 16us.
180      *
181      */
182     SK_U32	SkHwtRead(
183     SK_AC	*pAC,	/* Adapters context */
184     SK_IOC	Ioc)	/* IoContext */
185     {
186     	SK_U32	TRead ;
187     	SK_U32	IStatus ;
188     
189     	if (pAC->Hwt.TActive) {
190     		SkHwtStop(pAC,Ioc) ;
191     
192     		SK_IN32(Ioc, B2_TI_VAL, &TRead);
193     		TRead /= SK_HWT_FAC;
194     
195     		SK_IN32(Ioc, B0_ISRC, &IStatus);
196     
197     		/* Check if timer expired (or wraparound). */
198     		if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
199     			SkHwtStop(pAC,Ioc) ;
200     			pAC->Hwt.TStop = pAC->Hwt.TStart ;
201     		} else {
202     			pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
203     		}
204     	}
205     	return (pAC->Hwt.TStop) ;
206     }
207     
208     /*
209      * interrupt source= timer
210      */
211     void	SkHwtIsr(
212     SK_AC	*pAC,	/* Adapters context */
213     SK_IOC	Ioc)	/* IoContext */
214     {
215     	SkHwtStop(pAC,Ioc);
216     	pAC->Hwt.TStop = pAC->Hwt.TStart;
217     	SkTimerDone(pAC,Ioc) ;
218     }
219     
220     /* End of file */
221