|
|
@ -3,6 +3,8 @@
|
|
|
|
#include "portio.hpp"
|
|
|
|
#include "portio.hpp"
|
|
|
|
#include "tasking.hpp"
|
|
|
|
#include "tasking.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constexpr std::uint32_t Frequency = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
static volatile std::uint32_t ticks = 0;
|
|
|
|
static volatile std::uint32_t ticks = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static void timer_callback(const Registers& regs)
|
|
|
|
static void timer_callback(const Registers& regs)
|
|
|
@ -12,7 +14,7 @@ static void timer_callback(const Registers& regs)
|
|
|
|
schedule(regs);
|
|
|
|
schedule(regs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pit_initialize(std::uint32_t frequency)
|
|
|
|
void pit_initialize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Firstly, register our timer callback.
|
|
|
|
// Firstly, register our timer callback.
|
|
|
|
idt_register_callback(32, timer_callback);
|
|
|
|
idt_register_callback(32, timer_callback);
|
|
|
@ -20,7 +22,7 @@ void pit_initialize(std::uint32_t frequency)
|
|
|
|
// The value we send to the PIT is the value to divide it's input clock
|
|
|
|
// The value we send to the PIT is the value to divide it's input clock
|
|
|
|
// (1193180 Hz) by, to get our required frequency. Important to note is
|
|
|
|
// (1193180 Hz) by, to get our required frequency. Important to note is
|
|
|
|
// that the divisor must be small enough to fit into 16-bits.
|
|
|
|
// that the divisor must be small enough to fit into 16-bits.
|
|
|
|
auto divisor = 1193180 / frequency;
|
|
|
|
const auto divisor = 1193180ul / Frequency;
|
|
|
|
|
|
|
|
|
|
|
|
// Send the command byte.
|
|
|
|
// Send the command byte.
|
|
|
|
outb(0x43, 0x36);
|
|
|
|
outb(0x43, 0x36);
|
|
|
@ -30,9 +32,9 @@ void pit_initialize(std::uint32_t frequency)
|
|
|
|
outb(0x40, (divisor >> 8) & 0xFF);
|
|
|
|
outb(0x40, (divisor >> 8) & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pit_busy_wait(std::int32_t tks)
|
|
|
|
void pit_delay_ms(std::int32_t ms)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const auto end = ticks + tks;
|
|
|
|
const auto end = ticks + ms;
|
|
|
|
while (static_cast<std::int32_t>(end - ticks) > 0)
|
|
|
|
while (static_cast<std::int32_t>(end - ticks) > 0)
|
|
|
|
asm volatile("nop");
|
|
|
|
asm volatile("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|