| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #!/usr/bin/env python3
- """Test 6400 production RTL through actual ADC pad assignments and PCB inversion."""
- from __future__ import annotations
- import argparse
- import hashlib
- import json
- import re
- import shutil
- import subprocess
- import time
- from pathlib import Path
- # Independent physical evidence: FCB_FPGA+MCU_V2.0_20260914 BRD plus
- # temperature-system electrical drawing p4/p5/p6/p8. The ADC is the DUT
- # input, never the authority for these expected physical ball lists.
- FAN_BALLS = ("C4", "B5", "B1", "A14", "P12", "A10", "D8", "C7")
- PTC_BALLS = (
- "F16", "G16", "T4", "R5", "T6", "R7",
- "T2", "R3", "P16", "R16", "M16", "N16",
- "P10", "R10", "T13", "T12", "L3", "N2",
- "K5", "L4", "H4", "J6", "H5", "C15",
- )
- SPARE_BALLS = ("M1", "N1", "P1", "R1", "P8", "P7", "T9", "P9", "P2", "M3", "L5")
- SSR_BALLS = ("E14", "E8", "D9")
- def fixture_from_adc(adc: Path) -> tuple[str, dict[str, str]]:
- assignments = re.findall(
- r"set_pin_assignment\s*\{\s*([^{}]+?)\s*\}\s*\{[^{}]*?LOCATION\s*=\s*([A-Z]+\d+)\s*;[^{}]*\}",
- adc.read_text(encoding="utf-8"),
- )
- by_ball: dict[str, str] = {}
- by_port: dict[str, str] = {}
- for port, ball in assignments:
- port = port.strip()
- if ball in by_ball or port in by_port:
- raise ValueError(f"duplicate ADC ball or port: {ball} / {port}")
- by_ball[ball], by_port[port] = port, ball
- # UART/clock pins are explicit physical fixture inputs, so reject a
- # changed assignment instead of inadvertently driving the old port.
- for port, ball in {"sys_clk": "J1", "host_ttl_rx": "J4", "host_ttl_tx": "K2",
- "host_rs232_rx": "R13", "host_rs232_tx": "T14",
- "estop_btn_in": "F8", "hood_open_btn_in": "C11", "hood_close_btn_in": "A11",
- "buzzer_out": "H6"}.items():
- if by_port.get(port) != ball:
- raise ValueError(f"physical fixture input/output {port} expected {ball}, ADC has {by_port.get(port)}")
- if "F7" in by_ball:
- raise ValueError(f"CON165.12 (ball F7) must be NC/unbound in V3.0, ADC binds {by_ball['F7']}")
- lines = [
- "`timescale 1ns/1ps",
- "// Generated from the actual production ADC. No expected logical-to-pin permutation is substituted.",
- "module prod2u_6400_v2_physical_fixture (",
- " input wire clk, host_ttl_rx, host_rs232_rx,",
- " output wire host_ttl_tx, host_rs232_tx,",
- " output wire [7:0] fan_connector_pwm,",
- " output wire [23:0] ptc_connector_pwm,",
- " output wire [10:0] spare_connector_pwm,",
- " output wire [2:0] ssr_connector,",
- " input wire estop_btn_in, hood_open_btn_in, hood_close_btn_in,",
- " output wire buzzer_connector",
- ");",
- " wire [3:0] front_fan_pwm_out, rear_fan_pwm_out;",
- " wire [23:0] ptc_pwm_out;",
- " wire [10:0] ptc_spare_zero;",
- " wire ssr1_out, ssr2_out, ssr4_out;",
- " wire buzzer_out;",
- " tri1 temp_scl, temp_sda, temp_scl_alt, temp_sda_alt;",
- " prod2u_6400_v2_top #(.HOST_BAUD(921600)) dut (",
- " .sys_clk(clk), .host_ttl_rx(host_ttl_rx), .host_ttl_tx(host_ttl_tx),",
- " .host_rs232_rx(host_rs232_rx), .host_rs232_tx(host_rs232_tx),",
- " .bmc_rs232_rx(1'b1), .bmc_rs232_tx(),",
- " .ptc_pwm_out(ptc_pwm_out), .ptc_spare_zero(ptc_spare_zero),",
- " .front_fan_pwm_out(front_fan_pwm_out), .rear_fan_pwm_out(rear_fan_pwm_out),",
- " .temp_scl(temp_scl), .temp_sda(temp_sda),",
- " .temp_scl_alt(temp_scl_alt), .temp_sda_alt(temp_sda_alt),",
- " .ssr1_out(ssr1_out), .ssr2_out(ssr2_out), .ssr4_out(ssr4_out),",
- " .ssr_unused_zero(),",
- " .estop_btn_in(estop_btn_in), .hood_open_btn_in(hood_open_btn_in), .hood_close_btn_in(hood_close_btn_in),",
- " .buzzer_out(buzzer_out)",
- " );",
- ]
- used: dict[str, str] = {}
- def signal(ball: str) -> str:
- port = by_ball.get(ball)
- if port is None:
- raise ValueError(f"physical connector ball {ball} has no actual ADC assignment")
- if not re.fullmatch(r"(?:(?:front_fan_pwm_out|rear_fan_pwm_out|ptc_pwm_out|ptc_spare_zero)\[\d+\]|ssr[124]_out)", port):
- raise ValueError(f"connector ball {ball} mapped to unsupported/non-output port {port}")
- used[ball] = port
- return port
- for index, ball in enumerate(FAN_BALLS):
- gate = signal(ball)
- lines += [f" // Physical FAN_PWM{index+1}, FPGA ball {ball}: 2N7002 sink and +5V pull-up (digital model).",
- f" pullup p_fan{index+1}(fan_connector_pwm[{index}]);",
- f" nmos q_fan{index+1}(fan_connector_pwm[{index}], 1'b0, {gate});"]
- for name, balls in (("ptc_connector_pwm", PTC_BALLS),
- ("spare_connector_pwm", SPARE_BALLS), ("ssr_connector", SSR_BALLS)):
- for index, ball in enumerate(balls):
- lines.append(f" assign {name}[{index}] = {signal(ball)}; // physical ball {ball}")
- lines.append(" // Physical CON146.1 (ball H6): Q10621 2N7002 + Q10620 HL2309 high-side +24V buzzer switch (active high).")
- lines.append(" assign buzzer_connector = buzzer_out; // physical ball H6")
- lines.append("endmodule")
- return "\n".join(lines) + "\n", used
- def main() -> int:
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("--repo", type=Path, required=True)
- parser.add_argument("--tb", type=Path)
- parser.add_argument("--out", type=Path, required=True)
- args = parser.parse_args()
- repo, out = args.repo.resolve(), args.out.resolve()
- tb = args.tb or Path(__file__).with_name("prod2u_6400_v2_connector_tb.v")
- if not tb.exists() and args.tb is None:
- tb = repo / "tests/sim/prod2u_6400_v2_connector_tb.v"
- tb = tb.resolve()
- for tool in ("iverilog", "vvp"):
- if shutil.which(tool) is None:
- parser.error(f"required executable unavailable: {tool}")
- closure_path = repo / "products/6400-v2/source-closure.json"
- adc_path = repo / "constraints/prod2u_6400_v2.adc"
- closure = json.loads(closure_path.read_text(encoding="utf-8"))
- sources = [repo / name for name in closure["sources"] if Path(name).suffix == ".v"]
- all_inputs = [tb, adc_path, closure_path] + [repo / name for name in closure["sources"]]
- for path in all_inputs:
- if not path.is_file():
- parser.error(f"missing input: {path}")
- out.mkdir(parents=True, exist_ok=True)
- fixture_text, pad_map = fixture_from_adc(adc_path)
- fixture_path = out / "actual_adc_physical_fixture.v"
- fixture_path.write_text(fixture_text, encoding="utf-8")
- receipt = {
- "test": "prod2u_6400_v2_connector_tb", "status": "NOT_RUN",
- "scope": "production RTL plus actual ADC plus digital NMOS/connector topology; no physical fan/airflow/analog claim",
- "source_sha256": {str(path): hashlib.sha256(path.read_bytes()).hexdigest() for path in all_inputs},
- "actual_adc_pad_mapping": pad_map,
- "physical_fan_balls": FAN_BALLS, "physical_ptc_balls": PTC_BALLS,
- "physical_spare_balls": SPARE_BALLS, "physical_ssr_balls": SSR_BALLS,
- "physical_button_balls": {"estop_btn_in": "F8", "hood_open_btn_in": "C11", "hood_close_btn_in": "A11"},
- "physical_buzzer_ball": "H6",
- "fixture_sha256": hashlib.sha256(fixture_path.read_bytes()).hexdigest(),
- "commands": [],
- }
- commands = [
- ["iverilog", "-g2012", "-I", str(repo), "-s", "prod2u_6400_v2_connector_tb",
- "-o", str(out / "connector.vvp"), str(tb), str(fixture_path), *map(str, sources)],
- ["vvp", str(out / "connector.vvp")],
- ]
- success = True
- for name, command in zip(("compile", "simulate"), commands):
- started = time.monotonic()
- try:
- result = subprocess.run(command, cwd=repo, text=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, timeout=360, check=False)
- text, code = result.stdout, result.returncode
- except subprocess.TimeoutExpired as exc:
- raw = exc.stdout or ""
- text = raw.decode(errors="replace") if isinstance(raw, bytes) else raw
- text += "\nTIMEOUT after 360 seconds\n"
- code = 124
- log = out / f"{name}.log"
- log.write_text(text, encoding="utf-8")
- print(text, end="" if text.endswith("\n") else "\n")
- receipt["commands"].append({"argv": command, "returncode": code,
- "seconds": round(time.monotonic() - started, 3), "log": str(log)})
- if code:
- success = False
- break
- if name == "simulate":
- success = "PASS prod2u_6400_v2_connector_tb:" in text
- receipt["status"] = "PASS" if success else "FAIL"
- (out / "receipt.json").write_text(json.dumps(receipt, indent=2) + "\n", encoding="utf-8")
- print(f"{receipt['status']}: {out / 'receipt.json'}")
- return 0 if success else 1
- if __name__ == "__main__":
- raise SystemExit(main())
|