Reputation: 9632
I have written a rudimentary keyboard interrupt handler. It uses shared interrupts and is used to print to /var/log/messages which key got pressed. But i get the following error when i try to use arrow keys and rest of the keys work fine.
Aug 19 18:59:06 vim kernel: [ 112.485102] atkbd serio0: Unknown key released (translated set 2, code 0xe0 on isa0060/serio0). Aug 19 18:59:06 vim kernel: [ 112.485108] atkbd serio0: Use 'setkeycodes e060 ' to make it known.
Pasting the code.
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>
/* This function services keyboard interrupts */
irq_handler_t irq_handler (int irq, void *dev_id, struct pt_regs *regs) {
static unsigned char scancode;
/*
Read keyboard status
*/
scancode = inb (0x60);
if ((scancode == 0x01) || (scancode == 0x81))
{
printk ("You pressed Esc !\n");
}
}
return (irq_handler_t) IRQ_HANDLED;
}
/* Initialize the module and Register the IRQ handler */
static int __init keybrd_int_register(void)
{
int result;
/* Request IRQ 1, the keyboard IRQ */
result = request_irq (1, (irq_handler_t) irq_handler, IRQF_SHARED, "keyboard_stats_irq", (void *)(irq_handler));
if (result)
printk(KERN_INFO "can't get shared interrupt for keyboard\n");
return result;
}
/* Remove the interrupt handler */
static void __exit keybrd_int_unregister(void) {
free_irq(1, (void *)(irq_handler)); /* i can't pass NULL, this is a shared interrupt handler! */
}
MODULE_LICENSE ("GPL");
module_init(keybrd_int_register);
module_exit(keybrd_int_unregister);
Can anyone please give me some clue on why this arrow keys stop working when i insert my module and start working whey i remove them?
I am running my code on a Virtual Machine.
Upvotes: 6
Views: 10982
Reputation: 9632
The reason was due to some VM screw up. It works fine on base linux hosts. You can see the full implementation of code (naive) @ https://github.com/vigith/Linux-Device-Drivers/tree/master/keyboard
Upvotes: 4