一、硬件中断
嵌入式系统一般都有一个"独立自主运行"的中断控制器,用于接收外部设备的各种中断请求信号。如下图所示,当有来自外部的未被屏蔽的中断信号时,中断控制器会产生一个公共的中断请求信号INT,送至CPU。当CPU响应中断时会发起INTA信号送往中断控制器。中断控制器会把优先级最高的中断源对应的中断号经系统总线送给CPU,作为CPU查找中断服务程序入口地址的依据。所以,硬件中断属于嵌入式系统的硬件资源,硬件设计完成后,对应的中断源数量就确定了。
多核CPU的中断控制器如下图所示:
前面讲到,当外部中断信号产生,CPU响应中断后会根据中断源(中断号)查找对应的中断处理程序进行执行。而linux设备驱动是通过request_irq函数来注册中断处理程序。在kernel3.18中实际执行的是request_threaded_irq函数。
/**
* request_threaded_irq - allocate an interrupt line
* @irq: Interrupt line to allocate
* @handler: Function to be called when the IRQ occurs.
* Primary handler for threaded interrupts
* If NULL and thread_fn != NULL the default
* primary handler is installed
* @thread_fn: Function called from the irq handler thread
* If NULL, no irq thread is created
* @irqflags: Interrupt type flags
* @devname: An ascii name for the claiming device
* @dev_id: A cookie passed back to the handler function
*
* This call allocates interrupt resources and enables the
* interrupt line and IRQ handling. From the point this
* call is made your handler function may be invoked. Since
* your handler function must clear any interrupt the board
* raises, you must take care both to initialise your hardware
* and to set up the interrupt handler in the right order.
*
* If you want to set up a threaded irq handler for your device
* then you need to supply @handler and @thread_fn. @handler is
* still called in hard interr