From 11ced165e0df11cc3c889eb0cc402467361c421b Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Thu, 1 Sep 2022 23:45:47 +0200 Subject: timer & stdbuff --- kernel/src/devices/timer.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 kernel/src/devices/timer.c (limited to 'kernel/src/devices/timer.c') diff --git a/kernel/src/devices/timer.c b/kernel/src/devices/timer.c new file mode 100644 index 0000000..1291219 --- /dev/null +++ b/kernel/src/devices/timer.c @@ -0,0 +1,27 @@ +#include +#include +#include + +uint32_t tick = 0; +uint32_t seconds = 0; + +void timer_handler() +{ + tick++; + if (tick > TICKS_PER_SECOND) { + tick = 0; + seconds++; + } +} + +void init_timer(uint32_t frequency) +{ + uint32_t divisor = 1193180 / frequency; + outb(0x43, 0x36); + + uint8_t l = (uint8_t)(divisor & 0xFF); + uint8_t h = (uint8_t)((divisor>>8) & 0xFF); + + outb(0x40, l); + outb(0x40, h); +} -- cgit v1.2.3