Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 1 month ago.
How to disable specific interrupts?
I have a system that must react, in a specific order, to interrupts from Timers and pin-changes. One example is that I would like to *not* react to a pin-change interrupt within a time "window".
I can attach a function to an interrupt in the usual way, e.g. "NoEcho.attach(&DeadTime, 0.00018);" and "PinInt.fall(&PinFall);" but once I have set up the PinInt interrupt it stays set up.
I would like to enable the interrupt-on-pin-fall, wait for activity, then disable interrupt-on-pin-fall for a fixed time set by a Timer (which needs an interrupt to do this), then enable interrupt-on-pin-fall again. Clearly "disable_irq()" is not helpful.
Before I can re-enable an interrupt, I would have to clear the flag that says there is an interrupt pending, so that would have to be part of the solution.
I can bodge all this with an "ignore" flag, so the interrupt-on-pin-fall interrupt does happen, but does nothing if the "ignore" flag is set, but that's really not good as the interrupt is still serviced, and takes time.
My background is solidly in writing complex assembler programs that are locked to time-critical hardware, so I'm not used to have a compiler between me and the hardware!
6 years, 1 month ago.
First of all, which is not an answer directly to your question, but might be relevant, you can change the priority of interrupts with for example:
Where '0' is default, and highest priority.
Now for your specific question. In general the way to disable an mbed interrupt is to attach a NULL pointer, so:
This actually disables the interrupt, it doesn't just stop calling your user function, it is disabled in hardware. As a bit faster option, see: http://mbed.org/users/mbed_official/code/mbed/docs/824293ae5e43//classmbed_1_1InterruptIn.html#aac52723c749b32fe1750006adf23370b. There is also a disable/enable_irq function for InterruptIn. This disabled the entire interruptvector of the interruptin, and what that does exactly depends on the device (contrary to attaching a NULL pointer, which always does the same). On the LPC1768 I see you have it disables all pin interrupts.