中断触发方式

1. 设置控制器硬件:内核提供一些标准函数,用于注册irq_chip 和 设置电流处理程序。
    /* Set/get chip/data for an IRQ: */
    extern int set_irq_chip(unsigned int irq, struct irq_chip *chip);
    extern int set_irq_data(unsigned int irq, void *data);
    extern int set_irq_chip_data(unsigned int irq, void *data);
    extern int set_irq_type(unsigned int irq, unsigned int type);
    extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
    #define get_irq_chip(irq)    (irq_desc[irq].chip)
    #define get_irq_chip_data(irq)    (irq_desc[irq].chip_data)
    #define get_irq_data(irq)    (irq_desc[irq].handler_data)
    #define get_irq_msi(irq)    (irq_desc[irq].msi_desc)

    /*
     * Set a highlevel flow handler for a given IRQ:
     */
    static inline void
    set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
    {
        __set_irq_handler(irq, handle, 0, NULL);
    }
    /*
     * Set a highlevel chained flow handler for a given IRQ.
     * (a chained handler is automatically enabled and set to
     * IRQ_NOREQUEST and IRQ_NOPROBE)
     */
    static inline void
    set_irq_chained_handler(unsigned int irq,
                irq_flow_handler_t handle)
    {
        __set_irq_handler(irq, handle, 1, NULL);
    }

    extern void
    set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
                 irq_flow_handler_t handle);
    extern void
    set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
                 irq_flow_handler_t handle, const char *name);

2. 电流处理:中断触发模式
 
irq_flow_handler_t 指定了电流处理程序函数的原型:
 
    struct irq_desc;
    typedef    void fastcall (*irq_flow_handler_t)(unsigned int irq,
                         struct irq_desc *desc);

A. 边沿触发中断:上升沿或下降沿触发中断
 
    /**
     *    handle_edge_irq - edge type IRQ handler
     *    @irq:    the interrupt number
     *    @desc:    the interrupt description structure for this 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 pending interrupts are handled, the
     *    loop is left.
     */
    void fastcall
    handle_edge_irq(unsigned int irq, struct irq_desc *desc)
    {
        const unsigned int cpu = smp_processor_id();
        spin_lock(&desc->lock);
        desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
        /*
         * If we're currently running this IRQ, or its disabled,
         * we shouldn't process the IRQ. Mark it pending, handle
         * the necessary masking and go out
         */
        if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
             !desc->action)) {
            desc->status |= (IRQ_PENDING | IRQ_MASKED);
            mask_ack_irq(desc, irq);
            goto out_unlock;
        }
        kstat_cpu(cpu).irqs[irq]++;
        /* Start handling the irq */
        desc->chip->ack(irq);
        /* Mark the IRQ currently in progress.*/
        desc->status |= IRQ_INPROGRESS;
        do {
            struct irqaction *action = desc->action;
            irqreturn_t action_ret;
            if (unlikely(!action)) {
                desc->chip->mask(irq);
                goto out_unlock;
            }
            /*
             * When another irq arrived while we were handling
             * one, we could have masked the irq.
             * Renable it, if it was not disabled in meantime.
             */
            if (unlikely((desc->status &
                 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
                 (IRQ_PENDING | IRQ_MASKED))) {
                desc->chip->unmask(irq);
                desc->status &= ~IRQ_MASKED;
            }
            desc->status &= ~IRQ_PENDING;
            spin_unlock(&desc->lock);
            action_ret = handle_IRQ_event(irq, action);
            if (!noirqdebug)
                note_interrupt(irq, desc, action_ret);
            spin_lock(&desc->lock);
        } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
        desc->status &= ~IRQ_INPROGRESS;
    out_unlock:
        spin_unlock(&desc->lock);
    }

B. 电平触发中断: 高电平或低电平触发中断模式。
    /**
     *    handle_level_irq - Level type irq handler
     *    @irq:    the interrupt number
     *    @desc:    the interrupt description structure for this 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.
     */
    void fastcall
    handle_level_irq(unsigned int irq, struct irq_desc *desc)
    {
        unsigned int cpu = smp_processor_id();
        struct irqaction *action;
        irqreturn_t action_ret;
        spin_lock(&desc->lock);
        mask_ack_irq(desc, irq);
        if (unlikely(desc->status & IRQ_INPROGRESS))
            goto out_unlock;
        desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
        kstat_cpu(cpu).irqs[irq]++;
        /*
         * If its disabled or no action available
         * keep it masked and get out of here
         */
        action = desc->action;
        if (unlikely(!action || (desc->status & IRQ_DISABLED)))
            goto out_unlock;
        desc->status |= IRQ_INPROGRESS;
        spin_unlock(&desc->lock);
        action_ret = handle_IRQ_event(irq, action);
        if (!noirqdebug)
            note_interrupt(irq, desc, action_ret);
        spin_lock(&desc->lock);
        desc->status &= ~IRQ_INPROGRESS;
        if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
            desc->chip->unmask(irq);
    out_unlock:
        spin_unlock(&desc->lock);
    }

 
 
C. 其他中断触发模式:
 
void fastcall handle_simple_irq(unsigned int irq, struct irq_desc *desc);
void fastcall handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
void fastcall handle_percpu_irq(unsigned int irq, struct irq_desc *desc);


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值