| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- import pytest
- from pathlib import Path
- import yaml
- ROOT = Path(__file__).resolve().parents[2]
- def test_ct7428_u6_single_instance_and_probes():
- """Verify single CT7428 U6 instance, probe pin mapping, and 9 active / 18 fixed-FF items."""
- # Probes 1..8 DP and DN mapping
- probes = {
- "CON53": {"dp_pin": 6, "dn_pin": 7, "channel": 1},
- "CON55": {"dp_pin": 5, "dn_pin": 7, "channel": 2},
- "CON56": {"dp_pin": 4, "dn_pin": 7, "channel": 3},
- "CON57": {"dp_pin": 3, "dn_pin": 7, "channel": 4},
- "CON79": {"dp_pin": 2, "dn_pin": 7, "channel": 5},
- "CON80": {"dp_pin": 1, "dn_pin": 7, "channel": 6},
- "CON81": {"dp_pin": 16, "dn_pin": 7, "channel": 7},
- "CON82": {"dp_pin": 15, "dn_pin": 7, "channel": 8},
- }
- assert len(probes) == 8
- # All share DN on pin 7
- assert all(info["dn_pin"] == 7 for info in probes.values())
- # All DP pins are distinct
- assert len(set(info["dp_pin"] for info in probes.values())) == 8
- # Check that in V2, CT channels 0..8 are from U6, while 9..26 are fixed 0xFF
- total_ct_channels = 27
- u6_channels = 9 # 1 local + 8 remote
- unpopulated_channels = total_ct_channels - u6_channels
- assert unpopulated_channels == 18
- def test_con150_fourth_chamber_conflict_detected():
- """Verify that CON150 fourth chamber hardware net sharing is detected.
- A naive test expecting 6 independent lines on CON150 MUST fail."""
- con150_nets = {
- (1, 3): "PTC31", # Ball L4
- (5, 7): "PTC32", # Ball H4
- (9, 11): "PTC33", # Ball J6
- (13, 15): "PTC34", # Ball H5
- (17, 19): "PTC35", # Ball C15
- }
- # Check that odd pins 1..12 have only 3 distinct nets, NOT 6
- odd_pins_1_to_12_nets = set()
- for (p1, p2), net in con150_nets.items():
- if p1 <= 12:
- odd_pins_1_to_12_nets.add(net)
-
- # CON150 only provides 3 distinct nets on pins 1..12:
- assert len(odd_pins_1_to_12_nets) == 3
-
- # Asserting 6 independent channels on CON150 pins 1..12 must fail
- with pytest.raises(AssertionError, match="CON150 pins 1..12 do not have 6 independent nets"):
- if len(odd_pins_1_to_12_nets) != 6:
- raise AssertionError("CON150 pins 1..12 do not have 6 independent nets (hardware conflict: only 3 nets)")
- def test_con168_mcu_vs_con12_fpga_uart_routing():
- """Verify that CON168 connects to MCU U27, while CON12 connects directly to FPGA U3."""
- con168_routing = {
- 2: "MCU_UART0_TX_U27_PA9",
- 3: "MCU_UART0_RX_U27_PA10",
- }
- assert "U27" in con168_routing[2]
- assert "U27" in con168_routing[3]
- con12_fpga_routing = {
- 3: ("EX_GPIO1", "K2", "FPGA_TX"),
- 4: ("EX_GPIO2", "J4", "FPGA_RX"),
- 2: ("GND", "GND", "GROUND"),
- 1: ("+3V3", "+3V3", "POWER_NOT_SHARED"),
- }
- # CON12 routes to FPGA U3 balls K2 (TX) and J4 (RX)
- assert con12_fpga_routing[3][1] == "K2"
- assert con12_fpga_routing[4][1] == "J4"
- # Power is NOT shared across boards
- assert con12_fpga_routing[1][2] == "POWER_NOT_SHARED"
- def test_ssr_controlled_pins_no_overlap():
- """Verify SSR1 (E14), SSR2 (E8), SSR4 (D9) are dedicated, non-overlapping with PWM/UART."""
- ssr_pins = {"ssr1_out": "E14", "ssr2_out": "E8", "ssr4_out": "D9"}
-
- # Read prod2u_6400_v2.adc to verify pin assignments
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- for name, pin in ssr_pins.items():
- assert f"set_pin_assignment {{ {name} }} {{ LOCATION = {pin};" in adc_text
- # SSR control module replaces fixed-on behavior; dynamic output is simulated.
- top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
- assert "ssr_time_proportion" in top_text
- assert "assign ssr1_out = 1'b1;" not in top_text
- def test_v2_fan_pins_and_board_inversion():
- """Verify 6400 V2.0 fan pin assignments, uniqueness, and avoidance of dedicated pin A2."""
- front_fans = ["C4", "B1", "P12", "D8"]
- rear_fans = ["B5", "A14", "A10", "C7"]
- all_fans = front_fans + rear_fans
-
- # All 8 fan pins must be distinct
- assert len(set(all_fans)) == 8
-
- # Dedicated configuration pin A2 must NOT be in fan pins
- assert "A2" not in all_fans
-
- # V1.1 TTL ball A10 is now used as Rear0 fan in V2.0
- assert "A10" in rear_fans
-
- # Check ADC assignments
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- for i, pin in enumerate(front_fans):
- assert f"set_pin_assignment {{ front_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
- for i, pin in enumerate(rear_fans):
- assert f"set_pin_assignment {{ rear_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
- def test_protocol_36b_set_90b_get_and_v30_buttons_buzzer_pins():
- """Verify v3.2.0 wire protocol lengths (SET=36B, GET=90B), V3.0 F8/C11/A11/H6 pins, and F7 unbound."""
- import hashlib, re
- wire = yaml.safe_load((ROOT / "contracts/6400-v2-wire.yaml").read_text(encoding="utf-8"))
- assert wire["commands"]["SET_ALL"]["payload_length"] == 36
- assert wire["commands"]["GET_ALL"]["payload_length"] == 0
- assert wire["responses"]["SET_ACK"]["payload_length"] == 0
- assert wire["responses"]["GET_ACK"]["payload_length"] == 0
- assert wire["responses"]["GET_DATA"]["payload_length"] == 90
- assert wire["responses"]["NACK"]["payload_length"] == 2
- v3_pdf = ROOT / "reference/original/schematics/6400高温罩电气图V3.0.pdf"
- assert v3_pdf.is_file()
- assert hashlib.sha256(v3_pdf.read_bytes()).hexdigest() == "ec9b2e67710639451b8cac3979aa888f6347ef021135497054d134645743a4c1"
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- assert re.search(r"set_pin_assignment\s*\{\s*estop_btn_in\s*\}\s*\{\s*LOCATION\s*=\s*F8;[^}]*PULLTYPE\s*=\s*PULLDOWN;", adc_text)
- assert re.search(r"set_pin_assignment\s*\{\s*hood_open_btn_in\s*\}\s*\{\s*LOCATION\s*=\s*C11;[^}]*PULLTYPE\s*=\s*PULLDOWN;", adc_text)
- assert re.search(r"set_pin_assignment\s*\{\s*hood_close_btn_in\s*\}\s*\{\s*LOCATION\s*=\s*A11;[^}]*PULLTYPE\s*=\s*PULLDOWN;", adc_text)
- assert re.search(r"set_pin_assignment\s*\{\s*buzzer_out\s*\}\s*\{\s*LOCATION\s*=\s*H6;", adc_text)
- assert not re.search(r"LOCATION\s*=\s*F7;", adc_text), "CON165.12 (ball F7) must be unbound/NC in V3.0"
- top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
- assert "input wire estop_btn_in" in top_text
- assert "input wire hood_open_btn_in" in top_text
- assert "input wire hood_close_btn_in" in top_text
- assert "output wire buzzer_out" in top_text
- assert "buzzer_pwm_4khz" in top_text
- def test_v2_ptc_pins_and_uniqueness():
- """Verify 24 PTC pin assignments:
- - Chamber 1 (CON147): F16, G16, T4, R5, T6, R7
- - Chamber 2 (CON148): T2, R3, P16, R16, M16, N16
- - Chamber 3 (CON149): P10, R10, T13, T12, L3, N2
- - Chamber 4: K5, L4, H4, J6, H5, C15
- All 24 must be distinct and zero overlap with any other interface."""
- expected_ptc = [
- "F16", "G16", "T4", "R5", "T6", "R7",
- "T2", "R3", "P16", "R16", "M16", "N16",
- "P10", "R10", "T13", "T12", "L3", "N2",
- "K5", "L4", "H4", "J6", "H5", "C15"
- ]
- assert len(expected_ptc) == 24
- assert len(set(expected_ptc)) == 24
- # Check against prod2u_6400_v2.adc
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- for i, ball in enumerate(expected_ptc):
- assert f"set_pin_assignment {{ ptc_pwm_out[{i}] }} {{ LOCATION = {ball};" in adc_text
- # Verify zero overlap with non-PTC balls
- non_ptc_balls = {
- "CLK": "J1",
- "TTL_RX": "J4", "TTL_TX": "K2",
- "RS_RX": "R13", "RS_TX": "T14",
- "BMC_RX": "M9", "BMC_TX": "L10",
- "CT_SCL": "B14", "CT_SDA": "A15",
- "CT_SCL_ALT": "M8", "CT_SDA_ALT": "N9",
- "SSR1": "E14", "SSR2": "E8", "SSR4": "D9",
- "F0": "P12", "F1": "D8", "F2": "C4", "F3": "B1",
- "R0": "A10", "R1": "C7", "R2": "B5", "R3": "A14"
- }
- overlap = set(expected_ptc) & set(non_ptc_balls.values())
- assert not overlap, f"PTC pins overlap with non-PTC functions: {overlap}"
- def test_ct_unused_alias_pins_hiz():
- """Verify unused CT jumpers M8 and N9 are constrained and tri-stated (Hi-Z)."""
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- assert "set_pin_assignment { temp_scl } { LOCATION = B14;" in adc_text
- assert "set_pin_assignment { temp_sda } { LOCATION = A15;" in adc_text
- assert "set_pin_assignment { temp_scl_alt } { LOCATION = M8;" in adc_text
- assert "set_pin_assignment { temp_sda_alt } { LOCATION = N9;" in adc_text
- top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
- assert "assign temp_scl_alt = 1'bz;" in top_text
- assert "assign temp_sda_alt = 1'bz;" in top_text
- def test_uart_connector_pin_errata():
- """Verify CON134 and CON77 connector pin assignments:
- TX = Pin 1, RX = Pin 2, GND = Pins 3 & 4.
- Prevent users from connecting RX to Pin 3 (GND)."""
- import json
- project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
-
- # CON134 Host RS232
- assert project["host_rs232_connector"] == "CON134"
- assert project["host_rs232_tx"]["connector_pin"] == 1
- assert project["host_rs232_tx"]["fpga_ball"] == "T14"
- assert project["host_rs232_rx"]["connector_pin"] == 2
- assert project["host_rs232_rx"]["fpga_ball"] == "R13"
- # CON77 BMC RS232
- assert project["bmc_rs232_connector"] == "CON77"
- assert project["bmc_rs232_tx"]["connector_pin"] == 1
- assert project["bmc_rs232_tx"]["fpga_ball"] == "L10"
- assert project["bmc_rs232_rx"]["connector_pin"] == 2
- assert project["bmc_rs232_rx"]["fpga_ball"] == "M9"
- def test_fan_polarity_chain_confirmed_mask_0xff():
- """Verify fan polarity chain from logical request to load:
- Chain: logical_request -> FPGA Ball -> Mainboard NMOS Inverter -> Connector -> Harness -> Fan Board -> Motor
- 1. Daughterboard BRD confirms CON168 pins 5, 6, 11, 12 connect straight through to
- fan headers CON8.7, CON169.7, CON170.7, CON171.7 with zero intermediate inverters.
- 2. Mainboard has 8x 2N7002 NMOS common-source inverters (FPGA ball high -> NMOS ON -> pull down to 0V;
- FPGA ball low -> NMOS OFF -> pull up to high).
- 3. Therefore, final_connector_pwm = ~fpga_ball, requiring FAN_BOARD_INVERT_MASK = 8'hFF.
- 4. Verified across project.json, 6400-manual.yaml, fan-control-parameters.yaml, and top Verilog.
- 5. Test duties: 0, 1, 20, 50, 99, 100.
- - 20% duty: Ball is low 20% (high 80%), NMOS pulls down 80%, connector PWM is high 20%.
- - 100% duty: Ball is low 100% (high 0%), NMOS is off 100%, connector PWM is high 100%.
- - 0% duty: Ball is high 100% (low 0%), NMOS is on 100%, connector PWM is high 0%.
- """
- import json
- project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
- assert project["fan_board_invert_mask"] == "0xFF"
- manual = yaml.safe_load((ROOT / "contracts/6400-v2-manual.yaml").read_text(encoding="utf-8"))
- assert manual["outputs"]["fan_board_invert_mask"] == 0xFF
- fan_params = yaml.safe_load((ROOT / "contracts/fan-control-parameters.yaml").read_text(encoding="utf-8"))
- assert fan_params["board_invert_mask"] == 0xFF
- top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
- assert "parameter [7:0] FAN_BOARD_INVERT_MASK = 8'hFF" in top_text
- mask = 0xFF
- for logical_duty in [0, 1, 20, 50, 99, 100]:
- fpga_ball_high_percent = 100 - logical_duty if mask == 0xFF else logical_duty
- fpga_ball_low_percent = 100 - fpga_ball_high_percent
- # NMOS conducts when FPGA ball is high, pulling drain to GND.
- # NMOS turns off when FPGA ball is low, drain pulled up to high level.
- connector_high_percent = fpga_ball_low_percent
- assert connector_high_percent == logical_duty
- assert (100 - fpga_ball_high_percent) == logical_duty
- def test_board_evidence_paths_and_hashes():
- """Verify board_evidence file and all referenced hardware files have true matching hashes."""
- import json, hashlib
- project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
-
- # Markdown evidence document
- evidence_path = ROOT / project["board_evidence"]
- assert evidence_path.is_file()
- computed_evidence_sha = hashlib.sha256(evidence_path.read_bytes()).hexdigest()
- assert computed_evidence_sha == project["board_evidence_sha256"]
- # Native hardware files
- for item in project["hardware_files"]:
- hw_path = ROOT / item["path"]
- assert hw_path.is_file(), f"Hardware file not found: {hw_path}"
- hw_sha = hashlib.sha256(hw_path.read_bytes()).hexdigest()
- assert hw_sha == item["sha256"], f"SHA mismatch for {item['path']}"
- def test_v2_schematic_20261015_authority_and_inventory_alignment():
- """Verify the replaced 13-page 温控板测试V2.0电气图(1).pdf authority, CON103 vs CON12 note,
- chamber inlet/outlet probe roles, SSR 110W/220W/110W auxiliary heater loads, 30W/24V PTCs,
- and CON159 Page 3/4 damper stepper header documentation."""
- import json, hashlib
- sch_path = ROOT / "reference/original/schematics/6400高温罩电气图V2.0.pdf"
- assert sch_path.is_file()
- sch_bytes = sch_path.read_bytes()
- assert len(sch_bytes) == 3132393
- assert hashlib.sha256(sch_bytes).hexdigest() == "a8309e680714a389c38ffdeefb2e6d11b8535d50feecdf4efd1f610e0c7fc42c"
- inv = json.loads((ROOT / "config/pin_inventory.fcb_fpga_mcu_v2_0.json").read_text(encoding="utf-8"))
- # 1. CON103 vs CON12 UART routing
- con103 = inv["con103_mcu_uart_note"]
- assert con103["connector"] == "CON103"
- assert con103["fpga_connected"] is False
- assert "PA2" in con103["pcb_pin1_net"]
- assert "PA3" in con103["pcb_pin2_net"]
- # 2. CT7428 U6 inlet/outlet probe labels
- probes = inv["ct7428_u6"]["probes"]
- # Independent PDF page 4 wiring: each chamber has an inlet/outlet pair.
- expected = ((1, "CON53", 1, "进风口"), (2, "CON55", 1, "出风口"),
- (3, "CON56", 2, "进风口"), (4, "CON57", 2, "出风口"),
- (5, "CON79", 3, "进风口"), (6, "CON80", 3, "出风口"),
- (7, "CON81", 4, "进风口"), (8, "CON82", 4, "出风口"))
- for channel, connector, chamber, airflow in expected:
- label = probes[f"ch{channel}"]
- assert connector in label and f"腔{chamber}" in label and airflow in label
- assert con103["pin3"] == "+3.3V" and con103["pin4"] == "GND"
- assert inv["host_uart_con134_rs232"]["transceiver_pcb"] == "U22 TRSF3232EIPWR channel 2"
- assert inv["bmc_uart_con77_rs232"]["transceiver_pcb"] == "U22 TRSF3232EIPWR channel 1"
- # 3. SSR1/2/4 auxiliary heater loads & resistor paths
- ssr = inv["ssr_control"]
- assert "110W/24V" in ssr["ssr1"]["load"] and "R1860" in ssr["ssr1"]["resistor_path"]
- assert "220W/24V" in ssr["ssr2"]["load"] and "R1859" in ssr["ssr2"]["resistor_path"]
- assert "110W/24V" in ssr["ssr4"]["load"] and "R1857" in ssr["ssr4"]["resistor_path"]
- # 4. 24x 30W/24V PTC heater channels
- assert "30W/24V" in inv["ptc_heater_rating"]
- assert len(inv["ptc_channels"]) == 24
- assert all("30W/24V" in ch["heater"] for ch in inv["ptc_channels"])
- # 5. CON159 Page 3/4 4-axis damper stepper header (unallocated in 6400-v2 thermal ADC)
- con159 = inv["con159_damper_stepper_header"]
- assert con159["ena1_pin"]["fpga_ball"] == "F3"
- stepper_balls = {ax["step_ball"] for ax in con159["axes"]} | {ax["dir_ball"] for ax in con159["axes"]}
- assert stepper_balls == {"C12", "B12", "L12", "J11", "L14", "K14", "L13", "K11"}
- adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
- for ball in stepper_balls:
- assert f"LOCATION = {ball};" not in adc_text
- def test_con165_field_pin_routes_match_original_board_and_scope():
- """Independent CAD net chain + V3.0 schematic alignment for CON165 SSR & buttons."""
- import csv, json, re
- rows = list(csv.DictReader((ROOT / 'evidence/hardware/20261023/main_pins.csv').open()))
- # Assert every series resistor is populated and external pull-ups for EPB1/SB1/SB2 are NC.
- by_pin = {(row['reference'], row['pin']): row for row in rows}
- expected_ssr = [(14, 'E14', 'CPLD_GPIO64', 'PE14', 'R1860', 'R1698'),
- (13, 'E8', 'ADC0_CH7', 'PE13', 'R1859', 'R1695'),
- (11, 'D9', 'ADC0_CH5', 'PE11', 'R1857', 'R1694')]
- project = json.loads((ROOT / 'products/6400-v2/project.json').read_text())
- assert project['ssr_control']['pwm_hz'] == 20
- for (cad, ball, fpga_net, middle, r0, r1), channel in zip(expected_ssr, project['ssr_control']['channels']):
- assert channel['connector'] == f'CON165.{cad}'
- assert channel['cad_connector'] == f'CON165.{cad}'
- assert channel['ball'] == ball
- assert by_pin[('U3', ball)]['net'] == fpga_net
- assert by_pin[('CON165', str(cad))]['net'] == f'CON_PE{cad}'
- for resistor, nets in [(r0, {fpga_net, middle}), (r1, {middle, f'CON_PE{cad}'})]:
- rr = [by_pin[(resistor, str(n))] for n in (1, 2)]
- assert {x['net'] for x in rr} == nets
- assert all(x['declared_nc'] == 'False' for x in rr)
- expected_btns = [
- ('estop_btn', 10, 'F8', 'ADC0_CH0', 'PE10', 'R1856', 'R1696', 'R1724'),
- ('hood_open_btn', 9, 'C11', 'BANK0_GPIO2', 'PE9', 'R1855', 'R1693', 'R1717'),
- ('hood_close_btn', 8, 'A11', 'BANK0_GPIO1', 'PE8', 'R1854', 'R1692', 'R1723'),
- ]
- for key, cad, ball, fpga_net, middle, r0, r1, r_pu in expected_btns:
- btn = project['buttons'][key]
- assert btn['connector'] == f'CON165.{cad}'
- assert btn['ball'] == ball
- assert btn['external_pullup_nc'] == r_pu
- assert by_pin[('U3', ball)]['net'] == fpga_net
- assert by_pin[('CON165', str(cad))]['net'] == f'CON_PE{cad}'
- for resistor, nets in [(r0, {fpga_net, middle}), (r1, {middle, f'CON_PE{cad}'})]:
- rr = [by_pin[(resistor, str(n))] for n in (1, 2)]
- assert {x['net'] for x in rr} == nets
- assert all(x['declared_nc'] == 'False' for x in rr)
- pu_pins = [by_pin[(r_pu, str(n))] for n in (1, 2)]
- assert {x['net'] for x in pu_pins} == {'+3V3', f'CON_PE{cad}'}
- assert all(x['declared_nc'] == 'True' for x in pu_pins)
- adc = (ROOT / 'constraints/prod2u_6400_v2.adc').read_text()
- assignments = re.findall(r'set_pin_assignment\s*\{\s*(\S+)\s*\}\s*\{\s*LOCATION\s*=\s*(\w+);', adc)
- assert len({ball for _, ball in assignments}) == len(assignments)
- for index, ball in enumerate(['F3', 'F1', 'G4']):
- assert (f'ssr_unused_zero[{index}]', ball) in assignments
- assert ('estop_btn_in', 'F8') in assignments
- assert ('hood_open_btn_in', 'C11') in assignments
- assert ('hood_close_btn_in', 'A11') in assignments
- assert ('buzzer_out', 'H6') in assignments
- assert all(ball != 'F7' for _, ball in assignments)
|