DavePearce / JavaAVR

Simple AVR simulator written in Java
Apache License 2.0
9 stars 2 forks source link

Support for interrupts #8

Open DavePearce opened 6 years ago

DavePearce commented 6 years ago

Need to add support for interrupts. This can done by checking whether an interrupt is triggered before executing an instruction, and the Global Interrupt Enable flag is set.

DavePearce commented 5 years ago

One of the big challenges is how to determine when an interrupt has occurred. Always, the lowest interrupt vector is triggered first. There are some registers related to interrupt handling, such as MCUCR, GIFR and GIMSK and PCMSK. These seem primarily related to external interrupts which are detected using INT0 and PCINT0. Other relevant registers are the TIFR which is the Timer/Counter Interrupt Flag Register. This is used to signal when a timer-related interrupt has occurred.

As an example, for the INT0 interrupt this is the process:

One problem is that the exact mechanism for determining which interrupt vector is triggered is CPU dependent. For example, ATtiny85 has 15 vectors whereas ATmega328 as 26. Realistically, what we want is a "virtual" bit for each possible vector indicating the vector is set. Then, can configure this virtual register differently for different hardware.

DavePearce commented 5 years ago

Have now added concept of an interrupt table which provides a mapping from status registers to the interrupt dispatch mechanism. That seems to work quite well. However, I haven't connected any interrupt generators yet, or really tested it!!!