RootPhoenix
RootPhoenix

Reputation: 1747

How is ISR a callback function

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.

Upvotes: 2

Views: 10029

Answers (4)

mrbean
mrbean

Reputation: 581

A callback is a function pointer (i.e. address) that is passed to another piece of code.

Addresses of Interrupt Service Routine (ISR) functions or 'callbacks' are stored in an interrupt vector table.

An ISR interrupt is an unexpected event initiated by hardware. An Interrupt Service Routine (ISR) is a function which runs when an hardware interrupt is triggered.

An Interrupt Service Routine, also known as an Interrupt Handler, is a special kind of callback that takes no input parameters and returns nothing.

Interrupt handler functions are not called directly by software (at least not normally).

This may be worth a read:

Upvotes: 0

Boann
Boann

Reputation: 50041

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".

Upvotes: 4

vines
vines

Reputation: 5225

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.

Upvotes: 2

ouah
ouah

Reputation: 145829

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.

Upvotes: 1

Related Questions