Page 1 of 1
Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 2:13 pm
by amittomar
I followed the tutorial from
http://www.osdever.net/bkerndev/index.php and wrote some code to handle IRQs.
I am having a peculiar issue. Whenever I press a key, the key I pressed gets printed correctly, but again the IRQ fires and a junk value gets printed as well. Can someone guide what direction should I be looking into ?
Can it be 'spurious interrupt', but then When I run the code taken from the same tutorial as it is, it works fine with no multiple prints.
P.S. I have implemented a Timer as well, and it works fine (fires once).
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 2:27 pm
by xenos
You know that you get interrupts both on key press and release?
http://www.win.tue.nl/~aeb/linux/kbd/sc ... html#ss1.1
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 2:55 pm
by amittomar
This is how I am handling the key press :
Code: Select all
// Handles the keyboard interrupt
void handleKeyPress(registerStructure *registerInformation)
{
unsigned char keyPressed ;
unsigned short port = 0x60;
// Read the value from data register
asm volatile("inb %1, %0" : "=a" (keyPressed) : "dN" (port));
// When a key is released, highest byte is set to 1
if ( 1 == (keyPressed & 0x80))
{
// Handle shift/ctrl keys
}
// Key pressed
else
{
putCharacterOnScreen(keyboardMapping[keyPressed]);
}
}
I think it takes appropriate care of both press and release ?
Now that you pointed towards it I noticed something in the output :
1. Valid key is printed as soon as I press the key
2. Invalid key is printed only when I release the key
3. If I keep the key pressed, it keep printing the valid key till I release, which is when an invalid key is printed once.
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 3:04 pm
by jnc100
If I was you compiler, I would have optimized
amittomar wrote:Code: Select all
if ( 1 == (keyPressed & 0x80))
{
// Handle shift/ctrl keys
}
// Key pressed
else
{
putCharacterOnScreen(keyboardMapping[keyPressed]);
}
to
Code: Select all
putCharacterOnScreen(keyboardMapping[keyPressed]);
Regards,
John.
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 3:06 pm
by amittomar
@XenOS
if ( 1 == (keyPressed & 0x80))
Here is the bug. It should just have been
if ( (keyPressed & 0x80))
Thanks a lot. You made me think in the right direction. Am new to the forums, anything I can do to give you 'reputation' in any sense ? Some way to 'vote you up' or anything ?
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 3:07 pm
by amittomar
Hehe seems I was just a minute late to realize and reply..
Re: Keyboard IRQ handler getting fired twice
Posted: Mon Oct 28, 2013 11:57 pm
by xenos
amittomar wrote:Thanks a lot. You made me think in the right direction. Am new to the forums, anything I can do to give you 'reputation' in any sense ? Some way to 'vote you up' or anything ?
I don't think that the forums have something like this, but reading that my advice could help you already makes my day