Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wokwi different to real life: interrupts #924

Open
alto777 opened this issue Dec 2, 2024 · 1 comment
Open

Wokwi different to real life: interrupts #924

alto777 opened this issue Dec 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@alto777
Copy link

alto777 commented Dec 2, 2024

This on Arduino forum

The inquirer and ppl who helped have explained this in terms of how a continuously present interrupt level is handled differently to real life

In real life, an instruction is executed before the interrupt is taken again.

In the wokwi, the ISR runs over and over with no sunshine on the interrupted code.

Or vice versa.

a7

@alto777 alto777 added the bug Something isn't working label Dec 2, 2024
@drf5n
Copy link

drf5n commented Dec 4, 2024

The AVR datasheet says it should advance and execute one instruction per interrupt:

One demo in Wokwi:

https://wokwi.com/projects/416353531338279937

versus another test in silicon:

https://forum.arduino.cc/t/physical-uno-and-wokwi-give-different-results-for-a-simple-test/1328159/34?u=davex

I expect that while pin2 is held at a low level, the code in Wokwi should make progress through the program at 1 instruction per serviced interrupt and still blink the pin13 LED.

I observe that while pin2 is held low, the program makes no progress and does not blink the pin13 LED.

My completely uneducated guess about the not-advancing in https://forum.arduino.cc/t/physical-uno-and-wokwi-give-different-results-for-a-simple-test/1328159/39?u=davex is that it might be something in the RETI op-code's -1 backstep:

https://github.com/wokwi/avr8js/blob/6ecba64687e10113ad697860b5f103746a8ef329/src/cpu/instruction.ts#L551-L562

  } else if (opcode === 0x9518) {
    /* RETI, 1001 0101 0001 1000 */
    const { pc22Bits } = cpu;
    const i = cpu.dataView.getUint16(93, true) + (pc22Bits ? 3 : 2);
    cpu.dataView.setUint16(93, i, true);
    cpu.pc = (cpu.data[i - 1] << 8) + cpu.data[i] - 1;
    if (pc22Bits) {
      cpu.pc |= cpu.data[i - 2] << 16;
    }
    cpu.cycles += pc22Bits ? 4 : 3;
    cpu.data[95] |= 0x80; // Enable interrupts
  } else if ((opcode & 0xf000) === 0xc000) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants