Luna/kernel/src/arch/x86_64/Timer.cpp

16 lines
439 B
C++
Raw Normal View History

2022-11-19 19:01:01 +00:00
#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 / (ARCH_TIMER_FREQ * 1000));
static_assert(divisor >= 100, "ARCH_TIMER_FREQ is too high");
IO::outb(PIT_CHANNEL_0, (u8)(divisor & 0xFF));
2022-11-19 19:01:01 +00:00
IO::outb(0x80, 0); // short delay
IO::outb(PIT_CHANNEL_0, (u8)((divisor & 0xFF00) >> 8));
2023-01-02 12:07:29 +00:00
}