From 95dae572a09b85b2222e29a0583520c001744b00 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Thu, 13 Aug 2026 16:27:22 -0700 Subject: [PATCH] Tighten up non-reading TCB0 ISR timing --- src/avclan/target/avr-attiny3216/phy_avr.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/avclan/target/avr-attiny3216/phy_avr.c b/src/avclan/target/avr-attiny3216/phy_avr.c index edf7bcf..10e87f9 100644 --- a/src/avclan/target/avr-attiny3216/phy_avr.c +++ b/src/avclan/target/avr-attiny3216/phy_avr.c @@ -225,15 +225,18 @@ ISR(TCB0_INT_vect) { // last_tcb1 = cur_tcb1; // #endif - READING_BYTE <<= 1; // If the logical `0` pulse was less than the sync + data period threshold, // bit was a 1 - pulsewidth = TCB0.CCMP; - if (pulsewidth < (uint16_t)AVCLAN_READBIT_THRESHOLD) { - READING_BYTE++; - READING_PARITY++; + uint16_t tmp = pulsewidth = TCB0.CCMP; // non-volatile tmp saves re-read in + // read-bit-threshold comparison + if (READING_NBITS) { + READING_BYTE <<= 1; + if (tmp < (uint16_t)AVCLAN_READBIT_THRESHOLD) { + READING_BYTE++; + READING_PARITY++; + } + READING_NBITS--; } - READING_NBITS--; } // Read `len` bits on the AVCLAN bus; returns the even parity