Hi,
I am writing some code to perform communiction through 2 serial lines at the same time using interrupts. When in an ISR, other interrupts are blocked, so I need to leave the ISR as soon as possible.
I now have a (large) task to perform but want to start it after leaving the ISR.
In Windows there was the possibility to write a DPC (deferred procudure call) which changes the stack so it would first do this DPC procedure and when the procedure finishes, return to the original code which was left by the interrupt.
Suitability of interrupts for this application notwithstanding, generally speaking, you want to quickly do what needs to be done in the ISR and then set a flag. Pick up that flag and do the time-consuming processing as part of your non-ISR code:
volatile bool doLargeTask = false;
void myISR(void);
void setup() {
// Attach interrupts and do other stuff here
}
void loop() {
// Do your main processing here
if (doLargeTask) {
noInterrupts();
doLargeTask = false;
interrupts();
// Do the time-consuming task here
}
// Continue with main processing
}
void myISR() {
// Quickly service hardware, etc here
doLargeTask = true;
}