How is ISR a callback function

蹲街弑〆低调 提交于 2019-12-11 03:49:00

问题


The wikipedia entry states:

In computer system programming, an interrupt handler, also known as an interrupt service routine or ISR, is a callback function in microcontroller firmware, an operating system or a device driver, whose execution is triggered by the reception of an interrupt.

How is ISR a callback. Is it the PC value stored on stack itself is the callback function?

I.e., the ISR calls the interrupted function back. Hence the interrupted function is a callback.


回答1:


A bit of setup code stores the address of the ISR function in the interrupt vector table to say "call me back at this address when the interrupt occurs".

To be clear, the ISR itself is the function that is "called back". The interrupted code is not the callback; it is merely "interrupted" and later "resumed".




回答2:


ISR calls the interrupted function back

No, it doesn't, the program counter register is restored from stack like the return instruction does. ISR is a 'callback' because it is called via its address (stored in an interrupt vector table), and not directly.




回答3:


Micro-controllers have an interrupt vector table in their flash memory at a known location. The table contains the addresses of all the ISR (reset interrupt, timer interrupts, GPIO interrupts, etc.). When an interrupt is enabled, on a specific trigger the ISR function is called: the application program is interrupted, the program counter and the processor registers are saved in the stack and the interrupt code is called. When the interrupt code is finished, the application is restored and the application program is resumed.



来源:https://stackoverflow.com/questions/25093767/how-is-isr-a-callback-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!