38 lines
1.3 KiB
C
38 lines
1.3 KiB
C
#include "../include/pit.h"
|
|
|
|
//https://wiki.osdev.org/Programmable_Interval_Timer
|
|
|
|
/*
|
|
Bit/s Usage
|
|
7 Output pin state
|
|
6 Null count flags
|
|
5 and 4 Access mode :
|
|
0 0 = Latch count value command
|
|
0 1 = Access mode: lobyte only
|
|
1 0 = Access mode: hibyte only
|
|
1 1 = Access mode: lobyte/hibyte
|
|
3 to 1 Operating mode :
|
|
0 0 0 = Mode 0 (interrupt on terminal count)
|
|
0 0 1 = Mode 1 (hardware re-triggerable one-shot)
|
|
0 1 0 = Mode 2 (rate generator)
|
|
0 1 1 = Mode 3 (square wave generator)
|
|
1 0 0 = Mode 4 (software triggered strobe)
|
|
1 0 1 = Mode 5 (hardware triggered strobe)
|
|
1 1 0 = Mode 2 (rate generator, same as 010b)
|
|
1 1 1 = Mode 3 (square wave generator, same as 011b)
|
|
0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD
|
|
*/
|
|
|
|
#define PIT_COMMAND_PORT 0x43
|
|
#define PIT_DATA_PORT 0x40
|
|
|
|
void pit_init(int freq) {
|
|
int divisor = 1193180 / freq;
|
|
uint8_t command = 0x36;//00110110 see above to get the idea wtf is this number
|
|
|
|
outb(PIT_COMMAND_PORT, command);
|
|
|
|
outb(PIT_DATA_PORT, divisor & 0xFF);
|
|
outb(PIT_DATA_PORT, divisor >> 8);
|
|
}
|