linux内核模块中软中断的例子.doc

上传人:doc321 文档编号:14911930 上传时间:2022-02-24 格式:DOC 页数:4 大小:78.50KB
返回 下载 相关 举报
linux内核模块中软中断的例子.doc_第1页
第1页 / 共4页
linux内核模块中软中断的例子.doc_第2页
第2页 / 共4页
linux内核模块中软中断的例子.doc_第3页
第3页 / 共4页
linux内核模块中软中断的例子.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《linux内核模块中软中断的例子.doc》由会员分享,可在线阅读,更多相关《linux内核模块中软中断的例子.doc(4页珍藏版)》请在三一文库上搜索。

1、文档供参考,可复制、编制,期待您的好评与关注! 直接上例子吧。只是捕获某个设备的中断而已。该文件的名字是irq.cview plaincopy to clipboardprint?#include #include #include #include #include #define DEBUG #ifdef DEBUG #define MSG(message, args.) printk(KERN_DEBUG irq: message, #args) #else #define MSG(message, args.) #endif MODULE_LICENSE(GPL); MODULE_AU

2、THOR(silence1214); int irq; char *interface; / 下面这2个参数通过插入内核模块的时候赋值的. module_param(irq, int, 0644); module_param(interface, charp, 0644); / 中断捕获的时候的处理函数 int irq_handle_function(int irq, void *device_id) static int count = 1; MSG(%dreceive the irq at %ld.n, count, jiffies); count+; return IRQ_NONE; i

3、nt init_module() / 注册中断捕获,第三个参数的意思是和其他设备共享该中断号,最后一个参数是设备的id,其实对于共享下的设备这个号码据说是随便写,一般都写irq的了。 /只要注册成功就可以等待对应设备的该中断号的到来 就可以处理回调函数了。 if(request_irq(irq, irq_handle_function, IRQF_SHARED, interface, (void *)&irq) MSG(regist irq failure.n); return -EIO; MSG(interface=%s and irq=%d.n, interface, irq); MSG(

4、regist irq success.n); return 0; void cleanup_module() free_irq(irq, &irq); MSG(unregist irq.n); #include #include #include #include #include #define DEBUG#ifdef DEBUG#define MSG(message, args.) printk(KERN_DEBUG irq: message, #args)#else#define MSG(message, args.)#endifMODULE_LICENSE(GPL);MODULE_AU

5、THOR(silence1214);int irq;char *interface;/ 下面这2个参数通过插入内核模块的时候赋值的.module_param(irq, int, 0644);module_param(interface, charp, 0644);/ 中断捕获的时候的处理函数int irq_handle_function(int irq, void *device_id)static int count = 1;MSG(%dreceive the irq at %ld.n, count, jiffies);count+;return IRQ_NONE;int init_modu

6、le()/ 注册中断捕获,第三个参数的意思是和其他设备共享该中断号,最后一个参数是设备的id,其实对于共享下的设备这个号码据说是随便写,一般都写irq的了。/只要注册成功就可以等待对应设备的该中断号的到来 就可以处理回调函数了。if(request_irq(irq, irq_handle_function, IRQF_SHARED, interface, (void *)&irq)MSG(regist irq failure.n);return -EIO;MSG(interface=%s and irq=%d.n, interface, irq);MSG(regist irq success.

7、n);return 0;void cleanup_module()free_irq(irq, &irq);MSG(unregist irq.n);对应的makefile的内容是view plaincopy to clipboardprint?obj-m:=irq.o default: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules obj-m:=irq.odefault:make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules 我

8、的当前内核版本为:2.6.27.5-117.fc10.i686执行步骤:1:首先make一下生成irq.ko2:查看 cat /proc/interrupts我的打印结果是:这个19就是我需要使用的中断号,eth0其实就是网卡(第一块,我也就这么一块)。然后我使用插入内核模块的命令是:2.1:insmod irq.ko interface=eth1 irq=19如果没有报任何信息就是插入正确了,接着2.2:输入 dmesg 回车。就会看到如下截图的信息了。就是我们程序中打印的信息。好了这就是算成功了。2.3:原理就是,注册了一个捕获中断号为19的程序。然后当发出19的中断号的设备发出中断时。我程序捕获一下。3:最后使用命令 cat /proc/interrupts 查看一下刚才的变化那个19的记录后面是不是多出了个eth1?这个eth1就是刚才insmod irq.ko interface=eth1 irq=19 命令中的eth1哈 咱们设备的名字。ok了。算是入门了。4 / 4

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1