From c175c4994595815b62e13bfbe850f3163c238cc8 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 8 Jul 2025 13:46:02 +0200 Subject: [PATCH] works mostly --- arch/lapic_timer.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/lapic_timer.cc b/arch/lapic_timer.cc index 694c42b..4bbeed9 100644 --- a/arch/lapic_timer.cc +++ b/arch/lapic_timer.cc @@ -129,21 +129,23 @@ void set(uint32_t counter, uint8_t divide, uint8_t vector, bool periodic, LAPIC::write(TIMER_DIVIDE_CONFIGURATION, getClockDiv(divide)); LAPIC::write(TIMER_INITIAL_COUNTER, counter); } - +uint64_t time_tick; + +uint8_t dividender; + bool setup(uint32_t us) { - uint64_t timer_ticks = (static_cast(ticks()) * us) / 1000ULL; + time_tick = (static_cast(ticks()) * us) / 1000ULL; - uint8_t divisor = 1; - while (timer_ticks > UINT32_MAX) { + dividender = 1; + while (time_tick > UINT32_MAX) { // While timer_ticks is to large to fit in 32bits. - timer_ticks >>= 1; - divisor <<= 1; + time_tick >>= 1; + dividender <<= 1; } - if (divisor > 128) + if (dividender > 128) return false; // Timer interval is to large. // Setup Masked interrupts to effectively disable the timer. - set(static_cast(timer_ticks), divisor, Core::Interrupt::TIMER, true, true); return true; } @@ -156,15 +158,15 @@ uint32_t interval() { } void activate() { - uint32_t timer_ticks = LAPIC::read(TIMER_INITIAL_COUNTER); // Disable Counter to avoid spouriose interrupts. LAPIC::write(TIMER_INITIAL_COUNTER, 0); + set(static_cast(time_tick), dividender, Core::Interrupt::TIMER, true, true); // Activate Timer interrupts. setMasked(false); // enable counter with correct value. - LAPIC::write(TIMER_INITIAL_COUNTER, timer_ticks); + LAPIC::write(TIMER_INITIAL_COUNTER, time_tick); } void setMasked(bool masked) {