implements the PIT
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include <kernel/_kernel.h>
|
||||
#include <kernel/x86/idt.h>
|
||||
#include <kernel/x86/pic.h>
|
||||
#include <kernel/x86/pit.h>
|
||||
#include <kernel/x86/io.h>
|
||||
#include <kernel/x86/keyb.h>
|
||||
|
||||
@ -16,8 +17,7 @@ static idtr_t idtr;
|
||||
|
||||
static bool vectors[IDT_MAX_DESCRIPTORS];
|
||||
|
||||
extern struct keyboard_state keyb_state;
|
||||
|
||||
extern struct pit_state pit;
|
||||
|
||||
#define EXTERNAL_BIT (0x1)
|
||||
|
||||
@ -229,6 +229,10 @@ void exception_handler(struct cpu_state __attribute__((unused)) cpu, uint32_t in
|
||||
/** EXCEPTIONS END **/
|
||||
|
||||
/** PIC BEGIN **/
|
||||
case PIC_PIT:
|
||||
pit.interrupts++;
|
||||
PIC_sendEOI(0);
|
||||
break;
|
||||
case PIC_KEYB:
|
||||
inbyte = inb(0x60);
|
||||
do_keypress(decode_scancode(inbyte));
|
||||
@ -276,6 +280,7 @@ void idt_init(void)
|
||||
|
||||
PIC_remap(0x20, 0x28);
|
||||
pic_disable(); // mask everything
|
||||
IRQ_clear_mask(0);
|
||||
IRQ_clear_mask(1);
|
||||
|
||||
__asm__ volatile("sti"); // set the interrupt flag
|
||||
|
@ -61,4 +61,15 @@ void set_pit_count(uint8_t channel, uint16_t count) // Only in lobyte/hibyte mod
|
||||
// TODO: make sure to set interrupts
|
||||
}
|
||||
|
||||
void init_pit(uint8_t init_command, uint8_t channel, uint32_t divisor)
|
||||
{
|
||||
uint32_t normalized_div = normalize_divisor(divisor);
|
||||
|
||||
pit.divisor = normalized_div;
|
||||
pit.interrupts = 0;
|
||||
|
||||
outb(PIT_CMD_REG, init_command); // access mode must be lobyte/hibyte
|
||||
|
||||
outb(channel, normalized_div & 0xFF);
|
||||
outb(channel, (normalized_div & 0xFF00) >> 8);
|
||||
}
|
||||
|
Reference in New Issue
Block a user