test_6400_v2_electrical_contract.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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_fixed_pins_no_overlap_and_no_pwm():
  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. # Read top Verilog to verify SSR pins are tied constant 1'b1
  76. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  77. assert "assign ssr1_out = 1'b1;" in top_text
  78. assert "assign ssr2_out = 1'b1;" in top_text
  79. assert "assign ssr4_out = 1'b1;" in top_text
  80. def test_v2_fan_pins_and_board_inversion():
  81. """Verify 6400 V2.0 fan pin assignments, uniqueness, and avoidance of dedicated pin A2."""
  82. front_fans = ["P12", "D8", "C4", "B1"]
  83. rear_fans = ["A10", "C7", "B5", "A14"]
  84. all_fans = front_fans + rear_fans
  85. # All 8 fan pins must be distinct
  86. assert len(set(all_fans)) == 8
  87. # Dedicated configuration pin A2 must NOT be in fan pins
  88. assert "A2" not in all_fans
  89. # V1.1 TTL ball A10 is now used as Rear0 fan in V2.0
  90. assert "A10" in rear_fans
  91. # Check ADC assignments
  92. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  93. for i, pin in enumerate(front_fans):
  94. assert f"set_pin_assignment {{ front_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
  95. for i, pin in enumerate(rear_fans):
  96. assert f"set_pin_assignment {{ rear_fan_pwm_out[{i}] }} {{ LOCATION = {pin};" in adc_text
  97. def test_protocol_32b_set_83b_get():
  98. """Verify wire protocol lengths and responses."""
  99. wire = yaml.safe_load((ROOT / "contracts/6400-wire.yaml").read_text(encoding="utf-8"))
  100. assert wire["commands"]["SET_ALL"]["payload_length"] == 32
  101. assert wire["commands"]["GET_ALL"]["payload_length"] == 0
  102. assert wire["responses"]["SET_ACK"]["payload_length"] == 0
  103. assert wire["responses"]["GET_ACK"]["payload_length"] == 0
  104. assert wire["responses"]["GET_DATA"]["payload_length"] == 83
  105. assert wire["responses"]["NACK"]["payload_length"] == 2
  106. def test_v2_ptc_pins_and_uniqueness():
  107. """Verify 24 PTC pin assignments:
  108. - Chamber 1 (CON147): F16, G16, T4, R5, T6, R7
  109. - Chamber 2 (CON148): T2, R3, P16, R16, M16, N16
  110. - Chamber 3 (CON149): P10, R10, T13, T12, L3, N2
  111. - Chamber 4 rework candidate: L4, H4, J6, P2, M3, L5
  112. All 24 must be distinct and zero overlap with any other interface."""
  113. expected_ptc = [
  114. "F16", "G16", "T4", "R5", "T6", "R7",
  115. "T2", "R3", "P16", "R16", "M16", "N16",
  116. "P10", "R10", "T13", "T12", "L3", "N2",
  117. "L4", "H4", "J6", "P2", "M3", "L5"
  118. ]
  119. assert len(expected_ptc) == 24
  120. assert len(set(expected_ptc)) == 24
  121. # Check against prod2u_6400_v2.adc
  122. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  123. for i, ball in enumerate(expected_ptc):
  124. assert f"set_pin_assignment {{ ptc_pwm_out[{i}] }} {{ LOCATION = {ball};" in adc_text
  125. # Verify zero overlap with non-PTC balls
  126. non_ptc_balls = {
  127. "CLK": "J1",
  128. "TTL_RX": "J4", "TTL_TX": "K2",
  129. "RS_RX": "R13", "RS_TX": "T14",
  130. "BMC_RX": "M9", "BMC_TX": "L10",
  131. "CT_SCL": "M8", "CT_SDA": "N9",
  132. "CT_SCL_ALT": "B14", "CT_SDA_ALT": "A15",
  133. "SSR1": "F3", "SSR2": "F1", "SSR4": "G4",
  134. "F0": "P12", "F1": "D8", "F2": "C4", "F3": "B1",
  135. "R0": "A10", "R1": "C7", "R2": "B5", "R3": "A14"
  136. }
  137. overlap = set(expected_ptc) & set(non_ptc_balls.values())
  138. assert not overlap, f"PTC pins overlap with non-PTC functions: {overlap}"
  139. def test_ct_unused_alias_pins_hiz():
  140. """Verify CT alias pins B14 and A15 are constrained and tri-stated (Hi-Z)."""
  141. adc_text = (ROOT / "constraints/prod2u_6400_v2.adc").read_text(encoding="utf-8")
  142. assert "set_pin_assignment { temp_scl_alt } { LOCATION = B14;" in adc_text
  143. assert "set_pin_assignment { temp_sda_alt } { LOCATION = A15;" in adc_text
  144. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  145. assert "assign temp_scl_alt = 1'bz;" in top_text
  146. assert "assign temp_sda_alt = 1'bz;" in top_text
  147. def test_uart_connector_pin_errata():
  148. """Verify CON134 and CON77 connector pin assignments:
  149. TX = Pin 1, RX = Pin 2, GND = Pins 3 & 4.
  150. Prevent users from connecting RX to Pin 3 (GND)."""
  151. import json
  152. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  153. # CON134 Host RS232
  154. assert project["host_rs232_connector"] == "CON134"
  155. assert project["host_rs232_tx"]["connector_pin"] == 1
  156. assert project["host_rs232_tx"]["fpga_ball"] == "T14"
  157. assert project["host_rs232_rx"]["connector_pin"] == 2
  158. assert project["host_rs232_rx"]["fpga_ball"] == "R13"
  159. # CON77 BMC RS232
  160. assert project["bmc_rs232_connector"] == "CON77"
  161. assert project["bmc_rs232_tx"]["connector_pin"] == 1
  162. assert project["bmc_rs232_tx"]["fpga_ball"] == "L10"
  163. assert project["bmc_rs232_rx"]["connector_pin"] == 2
  164. assert project["bmc_rs232_rx"]["fpga_ball"] == "M9"
  165. def test_fan_polarity_chain_confirmed_mask_0xff():
  166. """Verify fan polarity chain from logical request to load:
  167. Chain: logical_request -> FPGA Ball -> Mainboard NMOS Inverter -> Connector -> Harness -> Fan Board -> Motor
  168. 1. Daughterboard BRD confirms CON168 pins 5, 6, 11, 12 connect straight through to
  169. fan headers CON8.7, CON169.7, CON170.7, CON171.7 with zero intermediate inverters.
  170. 2. Mainboard has 8x 2N7002 NMOS common-source inverters (FPGA ball high -> NMOS ON -> pull down to 0V;
  171. FPGA ball low -> NMOS OFF -> pull up to high).
  172. 3. Therefore, final_connector_pwm = ~fpga_ball, requiring FAN_BOARD_INVERT_MASK = 8'hFF.
  173. 4. Verified across project.json, 6400-manual.yaml, fan-control-parameters.yaml, and top Verilog.
  174. 5. Test duties: 0, 1, 20, 50, 99, 100.
  175. - 20% duty: Ball is low 20% (high 80%), NMOS pulls down 80%, connector PWM is high 20%.
  176. - 100% duty: Ball is low 100% (high 0%), NMOS is off 100%, connector PWM is high 100%.
  177. - 0% duty: Ball is high 100% (low 0%), NMOS is on 100%, connector PWM is high 0%.
  178. """
  179. import json
  180. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  181. assert project["fan_board_invert_mask"] == "0xFF"
  182. manual = yaml.safe_load((ROOT / "contracts/6400-manual.yaml").read_text(encoding="utf-8"))
  183. assert manual["outputs"]["fan_board_invert_mask"] == 0xFF
  184. fan_params = yaml.safe_load((ROOT / "contracts/fan-control-parameters.yaml").read_text(encoding="utf-8"))
  185. assert fan_params["board_invert_mask"] == 0xFF
  186. top_text = (ROOT / "src/top/prod2u_6400_v2_top.v").read_text(encoding="utf-8")
  187. assert "parameter [7:0] FAN_BOARD_INVERT_MASK = 8'hFF" in top_text
  188. mask = 0xFF
  189. for logical_duty in [0, 1, 20, 50, 99, 100]:
  190. fpga_ball_high_percent = 100 - logical_duty if mask == 0xFF else logical_duty
  191. fpga_ball_low_percent = 100 - fpga_ball_high_percent
  192. # NMOS conducts when FPGA ball is high, pulling drain to GND.
  193. # NMOS turns off when FPGA ball is low, drain pulled up to high level.
  194. connector_high_percent = fpga_ball_low_percent
  195. assert connector_high_percent == logical_duty
  196. assert (100 - fpga_ball_high_percent) == logical_duty
  197. def test_board_evidence_paths_and_hashes():
  198. """Verify board_evidence file and all referenced hardware files have true matching hashes."""
  199. import json, hashlib
  200. project = json.loads((ROOT / "products/6400-v2/project.json").read_text(encoding="utf-8"))
  201. # Markdown evidence document
  202. evidence_path = ROOT / project["board_evidence"]
  203. assert evidence_path.is_file()
  204. computed_evidence_sha = hashlib.sha256(evidence_path.read_bytes()).hexdigest()
  205. assert computed_evidence_sha == project["board_evidence_sha256"]
  206. # Native hardware files
  207. for item in project["hardware_files"]:
  208. hw_path = ROOT / item["path"]
  209. assert hw_path.is_file(), f"Hardware file not found: {hw_path}"
  210. hw_sha = hashlib.sha256(hw_path.read_bytes()).hexdigest()
  211. assert hw_sha == item["sha256"], f"SHA mismatch for {item['path']}"