Просмотр исходного кода

generator: derive phase-1 artifacts and active ADC

Codex Resource Selftest 4 месяцев назад
Родитель
Сommit
55c24cf378

+ 18 - 40
constraints/prod2u_p4_normal_v3.adc

@@ -1,48 +1,26 @@
-# Prod2U Profile 4 Normal v3 board constraints.
-# Host UART2 is true RS232 through U23 at 115200 8N1.
-# CT7428 I2C is open drain; RTL only drives low or releases the line.
+# Generated from project.json. Do not edit.
+# Active interface only; reserved board loads are intentionally absent.
 set_pin_assignment { sys_clk } { LOCATION = J1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { host_uart_rx } { LOCATION = N11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; PACKREG = OFF; }
+set_pin_assignment { host_uart_rx } { LOCATION = N11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { host_uart_tx } { LOCATION = M10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { temp_scl } { LOCATION = M8; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; PACKREG = OFF; }
-set_pin_assignment { temp_sda } { LOCATION = N9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; PACKREG = OFF; }
-set_pin_assignment { fan_pwm_out[0] } { LOCATION = C4; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[1] } { LOCATION = B5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { fan_pwm_out[2] } { LOCATION = B1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { temp_scl } { LOCATION = M8; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { temp_sda } { LOCATION = N9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[0] } { LOCATION = G16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[1] } { LOCATION = F16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[2] } { LOCATION = N1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[3] } { LOCATION = M1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[4] } { LOCATION = R16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[5] } { LOCATION = P16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[6] } { LOCATION = P9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { ptc_pwm_out[7] } { LOCATION = T9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { fan_pwm_out[0] } { LOCATION = B1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { fan_pwm_out[1] } { LOCATION = C4; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { fan_pwm_out[2] } { LOCATION = B5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { fan_pwm_out[3] } { LOCATION = A14; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[0] } { LOCATION = F16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[1] } { LOCATION = G16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[2] } { LOCATION = T4; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[3] } { LOCATION = R5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[4] } { LOCATION = T6; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[5] } { LOCATION = R7; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[6] } { LOCATION = M1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[7] } { LOCATION = N1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[8] } { LOCATION = P1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[9] } { LOCATION = R1; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[10] } { LOCATION = T2; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[11] } { LOCATION = R3; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[12] } { LOCATION = P16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[13] } { LOCATION = R16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[14] } { LOCATION = M16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[15] } { LOCATION = N16; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[16] } { LOCATION = P8; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[17] } { LOCATION = P7; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[18] } { LOCATION = T9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[19] } { LOCATION = P9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[20] } { LOCATION = P10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[21] } { LOCATION = R10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[22] } { LOCATION = T13; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { ptc_pwm_out[23] } { LOCATION = T12; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { solenoid_out } { LOCATION = P5; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { motor_en_n } { LOCATION = A10; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { x_step } { LOCATION = C11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { x_dir } { LOCATION = B12; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { y_step } { LOCATION = D15; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
 set_pin_assignment { y_dir } { LOCATION = H14; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { z_step } { LOCATION = H12; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-set_pin_assignment { z_dir } { LOCATION = F14; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
-# LS1/X: CON30.3 -> FAN_GPIO3 -> R662 -> BANK0_GPIO3 -> B9.
-# LS2/Y: CON12.3 -> FAN_GPIO1 -> R660 -> BANK0_GPIO1 -> A11. A5 is unassigned.
-set_pin_assignment { x_limit_raw } { LOCATION = B9; IOSTANDARD = LVCMOS33; PULLTYPE = PULLUP; PACKREG = OFF; }
-set_pin_assignment { y_limit_raw } { LOCATION = A11; IOSTANDARD = LVCMOS33; PULLTYPE = PULLUP; PACKREG = OFF; }
+set_pin_assignment { x_limit_raw } { LOCATION = B9; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }
+set_pin_assignment { y_limit_raw } { LOCATION = A11; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }

+ 2 - 1
src/generated/golden-vectors.json

@@ -1,4 +1,5 @@
 {
   "all_invalid_temperature": "A55A821BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA745",
-  "get_temperature": "A55A02006D7B"
+  "get_temperature": "A55A02006D7B",
+  "set_all": "A55A010E00010203040506070A141E280102B2C5"
 }

+ 246 - 26
src/generated/host-contract.json

@@ -6,7 +6,20 @@
       "type": "0x02"
     },
     "set_all": {
-      "payload_length": 30,
+      "duty_range": [
+        0,
+        100
+      ],
+      "heartbeat": [
+        0,
+        0
+      ],
+      "motor_values": [
+        0,
+        1,
+        2
+      ],
+      "payload_length": 14,
       "response": "none",
       "type": "0x01"
     },
@@ -16,62 +29,257 @@
       "type": "0x82"
     }
   },
-  "crc": {
-    "coverage": "type_length_payload",
-    "initial": 65535,
-    "name": "CRC-16/CCITT-FALSE",
-    "polynomial": 4129,
-    "reflect_input": false,
-    "reflect_output": false,
-    "wire_order": "little",
-    "xor_output": 0
+  "limits": {
+    "active_level": "high",
+    "channels": [
+      {
+        "ball": "B9",
+        "name": "x_limit_raw"
+      },
+      {
+        "ball": "A11",
+        "name": "y_limit_raw"
+      }
+    ],
+    "functional_use": false,
+    "limit_count": 2
   },
   "motors": {
-    "count": 2,
-    "dir_setup_cycles": 25000,
-    "direction_meaning": {
-      "0": "open",
-      "1": "close"
-    },
-    "direction_values": [
+    "busy_wait_ms": 600,
+    "command_values": [
       0,
-      1
+      1,
+      2
     ],
+    "count": 2,
+    "dir_setup_cycles": 25000,
     "enable_n": {
+      "active_level": "low",
       "ball": "A10",
-      "policy": "constant_low_enabled"
+      "policy": "shared_constant_low"
     },
-    "execution": "serial",
+    "execution": "overlap",
     "fixed_steps": 450,
-    "limits": "none",
+    "heartbeat_value": 0,
     "mapping": {
-      "inlet": {
+      "x": {
         "axis": "x",
         "dir_ball": "B12",
+        "role": "exhaust",
         "step_ball": "C11"
       },
-      "outlet": {
+      "y": {
         "axis": "y",
         "dir_ball": "H14",
+        "role": "exhaust",
         "step_ball": "D15"
       }
     },
     "order": [
-      "inlet",
-      "outlet"
+      "x",
+      "y"
     ],
+    "role": "exhaust",
     "step_half_cycles": 12500,
     "step_rate_hz": 1000
   },
+  "outputs": {
+    "boot_targets": {
+      "fan": 10,
+      "ptc": 0
+    },
+    "fan_board_inverts": true,
+    "fan_channels": [
+      {
+        "ball": "B1",
+        "board_signal": "FAN_PWM3",
+        "connector": "CON25",
+        "connector_pin": 7,
+        "index": 0,
+        "name": "fan1",
+        "polarity": "active_low",
+        "signal": "fan_pwm_out[0]"
+      },
+      {
+        "ball": "C4",
+        "board_signal": "FAN_PWM1",
+        "connector": "CON8",
+        "connector_pin": 7,
+        "index": 1,
+        "name": "fan2",
+        "polarity": "active_low",
+        "signal": "fan_pwm_out[1]"
+      },
+      {
+        "ball": "B5",
+        "board_signal": "FAN_PWM2",
+        "connector": "CON24",
+        "connector_pin": 7,
+        "index": 2,
+        "name": "fan3",
+        "polarity": "active_low",
+        "signal": "fan_pwm_out[2]"
+      },
+      {
+        "ball": "A14",
+        "board_signal": "FAN_PWM4",
+        "connector": "CON26",
+        "connector_pin": 7,
+        "index": 3,
+        "name": "fan4",
+        "polarity": "active_low",
+        "signal": "fan_pwm_out[3]"
+      }
+    ],
+    "fan_connector_active_level": "high",
+    "fan_count": 4,
+    "fan_default": 10,
+    "fan_polarity": "active_low",
+    "ptc_channels": [
+      {
+        "ball": "G16",
+        "board_signal": "HEAT2",
+        "connector": "CON18",
+        "connector_pin": 3,
+        "index": 0,
+        "name": "ptc1",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[0]"
+      },
+      {
+        "ball": "F16",
+        "board_signal": "HEAT1",
+        "connector": "CON18",
+        "connector_pin": 1,
+        "index": 1,
+        "name": "ptc2",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[1]"
+      },
+      {
+        "ball": "N1",
+        "board_signal": "HEAT8",
+        "connector": "CON27",
+        "connector_pin": 3,
+        "index": 2,
+        "name": "ptc3",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[2]"
+      },
+      {
+        "ball": "M1",
+        "board_signal": "HEAT7",
+        "connector": "CON27",
+        "connector_pin": 1,
+        "index": 3,
+        "name": "ptc4",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[3]"
+      },
+      {
+        "ball": "R16",
+        "board_signal": "HEAT14",
+        "connector": "CON28",
+        "connector_pin": 3,
+        "index": 4,
+        "name": "ptc5",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[4]"
+      },
+      {
+        "ball": "P16",
+        "board_signal": "HEAT13",
+        "connector": "CON28",
+        "connector_pin": 1,
+        "index": 5,
+        "name": "ptc6",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[5]"
+      },
+      {
+        "ball": "P9",
+        "board_signal": "HEAT20",
+        "connector": "CON29",
+        "connector_pin": 3,
+        "index": 6,
+        "name": "ptc7",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[6]"
+      },
+      {
+        "ball": "T9",
+        "board_signal": "HEAT19",
+        "connector": "CON29",
+        "connector_pin": 1,
+        "index": 7,
+        "name": "ptc8",
+        "polarity": "active_high",
+        "signal": "ptc_pwm_out[7]"
+      }
+    ],
+    "ptc_count": 8,
+    "ptc_default": 0,
+    "ptc_polarity": "active_high",
+    "pwm_actual_frequency_hz": 19.993602047,
+    "pwm_bits": 8,
+    "pwm_frequency_hz": 20,
+    "pwm_internal_width": 7,
+    "pwm_max_duty": 100,
+    "pwm_phase_count": 100,
+    "pwm_slot_clks": 1042
+  },
   "project_id": "prod2u-door-temp",
+  "protocol": {
+    "commands": {
+      "get_temperature": 2,
+      "set_all": 1,
+      "temperature_data": 130
+    },
+    "crc": {
+      "coverage": "type_length_payload",
+      "initial": 65535,
+      "name": "CRC-16/CCITT-FALSE",
+      "polynomial": 4129,
+      "reflect_input": false,
+      "reflect_output": false,
+      "wire_order": "little",
+      "xor_output": 0
+    },
+    "header_hex": "A55A",
+    "set_all": {
+      "duty_max": 100,
+      "duty_min": 0,
+      "fan_offset": 8,
+      "heartbeat": [
+        0,
+        0
+      ],
+      "motor_values": [
+        0,
+        1,
+        2
+      ],
+      "motor_x_offset": 12,
+      "motor_y_offset": 13,
+      "payload_length": 14,
+      "ptc_offset": 0,
+      "response": "none"
+    },
+    "temperature_data": {
+      "frame_length": 33,
+      "payload_length": 27
+    }
+  },
   "schema": "prod2u-simple-host-contract-v1",
   "temperature": {
+    "bus": "i2c",
     "conversion": {
       "profile": "ct7428-msb-integer",
       "raw_shift": 7,
       "raw_width": 9,
       "reject_sign_bit": true
     },
+    "device": "CT7428",
     "device_addresses": [
       73,
       72,
@@ -101,6 +309,18 @@
     "flow_control": "none",
     "inter_byte_timeout_ms": 10,
     "parity": "N",
-    "stop_bits": 1
+    "rx_ball": "N11",
+    "stop_bits": 1,
+    "tx_ball": "M10"
+  },
+  "watchdog": {
+    "target": {
+      "fan": 20,
+      "ptc": 0
+    },
+    "tick_clks": 12500,
+    "tick_us": 500,
+    "timeout_seconds": 10,
+    "timeout_ticks": 20000
   }
 }

+ 15 - 3
src/generated/prod2u_door_temp_params.vh

@@ -2,20 +2,32 @@
 `define P4_CLOCK_HZ 25000000
 `define P4_UART_BAUD 115200
 `define P4_UART_CLKS_PER_BIT 217
-`define P4_PTC_COUNT 24
+`define P4_PTC_COUNT 8
 `define P4_FAN_COUNT 4
+`define P4_PWM_PROTOCOL_WIDTH 8
+`define P4_PWM_INTERNAL_WIDTH 7
+`define P4_PWM_MAX_DUTY 100
+`define P4_PWM_PHASE_COUNT 100
 `define P4_PWM_FREQUENCY_HZ 20
-`define P4_PWM_SLOT_CLKS 174
+`define P4_PWM_SLOT_CLKS 1042
 `define P4_FIXED_MOTOR_STEPS 450
+`define P4_MOTOR_STEP_RATE_HZ 1000
 `define P4_MOTOR_STEP_HALF_CYCLES 12500
 `define P4_MOTOR_DIR_SETUP_CYCLES 25000
+`define P4_MOTOR_HEARTBEAT_COMMAND 2'd0
 `define P4_TEMPERATURE_COUNT 27
 `define P4_TEMPERATURE_COUNT_BYTE 8'h1B
 `define P4_TEMP_MAX_CELSIUS 150
 `define P4_PTC_ACTIVE_HIGH 1
 `define P4_FAN_ACTIVE_HIGH 0
 `define P4_PTC_DEFAULT_TARGET 8'h00
-`define P4_FAN_DEFAULT_TARGET 8'h1A
+`define P4_FAN_DEFAULT_TARGET 8'h0A
+`define P4_WATCHDOG_TIMEOUT_SECONDS 10
+`define P4_WATCHDOG_TICK_US 500
+`define P4_WATCHDOG_TICK_CLKS 12500
+`define P4_WATCHDOG_TIMEOUT_TICKS 20000
+`define P4_WATCHDOG_PTC_TARGET 8'h00
+`define P4_WATCHDOG_FAN_TARGET 8'h14
 `define P4_TEMP_DEVICE_ADDR_0 7'h49
 `define P4_TEMP_DEVICE_ADDR_1 7'h48
 `define P4_TEMP_DEVICE_ADDR_2 7'h4B

+ 23 - 10
src/generated/project-summary.json

@@ -1,22 +1,28 @@
 {
-  "actual_frequency_hz": 20.044386289,
+  "actual_frequency_hz": 19.993602047,
+  "boot_targets": {
+    "fan": 10,
+    "ptc": 0
+  },
   "fan_board_inverts": true,
   "fan_connector_active_level": "high",
-  "fan_default": 26,
+  "fan_default": 10,
   "fan_polarity": "active_low",
-  "frequency_error_percent": 0.221931445,
+  "frequency_error_percent": 0.031989763,
   "profile": "prod2u-normal-multiproject-115200-v1",
   "project_id": "prod2u-door-temp",
   "ptc_default": 0,
   "ptc_polarity": "active_high",
   "pwm_bits": 8,
   "pwm_frequency_hz": 20,
-  "pwm_period_clks": 1247232,
-  "pwm_period_seconds": 0.04988928,
-  "pwm_phase_count": 256,
-  "pwm_slot_clks": 174,
-  "set_all_frame_len": 36,
-  "set_all_payload_len": 30,
+  "pwm_internal_width": 7,
+  "pwm_max_duty": 100,
+  "pwm_period_clks": 1250400,
+  "pwm_period_seconds": 0.050016,
+  "pwm_phase_count": 100,
+  "pwm_slot_clks": 1042,
+  "set_all_frame_len": 20,
+  "set_all_payload_len": 14,
   "temperature_addresses": [
     73,
     72,
@@ -24,5 +30,12 @@
   ],
   "temperature_frame_len": 33,
   "temperature_payload_len": 27,
-  "uart_clks_per_bit": 217
+  "uart_clks_per_bit": 217,
+  "watchdog_target": {
+    "fan": 20,
+    "ptc": 0
+  },
+  "watchdog_tick_clks": 12500,
+  "watchdog_timeout_seconds": 10,
+  "watchdog_timeout_ticks": 20000
 }

+ 154 - 0
src/generated/td-source-manifest.json

@@ -1,4 +1,158 @@
 {
+  "active_interface": [
+    {
+      "ball": "J1",
+      "signal": "sys_clk"
+    },
+    {
+      "ball": "N11",
+      "signal": "host_uart_rx"
+    },
+    {
+      "ball": "M10",
+      "signal": "host_uart_tx"
+    },
+    {
+      "ball": "M8",
+      "signal": "temp_scl"
+    },
+    {
+      "ball": "N9",
+      "signal": "temp_sda"
+    },
+    {
+      "ball": "G16",
+      "signal": "ptc_pwm_out[0]"
+    },
+    {
+      "ball": "F16",
+      "signal": "ptc_pwm_out[1]"
+    },
+    {
+      "ball": "N1",
+      "signal": "ptc_pwm_out[2]"
+    },
+    {
+      "ball": "M1",
+      "signal": "ptc_pwm_out[3]"
+    },
+    {
+      "ball": "R16",
+      "signal": "ptc_pwm_out[4]"
+    },
+    {
+      "ball": "P16",
+      "signal": "ptc_pwm_out[5]"
+    },
+    {
+      "ball": "P9",
+      "signal": "ptc_pwm_out[6]"
+    },
+    {
+      "ball": "T9",
+      "signal": "ptc_pwm_out[7]"
+    },
+    {
+      "ball": "B1",
+      "signal": "fan_pwm_out[0]"
+    },
+    {
+      "ball": "C4",
+      "signal": "fan_pwm_out[1]"
+    },
+    {
+      "ball": "B5",
+      "signal": "fan_pwm_out[2]"
+    },
+    {
+      "ball": "A14",
+      "signal": "fan_pwm_out[3]"
+    },
+    {
+      "ball": "A10",
+      "signal": "motor_en_n"
+    },
+    {
+      "ball": "C11",
+      "signal": "x_step"
+    },
+    {
+      "ball": "B12",
+      "signal": "x_dir"
+    },
+    {
+      "ball": "D15",
+      "signal": "y_step"
+    },
+    {
+      "ball": "H14",
+      "signal": "y_dir"
+    },
+    {
+      "ball": "B9",
+      "signal": "x_limit_raw"
+    },
+    {
+      "ball": "A11",
+      "signal": "y_limit_raw"
+    }
+  ],
+  "contract": {
+    "protocol": {
+      "commands": {
+        "get_temperature": 2,
+        "set_all": 1,
+        "temperature_data": 130
+      },
+      "crc": {
+        "coverage": "type_length_payload",
+        "initial": 65535,
+        "name": "CRC-16/CCITT-FALSE",
+        "polynomial": 4129,
+        "reflect_input": false,
+        "reflect_output": false,
+        "wire_order": "little",
+        "xor_output": 0
+      },
+      "header_hex": "A55A",
+      "set_all": {
+        "duty_max": 100,
+        "duty_min": 0,
+        "fan_offset": 8,
+        "heartbeat": [
+          0,
+          0
+        ],
+        "motor_values": [
+          0,
+          1,
+          2
+        ],
+        "motor_x_offset": 12,
+        "motor_y_offset": 13,
+        "payload_length": 14,
+        "ptc_offset": 0,
+        "response": "none"
+      },
+      "temperature_data": {
+        "frame_length": 33,
+        "payload_length": 27
+      }
+    },
+    "set_all_payload_length": 14,
+    "temperature_frame_length": 33,
+    "uart": {
+      "baud": 115200,
+      "clks_per_bit": 217,
+      "data_bits": 8,
+      "flow_control": "none",
+      "inter_byte_timeout_ms": 10,
+      "parity": "N",
+      "rx_ball": "N11",
+      "stop_bits": 1,
+      "tx_ball": "M10"
+    }
+  },
   "generated_from": "project.json",
   "project_id": "prod2u-door-temp",
   "schema": "prod2u-simple-source-manifest-template-v1",

+ 438 - 63
tools/generate_project.py

@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-"""Validate a project.json and emit deterministic compile-time artifacts."""
+"""Validate a project configuration and emit deterministic contract artifacts."""
 
 from __future__ import annotations
 
@@ -33,80 +33,407 @@ ACTIVE_SOURCE_PATHS = (
     "src/top/prod2u_p4_normal_v3_top.v",
 )
 
+EXPECTED_CHANNEL_METADATA = {
+    "ptc": (
+        ("HEAT2", "G16", "CON18", 3, "active_high"),
+        ("HEAT1", "F16", "CON18", 1, "active_high"),
+        ("HEAT8", "N1", "CON27", 3, "active_high"),
+        ("HEAT7", "M1", "CON27", 1, "active_high"),
+        ("HEAT14", "R16", "CON28", 3, "active_high"),
+        ("HEAT13", "P16", "CON28", 1, "active_high"),
+        ("HEAT20", "P9", "CON29", 3, "active_high"),
+        ("HEAT19", "T9", "CON29", 1, "active_high"),
+    ),
+    "fan": (
+        ("FAN_PWM3", "B1", "CON25", 7, "active_low"),
+        ("FAN_PWM1", "C4", "CON8", 7, "active_low"),
+        ("FAN_PWM2", "B5", "CON24", 7, "active_low"),
+        ("FAN_PWM4", "A14", "CON26", 7, "active_low"),
+    ),
+}
+
+_TOP_LEVEL_KEYS = {
+    "project_id",
+    "profile",
+    "display_name",
+    "device",
+    "uart",
+    "outputs",
+    "motors",
+    "limits",
+    "temperature",
+    "pins",
+    "resources",
+    "protocol",
+    "timeouts",
+    "watchdog",
+}
+
 
 def _require(condition: bool, message: str) -> None:
     if not condition:
         raise ValueError(message)
 
 
+def _object(value: Any, name: str) -> Mapping[str, Any]:
+    _require(isinstance(value, dict), f"{name} must be an object")
+    return value
+
+
+def _keys(value: Mapping[str, Any], expected: set[str], name: str) -> None:
+    _require(set(value) == expected, f"{name} keys mismatch")
+
+
+def _integer(value: Any, name: str, *, minimum: int | None = None) -> None:
+    _require(isinstance(value, int) and not isinstance(value, bool), f"{name} must be an integer")
+    if minimum is not None:
+        _require(value >= minimum, f"{name} is below the minimum")
+
+
+def _number(value: Any, name: str) -> None:
+    _require(isinstance(value, (int, float)) and not isinstance(value, bool), f"{name} must be numeric")
+
+
+def _list(value: Any, name: str, length: int | None = None) -> list[Any]:
+    _require(isinstance(value, list), f"{name} must be an array")
+    if length is not None:
+        _require(len(value) == length, f"{name} must contain {length} items")
+    return value
+
+
+def _validate_channel(channel: Any, index: int, kind: str) -> None:
+    item = _object(channel, f"{kind}_channels[{index}]")
+    _keys(item, {"index", "name", "signal", "board_signal", "ball", "connector", "connector_pin", "polarity"}, f"{kind}_channels[{index}]")
+    _require(item["index"] == index, f"{kind} channel index mismatch at {index}")
+    _require(item["name"] == f"{kind}{index + 1}", f"{kind} channel name mismatch at {index}")
+    _require(item["signal"] == f"{kind}_pwm_out[{index}]", f"{kind} channel signal mismatch at {index}")
+    _require(isinstance(item["board_signal"], str) and item["board_signal"], f"invalid {kind} board signal at {index}")
+    _require(item["polarity"] in {"active_high", "active_low"}, f"invalid {kind} polarity at {index}")
+    _require(re.fullmatch(r"[A-Z][0-9]+", str(item["ball"])) is not None, f"invalid {kind} ball at {index}")
+    _require(re.fullmatch(r"CON[0-9]+", str(item["connector"])) is not None, f"invalid {kind} connector at {index}")
+    _integer(item["connector_pin"], f"{kind} channel connector pin", minimum=1)
+    expected = EXPECTED_CHANNEL_METADATA[kind][index]
+    _require(
+        (item["board_signal"], item["ball"], item["connector"], item["connector_pin"], item["polarity"]) == expected,
+        f"{kind} channel metadata mismatch at {index}",
+    )
+
+
+def _validate_project(payload: Mapping[str, Any]) -> None:
+    _keys(payload, _TOP_LEVEL_KEYS, "project")
+    _require(re.fullmatch(r"[a-z0-9-]+", str(payload["project_id"])) is not None, "invalid project_id")
+    _require(payload["profile"] == PROFILE, "unsupported project profile")
+    _require(isinstance(payload["display_name"], str) and payload["display_name"], "invalid display_name")
+
+    device = _object(payload["device"], "device")
+    _keys(device, {"family", "part", "clock_hz", "clock_ball"}, "device")
+    _require(device["family"] == "EF2" and device["part"] == "EF2L45BG256B", "device identity mismatch")
+    _require(device["clock_hz"] == 25_000_000 and device["clock_ball"] == "J1", "clock contract mismatch")
+
+    uart = _object(payload["uart"], "uart")
+    _keys(uart, {"baud", "data_bits", "parity", "stop_bits", "flow_control", "clks_per_bit", "inter_byte_timeout_ms", "rx_ball", "tx_ball"}, "uart")
+    _require(
+        uart["baud"] == 115200
+        and uart["data_bits"] == 8
+        and uart["parity"] == "N"
+        and uart["stop_bits"] == 1
+        and uart["flow_control"] == "none"
+        and uart["clks_per_bit"] == 217,
+        "UART contract mismatch",
+    )
+    _require(uart["rx_ball"] == "N11" and uart["tx_ball"] == "M10", "UART pin mapping mismatch")
+
+    outputs = _object(payload["outputs"], "outputs")
+    _keys(
+        outputs,
+        {
+            "ptc_count",
+            "fan_count",
+            "ptc_channels",
+            "fan_channels",
+            "pwm_bits",
+            "pwm_internal_width",
+            "pwm_max_duty",
+            "pwm_phase_count",
+            "pwm_slot_clks",
+            "pwm_frequency_hz",
+            "pwm_actual_frequency_hz",
+            "ptc_polarity",
+            "fan_polarity",
+            "ptc_default",
+            "fan_default",
+            "fan_connector_active_level",
+            "fan_board_inverts",
+            "boot_targets",
+        },
+        "outputs",
+    )
+    _require(outputs["ptc_count"] == len(outputs["ptc_channels"]) == 8, "PTC count/list mismatch")
+    _require(outputs["fan_count"] == len(outputs["fan_channels"]) == 4, "FAN count/list mismatch")
+    for index, channel in enumerate(outputs["ptc_channels"]):
+        _validate_channel(channel, index, "ptc")
+    for index, channel in enumerate(outputs["fan_channels"]):
+        _validate_channel(channel, index, "fan")
+    _require(outputs["pwm_bits"] == 8, "PWM protocol width mismatch")
+    _require(outputs["pwm_internal_width"] == 7, "PWM internal width mismatch")
+    _require(outputs["pwm_max_duty"] == 100, "PWM maximum duty mismatch")
+    _require(outputs["pwm_phase_count"] == 100 and outputs["pwm_slot_clks"] == 1042, "PWM phase contract mismatch")
+    _require(outputs["pwm_frequency_hz"] == 20, "PWM target frequency mismatch")
+    _require(abs(outputs["pwm_actual_frequency_hz"] - 19.993602047) < 1e-12, "PWM actual frequency mismatch")
+    _require(outputs["ptc_polarity"] == "active_high" and outputs["fan_polarity"] == "active_low", "PWM polarity mismatch")
+    _require(outputs["ptc_default"] == 0 and outputs["fan_default"] == 10, "PWM boot target mismatch")
+    _require(outputs["fan_connector_active_level"] == "high" and outputs["fan_board_inverts"] is True, "FAN board metadata mismatch")
+    boot_targets = _object(outputs["boot_targets"], "outputs.boot_targets")
+    _keys(boot_targets, {"ptc", "fan"}, "outputs.boot_targets")
+    _require(boot_targets == {"ptc": 0, "fan": 10}, "boot target mapping mismatch")
+
+    motors = _object(payload["motors"], "motors")
+    _keys(
+        motors,
+        {
+            "count",
+            "order",
+            "role",
+            "fixed_steps",
+            "execution",
+            "busy_wait_ms",
+            "step_rate_hz",
+            "step_half_cycles",
+            "dir_setup_cycles",
+            "command_values",
+            "heartbeat_value",
+            "mapping",
+            "enable_n",
+        },
+        "motors",
+    )
+    _require(motors["count"] == 2 and motors["order"] == ["x", "y"] and motors["role"] == "exhaust", "motor identity mismatch")
+    _require(motors["execution"] == "overlap" and motors["busy_wait_ms"] >= 600, "motor overlap/busy contract mismatch")
+    _require(motors["fixed_steps"] == 450 and motors["step_rate_hz"] == 1000, "motor speed/step mismatch")
+    _require(motors["step_half_cycles"] == 12_500 and motors["dir_setup_cycles"] == 25_000, "motor timing mismatch")
+    _require(motors["command_values"] == [0, 1, 2] and motors["heartbeat_value"] == 0, "motor command mismatch")
+    mapping = _object(motors["mapping"], "motors.mapping")
+    _keys(mapping, {"x", "y"}, "motors.mapping")
+    for axis in ("x", "y"):
+        item = _object(mapping[axis], f"motors.mapping.{axis}")
+        _keys(item, {"axis", "role", "step_ball", "dir_ball"}, f"motors.mapping.{axis}")
+        _require(item["axis"] == axis and item["role"] == "exhaust", f"motor {axis} role mismatch")
+    enable = _object(motors["enable_n"], "motors.enable_n")
+    _keys(enable, {"ball", "active_level", "policy"}, "motors.enable_n")
+    _require(enable == {"ball": "A10", "active_level": "low", "policy": "shared_constant_low"}, "motor enable mapping mismatch")
+
+    limits = _object(payload["limits"], "limits")
+    _keys(limits, {"limit_count", "active_level", "functional_use", "channels"}, "limits")
+    _require(limits["limit_count"] == len(limits["channels"]) == 2, "limit count/list mismatch")
+    _require(limits["active_level"] == "high" and limits["functional_use"] is False, "limit policy mismatch")
+    for index, item in enumerate(limits["channels"]):
+        entry = _object(item, f"limits.channels[{index}]")
+        _keys(entry, {"name", "ball"}, f"limits.channels[{index}]")
+        _require(entry["name"] in {"x_limit_raw", "y_limit_raw"}, "invalid limit name")
+
+    temperature = _object(payload["temperature"], "temperature")
+    _keys(
+        temperature,
+        {
+            "value_count",
+            "device_addresses",
+            "registers",
+            "scl_ball",
+            "sda_ball",
+            "bus",
+            "device",
+            "invalid_value",
+            "maximum_celsius",
+            "conversion",
+        },
+        "temperature",
+    )
+    _require(temperature["value_count"] == 27, "temperature count mismatch")
+    _require(temperature["device_addresses"] == [73, 72, 75] and temperature["registers"] == list(range(9)), "temperature mapping mismatch")
+    _require(temperature["scl_ball"] == "M8" and temperature["sda_ball"] == "N9" and temperature["device"] == "CT7428", "I2C mapping mismatch")
+    conversion = _object(temperature["conversion"], "temperature.conversion")
+    _keys(conversion, {"profile", "raw_shift", "raw_width", "reject_sign_bit"}, "temperature.conversion")
+    _require(conversion == {"profile": "ct7428-msb-integer", "raw_shift": 7, "raw_width": 9, "reject_sign_bit": True}, "temperature conversion mismatch")
+
+    pins = _object(payload["pins"], "pins")
+    _keys(
+        pins,
+        {
+            "host_uart_rx",
+            "host_uart_tx",
+            "temp_scl",
+            "temp_sda",
+            "ptc_pwm",
+            "fan_pwm",
+            "motor_en_n",
+            "x_step",
+            "x_dir",
+            "y_step",
+            "y_dir",
+            "x_limit_raw",
+            "y_limit_raw",
+        },
+        "pins",
+    )
+    _require(pins["host_uart_rx"] == uart["rx_ball"] and pins["host_uart_tx"] == uart["tx_ball"], "UART pin duplication mismatch")
+    _require(pins["temp_scl"] == temperature["scl_ball"] and pins["temp_sda"] == temperature["sda_ball"], "I2C pin duplication mismatch")
+    _require(pins["ptc_pwm"] == [item["ball"] for item in outputs["ptc_channels"]], "PTC pin/list mismatch")
+    _require(
+        len(pins["fan_pwm"]) == outputs["fan_count"]
+        and set(pins["fan_pwm"]) == {item["ball"] for item in outputs["fan_channels"]},
+        "FAN pin/list mismatch",
+    )
+    _require(pins["motor_en_n"] == enable["ball"], "motor enable pin mismatch")
+    _require(pins["x_step"] == mapping["x"]["step_ball"] and pins["x_dir"] == mapping["x"]["dir_ball"], "X motor pin mismatch")
+    _require(pins["y_step"] == mapping["y"]["step_ball"] and pins["y_dir"] == mapping["y"]["dir_ball"], "Y motor pin mismatch")
+    _require([pins["x_limit_raw"], pins["y_limit_raw"]] == [item["ball"] for item in limits["channels"]], "limit pin mismatch")
+
+    resources = _object(payload["resources"], "resources")
+    _keys(
+        resources,
+        {
+            "target_ram_blocks",
+            "request_ram_blocks",
+            "temperature_ram_blocks",
+            "dsp",
+            "shared_pwm_comparators",
+            "shared_motor_executors",
+            "shared_i2c_readers",
+        },
+        "resources",
+    )
+    _require(resources["shared_pwm_comparators"] == 1 and resources["shared_motor_executors"] == 1 and resources["shared_i2c_readers"] == 1, "shared resource contract mismatch")
+
+    protocol = _object(payload["protocol"], "protocol")
+    _keys(protocol, {"header_hex", "crc", "commands", "set_all", "temperature_data"}, "protocol")
+    _require(protocol["header_hex"] == "A55A", "frame header mismatch")
+    crc = _object(protocol["crc"], "protocol.crc")
+    _keys(crc, {"name", "polynomial", "initial", "reflect_input", "reflect_output", "xor_output", "coverage", "wire_order"}, "protocol.crc")
+    _require(
+        crc
+        == {
+            "name": "CRC-16/CCITT-FALSE",
+            "polynomial": 0x1021,
+            "initial": 0xFFFF,
+            "reflect_input": False,
+            "reflect_output": False,
+            "xor_output": 0,
+            "coverage": "type_length_payload",
+            "wire_order": "little",
+        },
+        "CRC contract mismatch",
+    )
+    _require(protocol["commands"] == {"set_all": 1, "get_temperature": 2, "temperature_data": 130}, "protocol type mismatch")
+    set_all = _object(protocol["set_all"], "protocol.set_all")
+    _keys(set_all, {"payload_length", "ptc_offset", "fan_offset", "motor_x_offset", "motor_y_offset", "duty_min", "duty_max", "motor_values", "heartbeat", "response"}, "protocol.set_all")
+    _require(
+        set_all
+        == {
+            "payload_length": 14,
+            "ptc_offset": 0,
+            "fan_offset": 8,
+            "motor_x_offset": 12,
+            "motor_y_offset": 13,
+            "duty_min": 0,
+            "duty_max": 100,
+            "motor_values": [0, 1, 2],
+            "heartbeat": [0, 0],
+            "response": "none",
+        },
+        "SET_ALL contract mismatch",
+    )
+    temperature_data = _object(protocol["temperature_data"], "protocol.temperature_data")
+    _keys(temperature_data, {"payload_length", "frame_length"}, "protocol.temperature_data")
+    _require(temperature_data == {"payload_length": 27, "frame_length": 33}, "temperature frame contract mismatch")
+
+    timeouts = _object(payload["timeouts"], "timeouts")
+    _keys(timeouts, {"frame_inter_byte_ms", "host_get_response_ms"}, "timeouts")
+    _require(timeouts["frame_inter_byte_ms"] == 10, "frame timeout mismatch")
+
+    watchdog = _object(payload["watchdog"], "watchdog")
+    _keys(watchdog, {"timeout_seconds", "tick_us", "tick_clks", "timeout_ticks", "target"}, "watchdog")
+    _require(watchdog["timeout_seconds"] == 10 and watchdog["tick_us"] == 500, "watchdog duration mismatch")
+    _require(watchdog["tick_clks"] == device["clock_hz"] * watchdog["tick_us"] // 1_000_000, "watchdog tick clock mismatch")
+    _require(watchdog["timeout_ticks"] == watchdog["timeout_seconds"] * 1_000_000 // watchdog["tick_us"], "watchdog tick count mismatch")
+    target = _object(watchdog["target"], "watchdog.target")
+    _keys(target, {"ptc", "fan"}, "watchdog.target")
+    _require(target == {"ptc": 0, "fan": 20}, "watchdog target mismatch")
+
+
 def load_project(path: Path) -> dict[str, Any]:
     project_path = Path(path)
     payload = json.loads(project_path.read_text(encoding="utf-8"))
     _require(isinstance(payload, dict), "project root must be an object")
-    _require(re.fullmatch(r"[a-z0-9-]+", str(payload.get("project_id", ""))) is not None, "invalid project_id")
-    _require(payload.get("profile") == PROFILE, "unsupported project profile")
-    device = payload.get("device")
-    uart = payload.get("uart")
-    outputs = payload.get("outputs")
-    motors = payload.get("motors")
-    temperature = payload.get("temperature")
-    protocol = payload.get("protocol")
-    for name, value in (("device", device), ("uart", uart), ("outputs", outputs), ("motors", motors), ("temperature", temperature), ("protocol", protocol)):
-        _require(isinstance(value, dict), f"{name} must be an object")
-    _require(device["part"] == "EF2L45BG256B" and device["clock_hz"] == 25_000_000, "device constants mismatch")
-    _require(uart == {**uart, "baud": 115200, "data_bits": 8, "parity": "N", "stop_bits": 1, "flow_control": "none", "clks_per_bit": 217}, "UART constants mismatch")
-    _require(outputs["ptc_count"] == 24 and outputs["fan_count"] == 4 and outputs["pwm_bits"] == 8, "output counts mismatch")
-    _require(outputs["pwm_frequency_hz"] == 20, "PWM frequency mismatch")
-    _require(outputs["ptc_polarity"] == "active_high" and outputs["fan_polarity"] == "active_low", "PWM polarity mismatch")
-    _require(outputs["ptc_default"] == 0 and outputs["fan_default"] == 26, "PWM default mismatch")
-    _require(outputs["fan_connector_active_level"] == "high" and outputs["fan_board_inverts"] is True, "FAN board polarity metadata mismatch")
-    _require(motors["count"] == 2 and motors["fixed_steps"] == 450 and motors["execution"] == "serial", "motor constants mismatch")
-    _require(motors["order"] == ["inlet", "outlet"] and motors["direction_values"] == [0, 1], "motor order mismatch")
-    _require(temperature["value_count"] == 27 and temperature["device_addresses"] == [73, 72, 75], "temperature constants mismatch")
-    _require(temperature["registers"] == list(range(9)), "temperature register order mismatch")
-    _require(protocol["commands"] == {"set_all": 1, "get_temperature": 2, "temperature_data": 130}, "protocol type mismatch")
-    _require(protocol["crc"]["polynomial"] == 0x1021 and protocol["crc"]["initial"] == 0xFFFF, "CRC constants mismatch")
-    _require(len(payload["pins"]["ptc_pwm"]) == 24 and len(payload["pins"]["fan_pwm"]) == 4, "pin count mismatch")
+    _validate_project(payload)
     return payload
 
 
+def _active_interface(project: Mapping[str, Any]) -> tuple[tuple[str, str], ...]:
+    outputs = project["outputs"]
+    pins = project["pins"]
+    motors = project["motors"]
+    limits = project["limits"]
+    return (
+        ("sys_clk", project["device"]["clock_ball"]),
+        ("host_uart_rx", pins["host_uart_rx"]),
+        ("host_uart_tx", pins["host_uart_tx"]),
+        ("temp_scl", pins["temp_scl"]),
+        ("temp_sda", pins["temp_sda"]),
+        *tuple((item["signal"], item["ball"]) for item in outputs["ptc_channels"]),
+        *tuple((item["signal"], item["ball"]) for item in outputs["fan_channels"]),
+        ("motor_en_n", pins["motor_en_n"]),
+        ("x_step", motors["mapping"]["x"]["step_ball"]),
+        ("x_dir", motors["mapping"]["x"]["dir_ball"]),
+        ("y_step", motors["mapping"]["y"]["step_ball"]),
+        ("y_dir", motors["mapping"]["y"]["dir_ball"]),
+        *tuple((item["name"], item["ball"]) for item in limits["channels"]),
+    )
+
+
+def render_adc(project: Mapping[str, Any]) -> tuple[tuple[str, str], ...]:
+    """Return the ordered active interface as (signal, ball) pairs."""
+    return _active_interface(project)
+
+
 def project_summary(path: Path) -> dict[str, Any]:
     project = load_project(path)
-    ptc_count = project["outputs"]["ptc_count"]
-    fan_count = project["outputs"]["fan_count"]
-    pwm_bits = project["outputs"]["pwm_bits"]
-    target_frequency_hz = project["outputs"]["pwm_frequency_hz"]
-    temperature_count = project["temperature"]["value_count"]
-    total_channels = ptc_count + fan_count
-    phase_count = 1 << pwm_bits
-    ideal_slot = project["device"]["clock_hz"] / (target_frequency_hz * total_channels * phase_count)
-    pwm_slot_clks = int(round(ideal_slot))
-    pwm_period_clks = pwm_slot_clks * total_channels * phase_count
+    outputs = project["outputs"]
+    temperature = project["temperature"]
+    watchdog = project["watchdog"]
+    total_channels = outputs["ptc_count"] + outputs["fan_count"]
+    pwm_period_clks = outputs["pwm_slot_clks"] * total_channels * outputs["pwm_phase_count"]
     actual_frequency_hz = project["device"]["clock_hz"] / pwm_period_clks
-    frequency_error_percent = abs(actual_frequency_hz - target_frequency_hz) / target_frequency_hz * 100.0
+    frequency_error_percent = abs(actual_frequency_hz - outputs["pwm_frequency_hz"]) / outputs["pwm_frequency_hz"] * 100.0
     return {
         "project_id": project["project_id"],
         "profile": project["profile"],
         "uart_clks_per_bit": project["uart"]["clks_per_bit"],
-        "pwm_bits": pwm_bits,
-        "pwm_phase_count": phase_count,
-        "pwm_frequency_hz": target_frequency_hz,
-        "pwm_slot_clks": pwm_slot_clks,
+        "pwm_bits": outputs["pwm_bits"],
+        "pwm_internal_width": outputs["pwm_internal_width"],
+        "pwm_max_duty": outputs["pwm_max_duty"],
+        "pwm_phase_count": outputs["pwm_phase_count"],
+        "pwm_frequency_hz": outputs["pwm_frequency_hz"],
+        "pwm_slot_clks": outputs["pwm_slot_clks"],
         "pwm_period_clks": pwm_period_clks,
         "pwm_period_seconds": round(pwm_period_clks / project["device"]["clock_hz"], 9),
         "actual_frequency_hz": round(actual_frequency_hz, 9),
         "frequency_error_percent": round(frequency_error_percent, 9),
-        "ptc_default": project["outputs"]["ptc_default"],
-        "fan_default": project["outputs"]["fan_default"],
-        "ptc_polarity": project["outputs"]["ptc_polarity"],
-        "fan_polarity": project["outputs"]["fan_polarity"],
-        "fan_connector_active_level": project["outputs"]["fan_connector_active_level"],
-        "fan_board_inverts": project["outputs"]["fan_board_inverts"],
-        "set_all_payload_len": ptc_count + fan_count + 2,
-        "set_all_frame_len": ptc_count + fan_count + 8,
-        "temperature_payload_len": temperature_count,
-        "temperature_frame_len": temperature_count + 6,
-        "temperature_addresses": tuple(project["temperature"]["device_addresses"]),
+        "ptc_default": outputs["ptc_default"],
+        "fan_default": outputs["fan_default"],
+        "ptc_polarity": outputs["ptc_polarity"],
+        "fan_polarity": outputs["fan_polarity"],
+        "fan_connector_active_level": outputs["fan_connector_active_level"],
+        "fan_board_inverts": outputs["fan_board_inverts"],
+        "set_all_payload_len": project["protocol"]["set_all"]["payload_length"],
+        "set_all_frame_len": project["protocol"]["set_all"]["payload_length"] + 6,
+        "temperature_payload_len": temperature["value_count"],
+        "temperature_frame_len": temperature["value_count"] + 6,
+        "temperature_addresses": list(temperature["device_addresses"]),
+        "boot_targets": dict(outputs["boot_targets"]),
+        "watchdog_timeout_seconds": watchdog["timeout_seconds"],
+        "watchdog_tick_clks": watchdog["tick_clks"],
+        "watchdog_timeout_ticks": watchdog["timeout_ticks"],
+        "watchdog_target": dict(watchdog["target"]),
     }
 
 
@@ -135,11 +462,7 @@ def _render_params(project: Mapping[str, Any]) -> str:
     motors = project["motors"]
     temperature = project["temperature"]
     uart = project["uart"]
-    total_channels = outputs["ptc_count"] + outputs["fan_count"]
-    phase_count = 1 << outputs["pwm_bits"]
-    pwm_slot_clks = int(round(project["device"]["clock_hz"] / (
-        outputs["pwm_frequency_hz"] * total_channels * phase_count
-    )))
+    watchdog = project["watchdog"]
     lines = [
         "// Generated from project.json. Do not edit.",
         f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
@@ -147,11 +470,17 @@ def _render_params(project: Mapping[str, Any]) -> str:
         f"`define P4_UART_CLKS_PER_BIT {uart['clks_per_bit']}",
         f"`define P4_PTC_COUNT {outputs['ptc_count']}",
         f"`define P4_FAN_COUNT {outputs['fan_count']}",
+        f"`define P4_PWM_PROTOCOL_WIDTH {outputs['pwm_bits']}",
+        f"`define P4_PWM_INTERNAL_WIDTH {outputs['pwm_internal_width']}",
+        f"`define P4_PWM_MAX_DUTY {outputs['pwm_max_duty']}",
+        f"`define P4_PWM_PHASE_COUNT {outputs['pwm_phase_count']}",
         f"`define P4_PWM_FREQUENCY_HZ {outputs['pwm_frequency_hz']}",
-        f"`define P4_PWM_SLOT_CLKS {pwm_slot_clks}",
+        f"`define P4_PWM_SLOT_CLKS {outputs['pwm_slot_clks']}",
         f"`define P4_FIXED_MOTOR_STEPS {motors['fixed_steps']}",
+        f"`define P4_MOTOR_STEP_RATE_HZ {motors['step_rate_hz']}",
         f"`define P4_MOTOR_STEP_HALF_CYCLES {motors['step_half_cycles']}",
         f"`define P4_MOTOR_DIR_SETUP_CYCLES {motors['dir_setup_cycles']}",
+        f"`define P4_MOTOR_HEARTBEAT_COMMAND 2'd{motors['heartbeat_value']}",
         f"`define P4_TEMPERATURE_COUNT {temperature['value_count']}",
         f"`define P4_TEMPERATURE_COUNT_BYTE 8'h{temperature['value_count']:02X}",
         f"`define P4_TEMP_MAX_CELSIUS {temperature['maximum_celsius']}",
@@ -159,6 +488,12 @@ def _render_params(project: Mapping[str, Any]) -> str:
         f"`define P4_FAN_ACTIVE_HIGH {1 if outputs['fan_polarity'] == 'active_high' else 0}",
         f"`define P4_PTC_DEFAULT_TARGET 8'h{outputs['ptc_default']:02X}",
         f"`define P4_FAN_DEFAULT_TARGET 8'h{outputs['fan_default']:02X}",
+        f"`define P4_WATCHDOG_TIMEOUT_SECONDS {watchdog['timeout_seconds']}",
+        f"`define P4_WATCHDOG_TICK_US {watchdog['tick_us']}",
+        f"`define P4_WATCHDOG_TICK_CLKS {watchdog['tick_clks']}",
+        f"`define P4_WATCHDOG_TIMEOUT_TICKS {watchdog['timeout_ticks']}",
+        f"`define P4_WATCHDOG_PTC_TARGET 8'h{watchdog['target']['ptc']:02X}",
+        f"`define P4_WATCHDOG_FAN_TARGET 8'h{watchdog['target']['fan']:02X}",
     ]
     lines.extend(
         f"`define P4_TEMP_DEVICE_ADDR_{index} 7'h{address:02X}"
@@ -172,33 +507,60 @@ def _render_params(project: Mapping[str, Any]) -> str:
     return "\n".join(lines)
 
 
+def render_adc_text(project: Mapping[str, Any]) -> str:
+    lines = [
+        "# Generated from project.json. Do not edit.",
+        "# Active interface only; reserved board loads are intentionally absent.",
+    ]
+    active_interface = list(render_adc(project))
+    for signal, ball in active_interface:
+        lines.append(f"set_pin_assignment {{ {signal} }} {{ LOCATION = {ball}; IOSTANDARD = LVCMOS33; PULLTYPE = NONE; }}")
+    return "\n".join(lines) + "\n"
+
+
 def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
     project = load_project(project_path)
-    temperature_count = project["temperature"]["value_count"]
     output = Path(output_root) / "generated"
     output.mkdir(parents=True, exist_ok=True)
-    (output / f"{project['project_id'].replace('-', '_')}_params.vh").write_text(_render_params(project), encoding="ascii", newline="\n")
+    (output / f"{project['project_id'].replace('-', '_')}_params.vh").write_text(
+        _render_params(project), encoding="ascii", newline="\n"
+    )
     summary = project_summary(project_path)
     contract = {
         "schema": "prod2u-simple-host-contract-v1",
         "project_id": project["project_id"],
         "uart": project["uart"],
+        "protocol": project["protocol"],
         "commands": {
-            "set_all": {"type": "0x01", "payload_length": summary["set_all_payload_len"], "response": "none"},
+            "set_all": {
+                "type": "0x01",
+                "payload_length": summary["set_all_payload_len"],
+                "response": "none",
+                "duty_range": [0, 100],
+                "motor_values": [0, 1, 2],
+                "heartbeat": [0, 0],
+            },
             "get_temperature": {"type": "0x02", "payload_length": 0, "response": "TEMPERATURE_DATA"},
-            "temperature_data": {"type": "0x82", "payload_length": summary["temperature_payload_len"], "frame_length": summary["temperature_frame_len"]},
+            "temperature_data": {
+                "type": "0x82",
+                "payload_length": summary["temperature_payload_len"],
+                "frame_length": summary["temperature_frame_len"],
+            },
         },
-        "crc": project["protocol"]["crc"],
+        "outputs": project["outputs"],
         "motors": project["motors"],
+        "limits": project["limits"],
         "temperature": project["temperature"],
+        "watchdog": project["watchdog"],
     }
     _write_json(output / "host-contract.json", contract)
     _write_json(output / "project-summary.json", summary)
     _write_json(
         output / "golden-vectors.json",
         {
+            "set_all": _frame_hex(0x01, bytes(range(8)) + bytes((10, 20, 30, 40, 1, 2))),
             "get_temperature": _frame_hex(0x02, b""),
-            "all_invalid_temperature": _frame_hex(0x82, bytes([0xFF] * temperature_count)),
+            "all_invalid_temperature": _frame_hex(0x82, bytes([0xFF] * project["temperature"]["value_count"])),
         },
     )
     _write_json(
@@ -208,8 +570,21 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
             "project_id": project["project_id"],
             "sources": list(ACTIVE_SOURCE_PATHS),
             "generated_from": "project.json",
+            "contract": {
+                "uart": project["uart"],
+                "protocol": project["protocol"],
+                "set_all_payload_length": summary["set_all_payload_len"],
+                "temperature_frame_length": summary["temperature_frame_len"],
+            },
+            "active_interface": [
+                {"signal": signal, "ball": ball}
+                for signal, ball in render_adc(project)
+            ],
         },
     )
+    (output / f"{project['project_id'].replace('-', '_')}.adc").write_text(
+        render_adc_text(project), encoding="ascii", newline="\n"
+    )
     return summary
 
 

+ 55 - 22
tools/prod2u_simple_protocol.py

@@ -1,24 +1,40 @@
 #!/usr/bin/env python3
-"""Reference model for the frozen 115200 Prod2U frame contract."""
+"""Reference model for the frozen Prod2U door-temperature frame contract."""
 
 from __future__ import annotations
 
 from dataclasses import dataclass
 from enum import IntEnum
+import json
+from pathlib import Path
 from typing import Iterable, Sequence
 
 
-FRAME_HEADER = b"\xA5\x5A"
-PTC_COUNT = 24
-FAN_COUNT = 4
-TEMPERATURE_COUNT = 27
-SET_ALL_PAYLOAD_LENGTH = PTC_COUNT + FAN_COUNT + 2
+_PROJECT_PATH = Path(__file__).resolve().parents[1] / "projects" / "prod2u-door-temp" / "project.json"
+_PROJECT = json.loads(_PROJECT_PATH.read_text(encoding="utf-8"))
+_OUTPUTS = _PROJECT["outputs"]
+_PROTOCOL = _PROJECT["protocol"]
+_SET_ALL = _PROTOCOL["set_all"]
+_CRC = _PROTOCOL["crc"]
+_COMMANDS = _PROTOCOL["commands"]
+
+FRAME_HEADER = bytes.fromhex(_PROTOCOL["header_hex"])
+PTC_COUNT = len(_OUTPUTS["ptc_channels"])
+FAN_COUNT = len(_OUTPUTS["fan_channels"])
+TEMPERATURE_COUNT = _PROJECT["temperature"]["value_count"]
+SET_ALL_PAYLOAD_LENGTH = _SET_ALL["payload_length"]
+DUTY_MIN = _SET_ALL["duty_min"]
+DUTY_MAX = _SET_ALL["duty_max"]
+MOTOR_COMMANDS = tuple(_SET_ALL["motor_values"])
+HEARTBEAT_MOTOR_COMMAND = _SET_ALL["heartbeat"][0]
+CRC_POLYNOMIAL = _CRC["polynomial"]
+CRC_INITIAL = _CRC["initial"]
 
 
 class FrameType(IntEnum):
-    SET_ALL = 0x01
-    GET_TEMPERATURE = 0x02
-    TEMPERATURE_DATA = 0x82
+    SET_ALL = _COMMANDS["set_all"]
+    GET_TEMPERATURE = _COMMANDS["get_temperature"]
+    TEMPERATURE_DATA = _COMMANDS["temperature_data"]
 
 
 class ProtocolError(ValueError):
@@ -32,11 +48,11 @@ class Frame:
 
 
 def crc16_ccitt_false(data: bytes | bytearray | Iterable[int]) -> int:
-    crc = 0xFFFF
+    crc = CRC_INITIAL
     for value in data:
         crc ^= (int(value) & 0xFF) << 8
         for _ in range(8):
-            crc = ((crc << 1) ^ 0x1021) & 0xFFFF if crc & 0x8000 else (crc << 1) & 0xFFFF
+            crc = ((crc << 1) ^ CRC_POLYNOMIAL) & 0xFFFF if crc & 0x8000 else (crc << 1) & 0xFFFF
     return crc
 
 
@@ -87,19 +103,36 @@ def decode_frame(raw: bytes | bytearray) -> Frame:
     return Frame(kind, payload)
 
 
-def _checked_bytes(values: Iterable[int], count: int, name: str) -> bytes:
-    body = bytes(values)
-    if len(body) != count:
+def _checked_duty_bytes(values: Iterable[int], count: int, name: str) -> bytes:
+    items = tuple(values)
+    if len(items) != count:
         raise ValueError(f"{name} must contain {count} bytes")
-    return body
+    if any(not isinstance(value, int) or not DUTY_MIN <= value <= DUTY_MAX for value in items):
+        raise ValueError(f"{name} values must be in the range {DUTY_MIN}..{DUTY_MAX}")
+    return bytes(items)
+
+
+def _checked_temperature_bytes(values: Iterable[int]) -> bytes:
+    items = tuple(values)
+    if len(items) != TEMPERATURE_COUNT:
+        raise ValueError(f"temperature must contain {TEMPERATURE_COUNT} bytes")
+    if any(not isinstance(value, int) or not 0 <= value <= 0xFF for value in items):
+        raise ValueError("temperature values must be in the range 0..255")
+    return bytes(items)
+
+
+def _checked_motor_command(value: int, name: str) -> int:
+    if value not in MOTOR_COMMANDS:
+        raise ValueError(f"{name} must be one of {MOTOR_COMMANDS}")
+    return value
 
 
-def build_set_all(ptc: Iterable[int], fan: Iterable[int], inlet_dir: int, outlet_dir: int) -> bytes:
-    if inlet_dir not in (0, 1) or outlet_dir not in (0, 1):
-        raise ValueError("motor directions must be 0 or 1")
-    payload = _checked_bytes(ptc, PTC_COUNT, "ptc")
-    payload += _checked_bytes(fan, FAN_COUNT, "fan")
-    return encode_frame(FrameType.SET_ALL, payload + bytes((inlet_dir, outlet_dir)))
+def build_set_all(ptc: Iterable[int], fan: Iterable[int], x_command: int, y_command: int) -> bytes:
+    x_command = _checked_motor_command(x_command, "x motor command")
+    y_command = _checked_motor_command(y_command, "y motor command")
+    payload = _checked_duty_bytes(ptc, PTC_COUNT, "ptc")
+    payload += _checked_duty_bytes(fan, FAN_COUNT, "fan")
+    return encode_frame(FrameType.SET_ALL, payload + bytes((x_command, y_command)))
 
 
 def build_get_temperature() -> bytes:
@@ -107,7 +140,7 @@ def build_get_temperature() -> bytes:
 
 
 def build_temperature_data(values: Iterable[int]) -> bytes:
-    return encode_frame(FrameType.TEMPERATURE_DATA, _checked_bytes(values, TEMPERATURE_COUNT, "temperature"))
+    return encode_frame(FrameType.TEMPERATURE_DATA, _checked_temperature_bytes(values))
 
 
 def decode_temperature_data(frame: Frame) -> tuple[int, ...]: