:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / io / timer.c
1 /* $Id$
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 NTSTATUS
27 STDCALL
28 IoInitializeTimer(PDEVICE_OBJECT DeviceObject, 
29                            PIO_TIMER_ROUTINE TimerRoutine,
30                            PVOID Context)
31 /*
32  * FUNCTION: Sets up a driver-supplied IoTimer routine associated with a given
33  * device object
34  * ARGUMENTS:
35  *     DeviceObject = Device object whose timer is be initialized
36  *     TimerRoutine = Driver supplied routine which will be called once per
37  *                    second if the timer is active
38  *     Context = Driver supplied context to be passed to the TimerRoutine
39  * RETURNS: Status
40  */
41 {
42    DeviceObject->Timer = ExAllocatePoolWithTag(NonPagedPool, sizeof(IO_TIMER),
43                                                TAG_IO_TIMER);
44    KeInitializeTimer(&(DeviceObject->Timer->timer));
45    KeInitializeDpc(&(DeviceObject->Timer->dpc),
46                    (PKDEFERRED_ROUTINE)TimerRoutine,Context);
47    
48    return(STATUS_SUCCESS);
49 }
50
51 VOID
52 STDCALL
53 IoStartTimer(PDEVICE_OBJECT DeviceObject)
54 /*
55  * FUNCTION: Starts a timer so the driver-supplied IoTimer routine will be
56  * called once per second
57  * ARGUMENTS:
58  *       DeviceObject = Device whose timer is to be started
59  */
60 {
61    long long int lli;
62    LARGE_INTEGER li;
63    
64    lli = -1000000;
65    li = *(LARGE_INTEGER *)&lli;
66       
67    KeSetTimerEx(&DeviceObject->Timer->timer,
68                 li,
69                 1000,
70                 &(DeviceObject->Timer->dpc));
71 }
72
73 VOID
74 STDCALL
75 IoStopTimer(PDEVICE_OBJECT DeviceObject)
76 /*
77  * FUNCTION: Disables for a specified device object so the driver-supplied
78  * IoTimer is not called
79  * ARGUMENTS:
80  *        DeviceObject = Device whose timer is to be stopped
81  */
82 {
83    KeCancelTimer(&(DeviceObject->Timer->timer));
84 }
85
86
87 /* EOF */