探测也可以在驱动自身实现没有太大麻烦. 它是一个少有的驱动必须实现它自己的探测, 但是看它是如何工作的能够给出对这个过程的内部认识. 为此目的, short 模块进行 do- it-yourself 的 IRQ 线探测, 如果它使用 probe=2 加载.

这个机制与前面描述的相同: 使能所有未使用的中断, 接着等待并观察发生什么. 我们能 够, 然而, 利用我们对设备的知识. 常常地一个设备能够配置为使用一个 IRQ 号从 3 个 或者 4 个一套; 只探测这些 IRQ 使我们能够探测正确的一个, 不必测试所有的可能中断.

short 实现假定 3, 5, 7, 和 9 是唯一可能的 IRQ 值. 这些数实际上是一些并口设备允 许你选择的数.

下面的代码通过测试所有"可能的"中断并且查看发生的事情来探测中断. trials 数组列 出要尝试的中断, 以 0 作为结尾标志; tried 数组用来跟踪哪个处理实际上被这个驱动 注册.

int
trials[] =

{

};

3, 5, 7, 9, 0

int tried[]  = {0, 0, 0,
0, 0}; int i, count = 0;

/*


install the probing handler for all possible lines. Remember


the result (0 for success, or -EBUSY) in order to
only free


what has been acquired */ for (i = 0; trials[i]; i++)

tried[i] =
request_irq(trials[i], short_probing,

SA_INTERRUPT,
"short probe", NULL);

do

{

short_irq =
0; /* none got, yet */ outb_p(0x10,short_base+2); /* enable */ outb_p(0x00,short_base);
outb_p(0xFF,short_base); /* toggle the bit */ outb_p(0x00,short_base+2); /*
disable */ udelay(5); /* give it some time */

/*
the value has been set by the handler */ if (short_irq == 0) { /* none of them?
*/

printk(KERN_INFO
"short: no irq reported by probe\n");

}

/*


If more than one line has been activated, the result is


negative. We should service the interrupt (but the
lpt port


doesn't need it) and loop over again. Do it at most
5 times

*/

}
while (short_irq <=0 && count++ < 5);

/*
end of loop, uninstall the handler */ for (i = 0; trials[i]; i++)

if
(tried[i] == 0)

free_irq(trials[i],
NULL);

if
(short_irq < 0)

printk("short:
probe failed %i times, giving up\n", count);

你可能事先不知道"可能的" IRQ 值是什么. 在这个情况, 你需要探测所有空闲的中断, 不是限制你自己在几个 trials[]. 为探测所有的中断, 你不得不从 IRQ 0 到 IRQ NR_IRQS-1 探测, 这里 NR_IRQS 在
<asm/irq.h> 中定义并且是独立于平台的.

现在我们只缺少探测处理自己了. 处理者的角色是更新 short_irq, 根据实际收到哪个中 断. short_irq 中的 0 值意味着"什么没有",
而一个负值意味着"模糊的". 这些值选择
来和 probe_irq_off 相一致并且允许同样的代码来调用任一种
short.c 中的探测.

irqreturn_t
short_probing(int irq, void *dev_id, struct pt_regs *regs)

{

if (short_irq == 0) short_irq = irq;  /*
found */

if
(short_irq != irq) short_irq = -irq; /* ambiguous */ return IRQ_HANDLED;

}

处理的参数在后面描述. 知道 irq 是在处理的中断应当是足够的来理解刚刚展示的函数.

最新文章

  1. 学习笔记 :DrawText
  2. c# long转 datetime
  3. pthread——pthread_cleanup
  4. MVC中如何设置路由指定默认页
  5. Msyql-检测数据库版本
  6. 作业七:团队项目——Alpha版本冲刺阶段 001
  7. Inno Setup 卸载前关闭进程或服务 x86 x64
  8. iOS:特殊符号大全
  9. 关于cmd的东西
  10. 树型动态规划(树形dp)
  11. Redis介绍和环境安装
  12. Node.js 蚕食计划(四)—— Express + SQL Server 搭建电影网站
  13. HDU6166-Senior Pan-Dijkstra迪杰斯特拉算法(添加超源点,超汇点)+二进制划分集合-2017多校Team09
  14. spring-boot-2.0.3启动源码篇四 - run方法(三)之createApplicationContext
  15. DNS 本质
  16. MAC基本操作
  17. CentOS 7 安装配置 MySQL
  18. js中数字直接点方法会报错,如1.toString()
  19. centos7更改引导项等待时间
  20. html5 canvas贝塞尔曲线篇(上)

热门文章

  1. Emacs用JDEE编写Android程序
  2. Silverlight 2.5D RPG游戏技巧与特效处理:(五)HLSL渲染动画
  3. 如何在iPhone 显示一个 星级评分
  4. oracle如何利用hostname方式连接数据库
  5. Android实战:手把手实现“捧腹网”APP(二)-----捧腹APP原型设计、实现框架选取
  6. 2018-9-30-C#-从零开始写-SharpDx-应用-画三角
  7. Redis源码解析:08对象
  8. CSS文本超过两行用省略号代替
  9. MySQL_分库分表
  10. Spark JDBC系列--Mysql tinyInt字段特殊处理