在linux中使用tasklet
软硬件环境:linux-2.6.36/s3c2440
tasklet是通过软中断实现的,所以它本身也是软中断。
test.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/delay.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("zhanglong");
struct tasklet_struct my_tasklet;
void tasklet_action(unsigned long arg)
{
printk("tasklet handle. arg = %ld\n", arg);
}
static irqreturn_t irq_handle(int irq, void *dev_id)
{
tasklet_schedule(&my_tasklet); //再中断处理函数中调度tasklet
printk("------irq handle. dev_id = %d\n", (int)dev_id);
return IRQ_HANDLED;
}
int test_init(void)
{
int ret = 0;
tasklet_init(&my_tasklet, tasklet_action, 789);
set_irq_type(IRQ_EINT0, IRQ_TYPE_EDGE_RISING);
ret = request_irq(IRQ_EINT0, irq_handle, 0, "my irq", (void *)123);
if (ret) {
printk("request irq failed.\n");
return -EBUSY;
}
return 0;
}
void test_exit(void)
{
free_irq(IRQ_EINT0, (void *)123);
}
module_init(test_init);
module_exit(test_exit);
|
Makefile
#KERNEL = /home/zl/my2440-2.6.13
KERNEL = /media/STUDY/linux/kernel/my2440-2.6.36
#KERNEL = /lib/modules/$(shell uname -r)/build
default:
make -C $(KERNEL) M=$(shell pwd) modules
clean:
make -C $(KERNEL) M=$(shell pwd) modules clean
modules_install:
make -C $(KERNEL) M=$(shell pwd) modules_install INSTALL_MOD_PATH=/home/zl/s3c2440_nfs
depmod -a -b /home/zl/s3c2440_nfs 2.6.13-ZL2440
obj-m += test.o
|
make后插入生成的test.ko模块。按下GPF0所在的按键,终端会有输出:
[root@zhanglong mytasklet]# ------irq handle. dev_id = 123
tasklet handle. arg = 789
------irq handle. dev_id = 123
tasklet handle. arg = 789
------irq handle. dev_id = 123
tasklet handle. arg = 789
……
阅读(922) | 评论(0) | 转发(0) |