diff options
author | Marvin Borner | 2019-09-19 19:56:59 +0200 |
---|---|---|
committer | Marvin Borner | 2019-09-19 20:05:38 +0200 |
commit | 05e1fedcc9cd30d1a34a65e640da45e980b4f859 (patch) | |
tree | 9cfb7620907ac126f26cdfe9363cb73ed74ea179 /src/kernel/timer | |
parent | ffd82e18b5259fab477ad375a7af8550fac526d8 (diff) |
Moved source to kernel directory
Diffstat (limited to 'src/kernel/timer')
-rw-r--r-- | src/kernel/timer/timer.c | 32 | ||||
-rw-r--r-- | src/kernel/timer/timer.h | 8 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/kernel/timer/timer.c b/src/kernel/timer/timer.c new file mode 100644 index 0000000..38f5be6 --- /dev/null +++ b/src/kernel/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 diff --git a/src/kernel/timer/timer.h b/src/kernel/timer/timer.h new file mode 100644 index 0000000..66b3c95 --- /dev/null +++ b/src/kernel/timer/timer.h @@ -0,0 +1,8 @@ +#ifndef MELVIX_TIMER_H +#define MELVIX_TIMER_H + +void timer_install(); + +void timer_wait(int ticks); + +#endif |