What happens if an interrupt occurs while the ISR is running?

I am programming arduino, I have attached the trailing edge interrupt pin2. So far I'm in the ISR and the ISR hasn't completed all the lines. Before finishing all the lines, if the falling edge comes up again, what happens? Whether starting from the beginning breaks or ignores it. Here I am only talking about the interrupt on pin2.

+3


source to share


1 answer


Atmel processor disables interrupts when interrupt is executed:

(section 4.4: bit 7 - I: global interrupt)

The global interrupt enable bit for interrupts must be set. Then the individual control of the interrupt enable is performed in the individual control registers. If the Global Interrupt Recorder is cleared, none of the interrupts are enabled regardless of the individual interrupt enable setting. The I-bit is cleared by the hardware after the interrupt occurs and is set by the RETI instruction to enable subsequent interrupts. The I-bit can also be set and cleared by the application with SEI and CLI instructions, as described in the instruction set instruction.

Further:

External Interrupt Flag Register - EIFR

• Bits 7..0 - INTF6, INTF3 - INTF0: Flags of external interrupt 6, 3 - 0 When an edge or logical change on the INT [6; 3: 0] triggers an interrupt request, INTF7: 0 is set (one). If the I-bit is in SREG and the corresponding interrupt enable bit, INT [6; 3: 0] in EIMSK, set (one), MCU will go to interrupt vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing logical code. These flags are always cleared when INT [6; 3: 0] configured as a level interrupt. Note that when entering sleep mode with INT3: 0 interrupts disabled, the input buffers on these pins will be disabled. This can lead to a logical change in the internal signals that set the INTF3: 0 flags.



In other words, when another interrupt is detected, the flags register will have this bit, and it is an interrupt received when interrupts are turned on again (when returning from interrupts, unless a separate action is taken).

http://www.atmel.com/Images/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_%20Datasheet.pdf

If you want, you can implement code that allows interrupts during this interrupt service routine, but you must make sure that the code after such a point is completely repeated and / or mask the current interrupt (some interrupt service routines are quite difficult to handle when you do not receive another interrupt shortly thereafter, and it becomes almost impossible if you receive another one while you are currently in that handler). However, often for the correct operating systems, all other interrupts are allowed, which means writing to the EIMSK register.

It is generally best to collect the necessary information in an interrupt handler, store it in a "safe" place (circular buffers are suitable for this), and signal that new data is available for a normal task in the system and process the data there.

[Also, as far as I can tell, there are no function call stops in the interrupt - if you understand what you are doing and there is no problem, for example, from calling a function from both interrupt and normal code at the same time]

+3


source







All Articles