blob: be177f93e461a806302506f4dfae1320fe6ebab5 [file] [log] [blame]
#include "timer.h"
#include "io.h"
#include "log.h"
#include "pic.h"
#include "registers.h"
#include "task.h"
static ulong tick = 0;
static void timer_cb(struct registers *regs)
{
if (tasks_initialized)
{
// Preemptive multitasking!
switch_task();
}
}
void init_timer(uint hz)
{
add_interrupt_handler(IRQ_TO_INT(0), timer_cb);
uint divisor = TIMER_FREQ / hz;
outb(0x43, 0x36);
uchar l = divisor & 0xff, h = (divisor >> 8) & 0xff;
outb(0x40, l);
outb(0x40, h);
}