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
18 * - Nearly this entire file is PAGED_CODE (with the exception of the
19 * MiniportTimerDpc() function)
28 PVOID DeferredContext
,
29 PVOID SystemArgument1
,
30 PVOID SystemArgument2
)
32 * FUNCTION: Scheduled by the SetTimer family of functions
34 * Dpc: Pointer to the DPC Object being executed
35 * DeferredContext: Pointer to a NDIS_MINIPORT_TIMER object
36 * SystemArgument1: Unused.
37 * SystemArgument2: Unused.
39 * - runs at IRQL = DISPATCH_LEVEL
42 PNDIS_MINIPORT_TIMER Timer
;
44 Timer
= (PNDIS_MINIPORT_TIMER
)DeferredContext
;
46 ASSERT(Timer
->MiniportTimerFunction
);
48 Timer
->MiniportTimerFunction (NULL
, Timer
->MiniportTimerContext
, NULL
, NULL
);
59 OUT PBOOLEAN TimerCancelled
)
61 * FUNCTION: Cancels a scheduled NDIS timer
63 * Timer: pointer to an NDIS_TIMER object to cancel
64 * TimerCancelled: boolean that returns cancellation status
66 * - call at IRQL <= DISPATCH_LEVEL
72 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
81 NdisGetCurrentSystemTime (
82 IN OUT PLARGE_INTEGER pSystemTime
)
84 * FUNCTION: Retrieve the current system time
86 * pSystemTime: pointer to the returned system time
88 * - call at IRQL <= DISPATCH_LEVEL
94 KeQuerySystemTime (pSystemTime
);
104 IN OUT PNDIS_TIMER Timer
,
105 IN PNDIS_TIMER_FUNCTION TimerFunction
,
106 IN PVOID FunctionContext
)
108 * FUNCTION: Set up an NDIS_TIMER for later use
110 * Timer: pointer to caller-allocated storage to receive an NDIS_TIMER
111 * TimerFunction: function pointer to routine to run when timer expires
112 * FunctionContext: context (param 2) to be passed to the timer function when it runs
114 * - TimerFunction will be called at DISPATCH_LEVEL
115 * - call at IRQL = PASSIVE_LEVEL
121 KeInitializeTimer (&Timer
->Timer
);
123 KeInitializeDpc (&Timer
->Dpc
, (PKDEFERRED_ROUTINE
)TimerFunction
, FunctionContext
);
133 IN PNDIS_MINIPORT_TIMER Timer
,
134 OUT PBOOLEAN TimerCancelled
)
136 * FUNCTION: cancel a scheduled NDIS_MINIPORT_TIMER
138 * Timer: timer object to cancel
139 * TimerCancelled: status of cancel operation
141 * - call at IRQL <= DISPATCH_LEVEL
145 ASSERT(TimerCancelled
);
148 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
157 NdisMInitializeTimer(
158 IN OUT PNDIS_MINIPORT_TIMER Timer
,
159 IN NDIS_HANDLE MiniportAdapterHandle
,
160 IN PNDIS_TIMER_FUNCTION TimerFunction
,
161 IN PVOID FunctionContext
)
163 * FUNCTION: Initialize an NDIS_MINIPORT_TIMER
165 * Timer: Timer object to initialize
166 * MiniportAdapterHandle: Handle to the miniport, passed in to MiniportInitialize
167 * TimerFunction: function to be executed when the timer expires
168 * FunctionContext: argument passed to TimerFunction when it is called
170 * - TimerFunction is called at IRQL = DISPATCH_LEVEL
171 * - call at IRQL = PASSIVE_LEVEL
176 KeInitializeTimer (&Timer
->Timer
);
178 KeInitializeDpc (&Timer
->Dpc
, MiniportTimerDpc
, (PVOID
) Timer
);
180 Timer
->MiniportTimerFunction
= TimerFunction
;
181 Timer
->MiniportTimerContext
= FunctionContext
;
182 Timer
->Miniport
= MiniportAdapterHandle
;
191 NdisMSetPeriodicTimer(
192 IN PNDIS_MINIPORT_TIMER Timer
,
193 IN UINT MillisecondsPeriod
)
195 * FUNCTION: Set a timer to go off periodically
197 * Timer: pointer to the timer object to set
198 * MillisecondsPeriod: period of the timer
200 * - Minimum predictible interval is ~10ms
201 * - Must be called at IRQL <= DISPATCH_LEVEL)
204 LARGE_INTEGER Timeout
;
209 /* relative delays are negative, absolute are positive; resolution is 100ns */
210 Timeout
.QuadPart
= MillisecondsPeriod
* -10000;
212 KeSetTimerEx (&Timer
->Timer
, Timeout
, MillisecondsPeriod
, &Timer
->Dpc
);
222 IN PNDIS_MINIPORT_TIMER Timer
,
223 IN UINT MillisecondsToDelay
)
225 * FUNCTION: Set a NDIS_MINIPORT_TIMER so that it goes off
227 * Timer: timer object to set
228 * MillisecondsToDelay: time to wait for the timer to expire
230 * - Minimum predictible interval is ~10ms
231 * - Must be called at IRQL <= DISPATCH_LEVEL)
234 LARGE_INTEGER Timeout
;
239 /* relative delays are negative, absolute are positive; resolution is 100ns */
240 Timeout
.QuadPart
= MillisecondsToDelay
* -10000;
242 KeSetTimer (&Timer
->Timer
, Timeout
, &Timer
->Dpc
);
252 IN PNDIS_TIMER Timer
,
253 IN UINT MillisecondsToDelay
)
255 * FUNCTION: Set an NDIS_TIMER so that it goes off
257 * Timer: timer object to set
258 * MillisecondsToDelay: time to wait for the timer to expire
260 * - Minimum predictible interval is ~10ms
261 * - Must be called at IRQL <= DISPATCH_LEVEL)
264 LARGE_INTEGER Timeout
;
269 /* relative delays are negative, absolute are positive; resolution is 100ns */
270 Timeout
.QuadPart
= MillisecondsToDelay
* -10000;
272 KeSetTimer (&Timer
->Timer
, Timeout
, &Timer
->Dpc
);