add: sleep
This commit is contained in:
@ -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)
|
||||
;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user