PIT Setup and Initialization
Posted: Wed Jul 26, 2023 12:03 am
I am currently trying to configure the PIT but can't seem to trigger any interrupts using it.
pit.h
pit.c
I receive other interrupts so I know that it does not have to do with my IDT but I still am unable to figure it out. Help is much appreciated!
pit.h
Code: Select all
#ifndef PIT_H_INCLUDED
#define PIT_H_INCLUDED
#include <stdint.h>
#include "../terminal.h"
#include "../byte.h"
#include "idt.h"
#define PIT_CHANNEL0 0x40
#define PIT_COMMAND 0x43
#define PIT_FREQUENCY 1193182
#define DESIRED_FREQUENCY 10
void pit_init();
#endif
Code: Select all
#include "pit.h"
void pit_irq_handler() {
print("hello");
outb(0x20, 0x20);
}
void pit_init() {
uint16_t divisor = PIT_FREQUENCY / DESIRED_FREQUENCY;
outb(PIT_COMMAND, 0x36);
outb(PIT_CHANNEL0, (uint8_t)(divisor & 0xFF));
outb(PIT_CHANNEL0, (uint8_t)((divisor >> 8) & 0xFF));
idt_set_descriptor(0x20, pit_irq_handler, 0x8E);
print("PIT: Initialized\n");
}