diff --git a/src/kernel/interrupts.c b/src/kernel/interrupts.c index 6647a0f..ac14bb2 100644 --- a/src/kernel/interrupts.c +++ b/src/kernel/interrupts.c @@ -6,6 +6,7 @@ #include #include #include +#include void interrupt_init() { @@ -115,9 +116,7 @@ void handle_interrupt(unsigned long code) switch (code) { case 7: - static volatile uint64_t *mtime = (uint64_t *)CLINT_MTIME; - static volatile uint64_t *mtimecmp = (uint64_t *)CLINT_MTIMECMP(0); - *mtimecmp = *mtime + 100000; + timer_handle_interrupt(); break; case 11: diff --git a/src/kernel/timer.c b/src/kernel/timer.c new file mode 100644 index 0000000..530c6fd --- /dev/null +++ b/src/kernel/timer.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +void timer_handle_interrupt() +{ + static volatile uint64_t *mtime = (uint64_t *)CLINT_MTIME; + static volatile uint64_t *mtimecmp = (uint64_t *)CLINT_MTIMECMP(0); + + *mtimecmp = *mtime + TIMER_FREQ; +} \ No newline at end of file diff --git a/src/kernel/timer.h b/src/kernel/timer.h new file mode 100644 index 0000000..3b6f452 --- /dev/null +++ b/src/kernel/timer.h @@ -0,0 +1,8 @@ +#ifndef KTIMER_H +#define KTIMER_H + +#define TIMER_FREQ 100000 + +void timer_handle_interrupt(); + +#endif \ No newline at end of file