mirror of
https://github.com/tailix/kernel.git
synced 2025-04-21 17:42:20 -04:00
Register timer callback
This commit is contained in:
parent
23180a23bd
commit
c5135b4a5d
5 changed files with 45 additions and 1 deletions
22
arch/hwint.c
22
arch/hwint.c
|
@ -1,3 +1,5 @@
|
|||
#include "hwint.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "asm.h"
|
||||
#include "logger.h"
|
||||
|
@ -28,6 +30,8 @@ static const char *const messages[] = {
|
|||
"Unhandled hardware interrupt: 15",
|
||||
};
|
||||
|
||||
static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
void hwint_handler(struct IsrRegisters regs)
|
||||
{
|
||||
if (
|
||||
|
@ -49,5 +53,21 @@ void hwint_handler(struct IsrRegisters regs)
|
|||
|
||||
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
|
||||
|
||||
logger_warn(messages[hwint_no]);
|
||||
const hwint_handler_t handler = handlers[hwint_no];
|
||||
|
||||
if (!handler) {
|
||||
logger_warn(messages[hwint_no]);
|
||||
return;
|
||||
}
|
||||
|
||||
handler();
|
||||
}
|
||||
|
||||
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
|
||||
{
|
||||
if (int_no >= INT_HWINT_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
handlers[int_no] = handler;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef KERNELMQ_INCLUDED_HWINT
|
||||
#define KERNELMQ_INCLUDED_HWINT 1
|
||||
|
||||
typedef void(*hwint_handler_t)();
|
||||
|
||||
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler);
|
||||
|
||||
void hwint_0();
|
||||
void hwint_1();
|
||||
void hwint_2();
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "protected.h"
|
||||
#include "timer.h"
|
||||
|
||||
static void on_timer();
|
||||
|
||||
void main(struct KernelMQ_Multiboot_Info multiboot_info)
|
||||
{
|
||||
logger_initialize();
|
||||
|
@ -12,8 +14,15 @@ void main(struct KernelMQ_Multiboot_Info multiboot_info)
|
|||
logger_info("Kernel initialization started.");
|
||||
|
||||
protected_initialize();
|
||||
|
||||
timer_register_handler(on_timer);
|
||||
timer_initialize(50);
|
||||
|
||||
logger_warn("Nothing to do.");
|
||||
logger_fail("Halt.");
|
||||
}
|
||||
|
||||
void on_timer()
|
||||
{
|
||||
logger_info("Timer tick.");
|
||||
}
|
||||
|
|
|
@ -16,3 +16,8 @@ void timer_initialize(unsigned int frequency)
|
|||
outportb(0x40, l);
|
||||
outportb(0x40, h);
|
||||
}
|
||||
|
||||
void timer_register_handler(timer_handler_t handler)
|
||||
{
|
||||
hwint_register_handler(0, handler);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#ifndef KERNELMQ_INCLUDED_TIMER
|
||||
#define KERNELMQ_INCLUDED_TIMER 1
|
||||
|
||||
#include "hwint.h"
|
||||
|
||||
typedef hwint_handler_t timer_handler_t;
|
||||
|
||||
void timer_initialize(unsigned int frequency);
|
||||
|
||||
void timer_register_handler(timer_handler_t handler);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue