以下这段代码能够在X86上很好的运行,他主要是重新分配键盘的IRQ,读取键盘的数据寄存器,安排队列的运行,最终打印出scancode的值和按键状态。
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/keyboard.h>
/* Bottom Half - 一旦内核模块认为他做任何事都是安全的时候这将被内核调用。 */
static void got_char(void *scancode)
{
printk("Scan Code %x %s.n",
(int) *((char *) scancode) & 0x
*((char *) scancode) & 0x80 ? "Released" : "Pressed");
}
/* 这个函数为键盘中断服务。他读取来自键盘的相关信息然后安排当内核认为bottom half安全的时候让他运行 */
void irq_handler(int irq,
void *dev_id,
struct pt_regs *regs)
{
/* 这些变量是静态的,因为他们需要对 bottom half 可见(通过指针)。 */
static unsigned char scancode;
static struct tq_struct task = {NULL, 0, got_char, &scancode};
unsigned char status;
/* Read keyboard status */
status = inb(0x64);
scancode = inb(0x60);
/* 安排 bottom half 运行 */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)
queue_task(&task, &tq_immediate);
#else
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




