According to the datasheet: "A CPU write overrides (has priority over)
all counter clear or count operations".
Currently, writing to the TCNTn register modifies its value, and then the tick() function runs and immediately checks (and possibly updates) the new value.
This creates a discrepancy between the simulation and the real AVR core, and can be demonstrated by the following program:
int main() {
int value = 0;
cli();
TCCR0A = 0;
TCCR0B = 1 << CS00;
TCNT0 = 0;
// TCNT0 should not increment in this clock cycle
value = TCNT0;
sei();
Serial.begin(115200);
Serial.print(value);
}
Running this code in the simulation prints "1", while running it on an Arduino Uno board prints "0".
According to the datasheet: "A CPU write overrides (has priority over) all counter clear or count operations".
Currently, writing to the TCNTn register modifies its value, and then the tick() function runs and immediately checks (and possibly updates) the new value.
This creates a discrepancy between the simulation and the real AVR core, and can be demonstrated by the following program:
Running this code in the simulation prints "1", while running it on an Arduino Uno board prints "0".