generate_mrdimm_adc.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Host TTL pads: those pads are deliberately NOT
  13. assigned (the production wrapper holds the inputs idle and does not export
  14. them, so TD cannot auto-place them onto unrelated board signals). The
  15. retired Host I2C interface is absent from this product. Only axes 0..2
  16. (X/Y/Z) have confirmed STEP/DIR/limit pads; the other nine logical axes
  17. have no bound pads on V1.2 and read inactive. LOGIC_TESTED, not PAD_BOUND.
  18. """
  19. from __future__ import annotations
  20. import argparse
  21. import json
  22. from pathlib import Path
  23. ROOT = Path(__file__).resolve().parents[1]
  24. OUT = ROOT / "constraints"
  25. # Active-authority motor seat override (see module docstring, point 2).
  26. MOTOR_SEATS = {
  27. "x_step": ("H4", "CON142.2"),
  28. "x_dir": ("J6", "CON142.3"),
  29. "y_step": ("E7", "CON126.2"),
  30. "y_dir": ("A4", "CON126.3"),
  31. "z_step": ("B4", "CON127.2"),
  32. "z_dir": ("A12", "CON127.3"),
  33. }
  34. # V1.2 fans are active_low at the ball; connector side is high duty. The
  35. # top-level fan board adapter inverts all four (evidence: inventory rows
  36. # fan_pwm_out[0..3] B1/C4/B5/A14 polarity active_low).
  37. FAN_INVERT_MASK = "4'hF"
  38. def generate(root: Path | None = None) -> dict[Path, bytes]:
  39. base = root if root is not None else ROOT
  40. inv = json.loads((base / "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("# Host RS232 (CON78) and Host TTL (CON140):")
  49. lv = "IOSTANDARD = LVCMOS33; PULLTYPE = NONE;"
  50. def emit(signal: str, ball: str, note: str = "") -> None:
  51. suffix = f" # {note}" if note else ""
  52. lines.append(f"set_pin_assignment {{ {signal} }} {{ LOCATION = {ball}; {lv} }}{suffix}")
  53. emit("sys_clk", rows["sys_clk"]["fpga_ball"])
  54. emit("host_rs232_tx", rows["host_uart_tx"]["fpga_ball"], "CON78.1")
  55. emit("host_rs232_rx", rows["host_uart_rx"]["fpga_ball"], "CON78.2")
  56. emit("host_ttl_tx", "T11", "CON140.1 (EX_GPIO29)")
  57. lines.append("set_pin_assignment { host_ttl_rx } { LOCATION = P13; IOSTANDARD = LVCMOS33; PULLTYPE = PULLUP; } # CON140.2 (EX_GPIO30)")
  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. return {base / 'constraints/prod2u_mrdimm.adc': text.encode('utf-8')}
  79. def main() -> int:
  80. ap = argparse.ArgumentParser()
  81. ap.add_argument('--check', action='store_true')
  82. args = ap.parse_args()
  83. for path, data in generate().items():
  84. if args.check:
  85. if not path.is_file() or path.read_bytes() != data:
  86. print('generated drift: constraints/prod2u_mrdimm.adc')
  87. return 1
  88. else:
  89. path.parent.mkdir(parents=True, exist_ok=True)
  90. path.write_bytes(data)
  91. print('PASS: mrdimm adc generated')
  92. return 0
  93. if __name__ == '__main__':
  94. raise SystemExit(main())