Something not entirely clear from the ATTiny861 datasheet (and probably similar for most AVRs) is what happens when a pin change occurs during the pin change ISR. An example might help.
Say there are two pins which are enabled for generating a pin change interrupt, and that they are part of the same bank so use the same interrupt vector:
ISR (PCINT_vect){ //so a pin change has occurred
//<---- (1) what happens if a pin change occurs *here* (before reading PINA, but after entering the ISR)
byte current = PINA; //lets assume that both belong to Port A
byte changed = old ^ current; //and that 'old' is a global containing the old value for PINA, then we know which have changed.
old = current; //back up for next time
//So at this point we have a 'changed' variable which has ones for each bit which has changed state
//<---- (2) what happens if a pin change occurs *here* (or for that matter any time after reading PINA)
... //other code - e.g. if statements to perform specific tasks depending on what changed
}
There are two places there where I am not entirely clear on the behaviour of the ATTiny at these points. Will the ISR be called again after it returns the first time? Or will the changes be lost?
Obviously if the interrupt flag is not set again, then it isn't an issue for (1) as that is already checked, however it causes an issue for (2) as that is not checked yet.
If the interrupt flag is set again, then that is fine for (2) as it needs checking, but it is a bit wasteful for (1) as it has already been checked [won't do any harm as we are backing up the last known value].
I'm hoping that another interrupt is triggered, but want to be sure.