blob: ca08eb1de117e183aac0028f29ec52f83309e473 [file] [log] [blame]
wdenkeb20ad32003-09-05 23:19:14 +00001/******************************************************************************
2 *
3 * Name: skgehwt.c
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.13 $
6 * Date: $Date: 1999/11/22 13:31:12 $
7 * Purpose: Hardware Timer.
8 *
9 ******************************************************************************/
10
11/******************************************************************************
12 *
13 * (C)Copyright 1998,1999 SysKonnect,
14 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * The information in this file is provided "AS IS" without warranty.
22 *
23 ******************************************************************************/
24
25/******************************************************************************
26 *
27 * History:
28 *
29 * $Log: skgehwt.c,v $
30 * Revision 1.13 1999/11/22 13:31:12 cgoos
31 * Changed license header to GPL.
wdenk9c53f402003-10-15 23:53:47 +000032 *
wdenkeb20ad32003-09-05 23:19:14 +000033 * Revision 1.12 1998/10/15 15:11:34 gklug
34 * fix: ID_sccs to SysKonnectFileId
wdenk9c53f402003-10-15 23:53:47 +000035 *
wdenkeb20ad32003-09-05 23:19:14 +000036 * Revision 1.11 1998/10/08 15:27:51 gklug
37 * chg: correction factor is host clock dependent
wdenk9c53f402003-10-15 23:53:47 +000038 *
wdenkeb20ad32003-09-05 23:19:14 +000039 * Revision 1.10 1998/09/15 14:18:31 cgoos
40 * Changed more BOOLEANs to SK_xxx
41 *
42 * Revision 1.9 1998/09/15 14:16:06 cgoos
43 * Changed line 107: FALSE to SK_FALSE
wdenk9c53f402003-10-15 23:53:47 +000044 *
wdenkeb20ad32003-09-05 23:19:14 +000045 * Revision 1.8 1998/08/24 13:04:44 gklug
46 * fix: typo
wdenk9c53f402003-10-15 23:53:47 +000047 *
wdenkeb20ad32003-09-05 23:19:14 +000048 * Revision 1.7 1998/08/19 09:50:49 gklug
49 * fix: remove struct keyword from c-code (see CCC) add typedefs
wdenk9c53f402003-10-15 23:53:47 +000050 *
wdenkeb20ad32003-09-05 23:19:14 +000051 * Revision 1.6 1998/08/17 09:59:02 gklug
52 * fix: typos
wdenk9c53f402003-10-15 23:53:47 +000053 *
wdenkeb20ad32003-09-05 23:19:14 +000054 * Revision 1.5 1998/08/14 07:09:10 gklug
55 * fix: chg pAc -> pAC
wdenk9c53f402003-10-15 23:53:47 +000056 *
wdenkeb20ad32003-09-05 23:19:14 +000057 * Revision 1.4 1998/08/10 14:14:52 gklug
58 * rmv: unneccessary SK_ADDR macro
wdenk9c53f402003-10-15 23:53:47 +000059 *
wdenkeb20ad32003-09-05 23:19:14 +000060 * Revision 1.3 1998/08/07 12:53:44 gklug
61 * fix: first compiled version
wdenk9c53f402003-10-15 23:53:47 +000062 *
wdenkeb20ad32003-09-05 23:19:14 +000063 * Revision 1.2 1998/08/07 09:19:29 gklug
64 * adapt functions to the C coding conventions
65 * rmv unneccessary functions.
wdenk9c53f402003-10-15 23:53:47 +000066 *
wdenkeb20ad32003-09-05 23:19:14 +000067 * Revision 1.1 1998/08/05 11:28:36 gklug
68 * first version: adapted from SMT/FDDI
wdenk9c53f402003-10-15 23:53:47 +000069 *
70 *
71 *
wdenkeb20ad32003-09-05 23:19:14 +000072 *
73 ******************************************************************************/
74
75
wdenkde887eb2003-09-10 18:20:28 +000076#include <config.h>
77
wdenkeb20ad32003-09-05 23:19:14 +000078/*
79 Event queue and dispatcher
80*/
81static const char SysKonnectFileId[] =
82 "$Header: /usr56/projects/ge/schedule/skgehwt.c,v 1.13 1999/11/22 13:31:12 cgoos Exp $" ;
83
84#include "h/skdrv1st.h" /* Driver Specific Definitions */
85#include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
86
87#ifdef __C2MAN__
88/*
89 Hardware Timer function queue management.
90
91 General Description:
92
93 */
94intro()
95{}
96#endif
97
98/*
99 * Prototypes of local functions.
100 */
101#define SK_HWT_MAX (65000)
102
103/* correction factor */
104#define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
105
106/*
107 * Initialize hardware timer.
108 *
109 * Must be called during init level 1.
110 */
111void SkHwtInit(
112SK_AC *pAC, /* Adapters context */
113SK_IOC Ioc) /* IoContext */
114{
115 pAC->Hwt.TStart = 0 ;
116 pAC->Hwt.TStop = 0 ;
117 pAC->Hwt.TActive = SK_FALSE ;
118
119 SkHwtStop(pAC,Ioc) ;
120}
121
122/*
123 *
124 * Start hardware timer (clock ticks are 16us).
125 *
126 */
127void SkHwtStart(
128SK_AC *pAC, /* Adapters context */
129SK_IOC Ioc, /* IoContext */
130SK_U32 Time) /* Time in units of 16us to load the timer with. */
131{
132 SK_U32 Cnt ;
133
134 if (Time > SK_HWT_MAX)
135 Time = SK_HWT_MAX ;
136
137 pAC->Hwt.TStart = Time ;
138 pAC->Hwt.TStop = 0L ;
139
140 Cnt = Time ;
141
142 /*
143 * if time < 16 us
144 * time = 16 us
145 */
146 if (!Cnt) {
147 Cnt++ ;
148 }
149
150 SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
151 SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ; /* Start timer. */
152
153 pAC->Hwt.TActive = SK_TRUE ;
154}
155
156/*
157 * Stop hardware timer.
158 * and clear the timer IRQ
159 */
160void SkHwtStop(
161SK_AC *pAC, /* Adapters context */
162SK_IOC Ioc) /* IoContext */
163{
164 SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
165 SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
166
167 pAC->Hwt.TActive = SK_FALSE ;
168}
169
170
171/*
172 * Stop hardware timer and read time elapsed since last start.
173 *
174 * returns
175 * The elapsed time since last start in units of 16us.
176 *
177 */
178SK_U32 SkHwtRead(
179SK_AC *pAC, /* Adapters context */
180SK_IOC Ioc) /* IoContext */
181{
182 SK_U32 TRead ;
183 SK_U32 IStatus ;
184
185 if (pAC->Hwt.TActive) {
186 SkHwtStop(pAC,Ioc) ;
187
188 SK_IN32(Ioc, B2_TI_VAL, &TRead);
189 TRead /= SK_HWT_FAC;
190
191 SK_IN32(Ioc, B0_ISRC, &IStatus);
192
193 /* Check if timer expired (or wraparound). */
194 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
195 SkHwtStop(pAC,Ioc) ;
196 pAC->Hwt.TStop = pAC->Hwt.TStart ;
197 } else {
198 pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
199 }
200 }
201 return (pAC->Hwt.TStop) ;
202}
203
204/*
205 * interrupt source= timer
206 */
207void SkHwtIsr(
208SK_AC *pAC, /* Adapters context */
209SK_IOC Ioc) /* IoContext */
210{
211 SkHwtStop(pAC,Ioc);
212 pAC->Hwt.TStop = pAC->Hwt.TStart;
213 SkTimerDone(pAC,Ioc) ;
214}
wdenkeb20ad32003-09-05 23:19:14 +0000215/* End of file */