skgehwt.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /******************************************************************************
  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. * (C)Copyright 1998,1999 SysKonnect,
  13. * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
  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. *
  25. * History:
  26. *
  27. * $Log: skgehwt.c,v $
  28. * Revision 1.13 1999/11/22 13:31:12 cgoos
  29. * Changed license header to GPL.
  30. *
  31. * Revision 1.12 1998/10/15 15:11:34 gklug
  32. * fix: ID_sccs to SysKonnectFileId
  33. *
  34. * Revision 1.11 1998/10/08 15:27:51 gklug
  35. * chg: correction factor is host clock dependent
  36. *
  37. * Revision 1.10 1998/09/15 14:18:31 cgoos
  38. * Changed more BOOLEANs to SK_xxx
  39. *
  40. * Revision 1.9 1998/09/15 14:16:06 cgoos
  41. * Changed line 107: FALSE to SK_FALSE
  42. *
  43. * Revision 1.8 1998/08/24 13:04:44 gklug
  44. * fix: typo
  45. *
  46. * Revision 1.7 1998/08/19 09:50:49 gklug
  47. * fix: remove struct keyword from c-code (see CCC) add typedefs
  48. *
  49. * Revision 1.6 1998/08/17 09:59:02 gklug
  50. * fix: typos
  51. *
  52. * Revision 1.5 1998/08/14 07:09:10 gklug
  53. * fix: chg pAc -> pAC
  54. *
  55. * Revision 1.4 1998/08/10 14:14:52 gklug
  56. * rmv: unneccessary SK_ADDR macro
  57. *
  58. * Revision 1.3 1998/08/07 12:53:44 gklug
  59. * fix: first compiled version
  60. *
  61. * Revision 1.2 1998/08/07 09:19:29 gklug
  62. * adapt functions to the C coding conventions
  63. * rmv unneccessary functions.
  64. *
  65. * Revision 1.1 1998/08/05 11:28:36 gklug
  66. * first version: adapted from SMT/FDDI
  67. *
  68. *
  69. *
  70. *
  71. ******************************************************************************/
  72. #include <config.h>
  73. /*
  74. Event queue and dispatcher
  75. */
  76. static const char SysKonnectFileId[] =
  77. "$Header: /usr56/projects/ge/schedule/skgehwt.c,v 1.13 1999/11/22 13:31:12 cgoos Exp $" ;
  78. #include "h/skdrv1st.h" /* Driver Specific Definitions */
  79. #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
  80. #ifdef __C2MAN__
  81. /*
  82. Hardware Timer function queue management.
  83. General Description:
  84. */
  85. intro()
  86. {}
  87. #endif
  88. /*
  89. * Prototypes of local functions.
  90. */
  91. #define SK_HWT_MAX (65000)
  92. /* correction factor */
  93. #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
  94. /*
  95. * Initialize hardware timer.
  96. *
  97. * Must be called during init level 1.
  98. */
  99. void SkHwtInit(
  100. SK_AC *pAC, /* Adapters context */
  101. SK_IOC Ioc) /* IoContext */
  102. {
  103. pAC->Hwt.TStart = 0 ;
  104. pAC->Hwt.TStop = 0 ;
  105. pAC->Hwt.TActive = SK_FALSE ;
  106. SkHwtStop(pAC,Ioc) ;
  107. }
  108. /*
  109. *
  110. * Start hardware timer (clock ticks are 16us).
  111. *
  112. */
  113. void SkHwtStart(
  114. SK_AC *pAC, /* Adapters context */
  115. SK_IOC Ioc, /* IoContext */
  116. SK_U32 Time) /* Time in units of 16us to load the timer with. */
  117. {
  118. SK_U32 Cnt ;
  119. if (Time > SK_HWT_MAX)
  120. Time = SK_HWT_MAX ;
  121. pAC->Hwt.TStart = Time ;
  122. pAC->Hwt.TStop = 0L ;
  123. Cnt = Time ;
  124. /*
  125. * if time < 16 us
  126. * time = 16 us
  127. */
  128. if (!Cnt) {
  129. Cnt++ ;
  130. }
  131. SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
  132. SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ; /* Start timer. */
  133. pAC->Hwt.TActive = SK_TRUE ;
  134. }
  135. /*
  136. * Stop hardware timer.
  137. * and clear the timer IRQ
  138. */
  139. void SkHwtStop(
  140. SK_AC *pAC, /* Adapters context */
  141. SK_IOC Ioc) /* IoContext */
  142. {
  143. SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
  144. SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
  145. pAC->Hwt.TActive = SK_FALSE ;
  146. }
  147. /*
  148. * Stop hardware timer and read time elapsed since last start.
  149. *
  150. * returns
  151. * The elapsed time since last start in units of 16us.
  152. *
  153. */
  154. SK_U32 SkHwtRead(
  155. SK_AC *pAC, /* Adapters context */
  156. SK_IOC Ioc) /* IoContext */
  157. {
  158. SK_U32 TRead ;
  159. SK_U32 IStatus ;
  160. if (pAC->Hwt.TActive) {
  161. SkHwtStop(pAC,Ioc) ;
  162. SK_IN32(Ioc, B2_TI_VAL, &TRead);
  163. TRead /= SK_HWT_FAC;
  164. SK_IN32(Ioc, B0_ISRC, &IStatus);
  165. /* Check if timer expired (or wraparound). */
  166. if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
  167. SkHwtStop(pAC,Ioc) ;
  168. pAC->Hwt.TStop = pAC->Hwt.TStart ;
  169. } else {
  170. pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
  171. }
  172. }
  173. return (pAC->Hwt.TStop) ;
  174. }
  175. /*
  176. * interrupt source= timer
  177. */
  178. void SkHwtIsr(
  179. SK_AC *pAC, /* Adapters context */
  180. SK_IOC Ioc) /* IoContext */
  181. {
  182. SkHwtStop(pAC,Ioc);
  183. pAC->Hwt.TStop = pAC->Hwt.TStart;
  184. SkTimerDone(pAC,Ioc) ;
  185. }
  186. /* End of file */