2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
3 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
6 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
7 * Distributed under the terms of the NewOS License.
11 #include <arch/x86/timer.h>
18 static bool sPITTimerInitialized
= false;
20 struct timer_info gPITTimer
= {
23 &pit_set_hardware_timer
,
24 &pit_clear_hardware_timer
,
37 pit_timer_interrupt(void *data
)
39 return timer_interrupt();
44 pit_set_hardware_timer(bigtime_t relativeTimeout
)
46 uint16 nextEventClocks
;
48 if (relativeTimeout
<= 0)
50 else if (relativeTimeout
< PIT_MAX_TIMER_INTERVAL
)
51 nextEventClocks
= relativeTimeout
* PIT_CLOCK_RATE
/ 1000000;
53 nextEventClocks
= 0xffff;
55 out8(PIT_SELCH0
| PIT_RWBOTH
| PIT_MD_INTON0
, PIT_CTRL
);
56 out8(nextEventClocks
& 0xff, PIT_CNT0
);
57 out8((nextEventClocks
>> 8) & 0xff, PIT_CNT0
);
59 arch_int_enable_io_interrupt(0);
65 pit_clear_hardware_timer(void)
67 arch_int_disable_io_interrupt(0);
73 pit_init(struct kernel_args
*args
)
75 if (sPITTimerInitialized
) {
79 install_io_interrupt_handler(0, &pit_timer_interrupt
, NULL
, 0);
80 pit_clear_hardware_timer();
82 sPITTimerInitialized
= true;