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