2022-09-07 17:41:08 +00:00
|
|
|
#define MODULE "pit"
|
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
#include "scheduling/PIT.h"
|
|
|
|
#include "io/IO.h"
|
2022-09-07 17:41:08 +00:00
|
|
|
#include "log/Log.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
|
|
|
#define PIT_CHANNEL_0_PORT 0x40
|
|
|
|
|
|
|
|
volatile uint64_t PIT::ms_since_boot = 0;
|
|
|
|
uint16_t divisor = 65535;
|
|
|
|
|
|
|
|
void PIT::initialize(uint64_t frequency)
|
|
|
|
{
|
|
|
|
divisor = base_frequency / frequency;
|
2022-09-07 17:41:08 +00:00
|
|
|
kinfoln("Configuring PIT to use divisor %d (will tick %lu times per second)", divisor, frequency);
|
2022-09-05 14:13:51 +00:00
|
|
|
if (divisor < 100) divisor = 100;
|
|
|
|
IO::outb(PIT_CHANNEL_0_PORT, (uint8_t)(divisor & 0xFF));
|
|
|
|
IO::delay();
|
|
|
|
IO::outb(PIT_CHANNEL_0_PORT, (uint8_t)((divisor & 0xFF00) >> 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t PIT::frequency()
|
|
|
|
{
|
|
|
|
return base_frequency / divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PIT::tick()
|
|
|
|
{
|
|
|
|
ms_since_boot += 1000 / frequency();
|
|
|
|
}
|