#include "headers/timer.h" #include "headers/isr.h" #include "headers/screen.h" #include uint32_t tick = 0; extern uint8_t current_color; static void timer_callback(registers_t *regs) { regs->eax++; // get it to compile fix this // later(regs is not really needed) tick++; static int j = 0; j = j%15; current_color = j++; kprintf("%d\n", tick); } void init_timer(uint32_t frequency) { // firstly register our timer callback register_interrupt_handler(IRQ0, &timer_callback); // the vaue sent to the pit is its clock divisor // (1193180 Hz) the divisor must be small enough // to fit into 16 bits uint32_t divisor = 1193180 / frequency; // send the command byte outb(0x43, 0x36); // divsor is set in bytes so serialize it uint8_t l = (uint8_t)(divisor & 0xff); uint8_t h = (uint8_t)( (divisor>>8) & 0xff); // send the freq divisor outb(0x40, l); outb(0x40, h); }