author: Joseph Yang @ DSLAB
mail: ganggexiongqi@gmail.com
==========================
附加:关于软中断的详细介绍,参考:http://blog.csdn.net/zqy2000zqy/archive/2006/08/29/1137881.aspx
在上一篇 “一个简单的并口驱动” 的基础上,我增加了softirq的使用。
具体描述:
Softirq:
1.
Add an entry in file 'include/linux/interrupt.h'.
enum
{
HI_SOFTIRQ=0,
TIMER_SOFTIRQ,
NET_TX_SOFTIRQ,
NET_RX_SOFTIRQ,
BLOCK_SOFTIRQ,
TASKLET_SOFTIRQ,
SCHED_SOFTIRQ,
#ifdef CONFIG_HIGH_RES_TIMERS
HRTIMER_SOFTIRQ,
#endif
MY_SOFTIRQ, // add our entry
};
2.
/*
The bottom half of IRQs.
Softirq implementation.
*/
void my_softirq(void)
{
printk(KERN_NOTICE "%s called./n", __func__);
}
3.
In my init block
add one line:
open_softirq(MY_SOFTIRQ, my_softirq, NULL);
4. In my IRQs
// Mark softirq as pending
raise_softirq(MY_SOFTIRQ);
NOTE:raise_softirq, and open_softirq are kernel inner function which can only be used by
your kernel if you compile your driver staticly with the kernel.
#cp joseph/td/tt.c drivers/char/myparport.c
#vim drivers/char/Kconfig
config MYPARPORT
bool "This is softirq test write by Joseph"
#vim driver/char/Makefile
add one line.
obj-$(CONFIG_MYPARPORT) += myparport.o
#make -j2
...
CC drivers/char/myparport.o
...
#reboot
重复 “一个简单的并口驱动” 中的测试过程,你会在 /var/log/messages中发现,
May 28 07:59:03 joseph kernel: [ 230.494022] my_p_open called success
May 28 07:59:03 joseph kernel: [ 230.494044] my_p_write is entered
May 28 07:59:03 joseph kernel: [ 230.494047] write parport:0
May 28 07:59:08 joseph kernel: [ 235.303304] my_p_open called success
May 28 07:59:08 joseph kernel: [ 235.303324] my_p_write is entered
May 28 07:59:08 joseph kernel: [ 235.303327] write parport:-128
May 28 07:59:08 joseph kernel: [ 235.303335] my_irq_handler called <---------<<<<<<
May 28 07:59:08 joseph kernel: [ 235.303338] my_softirq called.
注意:如果你单独编译你的模块,而不是跟内核编译到一起的话会有raise_softirq, open_softirq符号找不到的信息.因为它们是
内核的内部函数。不允许模块动态使用的。
我的代码如下: