红联Linux门户
Linux帮助

Linux模块编程之keyboard中断替换

发布时间:2007-05-22 09:55:16来源:红联作者:Prospect
把模块编程之keyboard中断替换弄掉了..

只40几行代码...不过得重启才能恢复原来的keyboard中断了..

先注册中断处理函数.

然后在中断处理函数中用tasklet处理.

当然还有读键盘的函数

要注意函数的原形匹配问题.内核各版本有的有差异的.可以差头文件.

/* 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);
文章评论

共有 0 条评论