文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>IRQ自己修改的中断函数

IRQ自己修改的中断函数

时间:2009-07-29  来源:mijianbin2008

在此,我们将编写一个模块,其中有一个中断函数,当内核接收到某个 IRQ 上的一个中断时会调用它。   /*======================================================================
    A simple kernel module: "hello world"
        
    The initial developer of the original code is Baohua Song
    <[email protected]>. All Rights Reserved.
======================================================================*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
MODULE_LICENSE("Dual BSD/GPL"); 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,struct pt_regs *regs)
{
   static int mycount = 0;
   if(mycount<10){
     printk("Interrupt!\n");
     mycount++;
   }
   return IRQ_NONE;
}
  static int myinterrupt_init(void)
{
  printk(KERN_EMERG "Driver World enter\n");
  if(request_irq(irq,&myinterrupt,IRQF_SHARED,interface,&irq)){
  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 myinterrupt_exit(void)
{
  printk(KERN_EMERG "Unloading Driver World\n");
  free_irq(irq,&irq);
  printk("Freeing IQR %d\n",irq);
} module_init(myinterrupt_init);
module_exit(myinterrupt_exit);
MODULE_AUTHOR("Song Baohua");
MODULE_DESCRIPTION("A simple Hello World Module");
MODULE_ALIAS("a simplest module");
这里要说明的是,在插入模块时,可以带两个参数,例如
insmod myirq.ko interface=eth0 irq=9

其中 具体网卡 irq的值可以查看 cat /proc/interrupts
   

irqflags是中断处理的属性,若设置了IRQF_DISABLED (老版本中的SA_INTERRUPT,本版zhon已经不支持了),则表示中断处理程序是快速处理程序,快速处理程序被调用时屏蔽所有中断,慢速处理程序不屏蔽;若设置了IRQF_SHARED (老版本中的SA_SHIRQ),则表示多个设备共享中断,若设置了IRQF_SAMPLE_RANDOM(老版本中的SA_SAMPLE_RANDOM),表示对系统熵有贡献,对系统获取随机数有好处。(这几个flag是可以通过或的方式同时使用的)

   
相关阅读 更多 +
排行榜 更多 +
宝宝切水果安卓版

宝宝切水果安卓版

休闲益智 下载
儿童脑筋急转弯

儿童脑筋急转弯

休闲益智 下载
袭击现场2

袭击现场2

飞行射击 下载