IRQ and timer problem
IRQ and timer problem
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.
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
I used the init_timer function provided by the tutorial .
I first copied and pasted the code just to confirm it is correct .
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);
}
- max
- Member
- Posts: 616
- Joined: Mon Mar 05, 2012 11:23 am
- Libera.chat IRC: maxdev
- Location: Germany
- Contact:
Re: IRQ and timer problem
Did you disable interrupts? Do you enable interrupts again using the STI instruction?
Re: IRQ and timer problem
Yah i do enable them using
Code: Select all
__asm__ __volatile__("sti");
-
- Member
- Posts: 190
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: IRQ and timer problem
Did you remap the PIC? Did you unmask it?
Re: IRQ and timer problem
I have remaped the pic :
But what do mean by unmask ?
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);
Re: IRQ and timer problem
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).
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
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: IRQ and timer problem
Thanks everyone but actually the problem was with my emulator - qemu .
My codes were correct and it is now working.
Thanks again .
My codes were correct and it is now working.
Thanks again .