2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
5 * PURPOSE: Time related routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Vizzini (vizzini@plasmic.com)
9 * CSH 01/08-2000 Created
10 * Vizzini 08-Oct-2003 Formatting, commenting, and ASSERTs
13 * - Although the standard kernel-mode M.O. is to trust the caller
14 * to not provide bad arguments, we have added lots of argument
15 * validation to assist in the effort to get third-party binaries
16 * working. It is easiest to track bugs when things break quickly
30 OUT PBOOLEAN TimerCancelled
)
32 * FUNCTION: Cancels a scheduled NDIS timer
34 * Timer: pointer to an NDIS_TIMER object to cancel
35 * TimerCancelled: boolean that returns cancellation status
37 * - call at IRQL <= DISPATCH_LEVEL
40 ASSERT_IRQL(DISPATCH_LEVEL
);
43 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
50 #undef NdisGetCurrentSystemTime
53 NdisGetCurrentSystemTime (
54 IN OUT PLARGE_INTEGER pSystemTime
)
56 * FUNCTION: Retrieve the current system time
58 * pSystemTime: pointer to the returned system time
60 * - call at IRQL <= DISPATCH_LEVEL
63 ASSERT_IRQL(DISPATCH_LEVEL
);
66 KeQuerySystemTime (pSystemTime
);
76 IN OUT PNDIS_TIMER Timer
,
77 IN PNDIS_TIMER_FUNCTION TimerFunction
,
78 IN PVOID FunctionContext
)
80 * FUNCTION: Set up an NDIS_TIMER for later use
82 * Timer: pointer to caller-allocated storage to receive an NDIS_TIMER
83 * TimerFunction: function pointer to routine to run when timer expires
84 * FunctionContext: context (param 2) to be passed to the timer function when it runs
86 * - TimerFunction will be called at DISPATCH_LEVEL
87 * - call at IRQL = PASSIVE_LEVEL
93 KeInitializeTimer (&Timer
->Timer
);
95 KeInitializeDpc (&Timer
->Dpc
, (PKDEFERRED_ROUTINE
)TimerFunction
, FunctionContext
);
105 IN PNDIS_MINIPORT_TIMER Timer
,
106 OUT PBOOLEAN TimerCancelled
)
108 * FUNCTION: cancel a scheduled NDIS_MINIPORT_TIMER
110 * Timer: timer object to cancel
111 * TimerCancelled: status of cancel operation
113 * - call at IRQL <= DISPATCH_LEVEL
116 ASSERT_IRQL(DISPATCH_LEVEL
);
117 ASSERT(TimerCancelled
);
120 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
129 NdisMInitializeTimer(
130 IN OUT PNDIS_MINIPORT_TIMER Timer
,
131 IN NDIS_HANDLE MiniportAdapterHandle
,
132 IN PNDIS_TIMER_FUNCTION TimerFunction
,
133 IN PVOID FunctionContext
)
135 * FUNCTION: Initialize an NDIS_MINIPORT_TIMER
137 * Timer: Timer object to initialize
138 * MiniportAdapterHandle: Handle to the miniport, passed in to MiniportInitialize
139 * TimerFunction: function to be executed when the timer expires
140 * FunctionContext: argument passed to TimerFunction when it is called
142 * - TimerFunction is called at IRQL = DISPATCH_LEVEL
143 * - call at IRQL = PASSIVE_LEVEL
148 KeInitializeTimer (&Timer
->Timer
);
150 KeInitializeDpc (&Timer
->Dpc
, (PKDEFERRED_ROUTINE
)TimerFunction
, FunctionContext
);
159 NdisMSetPeriodicTimer(
160 IN PNDIS_MINIPORT_TIMER Timer
,
161 IN UINT MillisecondsPeriod
)
163 * FUNCTION: Set a timer to go off periodically
165 * Timer: pointer to the timer object to set
166 * MillisecondsPeriod: period of the timer
168 * - Minimum predictible interval is ~10ms
169 * - Must be called at IRQL <= DISPATCH_LEVEL
172 LARGE_INTEGER Timeout
;
174 ASSERT_IRQL(DISPATCH_LEVEL
);
177 /* relative delays are negative, absolute are positive; resolution is 100ns */
178 Timeout
.QuadPart
= Int32x32To64(MillisecondsPeriod
, -10000);
180 KeSetTimerEx (&Timer
->Timer
, Timeout
, MillisecondsPeriod
, &Timer
->Dpc
);
191 IN PNDIS_MINIPORT_TIMER Timer
,
192 IN UINT MillisecondsToDelay
)
194 * FUNCTION: Set a NDIS_MINIPORT_TIMER so that it goes off
196 * Timer: timer object to set
197 * MillisecondsToDelay: time to wait for the timer to expire
199 * - Minimum predictible interval is ~10ms
200 * - Must be called at IRQL <= DISPATCH_LEVEL
203 LARGE_INTEGER Timeout
;
205 ASSERT_IRQL(DISPATCH_LEVEL
);
208 /* relative delays are negative, absolute are positive; resolution is 100ns */
209 Timeout
.QuadPart
= Int32x32To64(MillisecondsToDelay
, -10000);
211 KeSetTimer (&Timer
->Timer
, Timeout
, &Timer
->Dpc
);
221 IN PNDIS_TIMER Timer
,
222 IN UINT MillisecondsToDelay
)
224 * FUNCTION: Set an NDIS_TIMER so that it goes off
226 * Timer: timer object to set
227 * MillisecondsToDelay: time to wait for the timer to expire
229 * - Minimum predictible interval is ~10ms
230 * - Must be called at IRQL <= DISPATCH_LEVEL
233 LARGE_INTEGER Timeout
;
235 ASSERT_IRQL(DISPATCH_LEVEL
);
238 NDIS_DbgPrint(MAX_TRACE
, ("Called. Timer is: 0x%x, Timeout is: %ld\n", Timer
, MillisecondsToDelay
));
240 /* relative delays are negative, absolute are positive; resolution is 100ns */
241 Timeout
.QuadPart
= Int32x32To64(MillisecondsToDelay
, -10000);
243 KeSetTimer (&Timer
->Timer
, Timeout
, &Timer
->Dpc
);
252 IN PNDIS_TIMER Timer
,
253 IN UINT MillisecondsToDelay
,
254 IN PVOID FunctionContext
)
256 NDIS_DbgPrint(MAX_TRACE
, ("Called. Timer is: 0x%x, Timeout is: %ld, FunctionContext is: 0x%x\n",
257 Timer
, MillisecondsToDelay
, FunctionContext
));
259 Timer
->Dpc
.DeferredContext
= FunctionContext
;
261 NdisSetTimer(Timer
, MillisecondsToDelay
);