summaryrefslogtreecommitdiff
path: root/kernel/drivers/pit.c
blob: cb3c091e02a4577fcd40d510480de342be5da4a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <comus/asm.h>
#include <comus/drivers/pit.h>

#define CHAN_0 0x40
#define CHAN_1 0x41
#define CHAN_2 0x42
#define CMD 0x43

uint64_t ticks = 0;

uint16_t pit_read_divider(void) {
	uint16_t count = 0;
	cli();
	outb(CMD, 0); // clear bits
	count = inb(CHAN_0); // low byte
	count |= inb(CHAN_0)<<8; // highbyte
	return count;
}

void pit_set_divider(uint16_t count) {
	outb(CHAN_0, count & 0xFF); // low byte
	outb(CHAN_0, (count & 0xFF00) >> 8); // high byte
}