Skip to content

Programmable Interval Timer

void pit_init(void)
source
void pit_set_divisor(uint16_t divisor)
source
void pit_set_frequency(freq_hz_t freq_hz)
source
void pit_set_interval_ns(time_ns_t interval_ns)
source
void pit_set_periodic_mode(uint16_t divisor)
source
void pit_set_oneshot_mode(uint16_t divisor)
source
void pit_wire_periodic_nmi(time_ns_t interval_ns)
source
freq_hz_t pit_measure_tsc_freq(void)
source

IO ports

#define PIT_PORT_CHANNEL0 0x40
source
#define PIT_PORT_CHANNEL1 0x41
source
#define PIT_PORT_CHANNEL2 0x42
source
#define PIT_PORT_COMMAND 0x43
source
#define PIT_PORT_CHANNEL(ch)
source
Expansion
#define PIT_PORT_CHANNEL(ch) ((uint16_t) (PIT_PORT_CHANNEL0 + (ch)))
#define PIT_BASE_FREQUENCY_HZ 1193182ULL
source

PIT Base Frequency (1.193182 MHz)

#define PIT_FREQUENCY 1193182ULL
source
#define PIT_CMD_CHANNEL(ch)
source
Expansion
#define PIT_CMD_CHANNEL(ch) ((uint8_t) (((ch) & 0x3) << 6))
#define PIT_CMD_CHANNEL0 0x00
source
#define PIT_CMD_CHANNEL1 0x40
source
#define PIT_CMD_CHANNEL2 0x80
source
#define PIT_CMD_READBACK 0xC0
source
#define PIT_CMD_ACCESS_LATCH 0x00
source

Latch count value command

#define PIT_CMD_ACCESS_LO 0x10
source

Low byte only

#define PIT_CMD_ACCESS_HI 0x20
source

High byte only

#define PIT_CMD_ACCESS_LOHI 0x30
source

Low byte then high byte (16 bit)

Operating Modes

#define PIT_CMD_MODE_ONESHOT 0x00
source
#define PIT_CMD_MODE_HW_ONESHOT 0x02
source
#define PIT_CMD_MODE_RATE_GEN 0x04
source
#define PIT_CMD_MODE_SQUARE_WAVE 0x06
source
#define PIT_CMD_MODE_SW_STROBE 0x08
source
#define PIT_CMD_MODE_HW_STROBE 0x0A
source

Binary / BCD

#define PIT_CMD_BINARY 0x00
source
#define PIT_CMD_BCD 0x01
source
#define PIT_DEFAULT_MODE 0x34
source
#define PIT_DEFAULT_COUNT 0x4AF2
source
#define PIT_CALIBRATION_MODE 0x30
source
#define PIT_CALIBRATION_COUNT UINT16_MAX
source
#define PIT_DIVISOR_MIN 1
source
#define PIT_DIVISOR_MAX_COUNT UINT16_MAX
source
#define PIT_DIVISOR_ROLLOVER_VAL 0
source

0 is 65536 in binary mode