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
26 PVOID DeferredContext
,
27 PVOID SystemArgument1
,
28 PVOID SystemArgument2
)
30 * FUNCTION: Scheduled by the SetTimer family of functions
32 * Dpc: Pointer to the DPC Object being executed
33 * DeferredContext: Pointer to a NDIS_MINIPORT_TIMER object
34 * SystemArgument1: Unused.
35 * SystemArgument2: Unused.
37 * - runs at IRQL = DISPATCH_LEVEL
40 PNDIS_MINIPORT_TIMER Timer
;
42 Timer
= (PNDIS_MINIPORT_TIMER
)DeferredContext
;
44 ASSERT(Timer
->MiniportTimerFunction
);
46 Timer
->MiniportTimerFunction (NULL
, Timer
->MiniportTimerContext
, NULL
, NULL
);
57 OUT PBOOLEAN TimerCancelled
)
59 * FUNCTION: Cancels a scheduled NDIS timer
61 * Timer: pointer to an NDIS_TIMER object to cancel
62 * TimerCancelled: boolean that returns cancellation status
64 * - call at IRQL <= DISPATCH_LEVEL
67 ASSERT_IRQL(DISPATCH_LEVEL
);
70 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
77 #undef NdisGetCurrentSystemTime
80 NdisGetCurrentSystemTime (
81 IN OUT PLARGE_INTEGER pSystemTime
)
83 * FUNCTION: Retrieve the current system time
85 * pSystemTime: pointer to the returned system time
87 * - call at IRQL <= DISPATCH_LEVEL
90 ASSERT_IRQL(DISPATCH_LEVEL
);
93 KeQuerySystemTime (pSystemTime
);
103 IN OUT PNDIS_TIMER Timer
,
104 IN PNDIS_TIMER_FUNCTION TimerFunction
,
105 IN PVOID FunctionContext
)
107 * FUNCTION: Set up an NDIS_TIMER for later use
109 * Timer: pointer to caller-allocated storage to receive an NDIS_TIMER
110 * TimerFunction: function pointer to routine to run when timer expires
111 * FunctionContext: context (param 2) to be passed to the timer function when it runs
113 * - TimerFunction will be called at DISPATCH_LEVEL
114 * - call at IRQL = PASSIVE_LEVEL
120 KeInitializeTimer (&Timer
->Timer
);
122 KeInitializeDpc (&Timer
->Dpc
, (PKDEFERRED_ROUTINE
)TimerFunction
, FunctionContext
);
132 IN PNDIS_MINIPORT_TIMER Timer
,
133 OUT PBOOLEAN TimerCancelled
)
135 * FUNCTION: cancel a scheduled NDIS_MINIPORT_TIMER
137 * Timer: timer object to cancel
138 * TimerCancelled: status of cancel operation
140 * - call at IRQL <= DISPATCH_LEVEL
143 ASSERT_IRQL(DISPATCH_LEVEL
);
144 ASSERT(TimerCancelled
);
147 *TimerCancelled
= KeCancelTimer (&Timer
->Timer
);
156 NdisMInitializeTimer(
157 IN OUT PNDIS_MINIPORT_TIMER Timer
,
158 IN NDIS_HANDLE MiniportAdapterHandle
,
159 IN PNDIS_TIMER_FUNCTION TimerFunction
,
160 IN PVOID FunctionContext
)
162 * FUNCTION: Initialize an NDIS_MINIPORT_TIMER
164 * Timer: Timer object to initialize
165 * MiniportAdapterHandle: Handle to the miniport, passed in to MiniportInitialize
166 * TimerFunction: function to be executed when the timer expires
167 * FunctionContext: argument passed to TimerFunction when it is called
169 * - TimerFunction is called at IRQL = DISPATCH_LEVEL
170 * - call at IRQL = PASSIVE_LEVEL
175 KeInitializeTimer (&Timer
->Timer
);
177 KeInitializeDpc (&Timer
->Dpc
, MiniportTimerDpc
, (PVOID
) Timer
);
179 Timer
->MiniportTimerFunction
= TimerFunction
;
180 Timer
->MiniportTimerContext
= FunctionContext
;
181 Timer
->Miniport
= MiniportAdapterHandle
;
190 NdisMSetPeriodicTimer(
191 IN PNDIS_MINIPORT_TIMER Timer
,
192 IN UINT MillisecondsPeriod
)
194 * FUNCTION: Set a timer to go off periodically
196 * Timer: pointer to the timer object to set
197 * MillisecondsPeriod: period of the timer
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(MillisecondsPeriod
, -10000);
211 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
;
236 ASSERT_IRQL(DISPATCH_LEVEL
);
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
;
266 ASSERT_IRQL(DISPATCH_LEVEL
);
269 /* relative delays are negative, absolute are positive; resolution is 100ns */
270 Timeout
.QuadPart
= MillisecondsToDelay
* -10000;
272 KeSetTimer (&Timer
->Timer
, Timeout
, &Timer
->Dpc
);