From 2b89a28dac72eb864ee21f4e54596037bc296b14 Mon Sep 17 00:00:00 2001 From: Cryan209 Date: Thu, 24 Sep 2026 10:18:28 +1200 Subject: [PATCH] Clock the C52 at 40.32 MHz, and record ACC in the DSP PC trace At 20.16 MHz the V.34 answerer's per-sample echo-canceller update (~2080 instructions) overruns the 1964-cycle sample budget, and B's TRN task ran 780 of 1026 passes a frame. At the full oscillator both ends train through phase 3 and 4, and the dialled pair now reaches CONNECT .../LAPM/V42BIS once the answerer runs V.42 detection. The clock is inferred, not measured: TCLKX (DSP pin 96) or CLKMD1/CLKMD2 settles it. The AC01 power-up frame period doubles with it. The PC trace now carries ACC before each instruction (pc << 48 | opcode << 32 | ACC), which is what read J out of a4b2/a4ca. Co-Authored-By: Claude Opus 5.5 --- courier_emu/dsp.py | 6 +++--- courier_emu/timebase.py | 2 +- native/c5x_capi.cpp | 5 +++-- native/c5x_core.cpp | 9 +++++++-- native/c5x_core.h | 7 ++++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/courier_emu/dsp.py b/courier_emu/dsp.py index a8e11be..fc83f81 100644 --- a/courier_emu/dsp.py +++ b/courier_emu/dsp.py @@ -735,9 +735,9 @@ class NativeC5x: count = int(self.library.courier_c5x_get_pc_trace_count(self.handle)) result = [] for index in range(count): - values = (ctypes.c_uint64 * 2)() - self.library.courier_c5x_get_pc_trace(self.handle, index, values, 2) - result.append({"pc": int(values[0]), "op": int(values[1])}) + values = (ctypes.c_uint64 * 3)() + self.library.courier_c5x_get_pc_trace(self.handle, index, values, 3) + result.append({"pc": int(values[0]), "op": int(values[1]), "acc": int(values[2])}) return result def mailbox_events(self) -> list[dict[str, int]]: diff --git a/courier_emu/timebase.py b/courier_emu/timebase.py index 527eabc..b5b3f5b 100644 --- a/courier_emu/timebase.py +++ b/courier_emu/timebase.py @@ -111,7 +111,7 @@ class Timebase: # The 40.320 MHz can feeds the ASIC on both 186 boards, and the ASIC clocks the # C52 from it. Stated once because it is the one figure the two boards share. -ASIC_DSP_CLOCK_HZ = 20_160_000 +ASIC_DSP_CLOCK_HZ = 40_320_000 # inferred, not measured: see C5X_CLOCK_HZ COURIER_20MHZ = Timebase( name="courier-20.16", diff --git a/native/c5x_capi.cpp b/native/c5x_capi.cpp index 8fbcc6b..efb2fcb 100644 --- a/native/c5x_capi.cpp +++ b/native/c5x_capi.cpp @@ -465,8 +465,9 @@ void courier_c5x_get_pc_trace(void *handle, std::size_t index, uint64_t *values, if (!handle || !values || count < 2) return; const auto &trace = static_cast(handle)->pc_trace(); if (index >= trace.size()) return; - values[0] = trace[index] >> 16; - values[1] = trace[index] & 0xffff; + values[0] = trace[index] >> 48; + values[1] = (trace[index] >> 32) & 0xffff; + if (count >= 3) values[2] = trace[index] & 0xffffffff; } void courier_c5x_get_serial_state(void *handle, uint64_t *values, std::size_t count) diff --git a/native/c5x_core.cpp b/native/c5x_core.cpp index 1cca7e3..68ad4e2 100644 --- a/native/c5x_core.cpp +++ b/native/c5x_core.cpp @@ -255,7 +255,11 @@ void C5xCore::set_io_callbacks(IoRead read, IoWrite write) // cancels out of MCLK / (2 x A x B), but the DSP got that much more compute // per sample than it has. static constexpr uint64_t BOARD_OSCILLATOR_HZ = 40'320'000; -static constexpr uint64_t C5X_CLOCK_HZ = BOARD_OSCILLATOR_HZ / 2; +// The oscillator itself, not half of it. Unmeasured: at 20.16 MHz the V.34 +// answerer's 70-tap echo-canceller update alone (~2080 instructions a sample) +// overruns the 1964-cycle sample budget, so no cost model lets that clock run +// it. TCLKX (DSP pin 96, 5.04 vs 10.08 MHz) or CLKMD1/CLKMD2 would settle it. +static constexpr uint64_t C5X_CLOCK_HZ = BOARD_OSCILLATOR_HZ; static constexpr uint16_t ASIC_CODEC_TIMING_BASE = 0x0078; void C5xCore::set_hybrid_return(uint32_t return_scale, uint32_t delay) @@ -1374,7 +1378,8 @@ void C5xCore::step() (previous_pc >= 0x0200 && previous_pc < 0x0300) || (previous_pc >= m_trace_first && previous_pc <= m_trace_last)) { if (m_pc_trace.size() >= 512) m_pc_trace.pop_front(); - m_pc_trace.push_back((uint32_t(previous_pc) << 16) | m_op); + m_pc_trace.push_back((uint64_t(previous_pc) << 48) | (uint64_t(m_op) << 32) | + uint32_t(m_acc)); } (this->*s_opcode_table[m_op >> 8])(); if (negotiation_loop && m_pc != previous_pc) m_negotiation_loop_active = false; diff --git a/native/c5x_core.h b/native/c5x_core.h index 2a0f732..f1b10e9 100644 --- a/native/c5x_core.h +++ b/native/c5x_core.h @@ -80,7 +80,7 @@ constexpr uint16_t C5X_SHARED_FIRST = 0x8000, C5X_SHARED_LAST = 0xFEFF; // board's AC01 runs at until the firmware programs its A and B dividers. // Both are frame periods in C5x cycles. inline constexpr unsigned TDM_FRAME_PERIOD_CYCLES = 258; -inline constexpr unsigned AC01_POWERUP_FRAME_PERIOD_CYCLES = 2800; +inline constexpr unsigned AC01_POWERUP_FRAME_PERIOD_CYCLES = 5600; // 7200 Hz at 40.32 MHz class C5xCore { public: @@ -340,7 +340,8 @@ public: const std::vector &data_events() const { return m_data_events; } uint64_t data_write_count(uint16_t address) const { return m_data_write_counts[address]; } const PortStat &io_port_stat(uint16_t port) const { return m_io_port_stats[port]; } - const std::deque &pc_trace() const { return m_pc_trace; } + // Each entry: pc << 48 | opcode << 32 | ACC before the instruction. + const std::deque &pc_trace() const { return m_pc_trace; } // The trace windows. Two are compiled in for the call overlay and the // low-page stub; a third is settable so a caller can watch a handler // elsewhere - 3.1.2's mailbox tag 0x13 enters ee20, which neither @@ -401,7 +402,7 @@ private: std::vector m_data_events; std::array m_data_write_counts{}; std::array m_io_port_stats{}; - std::deque m_pc_trace; + std::deque m_pc_trace; uint16_t m_trace_first = 0xFFFF, m_trace_last = 0; bool m_trace_data_writes = false; uint16_t m_trace_filter = 0;