2017-11-03 04:19:48 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
#include "logger.h"
|
2020-11-29 04:50:35 +05:00
|
|
|
|
2020-11-30 16:31:20 +05:00
|
|
|
#include <kernaux/arch/x86.h>
|
2017-11-03 04:19:48 +00:00
|
|
|
|
|
|
|
void timer_initialize(unsigned int frequency)
|
|
|
|
{
|
2017-11-06 04:21:18 +00:00
|
|
|
logger_info_from("timer", "Initialize timer.");
|
2017-11-03 04:19:48 +00:00
|
|
|
|
2017-11-03 04:31:23 +00:00
|
|
|
const unsigned int divisor = 1193180 / frequency;
|
|
|
|
|
|
|
|
const unsigned char l = divisor & 0xFF;
|
|
|
|
const unsigned char h = (divisor >> 8) & 0xFF;
|
|
|
|
|
2020-11-30 16:31:20 +05:00
|
|
|
kernaux_arch_x86_outportb(0x43, 0x36);
|
|
|
|
kernaux_arch_x86_outportb(0x40, l);
|
|
|
|
kernaux_arch_x86_outportb(0x40, h);
|
2017-11-03 04:19:48 +00:00
|
|
|
}
|
2017-11-03 05:10:07 +00:00
|
|
|
|
|
|
|
void timer_register_handler(timer_handler_t handler)
|
|
|
|
{
|
|
|
|
hwint_register_handler(0, handler);
|
|
|
|
}
|
2017-11-06 12:06:28 +00:00
|
|
|
|
|
|
|
void timer_unregister_handler()
|
|
|
|
{
|
|
|
|
hwint_unregister_handler(0);
|
|
|
|
}
|