aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2020-09-06 19:37:58 +0200
committerMarvin Borner2020-09-06 19:37:58 +0200
commit586d58192b2c576393077c3944338b582c873f45 (patch)
tree7f93d4f5168266118541ffdbcefd32696ce0b281 /kernel/drivers
parent2876d92663be7f1b46d72217e79b9f83d1756fd8 (diff)
Finished switch to hpet timer
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/acpi.c15
-rw-r--r--kernel/drivers/timer.c6
2 files changed, 13 insertions, 8 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c
index 999c0ed..15007d7 100644
--- a/kernel/drivers/acpi.c
+++ b/kernel/drivers/acpi.c
@@ -74,15 +74,18 @@ void acpi_install()
hpet = find_sdt(rsdt, HPET_MAGIC);
}
-void hpet_install()
+void hpet_install(int period)
{
if (hpet && hpet->legacy_replacement && hpet->comparator_count > 0) {
struct hpet_registers *r = (struct hpet_registers *)hpet->address.phys;
- printf("HPET tick period: %dns\n", r->features.tick_period / 1000000);
- printf("Periodic support: %d\n", r->timer.periodic_support);
- r->config.enable = 1;
- r->config.legacy_replacement = 1;
- r->timer.enable = 1;
+ printf("HPET tick period: %dns\n", r->tick_period / 1000000);
+ if ((r->timer0 & hpet_periodic_support) == hpet_periodic_support) {
+ r->config |= hpet_enable;
+ r->config |= hpet_legacy_replacement;
+ r->timer0 |= hpet_periodic | hpet_set_accumulator | hpet_enable_timer;
+ r->timer_comparator0 = r->tick_period + period;
+ r->timer_comparator0 = period;
+ }
} else {
hpet = NULL;
}
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index 79e3cd8..788e286 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -1,5 +1,6 @@
// MIT License, Copyright (c) 2020 Marvin Borner
+#include <acpi.h>
#include <cpu.h>
#include <def.h>
#include <interrupts.h>
@@ -19,7 +20,6 @@ u32 timer_get()
return timer_ticks;
}
-// Executed 1000 times per second
void timer_handler()
{
timer_ticks++;
@@ -39,6 +39,8 @@ void timer_wait(u32 ticks)
// Install timer handler into IRQ0
void timer_install()
{
- timer_phase(1000);
+ hpet_install(10000); // TODO: Find optimal femtosecond period
+ if (!hpet)
+ timer_phase(1000);
irq_install_handler(0, timer_handler);
}