test_6400_v2_electrical_contract.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import pytest
  2. from pathlib import Path
  3. import yaml
  4. ROOT = Path(__file__).resolve().parents[2]
  5. def test_ct7428_u6_single_instance_and_probes():
  6. """Verify single CT7428 U6 instance, probe pin mapping, and 9 active / 18 fixed-FF items."""
  7. # Probes 1..8 DP and DN mapping
  8. probes = {
  9. "CON53": {"dp_pin": 6, "dn_pin": 7, "channel": 1},
  10. "CON55": {"dp_pin": 5, "dn_pin": 7, "channel": 2},
  11. "CON56": {"dp_pin": 4, "dn_pin": 7, "channel": 3},
  12. "CON57": {"dp_pin": 3, "dn_pin": 7, "channel": 4},
  13. "CON79": {"dp_pin": 2, "dn_pin": 7, "channel": 5},
  14. "CON80": {"dp_pin": 1, "dn_pin": 7, "channel": 6},
  15. "CON81": {"dp_pin": 16, "dn_pin": 7, "channel": 7},
  16. "CON82": {"dp_pin": 15, "dn_pin": 7, "channel": 8},
  17. }
  18. assert len(probes) == 8
  19. # All share DN on pin 7
  20. assert all(info["dn_pin"] == 7 for info in probes.values())
  21. # All DP pins are distinct
  22. assert len(set(info["dp_pin"] for info in probes.values())) == 8
  23. # Check that in V2, CT channels 0..8 are from U6, while 9..26 are fixed 0xFF
  24. total_ct_channels = 27
  25. u6_channels = 9 # 1 local + 8 remote
  26. unpopulated_channels = total_ct_channels - u6_channels
  27. assert unpopulated_channels == 18
  28. def test_con150_fourth_chamber_conflict_detected():
  29. """Verify that CON150 fourth chamber hardware net sharing is detected.
  30. A naive test expecting 6 independent lines on CON150 MUST fail."""
  31. con150_nets = {
  32. (1, 3): "PTC31", # Ball L4
  33. (5, 7): "PTC32", # Ball H4
  34. (9, 11): "PTC33", # Ball J6
  35. (13, 15): "PTC34", # Ball H5
  36. (17, 19): "PTC35", # Ball C15
  37. }
  38. # Check that odd pins 1..12 have only 3 distinct nets, NOT 6
  39. odd_pins_1_to_12_nets = set()
  40. for (p1, p2), net in con150_nets.items():
  41. if p1 <= 12:
  42. odd_pins_1_to_12_nets.add(net)
  43. # CON150 only provides 3 distinct nets on pins 1..12:
  44. assert len(odd_pins_1_to_12_nets) == 3
  45. # Asserting 6 independent channels on CON150 pins 1..12 must fail
  46. with pytest.raises(AssertionError, match="CON150 pins 1..12 do not have 6 independent nets"):
  47. if len(odd_pins_1_to_12_nets) != 6:
  48. raise AssertionError("CON150 pins 1..12 do not have 6 independent nets (hardware conflict: only 3 nets)")
  49. def test_con168_mcu_vs_con12_fpga_uart_routing():
  50. """Verify that CON168 connects to MCU U27, while CON12 connects directly to FPGA U3."""
  51. con168_routing = {
  52. 2: "MCU_UART0_TX_U27_PA9",
  53. 3: "MCU_UART0_RX_U27_PA10",
  54. }
  55. assert "U27" in con168_routing[2]
  56. assert "U27" in con168_routing[3]
  57. con12_fpga_routing = {
  58. 3: ("EX_GPIO1", "K2", "FPGA_TX"),
  59. 4: ("EX_GPIO2", "J4", "FPGA_RX"),
  60. 2: ("GND", "GND", "GROUND"),
  61. 1: ("+3V3", "+3V3", "POWER_NOT_SHARED"),
  62. }
  63. # CON12 routes to FPGA U3 balls K2 (TX) and J4 (RX)
  64. assert con12_fpga_routing[3][1] == "K2"
  65. assert con12_fpga_routing[4][1] == "J4"
  66. # Power is NOT shared across boards
  67. assert con12_fpga_routing[1][2] == "POWER_NOT_SHARED"
  68. def test_ssr_controlled_pins_no_overlap():
  69. """Verify SSR1 (F3), SSR2 (F1), SSR4 (G4) are dedicated, non-overlapping with PWM/UART."""
  70. ssr_pins = {"ssr1_out": "F3", "ssr2_out": "F1", "ssr4_out": "G4"}
  71. # Read prod2u_6400_v2.adc to verify pin assignments
  72. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  73. for name, pin in ssr_pins.items():
  74. assert f"set_pin_assignment {{ {name} }} {{ LOCATION = {pin};" in adc_text
  75. # SSR control module replaces fixed-on behavior; dynamic output is simulated.
  76. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  77. assert "ssr_time_proportion" in top_text
  78. assert "assign ssr1_out = 1'b1;" not in top_text
  79. def test_v2_fan_pins_and_board_inversion():
  80. """Verify 6400 V2.0 fan pin assignments, uniqueness, and avoidance of dedicated pin A2."""
  81. front_fans = ["C4", "B1", "P12", "D8"]
  82. rear_fans = ["B5", "A14", "A10", "C7"]
  83. all_fans = front_fans + rear_fans
  84. # All 8 fan pins must be distinct
  85. assert len(set(all_fans)) == 8
  86. # Dedicated configuration pin A2 must NOT be in fan pins
  87. assert "A2" not in all_fans
  88. # V1.1 TTL ball A10 is now used as Rear0 fan in V2.0
  89. assert "A10" in rear_fans
  90. # Check ADC assignments
  91. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  92. for i, pin in enumerate(front_fans):
  93. assert f"set_pin_assignment {{ front_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
  94. for i, pin in enumerate(rear_fans):
  95. assert f"set_pin_assignment {{ rear_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
  96. def test_protocol_35b_set_86b_get():
  97. """Verify wire protocol lengths and responses."""
  98. wire = yaml.safe_load((ROOT / "contracts/6400-v2-wire.yaml").read_text(encoding="utf-8"))
  99. assert wire["commands"]["SET_ALL"]["payload_length"] == 35
  100. assert wire["commands"]["GET_ALL"]["payload_length"] == 0
  101. assert wire["responses"]["SET_ACK"]["payload_length"] == 0
  102. assert wire["responses"]["GET_ACK"]["payload_length"] == 0
  103. assert wire["responses"]["GET_DATA"]["payload_length"] == 86
  104. assert wire["responses"]["NACK"]["payload_length"] == 2
  105. def test_v2_ptc_pins_and_uniqueness():
  106. """Verify 24 PTC pin assignments:
  107. - Chamber 1 (CON147): F16, G16, T4, R5, T6, R7
  108. - Chamber 2 (CON148): T2, R3, P16, R16, M16, N16
  109. - Chamber 3 (CON149): P10, R10, T13, T12, L3, N2
  110. - Chamber 4: K5, L4, H4, J6, H5, C15
  111. All 24 must be distinct and zero overlap with any other interface."""
  112. expected_ptc = [
  113. "F16", "G16", "T4", "R5", "T6", "R7",
  114. "T2", "R3", "P16", "R16", "M16", "N16",
  115. "P10", "R10", "T13", "T12", "L3", "N2",
  116. "K5", "L4", "H4", "J6", "H5", "C15"
  117. ]
  118. assert len(expected_ptc) == 24
  119. assert len(set(expected_ptc)) == 24
  120. # Check against prod2u_6400_v2.adc
  121. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  122. for i, ball in enumerate(expected_ptc):
  123. assert f"set_pin_assignment {{ ptc_pwm_out[{i}] }} {{ LOCATION = {ball};" in adc_text
  124. # Verify zero overlap with non-PTC balls
  125. non_ptc_balls = {
  126. "CLK": "J1",
  127. "TTL_RX": "J4", "TTL_TX": "K2",
  128. "RS_RX": "R13", "RS_TX": "T14",
  129. "BMC_RX": "M9", "BMC_TX": "L10",
  130. "CT_SCL": "B14", "CT_SDA": "A15",
  131. "CT_SCL_ALT": "M8", "CT_SDA_ALT": "N9",
  132. "SSR1": "F3", "SSR2": "F1", "SSR4": "G4",
  133. "F0": "P12", "F1": "D8", "F2": "C4", "F3": "B1",
  134. "R0": "A10", "R1": "C7", "R2": "B5", "R3": "A14"
  135. }
  136. overlap = set(expected_ptc) & set(non_ptc_balls.values())
  137. assert not overlap, f"PTC pins overlap with non-PTC functions: {overlap}"
  138. def test_ct_unused_alias_pins_hiz():
  139. """Verify unused CT jumpers M8 and N9 are constrained and tri-stated (Hi-Z)."""
  140. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  141. assert "set_pin_assignment { temp_scl } { LOCATION = B14;" in adc_text
  142. assert "set_pin_assignment { temp_sda } { LOCATION = A15;" in adc_text
  143. assert "set_pin_assignment { temp_scl_alt } { LOCATION = M8;" in adc_text
  144. assert "set_pin_assignment { temp_sda_alt } { LOCATION = N9;" in adc_text
  145. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  146. assert "assign temp_scl_alt = 1'bz;" in top_text
  147. assert "assign temp_sda_alt = 1'bz;" in top_text
  148. def test_uart_connector_pin_errata():
  149. """Verify CON134 and CON77 connector pin assignments:
  150. TX = Pin 1, RX = Pin 2, GND = Pins 3 & 4.
  151. Prevent users from connecting RX to Pin 3 (GND)."""
  152. import json
  153. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  154. # CON134 Host RS232
  155. assert project["host_rs232_connector"] == "CON134"
  156. assert project["host_rs232_tx"]["connector_pin"] == 1
  157. assert project["host_rs232_tx"]["fpga_ball"] == "T14"
  158. assert project["host_rs232_rx"]["connector_pin"] == 2
  159. assert project["host_rs232_rx"]["fpga_ball"] == "R13"
  160. # CON77 BMC RS232
  161. assert project["bmc_rs232_connector"] == "CON77"
  162. assert project["bmc_rs232_tx"]["connector_pin"] == 1
  163. assert project["bmc_rs232_tx"]["fpga_ball"] == "L10"
  164. assert project["bmc_rs232_rx"]["connector_pin"] == 2
  165. assert project["bmc_rs232_rx"]["fpga_ball"] == "M9"
  166. def test_fan_polarity_chain_confirmed_mask_0xff():
  167. """Verify fan polarity chain from logical request to load:
  168. Chain: logical_request -> FPGA Ball -> Mainboard NMOS Inverter -> Connector -> Harness -> Fan Board -> Motor
  169. 1. Daughterboard BRD confirms CON168 pins 5, 6, 11, 12 connect straight through to
  170. fan headers CON8.7, CON169.7, CON170.7, CON171.7 with zero intermediate inverters.
  171. 2. Mainboard has 8x 2N7002 NMOS common-source inverters (FPGA ball high -> NMOS ON -> pull down to 0V;
  172. FPGA ball low -> NMOS OFF -> pull up to high).
  173. 3. Therefore, final_connector_pwm = ~fpga_ball, requiring FAN_BOARD_INVERT_MASK = 8'hFF.
  174. 4. Verified across project.json, 6400-manual.yaml, fan-control-parameters.yaml, and top Verilog.
  175. 5. Test duties: 0, 1, 20, 50, 99, 100.
  176. - 20% duty: Ball is low 20% (high 80%), NMOS pulls down 80%, connector PWM is high 20%.
  177. - 100% duty: Ball is low 100% (high 0%), NMOS is off 100%, connector PWM is high 100%.
  178. - 0% duty: Ball is high 100% (low 0%), NMOS is on 100%, connector PWM is high 0%.
  179. """
  180. import json
  181. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  182. assert project["fan_board_invert_mask"] == "0xFF"
  183. manual = yaml.safe_load((ROOT / "contracts/6400-v2-manual.yaml").read_text(encoding="utf-8"))
  184. assert manual["outputs"]["fan_board_invert_mask"] == 0xFF
  185. fan_params = yaml.safe_load((ROOT / "contracts/fan-control-parameters.yaml").read_text(encoding="utf-8"))
  186. assert fan_params["board_invert_mask"] == 0xFF
  187. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  188. assert "parameter [7:0] FAN_BOARD_INVERT_MASK = 8'hFF" in top_text
  189. mask = 0xFF
  190. for logical_duty in [0, 1, 20, 50, 99, 100]:
  191. fpga_ball_high_percent = 100 - logical_duty if mask == 0xFF else logical_duty
  192. fpga_ball_low_percent = 100 - fpga_ball_high_percent
  193. # NMOS conducts when FPGA ball is high, pulling drain to GND.
  194. # NMOS turns off when FPGA ball is low, drain pulled up to high level.
  195. connector_high_percent = fpga_ball_low_percent
  196. assert connector_high_percent == logical_duty
  197. assert (100 - fpga_ball_high_percent) == logical_duty
  198. def test_board_evidence_paths_and_hashes():
  199. """Verify board_evidence file and all referenced hardware files have true matching hashes."""
  200. import json, hashlib
  201. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  202. # Markdown evidence document
  203. evidence_path = ROOT / project["board_evidence"]
  204. assert evidence_path.is_file()
  205. computed_evidence_sha = hashlib.sha256(evidence_path.read_bytes()).hexdigest()
  206. assert computed_evidence_sha == project["board_evidence_sha256"]
  207. # Native hardware files
  208. for item in project["hardware_files"]:
  209. hw_path = ROOT / item["path"]
  210. assert hw_path.is_file(), f"Hardware file not found: {hw_path}"
  211. hw_sha = hashlib.sha256(hw_path.read_bytes()).hexdigest()
  212. assert hw_sha == item["sha256"], f"SHA mismatch for {item['path']}"
  213. def test_v2_schematic_20261015_authority_and_inventory_alignment():
  214. """Verify the replaced 13-page 温控板测试V2.0电气图(1).pdf authority, CON103 vs CON12 note,
  215. chamber inlet/outlet probe roles, SSR 110W/220W/110W auxiliary heater loads, 30W/24V PTCs,
  216. and CON159 Page 3/4 damper stepper header documentation."""
  217. import json, hashlib
  218. sch_path = ROOT / "reference/original/schematics/6400高温罩电气图V2.0.pdf"
  219. assert sch_path.is_file()
  220. sch_bytes = sch_path.read_bytes()
  221. assert len(sch_bytes) == 3132393
  222. assert hashlib.sha256(sch_bytes).hexdigest() == "a8309e680714a389c38ffdeefb2e6d11b8535d50feecdf4efd1f610e0c7fc42c"
  223. inv = json.loads((ROOT / "config/pin_inventory.fcb_fpga_mcu_v2_0.json").read_text(encoding="utf-8"))
  224. # 1. CON103 vs CON12 UART routing
  225. con103 = inv["con103_mcu_uart_note"]
  226. assert con103["connector"] == "CON103"
  227. assert con103["fpga_connected"] is False
  228. assert "PA2" in con103["pcb_pin1_net"]
  229. assert "PA3" in con103["pcb_pin2_net"]
  230. # 2. CT7428 U6 inlet/outlet probe labels
  231. probes = inv["ct7428_u6"]["probes"]
  232. # Independent PDF page 4 wiring: each chamber has an inlet/outlet pair.
  233. expected = ((1, "CON53", 1, "进风口"), (2, "CON55", 1, "出风口"),
  234. (3, "CON56", 2, "进风口"), (4, "CON57", 2, "出风口"),
  235. (5, "CON79", 3, "进风口"), (6, "CON80", 3, "出风口"),
  236. (7, "CON81", 4, "进风口"), (8, "CON82", 4, "出风口"))
  237. for channel, connector, chamber, airflow in expected:
  238. label = probes[f"ch{channel}"]
  239. assert connector in label and f"腔{chamber}" in label and airflow in label
  240. assert con103["pin3"] == "+3.3V" and con103["pin4"] == "GND"
  241. assert inv["host_uart_con134_rs232"]["transceiver_pcb"] == "U22 TRSF3232EIPWR channel 2"
  242. assert inv["bmc_uart_con77_rs232"]["transceiver_pcb"] == "U22 TRSF3232EIPWR channel 1"
  243. # 3. SSR1/2/4 auxiliary heater loads & resistor paths
  244. ssr = inv["ssr_control"]
  245. assert "110W/24V" in ssr["ssr1"]["load"] and "R1847" in ssr["ssr1"]["resistor_path"]
  246. assert "220W/24V" in ssr["ssr2"]["load"] and "R1848" in ssr["ssr2"]["resistor_path"]
  247. assert "110W/24V" in ssr["ssr4"]["load"] and "R1850" in ssr["ssr4"]["resistor_path"]
  248. # 4. 24x 30W/24V PTC heater channels
  249. assert "30W/24V" in inv["ptc_heater_rating"]
  250. assert len(inv["ptc_channels"]) == 24
  251. assert all("30W/24V" in ch["heater"] for ch in inv["ptc_channels"])
  252. # 5. CON159 Page 3/4 4-axis damper stepper header (unallocated in 6400-v2 thermal ADC)
  253. con159 = inv["con159_damper_stepper_header"]
  254. assert con159["ena1_pin"]["fpga_ball"] == "F3"
  255. stepper_balls = {ax["step_ball"] for ax in con159["axes"]} | {ax["dir_ball"] for ax in con159["axes"]}
  256. assert stepper_balls == {"C12", "B12", "L12", "J11", "L14", "K14", "L13", "K11"}
  257. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  258. for ball in stepper_balls:
  259. assert f"LOCATION = {ball};" not in adc_text