skgehwt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /******************************************************************************
  2. *
  3. * Name: skgehwt.c
  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
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2002 SysKonnect GmbH.
  13. * (C)Copyright 2002-2003 Marvell.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * The information in this file is provided "AS IS" without warranty.
  21. *
  22. ******************************************************************************/
  23. /*
  24. * Event queue and dispatcher
  25. */
  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.";
  29. #endif
  30. #include "h/skdrv1st.h" /* Driver Specific Definitions */
  31. #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
  32. #ifdef __C2MAN__
  33. /*
  34. * Hardware Timer function queue management.
  35. */
  36. intro()
  37. {}
  38. #endif
  39. /*
  40. * Prototypes of local functions.
  41. */
  42. #define SK_HWT_MAX (65000)
  43. /* correction factor */
  44. #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
  45. /*
  46. * Initialize hardware timer.
  47. *
  48. * Must be called during init level 1.
  49. */
  50. void SkHwtInit(
  51. SK_AC *pAC, /* Adapters context */
  52. SK_IOC Ioc) /* IoContext */
  53. {
  54. pAC->Hwt.TStart = 0 ;
  55. pAC->Hwt.TStop = 0 ;
  56. pAC->Hwt.TActive = SK_FALSE;
  57. SkHwtStop(pAC, Ioc);
  58. }
  59. /*
  60. *
  61. * Start hardware timer (clock ticks are 16us).
  62. *
  63. */
  64. void SkHwtStart(
  65. SK_AC *pAC, /* Adapters context */
  66. SK_IOC Ioc, /* IoContext */
  67. SK_U32 Time) /* Time in units of 16us to load the timer with. */
  68. {
  69. SK_U32 Cnt;
  70. if (Time > SK_HWT_MAX)
  71. Time = SK_HWT_MAX;
  72. pAC->Hwt.TStart = Time;
  73. pAC->Hwt.TStop = 0L;
  74. Cnt = Time;
  75. /*
  76. * if time < 16 us
  77. * time = 16 us
  78. */
  79. if (!Cnt) {
  80. Cnt++;
  81. }
  82. SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC);
  83. SK_OUT16(Ioc, B2_TI_CTRL, TIM_START); /* Start timer. */
  84. pAC->Hwt.TActive = SK_TRUE;
  85. }
  86. /*
  87. * Stop hardware timer.
  88. * and clear the timer IRQ
  89. */
  90. void SkHwtStop(
  91. SK_AC *pAC, /* Adapters context */
  92. SK_IOC Ioc) /* IoContext */
  93. {
  94. SK_OUT16(Ioc, B2_TI_CTRL, TIM_STOP);
  95. SK_OUT16(Ioc, B2_TI_CTRL, TIM_CLR_IRQ);
  96. pAC->Hwt.TActive = SK_FALSE;
  97. }
  98. /*
  99. * Stop hardware timer and read time elapsed since last start.
  100. *
  101. * returns
  102. * The elapsed time since last start in units of 16us.
  103. *
  104. */
  105. SK_U32 SkHwtRead(
  106. SK_AC *pAC, /* Adapters context */
  107. SK_IOC Ioc) /* IoContext */
  108. {
  109. SK_U32 TRead;
  110. SK_U32 IStatus;
  111. if (pAC->Hwt.TActive) {
  112. SkHwtStop(pAC, Ioc);
  113. SK_IN32(Ioc, B2_TI_VAL, &TRead);
  114. TRead /= SK_HWT_FAC;
  115. SK_IN32(Ioc, B0_ISRC, &IStatus);
  116. /* Check if timer expired (or wraped around) */
  117. if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
  118. SkHwtStop(pAC, Ioc);
  119. pAC->Hwt.TStop = pAC->Hwt.TStart;
  120. }
  121. else {
  122. pAC->Hwt.TStop = pAC->Hwt.TStart - TRead;
  123. }
  124. }
  125. return(pAC->Hwt.TStop);
  126. }
  127. /*
  128. * interrupt source= timer
  129. */
  130. void SkHwtIsr(
  131. SK_AC *pAC, /* Adapters context */
  132. SK_IOC Ioc) /* IoContext */
  133. {
  134. SkHwtStop(pAC, Ioc);
  135. pAC->Hwt.TStop = pAC->Hwt.TStart;
  136. SkTimerDone(pAC, Ioc);
  137. }
  138. /* End of file */