generate_mrdimm_adc.py 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python3
  2. """Generate the mrdimm-chamber ADC pin constraints from V1.2 evidence.
  3. Sources, in authority order:
  4. 1. config/pin_inventory.prod2u_door_temp_v1_2.json (board fcb_fpga_mcu_v1_2_
  5. 20260717, evidence_matrix_v1_2_e2e) for clock, host RS232, CT7428 bus,
  6. PTC8 physical channels and FAN4.
  7. 2. ACTIVE-TASK board authority for the current motor seats: the door motor
  8. connectors were rewired from the old NPN-buffered CON104/105/106 seats
  9. (C12/B12, L12/J11, L14/K14 in the inventory) to direct 3.3V series-R
  10. seats CON142/126/127 (X H4/J6, Y E7/A4, Z B4/A12). Limits keep the
  11. six-limit map CON12/129 (A5/B6, C8/A8, K16/J15, active high).
  12. 3. No V1.2 evidence exists for BMC UART or Host I2C pads: those pads are
  13. deliberately NOT assigned (the production wrapper holds the inputs
  14. idle and does not export them, so TD cannot auto-place them onto
  15. unrelated board signals). LOGIC_TESTED, not PAD_BOUND.
  16. """
  17. from __future__ import annotations
  18. import argparse
  19. import json
  20. from pathlib import Path
  21. ROOT = Path(__file__).resolve().parents[1]
  22. OUT = ROOT / "constraints"
  23. # Active-authority motor seat override (see module docstring, point 2).
  24. MOTOR_SEATS = {
  25. "x_step": ("H4", "CON142.2"),
  26. "x_dir": ("J6", "CON142.3"),
  27. "y_step": ("E7", "CON126.2"),
  28. "y_dir": ("A4", "CON126.3"),
  29. "z_step": ("B4", "CON127.2"),
  30. "z_dir": ("A12", "CON127.3"),
  31. }
  32. # V1.2 fans are active_low at the ball; connector side is high duty. The
  33. # top-level fan board adapter inverts all four (evidence: inventory rows
  34. # fan_pwm_out[0..3] B1/C4/B5/A14 polarity active_low).
  35. FAN_INVERT_MASK = "4'hF"
  36. def main() -> int:
  37. ap = argparse.ArgumentParser()
  38. ap.add_argument("--check", action="store_true")
  39. args = ap.parse_args()
  40. inv = json.loads((ROOT / "config" / "pin_inventory.prod2u_door_temp_v1_2.json").read_text(encoding="utf-8"))
  41. assert inv["board_id"] == "fcb_fpga_mcu_v1_2_20260717", inv["board_id"]
  42. rows = {p["signal"]: p for p in inv["pins"]}
  43. lines: list[str] = []
  44. lines.append("# mrdimm-chamber FCB V1.2 confirmed pins (generated from")
  45. lines.append(f"# config/pin_inventory.prod2u_door_temp_v1_2.json {inv['board_id']},")
  46. lines.append(f"# status {inv['status']}). Motor seats overridden to the current")
  47. lines.append("# direct 3.3V CON142/126/127 wiring per the active board authority;")
  48. lines.append("# the superseded NPN-buffered seats appear in comments.")
  49. lines.append("# NOT BOUND on this product (no V1.2 evidence; wrapper holds idle):")
  50. lines.append("# bmc_rs232_rx/tx, host_ttl_rx/tx, host_i2c_scl/sda.")
  51. lv = "IOSTANDARD = LVCMOS33; PULLTYPE = NONE;"
  52. def emit(signal: str, ball: str, note: str = "") -> None:
  53. suffix = f" # {note}" if note else ""
  54. lines.append(f"set_pin_assignment {{ {signal} }} {{ LOCATION = {ball}; {lv} }}{suffix}")
  55. emit("sys_clk", rows["sys_clk"]["fpga_ball"])
  56. emit("host_rs232_tx", rows["host_uart_tx"]["fpga_ball"], "CON78.1")
  57. emit("host_rs232_rx", rows["host_uart_rx"]["fpga_ball"], "CON78.2")
  58. emit("temp_scl", rows["temp_scl"]["fpga_ball"], "CT7428 bus")
  59. emit("temp_sda", rows["temp_sda"]["fpga_ball"], "CT7428 bus")
  60. for i in range(8):
  61. sig = f"ptc_pwm_out[{i}]"
  62. chamber = i // 2 + 1
  63. half = "A" if i % 2 == 0 else "B"
  64. emit(sig, rows[sig]["fpga_ball"], f"chamber{chamber} physical {half}")
  65. for i in range(4):
  66. sig = f"fan_pwm_out[{i}]"
  67. emit(sig, rows[sig]["fpga_ball"], f"chamber{i+1} fan, board_invert=1")
  68. emit("motor_en_n", rows["motor_en_n"]["fpga_ball"], "constant 1, NPN invert at board")
  69. for axis in ("x", "y", "z"):
  70. index="xyz".index(axis)
  71. emit(f"limit_lower_raw[{index}]", rows[f"{axis}_limit_ls"]["fpga_ball"], "active high")
  72. emit(f"limit_upper_raw[{index}]", rows[f"{axis}_limit_hs"]["fpga_ball"], "active high")
  73. for sig, (ball, seat) in MOTOR_SEATS.items():
  74. old = rows[sig].get("fpga_ball", "?")
  75. emit(sig, ball, f"{seat} direct 3.3V; superseded NPN seat ball {old}")
  76. lines.append(f"# FAN_BOARD_INVERT_MASK = {FAN_INVERT_MASK} (all four V1.2 fans active low at ball)")
  77. text = "\n".join(lines) + "\n"
  78. path = OUT / "prod2u_mrdimm.adc"
  79. if args.check:
  80. if not path.is_file() or path.read_text(encoding="utf-8") != text:
  81. print("generated drift: constraints/prod2u_mrdimm.adc")
  82. return 1
  83. else:
  84. path.write_text(text, encoding="utf-8", newline="\n")
  85. print("PASS: mrdimm adc generated")
  86. return 0
  87. if __name__ == "__main__":
  88. raise SystemExit(main())