1 /******************************************************************************
4 * Project: Gigabit Ethernet Adapters, Event Scheduler Module
5 * Version: $Revision: 1.15 $
6 * Date: $Date: 2003/09/16 13:41:23 $
7 * Purpose: Hardware Timer
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
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.
21 * The information in this file is provided "AS IS" without warranty.
23 ******************************************************************************/
26 * Event queue and dispatcher
28 #if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
29 static const char SysKonnectFileId[] =
30 "@(#) $Id: skgehwt.c,v 1.15 2003/09/16 13:41:23 rschmidt Exp $ (C) Marvell.";
33 #include "h/skdrv1st.h" /* Driver Specific Definitions */
34 #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
38 * Hardware Timer function queue management.
45 * Prototypes of local functions.
47 #define SK_HWT_MAX (65000)
49 /* correction factor */
50 #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
53 * Initialize hardware timer.
55 * Must be called during init level 1.
58 SK_AC *pAC, /* Adapters context */
59 SK_IOC Ioc) /* IoContext */
63 pAC->Hwt.TActive = SK_FALSE;
70 * Start hardware timer (clock ticks are 16us).
74 SK_AC *pAC, /* Adapters context */
75 SK_IOC Ioc, /* IoContext */
76 SK_U32 Time) /* Time in units of 16us to load the timer with. */
80 if (Time > SK_HWT_MAX)
83 pAC->Hwt.TStart = Time;
96 SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC);
98 SK_OUT16(Ioc, B2_TI_CTRL, TIM_START); /* Start timer. */
100 pAC->Hwt.TActive = SK_TRUE;
104 * Stop hardware timer.
105 * and clear the timer IRQ
108 SK_AC *pAC, /* Adapters context */
109 SK_IOC Ioc) /* IoContext */
111 SK_OUT16(Ioc, B2_TI_CTRL, TIM_STOP);
113 SK_OUT16(Ioc, B2_TI_CTRL, TIM_CLR_IRQ);
115 pAC->Hwt.TActive = SK_FALSE;
120 * Stop hardware timer and read time elapsed since last start.
123 * The elapsed time since last start in units of 16us.
127 SK_AC *pAC, /* Adapters context */
128 SK_IOC Ioc) /* IoContext */
133 if (pAC->Hwt.TActive) {
137 SK_IN32(Ioc, B2_TI_VAL, &TRead);
140 SK_IN32(Ioc, B0_ISRC, &IStatus);
142 /* Check if timer expired (or wraped around) */
143 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
147 pAC->Hwt.TStop = pAC->Hwt.TStart;
151 pAC->Hwt.TStop = pAC->Hwt.TStart - TRead;
154 return(pAC->Hwt.TStop);
158 * interrupt source= timer
161 SK_AC *pAC, /* Adapters context */
162 SK_IOC Ioc) /* IoContext */
166 pAC->Hwt.TStop = pAC->Hwt.TStart;
168 SkTimerDone(pAC, Ioc);