Files
Espresso/drivers/irq.c

49 lines
814 B
C
Raw Normal View History

2025-06-13 19:53:54 -05:00
#include <stdio.h>
#include <drivers/ps2_keyboard.h>
2025-06-17 15:50:07 -05:00
#include <drivers/pit.h>
2025-10-20 21:57:30 -05:00
#include <port_io.h>
2025-06-13 18:03:39 -05:00
#include <drivers/irq.h>
2025-07-03 20:30:21 -05:00
#define NUM_IRQS 0x90
irq_func_t func_list[NUM_IRQS];
2025-07-04 14:23:29 -05:00
2025-07-03 20:30:21 -05:00
static volatile uint32_t num_irqs_missed = 0;
2025-07-01 20:39:38 -05:00
void irq_init(void)
{
2025-10-20 21:57:30 -05:00
for (int i = 0; i < NUM_IRQS; i++)
{
func_list[i] = 0x0;
}
2025-07-01 20:39:38 -05:00
set_irq_handler(0, (irq_func_t*)pit_handler);
set_irq_handler(1, (irq_func_t*)keyboard_handler);
}
2025-06-13 18:03:39 -05:00
void irq_handler(uint8_t irq_number)
{
2025-07-03 20:30:21 -05:00
if (irq_number < NUM_IRQS)
2025-07-01 20:39:38 -05:00
{
2025-07-03 20:30:21 -05:00
if (func_list[irq_number])
{
func_list[irq_number]();
2025-10-20 21:57:30 -05:00
outb(0x20, 0x20); /* Acknowledge the IRQ to PIC */
2025-07-03 20:30:21 -05:00
}
else
{
num_irqs_missed++;
}
2025-07-01 20:39:38 -05:00
}
}
void set_irq_handler(uint32_t num, irq_func_t* handler)
{
2025-07-03 20:30:21 -05:00
if (num < NUM_IRQS)
{
func_list[num] = (irq_func_t)handler;
}
}