Page 1 of 1

IRQ0 ? How would I setup the clock?

Posted: Sat Nov 09, 2002 7:59 pm
by gtsphere
I have read a lot about the IRQ0 but how would I actually go about setting it up in C? I have pretty lost with that right now, i've viewed other peoples but it doesn't really just answer, how can i get a simple clock, like that just counts seconds, no hours, etc?

Re:IRQ0 ? How would I setup the clock?

Posted: Mon Nov 11, 2002 6:43 am
by Tim
Set up your IDT. Write some assembly code which will save registers, call a C function, then restore registers. Write a handler for IRQ 0 which looks like:

Code: Select all

void irq0_handler(void)
{
    elapsed_ticks++;
}

unsigned get_system_uptime(void)
{
    // assumes default rate of 18.2 Hz (91/5 = 18.2)
    return (elapsed_ticks * 5) / 91;
}
There are examples elsewhere of how to set up an IDT, write interrupt wrapper routines, and change the clock rate.

Re:IRQ0 ? How would I setup the clock?

Posted: Tue Nov 12, 2002 7:41 pm
by Tom
does that update_time...thing return in seconds?

Re:IRQ0 ? How would I setup the clock?

Posted: Tue Nov 12, 2002 7:51 pm
by Tom
oh it does....( I think by now I should Remember to read better )