timer IRQ

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
OSNewbie

timer IRQ

Post by OSNewbie »

by default at boot, how often does a timer interrupt (IRQ0) occur? and is it possible to change this?
carbonBased

RE:timer IRQ

Post by carbonBased »

18.2 times per second, and yes, you can change it

void timerSetFreq(short freq) {
  long counter = PIT_FREQ / freq;

  outportb(TIMER_CTRL, /*0x43*/TIMER0 + TIMER_WHOLE + TIMER_MODE2);
  outportb(TIMER0_CNTR, counter % 256);  // send LSB
  outportb(TIMER0_CNTR, counter / 256);  // send MSB
  return;
}

Where:
PIT_FREQ = 0x1234DD
TIMER_CTRL = 0x43
TIMER0_CTRL = 0x40
TIMER0 = 0
TIMER_MODE2 = (1 << 1)
TIMER_WHOLE = (1 << 4) + (2 << 4)

There's more options to configure, of course.  Any documentation on the PIT should explain them all.  http://www.neuraldk.org/cgi-bin/download.pl?ndk contains a working example (timer.c,h)

Cheers,
Jeff
Post Reply