diff options
| author | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-09-01 23:45:47 +0200 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-09-01 23:45:47 +0200 |
| commit | 11ced165e0df11cc3c889eb0cc402467361c421b (patch) | |
| tree | ba6456fdae72e0deff0130612f226cd5d94aea17 /kernel/src/devices/timer.c | |
| parent | 9a54c41ad07ec00316bb8fcdeba51c215446d454 (diff) | |
timer & stdbuff
Diffstat (limited to 'kernel/src/devices/timer.c')
| -rw-r--r-- | kernel/src/devices/timer.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 <timer.h> +#include <libk/stdio.h> +#include <io.h> + +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); +} |
