Page 1 of 1

IRQ and timer problem

Posted: Thu Aug 18, 2016 12:50 am
by pcdever
Hello Everyone ,
This problem seems to be very common and many forums were related to this topic but no answer could solve my problem .
I was following the James Molloy tutorial . Everything was smooth untill i reached the irq and pit tutorial .
The problem with me is that the irq handler as well as the timer handler are not called .
I manually called the interrupt using __asm__ __volatile__("int $0x32") and the handler worked but this handler as according to the tutorial should be called automatically but it is not in my case.

Tutorial Link : http://johnvidler.co.uk/mirror/jamesm-k ... rial_html/

It's been a week i have been searching the web for solutions but i could not find any .
And just for information i have also setup a keyboard driver and it is working , but the timer is not.
I will really appreciate if anyone could find me a way out .

Thanks in Advance.

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 12:53 am
by max
Hello,

what did you do to enable the timer?

Greets

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 12:58 am
by pcdever
I used the init_timer function provided by the tutorial .

Code: Select all

void init_timer(u32int frequency)
{
   // Firstly, register our timer callback.
   register_interrupt_handler(IRQ0, &timer_callback);
   // The value we send to the PIT is the value to divide it's input clock
   // (1193180 Hz) by, to get our required frequency. Important to note is
   // that the divisor must be small enough to fit into 16-bits.
   u32int divisor = 1193180 / frequency;

   // Send the command byte.
   out(0x43, 0x36);

   // Divisor has to be sent byte-wise, so split here into upper/lower bytes.
   u8int l = (u8int)(divisor & 0xFF);
   u8int h = (u8int)( (divisor>>8) & 0xFF );

   // Send the frequency divisor.
   out(0x40, l);
   out(0x40, h);
} 
I first copied and pasted the code just to confirm it is correct .

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 1:09 am
by max
Did you disable interrupts? Do you enable interrupts again using the STI instruction?

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 1:10 am
by pcdever
Yah i do enable them using

Code: Select all

__asm__ __volatile__("sti");

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 1:48 am
by sebihepp
Did you remap the PIC? Did you unmask it?

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 2:00 am
by pcdever
I have remaped the pic :

Code: Select all

  //remap PIC
  out(0x20, 0x11);
  out(0xA0, 0x11);
  out(0x21, 0x20);
  out(0xA1, 0x28);
  out(0x21, 0x04);
  out(0xA1, 0x02);
  out(0x21, 0x01);
  out(0xA1, 0x01);
  out(0x21, 0x0);
  out(0xA1, 0x0);
But what do mean by unmask ?

Re: IRQ and timer problem

Posted: Thu Aug 18, 2016 7:27 am
by Octacone
Last night I finally fixed my PIT.
The thing was: lets just assume that you have some sort of an internal timer wait function. Inside that timer wait there is a while loop that does the "sleep management". Now you need to enable interrupts inside that loop. Also inside your handler you need to have a way of adding passed time once per interrupt. Also make sure that you variables are marked as volatile (so they don't get optimized by GCC).

Re: IRQ and timer problem

Posted: Sat Aug 20, 2016 12:44 am
by pcdever
Thanks everyone but actually the problem was with my emulator - qemu .
My codes were correct and it is now working.
Thanks again .