Luna/kernel/src/arch/x86_64/Timer.cpp
apio 916a73ca95
All checks were successful
continuous-integration/drone/push Build is passing
kernel: Rework the timer subsystem to count in microseconds
2023-05-07 21:51:36 +02:00

16 lines
459 B
C++

#include "arch/Timer.h"
#include "arch/x86_64/IO.h"
#define PIT_CHANNEL_0 0x40
const u64 base_frequency = 1193182;
void Timer::arch_init()
{
constexpr u16 divisor = (u16)(base_frequency / ((1000 / ARCH_TIMER_RESOLUTION) * 1000));
static_assert(divisor >= 100, "ARCH_TIMER_RESOLUTION is too low");
IO::outb(PIT_CHANNEL_0, (u8)(divisor & 0xFF));
IO::outb(0x80, 0); // short delay
IO::outb(PIT_CHANNEL_0, (u8)((divisor & 0xFF00) >> 8));
}