Keyboard interruption replacement For Linux module programming

Source: Internet
Author: User
Linux module programming keyboard interrupt replacement-Linux general technology-Linux programming and kernel information, the following is a detailed description. Replaced the module programming keyboard interrupt ..

Only 40 lines of code... You have to restart to restore the original keyboard interruption ..

Register the interrupt handler first.

Use tasklet In the interrupt processing function.

Of course, there are also functions for reading the keyboard.

Pay attention to the original function matching problem. The kernel versions may be different. The header file may be different.

/* The interrupt module, repalce the keyboard interrupt
* Edit by bo-liu
* 07-5-21
*/

# Include
# Include
# Include
# Include
# Include

MODULE_AUTHOR ("BO-LIU ");
MODULE_LICENSE ("GPL ");

Static unsigned char scancode;
Static void kbd_do_tasklet (unsigned long unused );
DECLARE_TASKLET (kbd_tasklet, kbd_do_tasklet, 0 );

Static void kbd_handler (int irq, void * dev_id, struct pt_regs * regs ){
// While (! (Inb (0x64) & 1 ));
Wait:
If (! (Inb (0x64) & 1 ))
Goto wait;
Scancode = inb (0x60 );
Tasklet_schedule (& kbd_tasklet );
}

Static void kbd_do_tasklet (unsigned long unused ){
Printk ("scancode % x % s.", scancode & 0x7f, (scancode & 0x80 )? "Released": "pressed ");
}

Static int kbd_init (void ){
Free_irq (1, NULL );
Request_irq (1, kbd_handler, 0, "keyboard", NULL );

}

Static void kbd_cleanup (void ){
Free_irq (1, NULL );
}


Module_init (kbd_init );
Module_exit (kbd_cleanup );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.