Hello together, I'm using the XC866-Board from Infineon. As I don't use all the availible interrupts in my program I would like to simply overwrite the NOPs of the interrupt vectors with RETIs to make sure the program does not accidentaly run into my code when an unused interrupt should occure. Is there a simpler alternative than writing a interrupt service routine for every unused interrupt like
void dummyISR() interrupt xy { }
Some people say it is good practise to provide a dummy ISR for every interrupt whether it is enabled or not, just in case the IE register gets written to by some program malfunction. I can't really see the point, though, as a program malfunction of that nature would most likely screw everything up anyway.
Why should it screw up everything? I mean if by some malfunction the IR-Bit of an unused interrupt is set and you reset it in an isr that does nothing else there's no problem, is there? But if an interrupt that's not used is called and there is no interrupt vector at its address the controller executes the NOPs until it gets to an instruction (maybe another isr or whatever was placed at the beginning of the memory after the interrupt vector table). This really causes your program to screw up everything if you're unlucky.
"Why should it screw up everything?" If the software has gone wild enough to write to a register you didn't intend it to then it is very unlikely it is going to recover gracefully. "I mean if by some malfunction the IR-Bit of an unused interrupt is set and you reset it in an isr that does nothing else there's no problem, is there?" No ISR will be called if the interrupt is disabled in IE. "But if an interrupt that's not used is called and there is no interrupt vector at its address the controller executes the NOPs until it gets to an instruction" In this case the controller will vector to the appropriate address and execute whatever instructions are there. I'm not sure where you get this idea about executing NOPs from. "This really causes your program to screw up everything if you're unlucky." If the interrupt was disabled yet some malfunction caused its ISR to be called then you are probably already screwed. Handling the interrupt isn't going to make much difference.
The issue of unused interrupts should not be an issue for production ready project. However it can really kill your productivity during development. Thus I make all unused interrupts like this
//////////////////////////////////////////////////////////// // // ISR 2: void ISR_EI1 (void) // void ISR_EI1 (void) interrupt 2 using 0 { Icrash(); // just kill stray interrupts } // end ISR_EI1
void Icrash(void) { for (;;) }
"If the software has gone wild enough to write to a register you didn't intend it to then it is very unlikely it is going to recover gracefully." No, but at least it could stay in the isr and not do any more harm... "No ISR will be called if the interrupt is disabled in IE." I know, but if I would enable all interrupts and have a dummy routine then it would jump to this routine and stay there. "I'm not sure where you get this idea about executing NOPs from." The NOPs are not in the isr but at the location of the interrupt vectors. And if the controller gets there it executes the NOPs
"The issue of unused interrupts should not be an issue for production ready project." The only 'production' my project will come to is one single controller. Insofar I thought it would not be too bad a idea. Thanks for the code, I'll try that.
"No, but at least it could stay in the isr and not do any more harm..." I just can't see that that would make any difference. It would stop the main thread of execution at some unknown point after that thread had already run wild. You've no way of telling whether this is a better or worse situation than the one you've prevented. "I know, but if I would enable all interrupts and have a dummy routine then it would jump to this routine and stay there." But why would you want to do that? Assume a glitch on an unused external interrupt pin. If the interrupt is disabled nothing happens, if it is enabled the program hangs. What's the point? "The NOPs are not in the isr but at the location of the interrupt vectors. And if the controller gets there it executes the NOPs" If you're using C51 and you don't have an ISR for that interrupt you'll most likely find there's program code at the location that is vectored to. There's no reason to suspect you'll find NOPs there.