IRQ and timer problem

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
pcdever
Posts: 17
Joined: Thu Jul 28, 2016 1:23 am
Libera.chat IRC: pcdever

IRQ and timer problem

Post 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.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: IRQ and timer problem

Post by max »

Hello,

what did you do to enable the timer?

Greets
pcdever
Posts: 17
Joined: Thu Jul 28, 2016 1:23 am
Libera.chat IRC: pcdever

Re: IRQ and timer problem

Post 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 .
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: IRQ and timer problem

Post by max »

Did you disable interrupts? Do you enable interrupts again using the STI instruction?
pcdever
Posts: 17
Joined: Thu Jul 28, 2016 1:23 am
Libera.chat IRC: pcdever

Re: IRQ and timer problem

Post by pcdever »

Yah i do enable them using

Code: Select all

__asm__ __volatile__("sti");
sebihepp
Member
Member
Posts: 190
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: IRQ and timer problem

Post by sebihepp »

Did you remap the PIC? Did you unmask it?
pcdever
Posts: 17
Joined: Thu Jul 28, 2016 1:23 am
Libera.chat IRC: pcdever

Re: IRQ and timer problem

Post 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 ?
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: IRQ and timer problem

Post 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).
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
pcdever
Posts: 17
Joined: Thu Jul 28, 2016 1:23 am
Libera.chat IRC: pcdever

Re: IRQ and timer problem

Post by pcdever »

Thanks everyone but actually the problem was with my emulator - qemu .
My codes were correct and it is now working.
Thanks again .
Post Reply