Skip to content

Emulator fidelity: reset, interrupts, Intel HEX, Mega and ATtiny85 configs - #30

Open
begeistert wants to merge 2 commits into
mainfrom
fix/emulator-fidelity
Open

begeistert wants to merge 2 commits into
mainfrom
fix/emulator-fidelity

Conversation

@begeistert

Copy link
Copy Markdown
Collaborator

Fixes from the audit of the CPU, the peripherals and the iCircuit (CircuitMirror) integration. Full list in the CHANGELOG [Unreleased] section.

Things that break real firmware

  • Intel HEX above 64 KB: LoadHex ignored record types 02/04, so a Mega sketch larger than 64 KB overwrote its own vectors. There is now a shared parser with checksum verification, plus a strict TryLoadHex.
  • Cpu.Reset(): it is now a real reset. The I/O space up to RamStart goes back to its reset values and every peripheral resets. Before, iCircuit's firmware-reload path could hang Serial.write.
  • ATmega2560:
    • Timer0/1/2 drove the 328P OCx pins (analogWrite on pins 4 and 9-13).
    • INT0-7 and the PCINTs were missing or pointed at 328P vectors.
    • All Mega configs now live in the core as Mega2560*Config, and the TestKit uses them.
  • ATtiny85:
    • EEARH was mapped to r0, so eeprom_write_byte threw with interrupts on.
    • Timer1 is replaced by a port of avr8js timer-attiny.ts.

Fidelity

  • Interrupt entry takes 4 cycles, 5 with a 22-bit PC. One instruction always runs after SEI or RETI, in every decoder.
  • USART kept clearing RXC on any UCSRB write. This bug is inherited from avr8js and lost bytes during TX.
  • Write-one-to-clear flags now behave correctly in TIFR, ADCSRA, SPSR, TWCR, WDTCSR and EECR.
  • Fast-PWM channel C now sets its pin at BOTTOM. EEPROM write time scales with F_CPU. Avcc/Aref are settable.

API (additive)

  • TryLoadHex/HexInfo.
  • Cpu.RamStart, AvrBuilder.WithRamStart and Cpu.PreserveOnReset.
  • Per-CPU OnInterruptDispatch/OnBreakpoint/OnSleep. The static hooks are now [Obsolete].
  • AvrRunner.Run/RunUntil/RunCycles.
  • Nullable AvrTimerConfig.CreateNew.
  • AvrAttinyTimer1. ATtiny85Simulation.Timer1 changes type to it.

Behaviour changes a test may notice

  • ISR timings move by 1 cycle (2 on the Mega). 17 existing tests were updated for this.
  • A pending IRQ is served one instruction later after sei.
  • Registers return to their reset values on Reset().

Verification

  • Avr8Sharp.Tests: 657/657 (was 583)
  • TestKit.Samples: 73/73 (was 45)
  • Python bindings: 28/28 against a fresh Native AOT build
  • CircuitMirror's Arduino and DataBus tests: 101/101 against this core packed locally
  • Native decoder benchmark: no regression

- Intel HEX: handle extended segment/linear records and checksums; add TryLoadHex.
- Cpu.Reset clears the I/O space up to RamStart and resets every peripheral.
- Interrupt entry takes 4 cycles (5 on 22-bit-PC parts); the instruction after
  SEI/RETI always runs before a pending interrupt. Per-CPU interrupt hooks.
- AvrRunner carries its cycle target across calls (Run, RunUntil, RunCycles).
- USART keeps RXC unless RXEN goes 1 to 0; write-one-to-clear flags in TIFR,
  ADCSRA, SPSR, TWCR, WDTCSR and EECR.
- ATmega2560 configs in the core with the right OCx pins, channel C, ICP,
  INT0-7 and PCINT0-2; fast PWM channel C sets its pin at BOTTOM.
- ATtiny85: EEARH at 0x3F, AvrAttinyTimer1 ported from avr8js.
- ADC Avcc/Aref settable; EEPROM write time scales with the CPU frequency.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying avr8sharp-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: f3924d1
Status: ✅  Deploy successful!
Preview URL: https://bf3f119b.avr8sharp-docs.pages.dev
Branch Preview URL: https://fix-emulator-fidelity.avr8sharp-docs.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant