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

greengnu
Posts: 66
Joined: Wed May 08, 2019 8:45 pm

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

Postby greengnu » Mon Jul 21, 2025 10:33 am

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)

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Tue Jul 22, 2025 8:52 am

You can try and use XT_INTEXC_HOOKS and _xt_intexc_hooks:
https://github.com/espressif/esp-idf/bl ... ors.S#L390

greengnu
Posts: 66
Joined: Wed May 08, 2019 8:45 pm

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

Postby greengnu » Wed Jul 23, 2025 12:08 pm

@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?

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Wed Jul 23, 2025 12:30 pm

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

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Wed Jul 23, 2025 10:17 pm

On the RISC-V's, you may be able to have the linker wrap _global_interrupt_handler.

Who is online

Users browsing this forum: No registered users and 2 guests