About "Nested interrupts"

I'm very happy to see arduino 7 , it adds many cool things. now we have interrupts, and is there a way for us to do a Nested interrupts ? thank you!

Not sure what you mean by nested interrupts. You generally cannot interrupt an interupt service routine (ISR).

How you handle interupts that come faster than they can be serviced is to simply let the ISR set a flag indicating that the interrupt has occured, then return control to the interrupted program. You program's event loop (the loop() function in arduino) would then handle the interrupt. More time sensitive interrupts would get handled first, then lower priority, then the main code of your program.

Make sense?

-j

Hi! kg4wsv

About Nested interrupts, there are some words in avr-lib:

Nested interrupts The AVR hardware clears the global interrupt flag in SREG before
entering an interrupt vector. Thus, normally interrupts will remain disabled inside
the handler until the handler exits, where the RETI instruction (that is emitted by the
compiler as part of the normal function epilogue for an interrupt handler) will eventually
re-enable further interrupts. For that reason, interrupt handlers normally do not nest. For most interrupt handlers, this is the desired behaviour, for some it is even
required in order to prevent infinitely recursive interrupts (like UART interrupts, or
level-triggered external interrupts). In rare circumstances though it might be desired to
re-enable the global interrupt flag as early as possible in the interrupt handler, in order
to not defer any other interrupt more than absolutely needed. This could be done using
an sei() instruction right at the beginning of the interrupt handler, but this still leaves
few instructions inside the compiler-generated function prologue to run with global interrupts
disabled. The compiler can be instructed to insert an SEI instruction right at
the beginning of an interrupt handler by declaring the handler the following way:
void XXX_vect(void) attribute((interrupt));
void XXX_vect(void) {
...
}
where XXX_vect is the name of a valid interrupt vector for the MCU type in question,
as explained below.

Now I can use "sei()" at the beginning of ISR in Arduino to have a Nested interrupts , but I want "The compiler can be instructed to insert an SEI instruction right at the beginning of an interrupt handler ". I have some old M16 project use Nested interrupts , I want to move them to Arduino.

At the eary time we can use "INTERRUPT(SIG_INTERRUPT)" for a Nested interrupts , "SIGNAL(SIG_INTERRUPT2)" for a no Nested interrupts , but in new avr-lib , there is only "ISR" , can Arduino give us some way to use the code like the old "INTERRUPT(SIG_INTERRUPT)" for a Nested interrupts?

Thank you!

It seems that avr-libc doesn't support nested interrupts (the INTERRUPT macro) anymore. If you want to use nested macros, you'll need to edit the Arduino core (in lib/targets/arduino) yourself, and insert the interrupt attribute manually:

void XXX_vect(void) __attribute__((interrupt));

This is an advanced feature that we probably won't be supporting unless there's a large demand for it. Sorry about that.

Thank you for your help mellis!
You are right , just little people need nested interrupts :cry:
I'll try to modify the Arduino core !

You have already do a perfect preject ! Arduino make programing MUC very easy !!!!