Skip to content

feat(emulator): model the software UART of the ATtiny85 (P6.3) - #335

Merged
ttbombadil merged 3 commits into
feature/browser-emulationfrom
feat/p6-3-attiny85-software-uart
Oct 24, 2026
Merged

ttbombadil merged 3 commits into
feature/browser-emulationfrom
feat/p6-3-attiny85-software-uart

Conversation

@ttbombadil

Copy link
Copy Markdown
Collaborator

Paket

P6.3 Software-UART ATtiny85 (M), Modell auf Paketebene. Gestapelt auf #334 (P6.2). Die Basis ist feature/browser-emulation; bis #334 gemergt ist, enthält der Diff dessen Commit mit.

Umgesetzt

packages/avr-emulator/src/io/software-uart.ts: SoftwareUart modelliert TinySoftwareSerial von ATTinyCore 1.5.2 (TX an PB0, RX an PB1 über den Analogkomparator). Die Klasse bietet die Mitglieder von AVRUSART, die SerialPorts nutzt, damit das ATtiny-Board in P6.4 dieselbe Serial-Schicht bekommt.

  • TX (Plan: „TX-Pin dekodieren, Baudrate aus der Bitbreite, PB0 nur als Ausgang und nicht PWM“):
    • Flanken von PB0 zählen nur, solange der Pin Ausgang ist und Timer 0 ihn nicht als OC0A treibt.
    • Baudrate = größte Standardrate, zu der mindestens 90 % von mindestens 8 Abständen innerhalb eines Rahmens als ganzzahlige Bitvielfache passen (±20 %).
    • Die Bitbreite wird aus diesen Abständen gemittelt (der Core sendet bei 9600 Baud mit 863 statt 833 Takten pro Bit).
    • Bis dahin dekodiert die eingestellte Rate eine ruhende Leitung (configuredBaud, später die des Serial Monitors).
    • Ein Startbit muss in Bitmitte noch LOW sein.
  • RX über ein Komparatormodell, wie im Spike:
    • ACSR mit ACD, ACBG, ACO, ACI, ACIE, ACIS; V+ ist die Bandlücke (wie der Core sie setzt) oder AIN0, V− ist PB1; Interrupt auf Vektor 7.
    • writeByte erzeugt die Wellenform in simulierter Zeit.
    • Der Empfänger gilt als aktiv, solange ACIE gesetzt und der Komparator an ist (Serial.begin()).

Funde, nicht im Spike:

  • Die Pin-Initialisierung erzeugt Kurzimpulse (3 und 139 Takte).
  • Der Core dehnt einzelne Bits; bei 19200 Baud lagen 3 von 39 Abständen mehr als 20 % daneben.

Mit dem Spike-Kriterium „95 %“ wurde 19200 deshalb nicht erkannt; jetzt gelten 90 %, dazu kommt die Startbit-Prüfung.

Abnahmeevidenz

  • tests/software-uart.test.ts, 7 Fälle mit ATTinyCore-Fixtures:
    • die Serial-Probe des Spikes vollständig (int-Überlauf, print(2.5), Umlaute, ADC, RAMEND);
    • 19200 Baud;
    • Rückfallrate für ein Byte 0xFF;
    • parseInt-Echo über den Komparator („got 21 / twice 42“);
    • Eingabe vor Serial.begin() und während eines laufenden Bytes abgewiesen;
    • synthetisch: Startbit direkt nach einem Kurzimpuls, PB0 als PWM ignoriert.
  • npm run test:unit: App 3562, Emulator 655; check, lint, knip, check:docs grün; Pre-Push mit Sonar grün.

Abweichungen vom Plan

  • Die Anbindung an SerialPorts/Worker und die Baudrate aus dem Serial Monitor brauchen die Board-Hardware und kommen mit P6.4. Das Benutzerhandbuch (Halbduplex, kein Empfang bei anderer Nutzung von PB1) kommt mit der Freigabe des Boards (P6.5).

Geänderte bestehende Tests

Keine.

🤖 Generated with Claude Code

ttbombadil and others added 3 commits October 23, 2026 19:57
Port B with INT0 and PCINT0, timer 0 with its own registers and one-word
vectors, the ATtiny timer 1, a four-channel ADC that reads REFS2 at bit 4,
EEPROM timed for 8 MHz, watchdog and clock prescaler. INT0 and the pin-change
interrupt share GIMSK and GIFR, which avr8js wires for one of them only; the
profile wraps both hooks. Registered with the board hardware in P6.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TX is decoded from PB0 with the baud rate found from the edge distances and
the bit width measured from them; RX drives PB1 through an analog comparator
model. SoftwareUart offers the USART members SerialPorts uses, for the
ATtiny85 board.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ttbombadil
ttbombadil merged commit bf502de into feature/browser-emulation Oct 24, 2026
6 checks passed
@ttbombadil
ttbombadil deleted the feat/p6-3-attiny85-software-uart branch October 24, 2026 08:30
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