Code: Select all
#include "system.h"
/* This will keep track of how many ticks that the system
* has been running for */
int timer_ticks = 0;
/** The timer frequency.
*/
int freq = 18; // default: 18.222 Hz
/** Increment our timer variable
*/
void timer_handler_standard(struct regs *r)
{
timer_ticks = timer_ticks + 1;
}
/** Call timer_handler_standard
*/
void timer_handler(struct regs *r)
{
timer_handler_standard(r);
}
/** Call timer_handler_standard and prints out a message if a
* second has passed.
*/
void timer_handler_message(struct regs *r)
{
timer_handler_standard(r);
/* Every freq clocks (approximately 1 second), we will
* display a message on the screen */
if (timer_ticks % freq == 0)
{
puts("One second has passed.\n");
}
}
/** Sets the frequency for the timer in Hz.
*/
void timer_phase(int hz)
{
int divisor = 1193180 / hz; /* Calculate our divisor */
outportb(0x43, 0x36); /* Set our command byte 0x36 */
outportb(0x40, divisor & 0xFF); /* Set low byte of divisor */
outportb(0x40, divisor >> 8); /* Set high byte of divisor */
freq = hz;
}
/* This will continuously loop until the given time has
* been reached.
*/
void timer_wait(int ticks)
{
unsigned long eticks;
eticks = timer_ticks + ticks;
while(timer_ticks < eticks)
{
;
}
}
/* Sets up the system clock by setting the frequency to 1kHz */
void timer_install()
{
timer_phase(1000);
irq_install_handler(0, timer_handler);
}
void timer_install_message()
{
timer_install();
irq_install_handler(0, timer_handler_message);
}
Does anyone know what's wrong here?
Cheers