mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 20:38:07 -08:00
624 tests across 51 files, 5-12 minutes, and this session showed what that
was worth: the 403 datapump carried a zero transmit level through every one
of them, and what found it was ATGLK2=0000:0C00 on the board. A green suite
here says the harness still does what it did, not that it matches the
hardware.
So the rule for what stays is: a test earns its place by pinning a fact
established against hardware or against a file format, cheaply, where a
refactor could break it silently. Fourteen files, thirty test functions,
32 collected - test_ac01_codec and test_dsp_board_ndx each run one of theirs
over both board images. 4.4 seconds.
formats xmf identity, sector checksum, Microwire round-trip and
write-enable, the 302 records and the 403 block offset,
flash program/erase 10
constants the instruction/timer-tick round trip, the timer gate,
AC01 reset registers and both B-register rate paths,
ASIC port decode 7
measured DSP the NDX/ARCR board probes and PA7, mailbox tag/data on
58-5e, the 1c commit bit, host cells not data memory,
the datapump family table 7
end to end the ROM reset stub, the C52 payload, the supervisor's
download through the bridge, 302 to its service loop,
fixture forwarding 5
board tools flash_dump address coverage and target selection,
ram_dump's opt-in and peripheral-window guard 3
What went is everything asserting main211/XMF behaviour - there is no 211
hardware, so those expectations are inferences that can never be settled -
along with the multi-second full-boot runs, the probe and sampler files, and
the ISDN/NAC/XMP and SV25 recovery tests, which cover machines this work is
not about. All of it is in the history if a specific one is wanted back.
Two things fixed in passing. README pointed at tests/test_nac.py as the
assertion behind the NAC/XMP cross-check; it now says to re-check that with
nac-info. And `make test` ran `unittest discover`, which never saw
pytest-style module-level tests - 369 of the old 624, and it would have seen
17 of these 30 - so it runs pytest now.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
112 lines
3.6 KiB
Python
112 lines
3.6 KiB
Python
"""The TLC320AC01 protocol, as docs/ac01-codec-protocol.md decodes it."""
|
|
from pathlib import Path
|
|
|
|
import math
|
|
import pytest
|
|
|
|
from courier_emu.bridge import CourierDspBridge, LineToCodec
|
|
from courier_emu.images import load_image
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
# The six control words the 20.16 MHz firmware sends at reset, and what each
|
|
# one means. Register 0 is the datasheet's no-op pseudo-register.
|
|
RESET_REGISTERS = [0x00, 0x0A, 0x14, 0x00, 0x09, 0x05, 0x20, 0x00, 0x01]
|
|
|
|
|
|
def _boot(path):
|
|
bridge = CourierDspBridge(load_image(ROOT / path))
|
|
payload = bridge.expected_bootstrap
|
|
for offset in range(0, len(payload), 8):
|
|
strobe, ports = bridge.transfer.windows[(offset // 8) % 2]
|
|
chunk = payload[offset:offset + 8].ljust(8, b'\xff')
|
|
for port, byte in zip(range(ports, ports + 16, 2), chunk):
|
|
bridge.write(port, 1, byte)
|
|
bridge.write(bridge.transfer.command_port, 1, strobe)
|
|
bridge.write(bridge.transfer.command_port, 1, bridge.transfer.checksum_strobe)
|
|
return bridge
|
|
|
|
|
|
@pytest.mark.parametrize('path', [
|
|
'IDSDL302.ROM',
|
|
'artifacts/courier-board-21210-capture-403/courier-board.rom',
|
|
])
|
|
def test_reset_programs_six_registers_through_secondary_frames(path):
|
|
bridge = _boot(path)
|
|
try:
|
|
bridge.core.step(1_500_000)
|
|
codec = bridge.core.codec_state()
|
|
assert codec['registers'] == RESET_REGISTERS
|
|
# Six secondary frames, one per register, none of them a read.
|
|
assert codec['secondary_frames'] == 6
|
|
assert codec['register_writes'] == 6
|
|
assert codec['register_reads'] == 0
|
|
# The two priming DXR writes at reset carry control bits 01, which is
|
|
# a phase-shift request rather than a secondary-frame request.
|
|
assert codec['phase_shifts'] == 2
|
|
assert codec['primary_frames'] > 100
|
|
finally:
|
|
bridge.core.close()
|
|
|
|
|
|
def test_rate_is_derived_from_the_b_register_not_a_constant():
|
|
bridge = _boot('IDSDL302.ROM')
|
|
try:
|
|
bridge.core.step(1_500_000)
|
|
codec = bridge.core.codec_state()
|
|
# A = 10 and B = 20 off a 2.880 MHz MCLK is the 2400-baud rate.
|
|
assert codec['mclk_hz'] == 2_880_000
|
|
assert codec['sample_rate'] == 7200.0
|
|
assert codec['frame_period'] == 3472 # 25 MHz / 7200, as before
|
|
assert codec['rate_programmed']
|
|
# Free run: the codec clocks its own converters off A and B, and the
|
|
# external frame sync only moves data.
|
|
assert codec['free_run']
|
|
# Register 5 bit 2 takes the high-pass filter out of the path.
|
|
assert not codec['high_pass_enabled']
|
|
assert not codec['loopback']
|
|
finally:
|
|
bridge.core.close()
|
|
|
|
|
|
def test_v34_rates_follow_the_b_register():
|
|
"""The three rates codec-sample-rates.md derives, driven through the part."""
|
|
from courier_emu.dsp import NativeC5x
|
|
|
|
class Image:
|
|
def dsp_program_segments(self):
|
|
return [(0, b'')]
|
|
|
|
core = NativeC5x(Image())
|
|
try:
|
|
core.configure_rom_codec()
|
|
for word, rate, period in (
|
|
(0x0214, 7200.0, 3472),
|
|
(0x0213, 7578.947, 3298),
|
|
(0x0212, 8000.0, 3125),
|
|
):
|
|
core.host_write(0x21, 0x0003) # request a secondary frame
|
|
core.host_write(0x21, 0x010A) # A = 10
|
|
core.host_write(0x21, 0x0003)
|
|
core.host_write(0x21, word) # B = 20 / 19 / 18
|
|
codec = core.codec_state()
|
|
assert codec['registers'][2] == word & 0xFF
|
|
assert round(codec['sample_rate'], 3) == rate
|
|
assert codec['frame_period'] == period
|
|
finally:
|
|
core.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|