2017-11-03 00:19:48 -04:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
#include "asm.h"
|
|
|
|
|
|
|
|
void timer_initialize(unsigned int frequency)
|
|
|
|
{
|
2017-11-05 23:21:18 -05:00
|
|
|
logger_info_from("timer", "Initialize timer.");
|
2017-11-03 00:19:48 -04:00
|
|
|
|
2017-11-03 00:31:23 -04:00
|
|
|
const unsigned int divisor = 1193180 / frequency;
|
|
|
|
|
|
|
|
const unsigned char l = divisor & 0xFF;
|
|
|
|
const unsigned char h = (divisor >> 8) & 0xFF;
|
|
|
|
|
2017-11-03 00:19:48 -04:00
|
|
|
outportb(0x43, 0x36);
|
2017-11-03 00:31:23 -04:00
|
|
|
outportb(0x40, l);
|
|
|
|
outportb(0x40, h);
|
2017-11-03 00:19:48 -04:00
|
|
|
}
|
2017-11-03 01:10:07 -04:00
|
|
|
|
|
|
|
void timer_register_handler(timer_handler_t handler)
|
|
|
|
{
|
|
|
|
hwint_register_handler(0, handler);
|
|
|
|
}
|
2017-11-06 07:06:28 -05:00
|
|
|
|
|
|
|
void timer_unregister_handler()
|
|
|
|
{
|
|
|
|
hwint_unregister_handler(0);
|
|
|
|
}
|