add: sleep
This commit is contained in:
parent
bab3069152
commit
916e8b6f19
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
void load_drivers(void);
|
void load_drivers(void);
|
||||||
void keyboard_handler(struct registers *regs);
|
void keyboard_handler(struct registers *regs);
|
||||||
void clock_handler(struct registers *regs);
|
void clock_init(struct registers *regs);
|
||||||
|
@ -18,3 +18,13 @@ typedef void (*isr_t)(struct registers *);
|
|||||||
void isr_handler(struct registers *regs);
|
void isr_handler(struct registers *regs);
|
||||||
void pic_send_eoi(uint8_t irq);
|
void pic_send_eoi(uint8_t irq);
|
||||||
void register_interrupt_handler(int index, isr_t handler);
|
void register_interrupt_handler(int index, isr_t handler);
|
||||||
|
|
||||||
|
static inline void cli(void)
|
||||||
|
{
|
||||||
|
__asm__ volatile("cli");
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void sti(void)
|
||||||
|
{
|
||||||
|
__asm__ volatile("sti");
|
||||||
|
}
|
5
headers/time.h
Normal file
5
headers/time.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void sleep(uint64_t delay);
|
@ -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;
|
(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)
|
void load_drivers(void)
|
||||||
{
|
{
|
||||||
register_interrupt_handler(0, clock_handler);
|
register_interrupt_handler(0, clock_init);
|
||||||
register_interrupt_handler(1, keyboard_handler);
|
register_interrupt_handler(1, keyboard_handler);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user