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