toaruos/kernel/core/timer.c

42 lines
588 B
C
Raw Normal View History

2011-01-16 11:56:44 -05:00
#include <system.h>
void
timer_phase(
int hz
) {
int divisor = 1193180 / hz;
outportb(0x43, 0x36);
outportb(0x40, divisor & 0xFF);
2011-01-20 19:49:35 -06:00
outportb(0x40, (divisor >> 8) & 0xFF);
2011-01-16 11:56:44 -05:00
}
2011-01-17 18:22:48 -06:00
long timer_ticks = 0;
2011-01-16 11:56:44 -05:00
unsigned long ticker = 0;
void
timer_handler(
struct regs *r
) {
++timer_ticks;
2011-03-03 01:39:26 -06:00
#if 0
2011-01-16 11:56:44 -05:00
if (timer_ticks % 18 == 0) {
++ticker;
2011-01-16 11:56:44 -05:00
}
2011-03-03 01:39:26 -06:00
#endif
switch_task();
2011-01-16 11:56:44 -05:00
}
void timer_install() {
irq_install_handler(0, timer_handler);
timer_phase(100); /* 100Hz */
2011-01-16 11:56:44 -05:00
}
void
timer_wait(
int ticks
) {
2011-01-17 18:22:48 -06:00
long eticks;
eticks = (long)timer_ticks + (long)ticks;
2011-01-16 11:56:44 -05:00
while(timer_ticks < eticks);
}