📄 linux设备驱动程序学习(11)-中断处理 - linux设备驱动程序 - tekkaman ninja.htm
字号:
style="COLOR: #000000"><SPAN
style="COLOR: #0000ff">int</SPAN> <SPAN
style="COLOR: #ff0000">count</SPAN> <SPAN
style="COLOR: #0000cc">=</SPAN> 0<SPAN
style="COLOR: #0000cc">;</SPAN><BR><SPAN
style="COLOR: #0000ff">do</SPAN><BR><SPAN
style="COLOR: #0000cc">{</SPAN><BR> <SPAN
style="COLOR: #0000ff">unsigned</SPAN> <SPAN
style="COLOR: #0000ff">long</SPAN> mask<SPAN
style="COLOR: #0000cc">;</SPAN><BR> mask
<SPAN style="COLOR: #0000cc">=</SPAN>
probe_irq_on<SPAN
style="COLOR: #0000cc">(</SPAN><SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR> outb_p<SPAN
style="COLOR: #0000cc">(</SPAN>0x10<SPAN
style="COLOR: #0000cc">,</SPAN>short_base<SPAN
style="COLOR: #0000cc">+</SPAN>2<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* enable reporting
*/</SPAN><BR> outb_p<SPAN
style="COLOR: #0000cc">(</SPAN>0x00<SPAN
style="COLOR: #0000cc">,</SPAN>short_base<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* clear the bit
*/</SPAN><BR> outb_p<SPAN
style="COLOR: #0000cc">(</SPAN>0xFF<SPAN
style="COLOR: #0000cc">,</SPAN>short_base<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* set the bit:
interrupt!
*/</SPAN><BR> outb_p<SPAN
style="COLOR: #0000cc">(</SPAN>0x00<SPAN
style="COLOR: #0000cc">,</SPAN>short_base<SPAN
style="COLOR: #0000cc">+</SPAN>2<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* disable reporting
*/</SPAN><BR> udelay<SPAN
style="COLOR: #0000cc">(</SPAN>5<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* give it some time
*/</SPAN><BR> short_irq
<SPAN style="COLOR: #0000cc">=</SPAN>
probe_irq_off<SPAN
style="COLOR: #0000cc">(</SPAN>mask<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR><BR> <SPAN
style="COLOR: #0000ff">if</SPAN> <SPAN
style="COLOR: #0000cc">(</SPAN>short_irq <SPAN
style="COLOR: #0000cc">=</SPAN><SPAN
style="COLOR: #0000cc">=</SPAN> 0<SPAN
style="COLOR: #0000cc">)</SPAN> <SPAN
style="COLOR: #0000cc">{</SPAN> <SPAN
style="COLOR: #ff9900">/* none of them?
*/</SPAN><BR> printk<SPAN
style="COLOR: #0000cc">(</SPAN>KERN_INFO <SPAN
style="COLOR: #ff00ff">"short: no irq reported
by probe\n"</SPAN><SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR> short_irq
<SPAN style="COLOR: #0000cc">=</SPAN> <SPAN
style="COLOR: #0000cc">-</SPAN>1<SPAN
style="COLOR: #0000cc">;</SPAN><BR> <SPAN
style="COLOR: #0000cc">}</SPAN><BR><SPAN
style="COLOR: #0000cc">}</SPAN> <SPAN
style="COLOR: #0000ff">while</SPAN> <SPAN
style="COLOR: #0000cc">(</SPAN>short_irq <SPAN
style="COLOR: #0000cc"><</SPAN> 0 <SPAN
style="COLOR: #0000cc">&</SPAN><SPAN
style="COLOR: #0000cc">&</SPAN> <SPAN
style="COLOR: #ff0000">count</SPAN><SPAN
style="COLOR: #0000cc">+</SPAN><SPAN
style="COLOR: #0000cc">+</SPAN> <SPAN
style="COLOR: #0000cc"><</SPAN> 5<SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR><SPAN
style="COLOR: #0000ff">if</SPAN> <SPAN
style="COLOR: #0000cc">(</SPAN>short_irq <SPAN
style="COLOR: #0000cc"><</SPAN> 0<SPAN
style="COLOR: #0000cc">)</SPAN><BR> printk<SPAN
style="COLOR: #0000cc">(</SPAN><SPAN
style="COLOR: #ff00ff">"short: probe failed %i
times, giving up\n"</SPAN><SPAN
style="COLOR: #0000cc">,</SPAN> <SPAN
style="COLOR: #ff0000">count</SPAN><SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN></SPAN></CODE></P></TD></TR></TBODY></TABLE>
<P>最好只在模块初始化时探测中断线一次。<BR>大部分体系定义了这两个函数( 即便是空的
)来简化设备驱动的移植。</P>
<P><FONT
color=#0000ff><STRONG>(2)DIY探测</STRONG></FONT></P><FONT
color=#0000ff>
<P><FONT color=#000000>DIY探测与前面原理相同: 使能所有未使用的中断,
接着等待并观察发生什么。我们对设备的了解:通常一个设备能够使用3或4个IRQ
号中的一个来进行配置,只探测这些 IRQ 号使我们能不必测试所有可能的中断就探测到正确的IRQ
号。</FONT></P>
<P></FONT><FONT
color=#000000>下面的LDD3中的代码通过测试所有"可能的"中断并且察看发生的事情来探测中断。
trials 数组列出要尝试的中断, 以 0 作为结尾标志; tried
数组用来跟踪哪个中断号已经被这个驱动注册。
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: #000000"><FONT face=新宋体><SPAN
style="COLOR: #0000ff">int</SPAN> trials<SPAN
style="COLOR: #0000cc">[</SPAN><SPAN
style="COLOR: #0000cc">]</SPAN> <SPAN
style="COLOR: #0000cc">=</SPAN> <SPAN
style="COLOR: #0000cc">{</SPAN>3<SPAN
style="COLOR: #0000cc">,</SPAN> 5<SPAN
style="COLOR: #0000cc">,</SPAN> 7<SPAN
style="COLOR: #0000cc">,</SPAN> 9<SPAN
style="COLOR: #0000cc">,</SPAN> 0<SPAN
style="COLOR: #0000cc">}</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR><SPAN
style="COLOR: #0000ff">int</SPAN> tried<SPAN
style="COLOR: #0000cc">[</SPAN><SPAN
style="COLOR: #0000cc">]</SPAN> <SPAN
style="COLOR: #0000cc">=</SPAN> <SPAN
style="COLOR: #0000cc">{</SPAN>0<SPAN
style="COLOR: #0000cc">,</SPAN> 0<SPAN
style="COLOR: #0000cc">,</SPAN> 0<SPAN
style="COLOR: #0000cc">,</SPAN> 0<SPAN
style="COLOR: #0000cc">,</SPAN> 0<SPAN
style="COLOR: #0000cc">}</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR><SPAN
style="COLOR: #0000ff">int</SPAN> i<SPAN
style="COLOR: #0000cc">,</SPAN> <SPAN
style="COLOR: #ff0000">count</SPAN> <SPAN
style="COLOR: #0000cc">=</SPAN> 0<SPAN
style="COLOR: #0000cc">;</SPAN></FONT></SPAN></CODE></P>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: #000000"><SPAN
style="COLOR: #0000cc"></SPAN><BR><FONT
face=新宋体><SPAN style="COLOR: #0000ff">for</SPAN>
<SPAN style="COLOR: #0000cc">(</SPAN>i <SPAN
style="COLOR: #0000cc">=</SPAN> 0<SPAN
style="COLOR: #0000cc">;</SPAN> trials<SPAN
style="COLOR: #0000cc">[</SPAN>i<SPAN
style="COLOR: #0000cc">]</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN> i<SPAN
style="COLOR: #0000cc">+</SPAN><SPAN
style="COLOR: #0000cc">+</SPAN><SPAN
style="COLOR: #0000cc">)</SPAN><BR> tried<SPAN
style="COLOR: #0000cc">[</SPAN>i<SPAN
style="COLOR: #0000cc">]</SPAN> <SPAN
style="COLOR: #0000cc">=</SPAN> request_irq<SPAN
style="COLOR: #0000cc">(</SPAN>trials<SPAN
style="COLOR: #0000cc">[</SPAN>i<SPAN
style="COLOR: #0000cc">]</SPAN><SPAN
style="COLOR: #0000cc">,</SPAN>
short_probing<SPAN
style="COLOR: #0000cc">,</SPAN><BR> SA_INTERRUPT<SPAN
style="COLOR: #0000cc">,</SPAN> <SPAN
style="COLOR: #ff00ff">"short probe"</SPAN><SPAN
style="COLOR: #0000cc">,</SPAN> <SPAN
style="COLOR: #ff0000">NULL</SPAN><SPAN
style="COLOR: #0000cc">)</SPAN><SPAN
style="COLOR: #0000cc">;</SPAN><BR><SPAN
style="COLOR: #0000ff">do</SPAN><BR><SPAN
style="COLOR: #0000cc">{</SPAN><BR> short_irq
<SPAN style="COLOR: #0000cc">=</SPAN> 0<SPAN
style="COLOR: #0000cc">;</SPAN> <SPAN
style="COLOR: #ff9900">/* none got, yet
*/</SPAN><BR> outb_p<SPAN
style="COLOR: #0000cc">(</SPAN>0x10<SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -