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).
Keyboard IRQ handler getting fired twice
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Keyboard IRQ handler getting fired twice
You know that you get interrupts both on key press and release?
http://www.win.tue.nl/~aeb/linux/kbd/sc ... html#ss1.1
http://www.win.tue.nl/~aeb/linux/kbd/sc ... html#ss1.1
Re: Keyboard IRQ handler getting fired twice
This is how I am handling the key press :
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.
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]);
}
}
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
If I was you compiler, I would have optimized
Regards,
John.
toamittomar wrote:Code: Select all
if ( 1 == (keyPressed & 0x80)) { // Handle shift/ctrl keys } // Key pressed else { putCharacterOnScreen(keyboardMapping[keyPressed]); }
Code: Select all
putCharacterOnScreen(keyboardMapping[keyPressed]);
John.
Re: Keyboard IRQ handler getting fired twice
@XenOS
Here is the bug. It should just have beenif ( 1 == (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 ?if ( (keyPressed & 0x80))
Re: Keyboard IRQ handler getting fired twice
Hehe seems I was just a minute late to realize and reply..
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Keyboard IRQ handler getting fired twice
I don't think that the forums have something like this, but reading that my advice could help you already makes my dayamittomar 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 ?