Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
537dde170b (timer): basic start 2026-02-16 17:41:07 +00:00
3 changed files with 22 additions and 3 deletions

View file

@ -6,6 +6,7 @@
#include <kernel/plic.h> #include <kernel/plic.h>
#include <kernel/interrupts.h> #include <kernel/interrupts.h>
#include <kernel/memory.h> #include <kernel/memory.h>
#include <kernel/timer.h>
void interrupt_init() void interrupt_init()
{ {
@ -115,9 +116,7 @@ void handle_interrupt(unsigned long code)
switch (code) switch (code)
{ {
case 7: case 7:
static volatile uint64_t *mtime = (uint64_t *)CLINT_MTIME; timer_handle_interrupt();
static volatile uint64_t *mtimecmp = (uint64_t *)CLINT_MTIMECMP(0);
*mtimecmp = *mtime + 100000;
break; break;
case 11: case 11:

12
src/kernel/timer.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdint.h>
#include <kernel/interrupts.h>
#include <kernel/plic.h>
#include <kernel/timer.h>
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;
}

8
src/kernel/timer.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef KTIMER_H
#define KTIMER_H
#define TIMER_FREQ 100000
void timer_handle_interrupt();
#endif