forked from CHatingPython/towos
35 lines
728 B
C++
35 lines
728 B
C++
#ifndef ARCH_X86_64_PIT_HPP
|
|
#define ARCH_X86_64_PIT_HPP
|
|
|
|
#include "arch/x86_64/int.hpp"
|
|
#include "arch/x86_64/io.hpp"
|
|
#include "types.hpp"
|
|
|
|
namespace x86_64 {
|
|
|
|
struct pit {
|
|
pit(u32 targetHz = 100) {
|
|
constexpr u32 PIT_INPUT_HZ = 1193182;
|
|
|
|
const u16 divisor = static_cast<u16>(PIT_INPUT_HZ / targetHz);
|
|
|
|
io::outb(0x43, 0x36);
|
|
|
|
io::outb(0x40, static_cast<u8>(divisor & 0xFF));
|
|
io::outb(0x40, static_cast<u8>(divisor >> 8));
|
|
}
|
|
|
|
static void handler(interrupt_frame& frame, void* data) {
|
|
(void)frame;
|
|
|
|
pit* pit = reinterpret_cast<decltype(pit)>(data);
|
|
++pit->ticks;
|
|
}
|
|
|
|
volatile u64 ticks = 0;
|
|
};
|
|
|
|
} // namespace x86_64
|
|
|
|
#endif // ARCH_X86_64_PIT_HPP
|