我是学习Linux设备驱动程序的初学者。我写了一个键盘驱动程序:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>
/*
This function services keyboard interrupts.
*/
int packetNumber=3000;
EXPORT_SYMBOL(packetNumber);
irqreturn_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)
{
packetNumber += 10;
printk(KERN_ALERT "packetNumber:%x\n",&packetNumber);
printk (KERN_ALERT "You pressed Esc ! packetNumber: %d\n", packetNumber);
}
return (irqreturn_t) IRQ_HANDLED;
}
/*
Initialize the module ? register the IRQ handler
*/
static int hello_keyboard (void)
{
/*
Request IRQ 1, the keyboard IRQ, to go to our irq_handler SA_SHIRQ means we're willing to have othe handlers on this IRQ. SA_INTERRUPT can be used to make the handler into a fast interrupt.
*/
packetNumber += 10;
printk(KERN_ALERT "hello, keyboard.%d\n", packetNumber);
return request_irq (1, (irqreturn_t) irq_handler, SA_SHIRQ, "test_keyboard_irq_handler", (void *)(irq_handler));
}
static void bye_keyboard(void)
{
printk(KERN_ALERT "Goodbye, keyboard\n");
}
module_init(hello_keyboard);
module_exit(bye_keyboard);
MODULE_AUTHOR("e-Friends");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("a simple keyboard driver.");
我想使用这个键盘驱动程序模拟这样的竞争条件场景: http://ww3.sinaimg.cn/mw690/5f10acdbjw1ealisec0frj20lk0e8gnm.jpg
我对上面的图片不太了解。
为了模拟场景,我想知道:
PS: 我暂时在init函数中使用了packetNumber变量(hello_keyboard函数),对吗?