blob: 0e52d0ef4264109c39a33d9e68149ebf1ac0bbda [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(*regs);
}
}
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);
}