博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
你的第一个中断处理程序
阅读量:4229 次
发布时间:2019-05-26

本文共 1793 字,大约阅读时间需要 5 分钟。

 

//平台:ubuntu9.10  

 

#include "linux/init.h"

#include "linux/module.h"

#include "linux/kernel.h"

 

#include "linux/interrupt.h"

 

static int irq;

static char * interface;

 

module_param(interface,charp,0644);

module_param(irq,int,0644);

 

static irqreturn_t myinterrupt(int irq,void * dev_id)

{

static int mycount = 0;

static long mytime = 0;

struct net_device *dev=(struct net_device *)dev_id;

if(mycount==0){

mytime=jiffies;

}

//count the interval between two irqs

if (mycount < 10) {

mytime=jiffies-mytime;

printk("Interrupt number %d — intterval(jiffies) %ld  — jiffies:%ld /n", irq,mytime, jiffies);

mytime=jiffies;

//printk("Interrupt on %s —–%d /n",dev->name,dev->irq);

}

mycount++;

return IRQ_NONE;

}

 

 

static int __init myirqtest_init(void)

{

printk ("My module worked!/n");

//regist irq

//if (request_irq(irq,&myinterrupt,SA_SHIRQ,interface,&irq)) { //early than 2.6.23

if (request_irq(irq,&myinterrupt,IRQF_SHARED,interface,&irq)) { //later than 2.6.23

printk(KERN_ERR "myirqtest: cannot register IRQ %d/n", irq);

return -EIO;

}

printk("%s Request on IRQ %d succeeded/n",interface,irq);

 

return 0;

}

 

static void __exit myirqtest_exit(void)

{

printk ("Unloading my module./n");

free_irq(irq, &irq); //release irq

printk("Freeing IRQ %d/n", irq);

 

return;

}

 

module_init(myirqtest_init);

module_exit(myirqtest_exit);

 

MODULE_AUTHOR("lin.tang");

MODULE_LICENSE("GPL");

 

 

对应Makefile文件:

 

 

 

obj-m += interrupt.o

#generate the path

CURRENT_PATH:=$(shell pwd)

 

#the current kernel version number

LINUX_KERNEL:=$(shell uname -r)

 

#the absolute path

LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)

 

#complie object

all:

make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules

#clean

clean:

make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean

rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

 

 

 

//参考文档:

 

 

转载地址:http://visqi.baihongyu.com/

你可能感兴趣的文章
Pro WF: Windows Workflow in .NET 3.0
查看>>
Beginning SQL Server 2005 Express for Developers: From Novice to Professional
查看>>
Multimedia over IP and Wireless Networks: Compression, Networking, and Systems
查看>>
Hacking Ubuntu: Serious Hacks Mods and Customizations
查看>>
PHP 5 Advanced: Visual QuickPro Guide
查看>>
Adobe Illustrator CS3 Classroom in a Book
查看>>
Sams Teach Yourself Adobe Photoshop CS3 in 24 Hours
查看>>
FileMaker Pro 8.5 Bible
查看>>
AutoCAD: Secrets Every User Should Know
查看>>
Combating Spyware in the Enterprise
查看>>
Microsoft Windows Vista Unveiled
查看>>
How to Cheat at Securing a Wireless Network
查看>>
Sams Teach Yourself Visual C# 2005 in 24 Hours, Complete Starter Kit
查看>>
Smarty Php Template Programming And Applications
查看>>
Web Site Measurement Hacks
查看>>
The Best Damn Windows Server 2003 Book Period
查看>>
Cleaning Windows XP For Dummies
查看>>
The Windows 2000 Device Driver Book: A Guide for Programmers (2nd Edition)
查看>>
Python in a Nutshell
查看>>
Microsoft Visual C++ .NET Professional Projects
查看>>