feat(pit): add pit initialization and handler

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
master
Julien CLEMENT 3 years ago
parent 5064efa101
commit f6cdc3005d
  1. 4
      k/events/idt.c
  2. 1
      k/events/pic/pic.c
  3. 14
      k/events/pic/pit.c
  4. 10
      k/events/pic/pit.h

@ -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 */

Loading…
Cancel
Save