Linux中断子系统:request_irq()
Posted rtoax
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux中断子系统:request_irq()相关的知识,希望对你有一定的参考价值。
https://gitee.com/rtoax/test/tree/master/linux/interrupt/request_irq
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
#include <linux/interrupt.h> // included for request_irq and free_irq macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Rong Tao");
MODULE_DESCRIPTION("A Simple request irq module");
MODULE_VERSION("0.1");
static char *name = "[RToax]";
module_param( name, charp, S_IRUGO);
MODULE_PARM_DESC(name, "[RToax] irq name");
/**
* 找一个 /proc/interrupt 中没有的 中断号
*/
#define IRQ_NUM 2
irqreturn_t no_action(int cpl, void *dev_id)
{
printk(KERN_INFO "[RToax]cpl %d!\\n", cpl);
return IRQ_NONE;
}
static int __init rtoax_irq_init(void) {
printk(KERN_INFO "[RToax]request irq %s!\\n", name);
/*
* 注册中断
*/
if (request_irq(IRQ_NUM, no_action, IRQF_NO_THREAD, name, NULL))
printk(KERN_ERR "%s: request_irq() failed\\n", name);
return 0;
}
static void __exit rtoax_irq_cleanup(void) {
printk(KERN_INFO "[RToax]free irq.\\n");
/*
* 释放中断
*/
free_irq(IRQ_NUM, NULL);
}
module_init(rtoax_irq_init);
module_exit(rtoax_irq_cleanup);
Makefile
obj-m += request-irq.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
测试
[rongtao@localhost request_irq]$ make
make -C /lib/modules/3.10.0-1062.el7.x86_64/build M=/home/rongtao/test/linux/interrupt/request_irq modules
make[1]: 进入目录“/usr/src/kernels/3.10.0-1062.el7.x86_64”
CC [M] /home/rongtao/test/linux/interrupt/request_irq/request-irq.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/rongtao/test/linux/interrupt/request_irq/request-irq.mod.o
LD [M] /home/rongtao/test/linux/interrupt/request_irq/request-irq.ko
make[1]: 离开目录“/usr/src/kernels/3.10.0-1062.el7.x86_64”
[rongtao@localhost request_irq]$ sudo insmod request-irq.ko
[rongtao@localhost request_irq]$ cat /proc/interrupts | grep RToax
2: 0 0 0 0 XT-PIC-XT-PIC [RToax]
[rongtao@localhost request_irq]$ sudo rmmod request-irq.ko
以上是关于Linux中断子系统:request_irq()的主要内容,如果未能解决你的问题,请参考以下文章
往linux内核注册中断,request_irq返回值-22,不能注册成功