add: sleep

This commit is contained in:
2025-01-08 16:38:02 +01:00
parent bab3069152
commit 916e8b6f19
5 changed files with 60 additions and 4 deletions

View File

@ -1,6 +1,47 @@
#include "interrupts.h"
#include <stdint.h>
void clock_handler(struct registers *regs)
#include "debug.h"
#include "drivers.h"
#include "interrupts.h"
#include "kprintf.h"
#include "memory.h"
#include "sys/io.h"
#define PIT_CHANNEL0 0x40
#define PIT_FREQUENCY 1193182
#define PIT_COUNT (65535 / 2)
#define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
uint32_t counter = 0;
static void clock_handler(struct registers *regs);
static void set_pit_count(unsigned count)
{
cli();
outb(0x40, count & 0xFF); // Low byte
outb(0x40, (count & 0xFF00) >> 8); // High byte
sti();
}
void clock_init(struct registers *regs)
{
(void)regs;
set_pit_count(PIT_COUNT);
register_interrupt_handler(0, clock_handler);
}
static void clock_handler(struct registers *regs)
{
(void)regs;
counter--;
}
void sleep(uint64_t delay)
{
counter = delay / DELAY;
while (counter)
;
}

View File

@ -3,6 +3,6 @@
void load_drivers(void)
{
register_interrupt_handler(0, clock_handler);
register_interrupt_handler(0, clock_init);
register_interrupt_handler(1, keyboard_handler);
}