67d04c2f6fe7e41eccec83bb785cb6b6bb433052
[reactos.git] / reactos / ntoskrnl / io / timer.c
1 /* $Id: timer.c,v 1.11 2003/12/30 18:52:04 fireball Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/timer.c
6 * PURPOSE: io timers
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/pool.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* GLBOALS *******************************************************************/
21
22 #define TAG_IO_TIMER TAG('I', 'O', 'T', 'M')
23
24 /* FUNCTIONS *****************************************************************/
25
26 static VOID STDCALL
27 IoTimerCallback(IN PKDPC Dpc,
28 IN PVOID DeferredContext,
29 IN PVOID SystemArgument1,
30 IN PVOID SystemArgument2)
31 {
32 PIO_TIMER Timer = (PIO_TIMER) DeferredContext;
33
34 Timer->TimerRoutine(Timer->DeviceObject, Timer->Context);
35 }
36
37 /*
38 * @implemented
39 */
40 NTSTATUS
41 STDCALL
42 IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
43 PIO_TIMER_ROUTINE TimerRoutine,
44 PVOID Context)
45 /*
46 * FUNCTION: Sets up a driver-supplied IoTimer routine associated with a given
47 * device object
48 * ARGUMENTS:
49 * DeviceObject = Device object whose timer is be initialized
50 * TimerRoutine = Driver supplied routine which will be called once per
51 * second if the timer is active
52 * Context = Driver supplied context to be passed to the TimerRoutine
53 * RETURNS: Status
54 */
55 {
56 DeviceObject->Timer = ExAllocatePoolWithTag(NonPagedPool, sizeof(IO_TIMER),
57 TAG_IO_TIMER);
58 DeviceObject->Timer->DeviceObject = DeviceObject;
59 DeviceObject->Timer->TimerRoutine = TimerRoutine;
60 DeviceObject->Timer->Context = Context;
61 KeInitializeTimer(&(DeviceObject->Timer->timer));
62 KeInitializeDpc(&(DeviceObject->Timer->dpc),
63 IoTimerCallback, DeviceObject->Timer);
64
65 return(STATUS_SUCCESS);
66 }
67
68 /*
69 * @implemented
70 */
71 VOID
72 STDCALL
73 IoStartTimer(PDEVICE_OBJECT DeviceObject)
74 /*
75 * FUNCTION: Starts a timer so the driver-supplied IoTimer routine will be
76 * called once per second
77 * ARGUMENTS:
78 * DeviceObject = Device whose timer is to be started
79 */
80 {
81 LONGLONG lli;
82 LARGE_INTEGER li;
83
84 lli = -1000000;
85 li = *(LARGE_INTEGER *)&lli;
86
87 KeSetTimerEx(&DeviceObject->Timer->timer,
88 li,
89 1000,
90 &(DeviceObject->Timer->dpc));
91 }
92
93 /*
94 * @implemented
95 */
96 VOID
97 STDCALL
98 IoStopTimer(PDEVICE_OBJECT DeviceObject)
99 /*
100 * FUNCTION: Disables for a specified device object so the driver-supplied
101 * IoTimer is not called
102 * ARGUMENTS:
103 * DeviceObject = Device whose timer is to be stopped
104 */
105 {
106 KeCancelTimer(&(DeviceObject->Timer->timer));
107 }
108
109
110 /* EOF */