Page 1 of 1

Is there any way to get a callback whenever an interrupt fires

Posted: Mon Jul 21, 2025 10:33 am
by greengnu
Is there some way to be notified in general whenever an interrupt fires? Basically whenever the cpu is forced to push the current registers on the stack and continue with the interrupt routine

I'm looking for a generic way to log interrupts (not logging to uart - something fast of course like setting some gpio values or writing to some memory)

Re: Is there any way to get a callback whenever an interrupt fires

Posted: Tue Jul 22, 2025 8:52 am
by MicroController
You can try and use XT_INTEXC_HOOKS and _xt_intexc_hooks:
https://github.com/espressif/esp-idf/bl ... ors.S#L390

Re: Is there any way to get a callback whenever an interrupt fires

Posted: Wed Jul 23, 2025 12:08 pm
by greengnu
@MicroController thanks, this looks interesting! I couldn't find any documentation or examples on how to use this, could you possibly provide some pointers?

Also I assume this only works on xtensa based esp32 socs? what about RISC-V based chips?

Re: Is there any way to get a callback whenever an interrupt fires

Posted: Wed Jul 23, 2025 12:30 pm
by MicroController
There likely is no 'proper' documentation, and no 'official' examples either.
Hooking interrupts at this level is very low-level stuff and not supported via an IDF API.

What I glean from it is that you 1) -D XT_INTEXC_HOOKS, then 2) in your code, declare "extern int (*_xt_intexc_hooks)(int);" and assign your hook function ("int myHook(int cause)") to it. If the hook function returns -1 the actual interrupt handler is not called.
Haven't checked if this hook can be written in C or in assembly only.

See also: viewtopic.php?t=2197

Re: Is there any way to get a callback whenever an interrupt fires

Posted: Wed Jul 23, 2025 10:17 pm
by MicroController
On the RISC-V's, you may be able to have the linker wrap _global_interrupt_handler.