skgehwt.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. #ifdef CONFIG_SK98
  74. /*
  75. Event queue and dispatcher
  76. */
  77. static const char SysKonnectFileId[] =
  78. "$Header: /usr56/projects/ge/schedule/skgehwt.c,v 1.13 1999/11/22 13:31:12 cgoos Exp $" ;
  79. #include "h/skdrv1st.h" /* Driver Specific Definitions */
  80. #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
  81. #ifdef __C2MAN__
  82. /*
  83. Hardware Timer function queue management.
  84. General Description:
  85. */
  86. intro()
  87. {}
  88. #endif
  89. /*
  90. * Prototypes of local functions.
  91. */
  92. #define SK_HWT_MAX (65000)
  93. /* correction factor */
  94. #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
  95. /*
  96. * Initialize hardware timer.
  97. *
  98. * Must be called during init level 1.
  99. */
  100. void SkHwtInit(
  101. SK_AC *pAC, /* Adapters context */
  102. SK_IOC Ioc) /* IoContext */
  103. {
  104. pAC->Hwt.TStart = 0 ;
  105. pAC->Hwt.TStop = 0 ;
  106. pAC->Hwt.TActive = SK_FALSE ;
  107. SkHwtStop(pAC,Ioc) ;
  108. }
  109. /*
  110. *
  111. * Start hardware timer (clock ticks are 16us).
  112. *
  113. */
  114. void SkHwtStart(
  115. SK_AC *pAC, /* Adapters context */
  116. SK_IOC Ioc, /* IoContext */
  117. SK_U32 Time) /* Time in units of 16us to load the timer with. */
  118. {
  119. SK_U32 Cnt ;
  120. if (Time > SK_HWT_MAX)
  121. Time = SK_HWT_MAX ;
  122. pAC->Hwt.TStart = Time ;
  123. pAC->Hwt.TStop = 0L ;
  124. Cnt = Time ;
  125. /*
  126. * if time < 16 us
  127. * time = 16 us
  128. */
  129. if (!Cnt) {
  130. Cnt++ ;
  131. }
  132. SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
  133. SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ; /* Start timer. */
  134. pAC->Hwt.TActive = SK_TRUE ;
  135. }
  136. /*
  137. * Stop hardware timer.
  138. * and clear the timer IRQ
  139. */
  140. void SkHwtStop(
  141. SK_AC *pAC, /* Adapters context */
  142. SK_IOC Ioc) /* IoContext */
  143. {
  144. SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
  145. SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
  146. pAC->Hwt.TActive = SK_FALSE ;
  147. }
  148. /*
  149. * Stop hardware timer and read time elapsed since last start.
  150. *
  151. * returns
  152. * The elapsed time since last start in units of 16us.
  153. *
  154. */
  155. SK_U32 SkHwtRead(
  156. SK_AC *pAC, /* Adapters context */
  157. SK_IOC Ioc) /* IoContext */
  158. {
  159. SK_U32 TRead ;
  160. SK_U32 IStatus ;
  161. if (pAC->Hwt.TActive) {
  162. SkHwtStop(pAC,Ioc) ;
  163. SK_IN32(Ioc, B2_TI_VAL, &TRead);
  164. TRead /= SK_HWT_FAC;
  165. SK_IN32(Ioc, B0_ISRC, &IStatus);
  166. /* Check if timer expired (or wraparound). */
  167. if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
  168. SkHwtStop(pAC,Ioc) ;
  169. pAC->Hwt.TStop = pAC->Hwt.TStart ;
  170. } else {
  171. pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
  172. }
  173. }
  174. return (pAC->Hwt.TStop) ;
  175. }
  176. /*
  177. * interrupt source= timer
  178. */
  179. void SkHwtIsr(
  180. SK_AC *pAC, /* Adapters context */
  181. SK_IOC Ioc) /* IoContext */
  182. {
  183. SkHwtStop(pAC,Ioc);
  184. pAC->Hwt.TStop = pAC->Hwt.TStart;
  185. SkTimerDone(pAC,Ioc) ;
  186. }
  187. #endif /* CONFIG_SK98 */
  188. /* End of file */