Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1990-1995 Microsoft Corporation
  3. Module Name:
  4. timer.c
  5. Abstract:
  6. NDIS wrapper functions for full mac drivers isr/timer
  7. Author:
  8. Sean Selitrennikoff (SeanSe) 05-Oct-93
  9. Environment:
  10. Kernel mode, FSD
  11. Revision History:
  12. Jameel Hyder (JameelH) Re-organization 01-Jun-95
  13. --*/
  14. #include <precomp.h>
  15. #pragma hdrstop
  16. #include <stdarg.h>
  17. //
  18. // Define the module number for debug code.
  19. //
  20. #define MODULE_NUMBER MODULE_TIMER
  21. VOID
  22. NdisInitializeTimer(
  23. IN OUT PNDIS_TIMER NdisTimer,
  24. IN PNDIS_TIMER_FUNCTION TimerFunction,
  25. IN PVOID FunctionContext
  26. )
  27. /*++
  28. Routine Description:
  29. Sets up an NdisTimer object, initializing the DPC in the timer to
  30. the function and context.
  31. Arguments:
  32. NdisTimer - the timer object.
  33. TimerFunction - Routine to start.
  34. FunctionContext - Context of TimerFunction.
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. INITIALIZE_TIMER(&NdisTimer->Timer);
  40. //
  41. // Initialize our dpc. If Dpc was previously initialized, this will
  42. // reinitialize it.
  43. //
  44. INITIALIZE_DPC(&NdisTimer->Dpc,
  45. (PKDEFERRED_ROUTINE)TimerFunction,
  46. FunctionContext);
  47. SET_DPC_IMPORTANCE(&NdisTimer->Dpc);
  48. }
  49. VOID
  50. NdisSetTimer(
  51. IN PNDIS_TIMER NdisTimer,
  52. IN UINT MillisecondsToDelay
  53. )
  54. /*++
  55. Routine Description:
  56. Sets up TimerFunction to fire after MillisecondsToDelay.
  57. Arguments:
  58. NdisTimer - the timer object.
  59. MillisecondsToDelay - Amount of time before TimerFunction is started.
  60. Return Value:
  61. None.
  62. --*/
  63. {
  64. LARGE_INTEGER FireUpTime;
  65. if ((NdisTimer->Dpc.DeferredRoutine == ndisMTimerDpc) ||
  66. (NdisTimer->Dpc.DeferredRoutine == ndisMTimerDpcX))
  67. {
  68. NdisMSetTimer((PNDIS_MINIPORT_TIMER)NdisTimer, MillisecondsToDelay);
  69. }
  70. else
  71. {
  72. FireUpTime.QuadPart = Int32x32To64((LONG)MillisecondsToDelay, -10000);
  73. //
  74. // Set the timer
  75. //
  76. SET_TIMER(&NdisTimer->Timer, FireUpTime, &NdisTimer->Dpc);
  77. }
  78. }
  79. VOID
  80. NdisSetTimerEx(
  81. IN PNDIS_TIMER NdisTimer,
  82. IN UINT MillisecondsToDelay,
  83. IN PVOID FunctionContext
  84. )
  85. /*++
  86. Routine Description:
  87. Sets up TimerFunction to fire after MillisecondsToDelay.
  88. Arguments:
  89. NdisTimer - the timer object.
  90. MillisecondsToDelay - Amount of time before TimerFunction is started.
  91. FunctionContext - This over-rides the one specified via NdisInitializeTimer
  92. Return Value:
  93. None.
  94. --*/
  95. {
  96. LARGE_INTEGER FireUpTime;
  97. NdisTimer->Dpc.DeferredContext = FunctionContext;
  98. if ((NdisTimer->Dpc.DeferredRoutine == ndisMTimerDpc) ||
  99. (NdisTimer->Dpc.DeferredRoutine == ndisMTimerDpcX))
  100. {
  101. NdisMSetTimer((PNDIS_MINIPORT_TIMER)NdisTimer, MillisecondsToDelay);
  102. }
  103. else
  104. {
  105. FireUpTime.QuadPart = Int32x32To64((LONG)MillisecondsToDelay, -10000);
  106. //
  107. // Set the timer
  108. //
  109. SET_TIMER(&NdisTimer->Timer, FireUpTime, &NdisTimer->Dpc);
  110. }
  111. }
  112. VOID
  113. NdisCancelTimer(
  114. IN PNDIS_TIMER Timer,
  115. OUT PBOOLEAN TimerCancelled
  116. )
  117. {
  118. *TimerCancelled = KeCancelTimer(&Timer->Timer);
  119. }