blob: d17025cf5cb410b3087c32d1dfa29af07122015d [file] [log] [blame]
swissChilidefeb0d2021-02-18 15:28:36 -08001#include "timer.h"
swissChilidefeb0d2021-02-18 15:28:36 -08002#include "io.h"
swissChili825d46b2021-02-21 10:14:16 -08003#include "log.h"
4#include "pic.h"
5#include "registers.h"
swissChilidefeb0d2021-02-18 15:28:36 -08006
7static ulong tick = 0;
8
swissChili19ef4182021-02-21 17:45:51 -08009static void timer_cb(struct registers *regs)
swissChilidefeb0d2021-02-18 15:28:36 -080010{
swissChili19ef4182021-02-21 17:45:51 -080011 // do nothing :)
swissChilidefeb0d2021-02-18 15:28:36 -080012}
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
swissChilidefeb0d2021-02-18 15:28:36 -080020 outb(0x43, 0x36);
21 io_wait();
swissChili825d46b2021-02-21 10:14:16 -080022 uchar l = divisor & 0xff, h = (divisor >> 8) & 0xff;
swissChilidefeb0d2021-02-18 15:28:36 -080023
24 outb(0x40, l);
25 io_wait();
26 outb(0x40, h);
27 io_wait();
swissChilidefeb0d2021-02-18 15:28:36 -080028}