diff options
author | Marvin Borner | 2019-09-15 15:11:17 +0200 |
---|---|---|
committer | Marvin Borner | 2019-09-15 15:11:17 +0200 |
commit | d3bb62c3b99b3b7108de0c2aa4d1d1ead0bd3fb8 (patch) | |
tree | 7cb8f5b8d099448ec7f518085e261eda67caf202 /src/timer/timer.c | |
parent | 4292369d5c80afe71479228e79969855f449f1c3 (diff) |
Added system clock support
Diffstat (limited to 'src/timer/timer.c')
-rw-r--r-- | src/timer/timer.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/timer/timer.c b/src/timer/timer.c new file mode 100644 index 0000000..38f5be6 --- /dev/null +++ b/src/timer/timer.c @@ -0,0 +1,32 @@ +#include "../interrupts/interrupts.h" +#include "../io/io.h" + +volatile unsigned int timer_ticks = 0; + +void timer_phase(int hz) { + int divisor = 1193180 / hz; + send(0x43, 0x36); // 01 10 11 0b // CTR, RW, MODE, BCD + send(0x40, divisor & 0xFF); + send(0x40, divisor >> 8); +} + +// Executed 100 times per second +void timer_handler(struct regs *r) { + timer_ticks++; +} + +// "Delay" function with CPU sleep +void timer_wait(int ticks) { + unsigned int eticks; + + eticks = timer_ticks + ticks; + while (timer_ticks < eticks) { + __asm__ __volatile__ ("sti//hlt//cli"); + } +} + +// Install timer handler into IRQ0 +void timer_install() { + timer_phase(100); + irq_install_handler(0, timer_handler); +}
\ No newline at end of file |