Will an AVR MCU (Arduino) remember all interrupts that happen while in nointerrupts() section?
void f1() {
noInterrupts();
// critical, time-sensitive code here
interrupts();
}
//now jump to queued interrupts if any
Will it execute them after interrupts()?
I ask this because after reading the datasheet, I have the feeling that all interrupts have their flag, so this could be no problem. But I'm not that experienced, and I'm missing something probably, because other tutorials always state vaguely that "don't stay there too long, since no interrupts at all may happen at that time".
Why?
I have a circular buffer where I put some packets from I2C (they are put whenever I2C interrupt occurs). I also read this buffer from the main loop once in a while, at unpredictable time and overwrite is allowed.
Also, I use the same buffer class (but different instances) in the opposite direction (I2C then triggers interrupt and reads).
My problem is: I would like to turn off interrupts during non-interrupt read/write, so I can be sure I will not be in a situation when I2C triggers and overwrites my item being currently read from normal, main loop.
I now kind of handle the situation with flags before and after read, so the interrupt first checks if the item is free, but I'm not confident in that approach, and I would like to make it work with noInterrupts() and interrupts() during main loop read.
Thank you.