Interrupts (ATmega328P)

Psuedo-code showing hardware behavior:

while (true)
{
	if (isInterruptConditionMet())
	{
		interruptFlag = 1
	}

	if (interruptFlag == 1 && globalEnableBit == 1 && enableBit == 1)
	{
		interruptFlag = 0
		globalEnableBit = 0
		
		interruptFunction()
		
		globalEnableBit = 1
	}
}

globalEnableBit: Global interrupt enable bit. I-bit (7th bit) in SREG (status register).

enableBit: Individual interrupt enable bit. For example, Timer/Counter0 overflow interrupt is enabled by setting TOIE0 (Timer/Counter0 Overflow Interrupt Enable bit) in TIMSK0 (Timer/Counter0 Interrupt Mask register).

interruptFlag Individual interrupt flag. For example, Timer/Counter0 overflow flag is TOV0 (Timer/Counter0 Overflow Flag) in TIFR0 (Timer/Counter 0 Interrupt Flag register).

Observations