中断子系统5_电流层处理

本文详细介绍了Linux内核中断处理机制,重点讲解了电平型和边沿型中断的处理方式。电平型中断需要在处理前屏蔽中断,以防重复触发,而边沿型中断则在确认后直接处理,因为每个边沿只触发一次中断。文中还阐述了中断处理函数的工作流程,并解释了为何在处理过程中需要控制中断状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    
//  电流类型:
//    1.电平型:handle_level_irq
/*
 *    Level type interrupts are active as long as the hardware line has
 *    the active level. This may require to mask the interrupt and unmask
 *    it after the associated handler has acknowledged the device, so the
 *    interrupt line is back to inactive.
 */
//      译:当中断线电平达到激活电平,中断一直会被激活。 所以需要刚进中断处理函数就要屏蔽掉中断,
//          等handler 处理完后再打开中断(unmask)。
//      问:为什么要先屏蔽中断中断,后确认呢(mask_and_ack)?
//      答:因为cpu周期性采样中断线,当发现电平有效时,触发中断,因此外部设备为了保证cpu可以检测到
//          有效电平,需要将电平保持一段时间。当cpu检测到有效电平后,cpu引脚被置位,如果不先屏蔽中断,
//          直接确认,当cpu引脚复位时,如果此时电平依然有效,那么同一个中断又被触发,此为不正确的。
//            (注:cpu确认是用于复位cpu引脚,对外设的应答在注册的irq_action由特定的驱动程序进行)
//      问:这对于编写ISR有什么启示呢?
//      答:由于在handle_level_irq调用ISR过程中,中断被屏蔽,因此在此期间的新发生的中断可能会丢失(
//          因为电平型中断信号不被中断控制器锁存,电平恢复之前,如果cpu没有通过采样发现此有效电平,
//          则中断丢失),所以ISR应该尽快执行完毕。
//          

//    2.边沿型:handle_edge_irq
/*
 *    Interrupt occures on the falling and/or rising edge of a hardware
 *    signal. The occurence is latched into the irq controller hardware
 *    and must be acked in order to be reenabled. After the ack another
 *    interrupt can happen on the same source even before the first one
 *    is handled by the assosiacted event handler. If this happens it
 *    might be necessary to disable (mask) the interrupt depending on the
 *    controller hardware. This requires to reenable the interrupt inside
 *    of the loop which handles the interrupts which have arrived while
 *    the handler was running. If all p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值