timer.c (679B)
1 #include <libc.h> 2 #include "libk.h" 3 #include "idt.h" 4 #include "io.h" 5 6 #define TIMER_CMD 0x43 7 #define TIMER_DATA 0x40 8 #define SQUARE_WAVE 0x36 9 #define FREQ 1193180 10 #define HZ 100 11 12 static void timer_callback(struct regs *); 13 14 static u_int32_t ticks = 0; 15 16 static void 17 timer_callback(struct regs *r) 18 { 19 ticks++; 20 UNUSED(r); 21 } 22 23 void 24 timer_init(void) 25 { 26 u_int32_t div = FREQ / HZ; 27 28 intr_register_handler(IRQ0, timer_callback); 29 /* Repating mode. */ 30 outb(TIMER_CMD, SQUARE_WAVE); 31 outb(TIMER_DATA, (u_int8_t)(div & 0xff)); 32 outb(TIMER_DATA, (u_int8_t)(div >> 8)); 33 printf("timer on irq 0\n"); 34 35 /*outb(TIMER_CMD, SQUARE_WAVE);*/ 36 /*outb(TIMER_DATA, 0);*/ 37 /*outb(TIMER_DATA, 0);*/ 38 }