Interrupt understanding caused by request_irq() function

http://blog.chinaunix.net/uid-24666775-id-3787938.html

http://blog.chinaunix.net/uid-24666775-id-3787938.html


Category: LINUX

 

1.  Interrupt understanding

You can understand an interrupt as an electrical signal, which is generated by a hardware device and sent to the processor . After the processor receives the interrupt, it will immediately reflect the signal to the operating system, and then the system will work.

There are two points to note here. The first interrupt can be generated at any time, which means that the interrupt handler can be executed at any time. Therefore, it is necessary to ensure that the interrupt handler can be executed quickly, so that the execution of the interrupt code can be resumed as soon as possible, so the interrupt code Keep it as brief as possible . Second, each interrupt has its own unique digital tag , so that the operating system can prescribe the right medicine

2.  Register interrupt interrupt handler

The interrupt handler is an integral part of the driver that manages the hardware. Each device has a related driver. The driver can register an interrupt handler through the request_irq() function and activate the given interrupt line to process the specified interrupt. Interrupt, the prototype is as follows:

int request_irq(unsigned int irq,

           irq_handler_t handler,

           unsigned long flags, const char *devname, void *dev_id)

The first parameter , irq , indicates the interrupt number to be allocated. As far as I have been contacted, it has been pre-booked in advance, and I have not tried to determine the interrupt number through detection or dynamics.

The second parameter handler is a pointer to the actual interrupt handler that handles this interrupt. This function is called as soon as the operating system receives the interrupt. This function is discussed later

The third parameter , flags , is the flag of the interrupt handler. This flag can be one or more. List the most important flags:

           IRQF_DISABLED: When this flag is set, it means that the kernel disables all other interrupts when processing the interrupt handler itself. If not set, the interrupt handler can run concurrently with any other interrupt except itself. Obviously we don't usually set this flag so brutally

           IRQF_TIMER: Prepared for the interrupt processing of the system timer

           IRQF_SHARED: This interrupt flag is often encountered. This flag means that multiple interrupt handlers can share the interrupt line. To sum up, without this flag, only one person can occupy it. The flag means that many people can occupy this interrupt. number to come

The fourth parameter is to customize the text related to the interrupt device.

The fifth parameter dev , when you see IRQF_SHARED in the third parameter , will you have such a question, if I want to release the currently shared designated interrupt program, how do I release it? Will other occupations be deleted? This is the meaning of the fifth parameter. If the interrupt line is shared, then the only information that can represent the current device must be passed.

request_irq() successfully returns 0. If it returns non- 0 , it means that an error has occurred. At this time, you can consider whether the current interrupt is occupied, so you can add the IRQF_SHARED flag

3.  Interrupt handler

Here is a continuation of the handler pointer above, the prototype is as follows:

           Staticirqreturn_t intr_handler(int irq, void *dev) 

Nagging here, I don't know if you have encountered such a problem during the interview.

__interrupt double compute_area (double radius)

{

double area = PI * radius * radius;

printf(" Area = %f", area);

return area;

} , point out the error in the above interrupt function, if you don't know it, look carefully at the following O(_ )O 

The first parameter irq is the interrupt number that the handler should respond to. I don't think this makes much sense now, because the meaning of the fifth parameter is described above.

 The second parameter dev is a general pointer. Similarly, the fifth parameter mentioned above is still understood.

Return value irqreturn_t, first look at the following definition

enum irqreturn {

//中断处理程序检测到一个中断,但该中断对应的设备并不是在注册处理函数期间指定的产生源时,返回这个值

    IRQ_NONE,

//中断处理程序被正确调用且确实是它多对应的设备产生了中断,返回这个值

    IRQ_HANDLED,

    IRQ_WAKE_THREAD,

};

typedef enum irqreturn irqreturn_t;

关于描述到这里,我想对中断有一个大概的了解,说白了就是硬件向处理器发送一个电信号,系统收到信号之后根据初始化的标志去处理相应的中断处理程序。
如果熟悉中断的应该知道,我这里所有描述的其实都是中断处理程序的上半部,而下半部是什么,为啥要将中断分为上下部两部分?现在脑子里先有一个概念就是中断是随时产生的,也就意味着可能会打断了一些当前重要的工作而去处理你的中断处理程序,那当然我的中断程序是越快越好。同时中断他是不能被阻塞的,即不能在进程的上下文运行。基于上述原因 就是引入下半部的原因了。






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325476304&siteId=291194637