16 lines
456 B
C++
16 lines
456 B
C++
|
#include "arch/Timer.h"
|
||
|
#include "arch/x86_64/IO.h"
|
||
|
|
||
|
#define PIT_CHANNEL_0 0x40
|
||
|
|
||
|
const u64 base_frequency = 1193182;
|
||
|
const usize ARCH_TIMER_FREQ = 10;
|
||
|
|
||
|
void Timer::arch_init()
|
||
|
{
|
||
|
constexpr u16 divisor = (uint16_t)(base_frequency / (ARCH_TIMER_FREQ * 1000));
|
||
|
static_assert(divisor >= 100);
|
||
|
IO::outb(PIT_CHANNEL_0, (uint8_t)(divisor & 0xFF));
|
||
|
IO::outb(0x80, 0); // short delay
|
||
|
IO::outb(PIT_CHANNEL_0, (uint8_t)((divisor & 0xFF00) >> 8));
|
||
|
}
|