// modify NMI ISR to return immediately
void *nmi_isr;
__asm__ __volatile__ ("rsr.vecbase %0" : "=r" (nmi_isr));
nmi_isr += XCHAL_NMI_VECOFS;
uint32 nmi_backup = *((uint32 *) nmi_isr);
*((uint32 *) nmi_isr) = 0x00003310; // asm ("reti 3")
and after my time-critical stuff, I try to restore the original code:
// restore original NMI ISR
*((uint32 *) nmi_isr) = nmi_backup;
And well, it doesn't yet work...
After a couple of 100 runs of the function the ESP8266 crashes, and "wdev.c 1166" is printed on the UART before the crash. I assume that "wdev" correlates to WiFi stuff.
If I just leave the NMI ISR dead, it runs for a little more time, starts to complain about missing buffers on the UART and crashes somewhat later. It seems that the NMI is in fact used by the WiFi to notify that some stuff has been received and needs to be taken out of some queue/buffer/...
Back to my code that restores the original NMI -the system doesn't seem to tolerate that the NMI is potentially lost. And I don't know how to 'emulate' this NMI yet. I can't just jump into the original routine, because that will eventually do a "RFI 3" and that opcode will fail because it wasn't called by a NMI in the first place.
Any ideas?
-Roland