2 * PROJECT: ReactOS TDI driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/network/tdi/cte/timer.c
5 * PURPOSE: CTE timer support
6 * PROGRAMMERS: Oleg Baikalow (obaikalow@gmail.com)
9 /* INCLUDES *****************************************************************/
13 /* FIXME: Move to a common header! */
14 struct _CTE_DELAYED_EVENT
;
15 typedef void (*CTE_WORKER_ROUTINE
)(struct _CTE_DELAYED_EVENT
*, void *Context
);
17 typedef struct _CTE_TIMER
21 CTE_WORKER_ROUTINE Callback
;
25 } CTE_TIMER
, *PCTE_TIMER
;
27 LONG CteTimeIncrement
;
29 /* FUNCTIONS *****************************************************************/
33 InternalDpcRoutine(PKDPC Dpc
,
35 PVOID SystemArgument1
,
36 PVOID SystemArgument2
)
38 PCTE_TIMER Timer
= (PCTE_TIMER
)Context
;
40 /* Call our registered callback */
41 Timer
->Callback((struct _CTE_DELAYED_EVENT
*)Timer
, Timer
->Context
);
49 CTEInitTimer(PCTE_TIMER Timer
)
52 RtlZeroMemory(Timer
, sizeof(CTE_TIMER
));
54 /* Create a DPC and a timer */
55 KeInitializeDpc(&Timer
->Dpc
, InternalDpcRoutine
, Timer
);
56 KeInitializeTimer(&Timer
->Timer
);
64 CTEStartTimer(PCTE_TIMER Timer
,
66 CTE_WORKER_ROUTINE Callback
,
69 LARGE_INTEGER DueTime
;
71 /* Make sure a callback was provided */
74 /* We need to convert due time, because DueTimeShort is in ms,
75 but NT timer expects 100s of ns, negative one */
76 DueTime
.QuadPart
= -Int32x32To64(DueTimeShort
, 10000);
78 /* Set other timer members */
79 Timer
->Callback
= Callback
;
80 Timer
->Context
= Context
;
83 KeSetTimer(&Timer
->Timer
, DueTime
, &Timer
->Dpc
);
98 /* Get the tick count */
99 KeQueryTickCount(&Ticks
);
101 /* Convert to 100s of ns and then to ms*/
102 Ticks
.QuadPart
= (Ticks
.QuadPart
* CteTimeIncrement
) / 10000ULL;
104 return Ticks
.LowPart
;
114 /* Just return success */