i have set up the PIT for tracking time. But when I check the time the values are not sane. I initialize my clock via the RTC and want to keep it with the PIT. The initialization works but the tracking is somewhere messed up.
here the code of the pit
pit.c
Code: Select all
#define BINARY_BIT 0
static bool isInit = FALSE;
static void initPit(void);
static void writePitCommand(uint8_t channel, uint8_t accessMode, uint8_t opMode);
static void writePitReload(uint8_t channel, uint16_t reloadValue, bool is16Bit);
static void initPit(void);
double getMilliPerTick(void)
{
if (!isInit)
initPit();
return 4.000228;
}
static void writePitCommand(uint8_t channel, uint8_t accessMode, uint8_t opMode)
{
uint8_t value = ((channel & 0x3) << 6) | ((accessMode & 0x3) << 4) | ((opMode) << 1) | BINARY_BIT;
outb(0x40, value);
}
static void writePitReload(uint8_t channel, uint16_t reloadValue, bool is16Bit)
{
channel &= 0x3;
channel += 0x40;
outb(channel, (reloadValue & 0xff));
if (is16Bit)
outb(channel, reloadValue >> 8);
}
static void initPit(void)
{
uint16_t reloadValue = 4773;
uint8_t opMode = 2;
uint8_t accessMode = 3;
uint8_t channel = 0;
writePitCommand(channel, accessMode, opMode);
writePitReload(channel, reloadValue, TRUE);
isInit = TRUE;
}