1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS TDI driver
3*c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4*c2c66affSColin Finck * FILE: drivers/network/tdi/cte/timer.c
5*c2c66affSColin Finck * PURPOSE: CTE timer support
6*c2c66affSColin Finck * PROGRAMMERS: Oleg Baikalow (obaikalow@gmail.com)
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck /* INCLUDES *****************************************************************/
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include "precomp.h"
12*c2c66affSColin Finck
13*c2c66affSColin Finck /* FIXME: Move to a common header! */
14*c2c66affSColin Finck struct _CTE_DELAYED_EVENT;
15*c2c66affSColin Finck typedef void (*CTE_WORKER_ROUTINE)(struct _CTE_DELAYED_EVENT *, void *Context);
16*c2c66affSColin Finck
17*c2c66affSColin Finck typedef struct _CTE_TIMER
18*c2c66affSColin Finck {
19*c2c66affSColin Finck BOOLEAN Queued;
20*c2c66affSColin Finck KSPIN_LOCK Lock;
21*c2c66affSColin Finck CTE_WORKER_ROUTINE Callback;
22*c2c66affSColin Finck PVOID Context;
23*c2c66affSColin Finck KDPC Dpc;
24*c2c66affSColin Finck KTIMER Timer;
25*c2c66affSColin Finck } CTE_TIMER, *PCTE_TIMER;
26*c2c66affSColin Finck
27*c2c66affSColin Finck LONG CteTimeIncrement;
28*c2c66affSColin Finck
29*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
30*c2c66affSColin Finck
31*c2c66affSColin Finck VOID
32*c2c66affSColin Finck NTAPI
InternalDpcRoutine(PKDPC Dpc,PVOID Context,PVOID SystemArgument1,PVOID SystemArgument2)33*c2c66affSColin Finck InternalDpcRoutine(PKDPC Dpc,
34*c2c66affSColin Finck PVOID Context,
35*c2c66affSColin Finck PVOID SystemArgument1,
36*c2c66affSColin Finck PVOID SystemArgument2)
37*c2c66affSColin Finck {
38*c2c66affSColin Finck PCTE_TIMER Timer = (PCTE_TIMER)Context;
39*c2c66affSColin Finck
40*c2c66affSColin Finck /* Call our registered callback */
41*c2c66affSColin Finck Timer->Callback((struct _CTE_DELAYED_EVENT *)Timer, Timer->Context);
42*c2c66affSColin Finck }
43*c2c66affSColin Finck
44*c2c66affSColin Finck /*
45*c2c66affSColin Finck * @implemented
46*c2c66affSColin Finck */
47*c2c66affSColin Finck VOID
48*c2c66affSColin Finck NTAPI
CTEInitTimer(PCTE_TIMER Timer)49*c2c66affSColin Finck CTEInitTimer(PCTE_TIMER Timer)
50*c2c66affSColin Finck {
51*c2c66affSColin Finck /* Zero all fields */
52*c2c66affSColin Finck RtlZeroMemory(Timer, sizeof(CTE_TIMER));
53*c2c66affSColin Finck
54*c2c66affSColin Finck /* Create a DPC and a timer */
55*c2c66affSColin Finck KeInitializeDpc(&Timer->Dpc, InternalDpcRoutine, Timer);
56*c2c66affSColin Finck KeInitializeTimer(&Timer->Timer);
57*c2c66affSColin Finck }
58*c2c66affSColin Finck
59*c2c66affSColin Finck /*
60*c2c66affSColin Finck * @implemented
61*c2c66affSColin Finck */
62*c2c66affSColin Finck BOOLEAN
63*c2c66affSColin Finck NTAPI
CTEStartTimer(PCTE_TIMER Timer,ULONG DueTimeShort,CTE_WORKER_ROUTINE Callback,PVOID Context)64*c2c66affSColin Finck CTEStartTimer(PCTE_TIMER Timer,
65*c2c66affSColin Finck ULONG DueTimeShort,
66*c2c66affSColin Finck CTE_WORKER_ROUTINE Callback,
67*c2c66affSColin Finck PVOID Context)
68*c2c66affSColin Finck {
69*c2c66affSColin Finck LARGE_INTEGER DueTime;
70*c2c66affSColin Finck
71*c2c66affSColin Finck /* Make sure a callback was provided */
72*c2c66affSColin Finck ASSERT(Callback);
73*c2c66affSColin Finck
74*c2c66affSColin Finck /* We need to convert due time, because DueTimeShort is in ms,
75*c2c66affSColin Finck but NT timer expects 100s of ns, negative one */
76*c2c66affSColin Finck DueTime.QuadPart = -Int32x32To64(DueTimeShort, 10000);
77*c2c66affSColin Finck
78*c2c66affSColin Finck /* Set other timer members */
79*c2c66affSColin Finck Timer->Callback = Callback;
80*c2c66affSColin Finck Timer->Context = Context;
81*c2c66affSColin Finck
82*c2c66affSColin Finck /* Set the timer */
83*c2c66affSColin Finck KeSetTimer(&Timer->Timer, DueTime, &Timer->Dpc);
84*c2c66affSColin Finck
85*c2c66affSColin Finck return TRUE;
86*c2c66affSColin Finck }
87*c2c66affSColin Finck
88*c2c66affSColin Finck
89*c2c66affSColin Finck /*
90*c2c66affSColin Finck * @implemented
91*c2c66affSColin Finck */
92*c2c66affSColin Finck ULONG
93*c2c66affSColin Finck NTAPI
CTESystemUpTime(VOID)94*c2c66affSColin Finck CTESystemUpTime(VOID)
95*c2c66affSColin Finck {
96*c2c66affSColin Finck LARGE_INTEGER Ticks;
97*c2c66affSColin Finck
98*c2c66affSColin Finck /* Get the tick count */
99*c2c66affSColin Finck KeQueryTickCount(&Ticks);
100*c2c66affSColin Finck
101*c2c66affSColin Finck /* Convert to 100s of ns and then to ms*/
102*c2c66affSColin Finck Ticks.QuadPart = (Ticks.QuadPart * CteTimeIncrement) / 10000ULL;
103*c2c66affSColin Finck
104*c2c66affSColin Finck return Ticks.LowPart;
105*c2c66affSColin Finck }
106*c2c66affSColin Finck
107*c2c66affSColin Finck /*
108*c2c66affSColin Finck * @implemented
109*c2c66affSColin Finck */
110*c2c66affSColin Finck BOOLEAN
111*c2c66affSColin Finck NTAPI
CTEInitialize(VOID)112*c2c66affSColin Finck CTEInitialize(VOID)
113*c2c66affSColin Finck {
114*c2c66affSColin Finck /* Just return success */
115*c2c66affSColin Finck return TRUE;
116*c2c66affSColin Finck }
117*c2c66affSColin Finck
118*c2c66affSColin Finck /* EOF */
119