From 6a52d123672b7a00af6e22b4c138205be2042a94 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sat, 6 Feb 2010 20:51:56 +0100 Subject: Reorganisation --- src/kernel/task/timer.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/kernel/task/timer.c (limited to 'src/kernel/task/timer.c') diff --git a/src/kernel/task/timer.c b/src/kernel/task/timer.c new file mode 100644 index 0000000..8c1a2b8 --- /dev/null +++ b/src/kernel/task/timer.c @@ -0,0 +1,36 @@ +#include "timer.h" +#include "idt.h" +#include +#include + +static uint32_t tick = 0, frequency = 0, uptime = 0; + +void timer_callback(struct registers *regs) { + tick++; + if (tick == frequency) { + uptime++; + tick = 0; + } +} + +uint32_t timer_uptime() { return uptime; } + +uint32_t timer_time() { + return (uptime * 1000) + (tick * 1000 / frequency); +} + +void timer_init(uint32_t freq) { + frequency = freq; + + idt_handleIrq(0, timer_callback); + + uint32_t divisor = 1193180 / freq; + + outb(0x43, 0x36); //Command byte + + uint8_t l = (divisor & 0xFF), h = (divisor >> 8); + outb(0x40, l); + outb(0x40, h); + + monitor_write("Timer started\n"); +} -- cgit v1.2.3