blob: 72ff1c66cb14b33203592e294e73604745a4ab2e [file] [log] [blame]
swissChilidefeb0d2021-02-18 15:28:36 -08001#include "timer.h"
2#include "pic.h"
3#include "log.h"
4#include "registers.h"
5#include "io.h"
6
7static ulong tick = 0;
8
9static void timer_cb(struct registers regs)
10{
11 kprintf("Timer tick %d\n", tick++);
12}
13
14void init_timer(uint hz)
15{
16 add_interrupt_handler(IRQ_TO_INT(0), timer_cb);
17
18 uint divisor = TIMER_FREQ / hz;
19
20 kprintf("Divisor is %d\n", divisor);
21
22 outb(0x43, 0x36);
23 io_wait();
24 uchar l = divisor & 0xff,
25 h = (divisor >> 8) & 0xff;
26
27 outb(0x40, l);
28 io_wait();
29 outb(0x40, h);
30 io_wait();
31
32 kprintf("Initialized timer\n");
33}