timer.c (428B)
1 #include "extern.h" 2 #include "idt.h" 3 #include "port.h" 4 5 static void timer_callback(struct reg *); 6 7 static uint32_t timer_ticks = 0; 8 9 static void 10 timer_callback(struct reg *r) 11 { 12 timer_ticks++; 13 (void)r; 14 } 15 16 void 17 timer_init(uint32_t hz) 18 { 19 uint32_t div = 1193180 / hz; 20 21 int_add_handler(0, timer_callback); 22 outb(P_TIMER_CMD, 0x36); 23 outb(P_TIMER_DATA, (uint8_t)(div & 0xff)); 24 outb(P_TIMER_DATA, (uint8_t)((div >> 8) & 0xff)); 25 }