linux中断编程 pdf,linux中断之中断注册.pdf

linux 中断之中断注册中断之中断注册 专业的 linux 驱动开发离不开中断处理 在处理中断 首先要注册中断 在 linux 下通过 request irq 来注册中断的 不同内核版本 注册中断所需要的参数也不同 本文以 linux 2 6 34 为例 对比老版本进行说明 request irq 函数在 include linux interrupt h 中定义 原型为 static inline int must check request irq unsigned int irq irq handler t handler unsigned long flags const char name void dev 参数说明 unsigned int irq 注册中断服务程序对应的硬件中断号 irq handler t handler 注册的中断服务程序 函数指针 原型定义为 typedef irqreturn t irq handler t int void unsigned long flags 中断标志 表明中断程序的属性 注意 在新老内核中 相关 属性定义不同 具体参考后面的中断标志位说明 const char name 与该中断相关联的名称 在 proc interrupt 中可看到 void dev 中断服务程序的参数 可以为 NULL 但在注册共享中断时 此参数不能 为 NULL 中断标志位中断标志位 新版本中的 IRQF XXX 替代了老版本中的 SA XXX 主要标志包括以下 IRQF DISABLED 快速中断标志 对应老版本中的 SA INTERRUPT 标志 表明在处 理本中断时屏蔽所有中断 而在没设置此标志位的程序中 都是开中断处理的 可以进行中 断嵌套 IRQF SAMPLE RANDOM 用于随机数据产生 PDF 文件使用 pdfFactory Pro 试用版本创建 IRQF SHARED 用于共享中断 设置此标志时 request irq 最后一个参数 dev 不能 为 NULL 对应老版本内核的 SA SHIRQ IRQF PROBE SHARED 探测共享中断 IRQF TIMER 专用于定时中断 IRQF PERCPU Interrupt is per cpu IRQF NOBALANCING Flag to exclude this interrupt from irq balancing IRQF IRQPOLL Interrupt is used for polling only the interrupt that is registered first in an shared interrupt is considered for performance reasons IRQF ONESHOT Interrupt is not reenabled after the hardirq handler finished Used by threaded interrupts which need to keep the irq line disabled until the threaded handler has been run 注册中断注册中断 相关实现在 kernel irq manage c 中 static inline int must check request irq unsigned int irq irq handler t handler unsigned long flags const char name void dev return request threaded irq irq handler NULL flags name dev int request threaded irq unsigned int irq irq handler t handler irq handler t thread fn unsigned long irqflags const char devname void dev id PDF 文件使用 pdfFactory Pro 试用版本创建 struct irqaction action struct irq desc desc int retval handle IRQ event always ignores IRQF DISABLED except for the first irqaction sigh That can cause oopsing but the behavior is classified as will not fix so we need to start nudging drivers away from using that idiom if irqflags ifdef CONFIG LOCKDEP 若定义此宏 则禁止中断嵌套 所有中断都关中断运行 Lockdep wants atomic interrupt handlers irqflags IRQF DISABLED endif Sanity check shared interrupts must pass in a real dev ID otherwise we ll have trouble later trying to figure out which interrupt is which messes up the interrupt freeing logic etc PDF 文件使用 pdfFactory Pro 试用版本创建 if irqflags desc irq to desc irq 找到该中断号对应的irq desc 即全局数组irq desc的第 irq 个表项 if desc 所有 irq desc 在系统启动时 通过 init IRQ 初始化 return EINVAL if desc status if handler 中断服务程序不能为 NULL if thread fn return EINVAL handler irq default primary handler action kzalloc sizeof struct irqaction GFP KERNEL if action 中断的入口是 irq desc handle irq 或 do IRQ 但我们注册的中 断处理程序都是 irq desc 下的一个 action return ENOMEM action handler handler action thread fn thread fn action flags irqflags action name devname action dev id dev id chip bus lock irq desc retval setup irq irq desc action 注册中断处理 将 action 挂到 PDF 文件使用 pdfFactory Pro 试用版本创建 irq desc action 中 或初始化中断线程等 chip bus sync unlock irq desc if retval kfree action ifdef CONFIG DEBUG SHIRQ 用于调试共享中断 if retval disable irq irq local irq save flags handler irq dev id local irq restore flags enable irq irq endif return retval PDF 文件使用 pdfFactory Pro 试用版本创建

展开阅读全文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值