1 /******************************************************************************
4 * Project: Gigabit Ethernet Adapters, Event Scheduler Module
5 * Purpose: Hardware Timer
7 ******************************************************************************/
9 /******************************************************************************
11 * (C)Copyright 1998-2002 SysKonnect GmbH.
12 * (C)Copyright 2002-2003 Marvell.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * The information in this file is provided "AS IS" without warranty.
21 ******************************************************************************/
24 * Event queue and dispatcher
26 #if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
27 static const char SysKonnectFileId[] =
28 "@(#) $Id: skgehwt.c,v 1.15 2003/09/16 13:41:23 rschmidt Exp $ (C) Marvell.";
31 #include "h/skdrv1st.h" /* Driver Specific Definitions */
32 #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
36 * Hardware Timer function queue management.
43 * Prototypes of local functions.
45 #define SK_HWT_MAX (65000)
47 /* correction factor */
48 #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
51 * Initialize hardware timer.
53 * Must be called during init level 1.
56 SK_AC *pAC, /* Adapters context */
57 SK_IOC Ioc) /* IoContext */
61 pAC->Hwt.TActive = SK_FALSE;
68 * Start hardware timer (clock ticks are 16us).
72 SK_AC *pAC, /* Adapters context */
73 SK_IOC Ioc, /* IoContext */
74 SK_U32 Time) /* Time in units of 16us to load the timer with. */
78 if (Time > SK_HWT_MAX)
81 pAC->Hwt.TStart = Time;
94 SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC);
96 SK_OUT16(Ioc, B2_TI_CTRL, TIM_START); /* Start timer. */
98 pAC->Hwt.TActive = SK_TRUE;
102 * Stop hardware timer.
103 * and clear the timer IRQ
106 SK_AC *pAC, /* Adapters context */
107 SK_IOC Ioc) /* IoContext */
109 SK_OUT16(Ioc, B2_TI_CTRL, TIM_STOP);
111 SK_OUT16(Ioc, B2_TI_CTRL, TIM_CLR_IRQ);
113 pAC->Hwt.TActive = SK_FALSE;
118 * Stop hardware timer and read time elapsed since last start.
121 * The elapsed time since last start in units of 16us.
125 SK_AC *pAC, /* Adapters context */
126 SK_IOC Ioc) /* IoContext */
131 if (pAC->Hwt.TActive) {
135 SK_IN32(Ioc, B2_TI_VAL, &TRead);
138 SK_IN32(Ioc, B0_ISRC, &IStatus);
140 /* Check if timer expired (or wraped around) */
141 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
145 pAC->Hwt.TStop = pAC->Hwt.TStart;
149 pAC->Hwt.TStop = pAC->Hwt.TStart - TRead;
152 return(pAC->Hwt.TStop);
156 * interrupt source= timer
159 SK_AC *pAC, /* Adapters context */
160 SK_IOC Ioc) /* IoContext */
164 pAC->Hwt.TStop = pAC->Hwt.TStart;
166 SkTimerDone(pAC, Ioc);