feat(pit): add pit initialization and handler

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2021-07-26 14:15:21 +02:00
parent 5064efa101
commit f6cdc3005d
4 changed files with 25 additions and 4 deletions

@ -46,8 +46,6 @@ static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = {
void interrupt_handler(struct isr_param *isr_param)
{
printf("Oh no %d!\r\n", isr_param->int_vector);
switch (isr_param->int_vector)
{
case PIT_INT_VECTOR:
@ -58,7 +56,7 @@ void interrupt_handler(struct isr_param *isr_param)
break;
}
if (isr_param->int_vector > IDT_RESERVED_ENTRIES
if (isr_param->int_vector >= IDT_RESERVED_ENTRIES
&& isr_param->int_vector < IDT_RESERVED_ENTRIES + 16)
acknowledge(isr_param->int_vector);
}

@ -44,6 +44,7 @@ void init_pic(void)
send_icw4();
mask_irqs();
init_keyboard();
init_pit();
asm volatile("sti");
}

@ -1,9 +1,23 @@
#include "pit.h"
#include "io.h"
#include "stdio.h"
static unsigned long ticks = 0;
void pit_handler(void)
{
++ticks;
}
unsigned long gettick(void)
{
return ticks;
}
void init_pit(void)
{
outb(PIT_CONTROL_REG, PIT_MODE_2 | PIT_RW_LSB | PIT_RW_MSB);
outb(PIT_COUNTER_0, PIT_DIVIDER & 0xff);
outb(PIT_COUNTER_0, PIT_DIVIDER >> 8);
}

@ -4,9 +4,17 @@
#define PIT_COUNTER_0 0x40
#define PIT_COUNTER_1 0x41
#define PIT_COUNTER_2 0x42
#define PIT_CONTROL_REGISTER 0x43
#define PIT_CONTROL_REG 0x43
#define PIT_MODE_2 (0x2 << 1)
#define PIT_RW_LSB (0x1 << 4)
#define PIT_RW_MSB (0x1 << 5)
#define PIT_DIVIDER 11931
void pit_handler(void);
unsigned long gettick(void);
void init_pit(void);
#endif /* !PIT_H */