Ver Fonte

product: derive door temperature RTL contracts

Codex Resource Selftest há 4 meses atrás
pai
commit
2792b2ef5b

+ 2 - 2
projects/prod2u-door-temp/project.json

@@ -103,7 +103,7 @@
     "temp_scl": "M8",
     "temp_scl": "M8",
     "temp_sda": "N9",
     "temp_sda": "N9",
     "ptc_pwm": ["G16", "F16", "N1", "M1", "R16", "P16", "P9", "T9"],
     "ptc_pwm": ["G16", "F16", "N1", "M1", "R16", "P16", "P9", "T9"],
-    "fan_pwm": ["C4", "B5", "B1", "A14"],
+    "fan_pwm": ["B1", "C4", "B5", "A14"],
     "motor_en_n": "A10",
     "motor_en_n": "A10",
     "x_step": "C11",
     "x_step": "C11",
     "x_dir": "B12",
     "x_dir": "B12",
@@ -112,7 +112,7 @@
     "x_limit_raw": "B9",
     "x_limit_raw": "B9",
     "y_limit_raw": "A11"
     "y_limit_raw": "A11"
   },
   },
-  "resources": {
+  "resource_policy": {
     "target_ram_blocks": 1,
     "target_ram_blocks": 1,
     "request_ram_blocks": 1,
     "request_ram_blocks": 1,
     "temperature_ram_blocks": 1,
     "temperature_ram_blocks": 1,

+ 10 - 10
schemas/project.schema.json

@@ -12,7 +12,7 @@
                      "limits",
                      "limits",
                      "temperature",
                      "temperature",
                      "pins",
                      "pins",
-                     "resources",
+                     "resource_policy",
                      "protocol",
                      "protocol",
                      "timeouts",
                      "timeouts",
                      "watchdog"
                      "watchdog"
@@ -128,16 +128,16 @@
                                                                         },
                                                                         },
                                                           "ptc_channels":  {
                                                           "ptc_channels":  {
                                                                                "type":  "array",
                                                                                "type":  "array",
-                                                                               "minItems":  8,
-                                                                               "maxItems":  8,
+                                                                               "minItems":  1,
+                                                                               "maxItems":  64,
                                                                                "items":  {
                                                                                "items":  {
                                                                                              "$ref":  "#/$defs/channel"
                                                                                              "$ref":  "#/$defs/channel"
                                                                                          }
                                                                                          }
                                                                            },
                                                                            },
                                                           "fan_channels":  {
                                                           "fan_channels":  {
                                                                                "type":  "array",
                                                                                "type":  "array",
-                                                                               "minItems":  4,
-                                                                               "maxItems":  4,
+                                                                               "minItems":  1,
+                                                                               "maxItems":  64,
                                                                                "items":  {
                                                                                "items":  {
                                                                                              "$ref":  "#/$defs/channel"
                                                                                              "$ref":  "#/$defs/channel"
                                                                                          }
                                                                                          }
@@ -427,13 +427,13 @@
                                                                     },
                                                                     },
                                                        "ptc_pwm":  {
                                                        "ptc_pwm":  {
                                                                        "type":  "array",
                                                                        "type":  "array",
-                                                                       "minItems":  8,
-                                                                       "maxItems":  8
+                                                                       "minItems":  1,
+                                                                       "maxItems": 64
                                                                    },
                                                                    },
                                                        "fan_pwm":  {
                                                        "fan_pwm":  {
                                                                        "type":  "array",
                                                                        "type":  "array",
-                                                                       "minItems":  4,
-                                                                       "maxItems":  4
+                                                                       "minItems": 1,
+                                                                       "maxItems": 64
                                                                    },
                                                                    },
                                                        "motor_en_n":  {
                                                        "motor_en_n":  {
                                                                           "type":  "string"
                                                                           "type":  "string"
@@ -459,7 +459,7 @@
                                                    },
                                                    },
                                     "additionalProperties":  false
                                     "additionalProperties":  false
                                 },
                                 },
-                       "resources":  {
+                       "resource_policy":  {
                                          "type":  "object",
                                          "type":  "object",
                                          "required":  [
                                          "required":  [
                                                           "target_ram_blocks",
                                                           "target_ram_blocks",

+ 1 - 1
src/common/frame_rx.v

@@ -1,7 +1,7 @@
 `timescale 1ns/1ps
 `timescale 1ns/1ps
 
 
 module frame_rx #(
 module frame_rx #(
-    parameter integer MAX_PAYLOAD = 30,
+    parameter integer MAX_PAYLOAD = 14,
     parameter integer INTER_BYTE_TIMEOUT_CYCLES = 250000
     parameter integer INTER_BYTE_TIMEOUT_CYCLES = 250000
 ) (
 ) (
     input  wire       clk,
     input  wire       clk,

+ 2 - 1
src/common/payload_ram.v

@@ -1,7 +1,8 @@
 `timescale 1ns/1ps
 `timescale 1ns/1ps
 
 
 module payload_ram #(
 module payload_ram #(
-    parameter integer DEPTH = 30,
+    // The active Prod2U contract uses a 14-byte SET_ALL payload.
+    parameter integer DEPTH = 14,
     parameter integer ADDR_WIDTH = 8
     parameter integer ADDR_WIDTH = 8
 ) (
 ) (
     input  wire                  clk,
     input  wire                  clk,

+ 3 - 0
src/generated/prod2u_door_temp_params.vh

@@ -12,13 +12,16 @@
 `define P4_PWM_FREQUENCY_HZ 20
 `define P4_PWM_FREQUENCY_HZ 20
 `define P4_PWM_SLOT_CLKS 1042
 `define P4_PWM_SLOT_CLKS 1042
 `define P4_SET_ALL_PAYLOAD_LENGTH 14
 `define P4_SET_ALL_PAYLOAD_LENGTH 14
+`define P4_FRAME_INTER_BYTE_TIMEOUT_CYCLES 250000
 `define P4_FIXED_MOTOR_STEPS 450
 `define P4_FIXED_MOTOR_STEPS 450
 `define P4_MOTOR_STEP_RATE_HZ 1000
 `define P4_MOTOR_STEP_RATE_HZ 1000
 `define P4_MOTOR_STEP_HALF_CYCLES 12500
 `define P4_MOTOR_STEP_HALF_CYCLES 12500
 `define P4_MOTOR_DIR_SETUP_CYCLES 25000
 `define P4_MOTOR_DIR_SETUP_CYCLES 25000
+`define P4_MOTOR_DIR_SETUP_TICKS 2
 `define P4_MOTOR_HEARTBEAT_COMMAND 2'd0
 `define P4_MOTOR_HEARTBEAT_COMMAND 2'd0
 `define P4_TEMPERATURE_COUNT 27
 `define P4_TEMPERATURE_COUNT 27
 `define P4_TEMPERATURE_COUNT_BYTE 8'h1B
 `define P4_TEMPERATURE_COUNT_BYTE 8'h1B
+`define P4_TEMPERATURE_FRAME_LENGTH 33
 `define P4_TEMP_MAX_CELSIUS 150
 `define P4_TEMP_MAX_CELSIUS 150
 `define P4_PTC_ACTIVE_HIGH 1
 `define P4_PTC_ACTIVE_HIGH 1
 `define P4_FAN_ACTIVE_HIGH 0
 `define P4_FAN_ACTIVE_HIGH 0

+ 6 - 5
src/modules/door_motor_engine.v

@@ -17,8 +17,9 @@ module door_motor_engine #(
     output reg  [1:0] dir
     output reg  [1:0] dir
 );
 );
     localparam integer SETUP_BITS = (DIR_SETUP_TICKS <= 1) ? 1 : $clog2(DIR_SETUP_TICKS + 1);
     localparam integer SETUP_BITS = (DIR_SETUP_TICKS <= 1) ? 1 : $clog2(DIR_SETUP_TICKS + 1);
+    localparam integer STEP_COUNT_WIDTH = (FIXED_STEPS <= 1) ? 1 : $clog2(FIXED_STEPS + 1);
     reg [SETUP_BITS-1:0] setup_count;
     reg [SETUP_BITS-1:0] setup_count;
-    reg [31:0] rising_edges;
+    reg [STEP_COUNT_WIDTH-1:0] rising_edges;
     reg [1:0] active_reg;
     reg [1:0] active_reg;
 
 
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
@@ -28,7 +29,7 @@ module door_motor_engine #(
             step <= 2'b00;
             step <= 2'b00;
             dir <= 2'b00;
             dir <= 2'b00;
             setup_count <= {SETUP_BITS{1'b0}};
             setup_count <= {SETUP_BITS{1'b0}};
-            rising_edges <= 32'd0;
+            rising_edges <= {STEP_COUNT_WIDTH{1'b0}};
             active_reg <= 2'b00;
             active_reg <= 2'b00;
         end else begin
         end else begin
             done <= 1'b0;
             done <= 1'b0;
@@ -37,7 +38,7 @@ module door_motor_engine #(
                 step <= 2'b00;
                 step <= 2'b00;
                 active_reg <= 2'b00;
                 active_reg <= 2'b00;
                 setup_count <= {SETUP_BITS{1'b0}};
                 setup_count <= {SETUP_BITS{1'b0}};
-                rising_edges <= 32'd0;
+                rising_edges <= {STEP_COUNT_WIDTH{1'b0}};
                 done <= 1'b1;
                 done <= 1'b1;
             end else if (!busy) begin
             end else if (!busy) begin
                 step <= 2'b00;
                 step <= 2'b00;
@@ -45,7 +46,7 @@ module door_motor_engine #(
                     dir <= dir_mask;
                     dir <= dir_mask;
                     active_reg <= active_mask;
                     active_reg <= active_mask;
                     setup_count <= {SETUP_BITS{1'b0}};
                     setup_count <= {SETUP_BITS{1'b0}};
-                    rising_edges <= 32'd0;
+                    rising_edges <= {STEP_COUNT_WIDTH{1'b0}};
                     if (active_mask == 2'b00) begin
                     if (active_mask == 2'b00) begin
                         done <= 1'b1;
                         done <= 1'b1;
                         busy <= 1'b0;
                         busy <= 1'b0;
@@ -62,7 +63,7 @@ module door_motor_engine #(
                 end else begin
                 end else begin
                     step <= 2'b00;
                     step <= 2'b00;
                     if (rising_edges + 1 >= FIXED_STEPS) begin
                     if (rising_edges + 1 >= FIXED_STEPS) begin
-                        rising_edges <= 32'd0;
+                        rising_edges <= {STEP_COUNT_WIDTH{1'b0}};
                         active_reg <= 2'b00;
                         active_reg <= 2'b00;
                         busy <= 1'b0;
                         busy <= 1'b0;
                         done <= 1'b1;
                         done <= 1'b1;

+ 6 - 1
src/modules/pwm_scheduler.v

@@ -20,6 +20,7 @@ module pwm_scheduler #(
     localparam integer SLOT_BITS = (PWM_SLOT_CLKS <= 1) ? 1 : $clog2(PWM_SLOT_CLKS);
     localparam integer SLOT_BITS = (PWM_SLOT_CLKS <= 1) ? 1 : $clog2(PWM_SLOT_CLKS);
 
 
     reg [CHANNEL_BITS-1:0] current_channel;
     reg [CHANNEL_BITS-1:0] current_channel;
+    reg [CHANNEL_BITS-1:0] data_channel;
     reg [PHASE_BITS-1:0] phase;
     reg [PHASE_BITS-1:0] phase;
     reg [SLOT_BITS-1:0] slot_counter;
     reg [SLOT_BITS-1:0] slot_counter;
     wire [PWM_DUTY_WIDTH-1:0] selected_duty = target_rd_data[PWM_DUTY_WIDTH-1:0];
     wire [PWM_DUTY_WIDTH-1:0] selected_duty = target_rd_data[PWM_DUTY_WIDTH-1:0];
@@ -30,6 +31,7 @@ module pwm_scheduler #(
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
         if (!rst_n) begin
             current_channel <= {CHANNEL_BITS{1'b0}};
             current_channel <= {CHANNEL_BITS{1'b0}};
+            data_channel <= {CHANNEL_BITS{1'b0}};
             phase <= {PHASE_BITS{1'b0}};
             phase <= {PHASE_BITS{1'b0}};
             slot_counter <= {SLOT_BITS{1'b0}};
             slot_counter <= {SLOT_BITS{1'b0}};
             logical_pwm_on <= {CHANNEL_COUNT{1'b0}};
             logical_pwm_on <= {CHANNEL_COUNT{1'b0}};
@@ -37,7 +39,10 @@ module pwm_scheduler #(
             slot_counter <= slot_counter + 1'b1;
             slot_counter <= slot_counter + 1'b1;
         end else begin
         end else begin
             slot_counter <= {SLOT_BITS{1'b0}};
             slot_counter <= {SLOT_BITS{1'b0}};
-            logical_pwm_on[current_channel] <= logical_on;
+            // target_rd_data belongs to the address requested during the
+            // preceding slot because output_target_ram has one-cycle latency.
+            logical_pwm_on[data_channel] <= logical_on;
+            data_channel <= current_channel;
             if (current_channel == CHANNEL_COUNT - 1) begin
             if (current_channel == CHANNEL_COUNT - 1) begin
                 current_channel <= {CHANNEL_BITS{1'b0}};
                 current_channel <= {CHANNEL_BITS{1'b0}};
                 if (phase == PWM_PHASE_COUNT - 1)
                 if (phase == PWM_PHASE_COUNT - 1)

+ 3 - 2
src/project/project_adapter.v

@@ -2,7 +2,8 @@
 
 
 module project_adapter #(
 module project_adapter #(
     parameter integer PTC_COUNT = 8,
     parameter integer PTC_COUNT = 8,
-    parameter integer FAN_COUNT = 4
+    parameter integer FAN_COUNT = 4,
+    parameter integer SET_ALL_PAYLOAD_LENGTH = 14
 ) (
 ) (
     input  wire       clk,
     input  wire       clk,
     input  wire       rst_n,
     input  wire       rst_n,
@@ -30,7 +31,7 @@ module project_adapter #(
     command_controller #(
     command_controller #(
         .PTC_COUNT(PTC_COUNT),
         .PTC_COUNT(PTC_COUNT),
         .FAN_COUNT(FAN_COUNT),
         .FAN_COUNT(FAN_COUNT),
-        .SET_ALL_PAYLOAD_LENGTH(14)
+        .SET_ALL_PAYLOAD_LENGTH(SET_ALL_PAYLOAD_LENGTH)
     ) controller (
     ) controller (
         .clk(clk), .rst_n(rst_n),
         .clk(clk), .rst_n(rst_n),
         .frame_valid(frame_valid), .frame_ready(frame_ready),
         .frame_valid(frame_valid), .frame_ready(frame_ready),

+ 10 - 8
src/top/prod2u_p4_normal_v3_top.v

@@ -110,7 +110,8 @@ module prod2u_p4_normal_v3_top (
         .framing_error(uart_framing_error)
         .framing_error(uart_framing_error)
     );
     );
 
 
-    frame_rx #(.MAX_PAYLOAD(14), .INTER_BYTE_TIMEOUT_CYCLES(250000)) u_frame_rx (
+    frame_rx #(.MAX_PAYLOAD(`P4_SET_ALL_PAYLOAD_LENGTH),
+        .INTER_BYTE_TIMEOUT_CYCLES(`P4_FRAME_INTER_BYTE_TIMEOUT_CYCLES)) u_frame_rx (
         .clk(sys_clk), .rst_n(sys_rst_n),
         .clk(sys_clk), .rst_n(sys_rst_n),
         .byte_valid(uart_rx_valid), .byte_data(uart_rx_data),
         .byte_valid(uart_rx_valid), .byte_data(uart_rx_data),
         .accept_enable(frame_accept_enable), .frame_valid(frame_valid),
         .accept_enable(frame_accept_enable), .frame_valid(frame_valid),
@@ -120,13 +121,14 @@ module prod2u_p4_normal_v3_top (
         .payload_wr_data(payload_wr_data)
         .payload_wr_data(payload_wr_data)
     );
     );
 
 
-    payload_ram #(.DEPTH(14), .ADDR_WIDTH(8)) u_payload_ram (
+    payload_ram #(.DEPTH(`P4_SET_ALL_PAYLOAD_LENGTH), .ADDR_WIDTH(8)) u_payload_ram (
         .clk(sys_clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr),
         .clk(sys_clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr),
         .wr_data(payload_wr_data), .rd_addr(payload_read_addr),
         .wr_data(payload_wr_data), .rd_addr(payload_read_addr),
         .rd_data(payload_read_data)
         .rd_data(payload_read_data)
     );
     );
 
 
-    project_adapter #(.PTC_COUNT(8), .FAN_COUNT(4)) u_project_adapter (
+    project_adapter #(.PTC_COUNT(`P4_PTC_COUNT), .FAN_COUNT(`P4_FAN_COUNT),
+        .SET_ALL_PAYLOAD_LENGTH(`P4_SET_ALL_PAYLOAD_LENGTH)) u_project_adapter (
         .clk(sys_clk), .rst_n(sys_rst_n), .frame_valid(frame_valid),
         .clk(sys_clk), .rst_n(sys_rst_n), .frame_valid(frame_valid),
         .frame_ready(frame_ready), .frame_accept_enable(frame_accept_enable),
         .frame_ready(frame_ready), .frame_accept_enable(frame_accept_enable),
         .frame_type(frame_type), .frame_length(frame_length),
         .frame_type(frame_type), .frame_length(frame_length),
@@ -141,7 +143,7 @@ module prod2u_p4_normal_v3_top (
     );
     );
 
 
     output_target_ram #(
     output_target_ram #(
-        .DEPTH(12), .PTC_COUNT(8),
+        .DEPTH(`P4_OUTPUT_CHANNEL_COUNT), .PTC_COUNT(`P4_PTC_COUNT),
         .BOOT_PTC_TARGET(`P4_PTC_DEFAULT_TARGET),
         .BOOT_PTC_TARGET(`P4_PTC_DEFAULT_TARGET),
         .BOOT_FAN_TARGET(`P4_FAN_DEFAULT_TARGET),
         .BOOT_FAN_TARGET(`P4_FAN_DEFAULT_TARGET),
         .WATCHDOG_PTC_TARGET(`P4_WATCHDOG_PTC_TARGET),
         .WATCHDOG_PTC_TARGET(`P4_WATCHDOG_PTC_TARGET),
@@ -154,7 +156,7 @@ module prod2u_p4_normal_v3_top (
     );
     );
 
 
     pwm_scheduler #(
     pwm_scheduler #(
-        .CHANNEL_COUNT(12), .PWM_BITS(`P4_PWM_PROTOCOL_WIDTH),
+        .CHANNEL_COUNT(`P4_OUTPUT_CHANNEL_COUNT), .PWM_BITS(`P4_PWM_PROTOCOL_WIDTH),
         .PWM_DUTY_WIDTH(`P4_PWM_INTERNAL_WIDTH),
         .PWM_DUTY_WIDTH(`P4_PWM_INTERNAL_WIDTH),
         .PWM_PHASE_COUNT(`P4_PWM_PHASE_COUNT),
         .PWM_PHASE_COUNT(`P4_PWM_PHASE_COUNT),
         .PWM_SLOT_CLKS(`P4_PWM_SLOT_CLKS)
         .PWM_SLOT_CLKS(`P4_PWM_SLOT_CLKS)
@@ -164,7 +166,7 @@ module prod2u_p4_normal_v3_top (
     );
     );
 
 
     door_motor_engine #(
     door_motor_engine #(
-        .FIXED_STEPS(`P4_FIXED_MOTOR_STEPS), .DIR_SETUP_TICKS(2)
+        .FIXED_STEPS(`P4_FIXED_MOTOR_STEPS), .DIR_SETUP_TICKS(`P4_MOTOR_DIR_SETUP_TICKS)
     ) u_motor_engine (
     ) u_motor_engine (
         .clk(sys_clk), .rst_n(sys_rst_n), .start(motor_start),
         .clk(sys_clk), .rst_n(sys_rst_n), .start(motor_start),
         .active_mask(motor_active_mask), .dir_mask(motor_dir_mask),
         .active_mask(motor_active_mask), .dir_mask(motor_dir_mask),
@@ -192,7 +194,7 @@ module prod2u_p4_normal_v3_top (
         .wr_data(temperature_wr_data)
         .wr_data(temperature_wr_data)
     );
     );
 
 
-    temperature_ram #(.DEPTH(27)) u_temperature_ram (
+    temperature_ram #(.DEPTH(`P4_TEMPERATURE_COUNT)) u_temperature_ram (
         .clk(sys_clk), .wr_en(temperature_wr_en), .wr_addr(temperature_wr_addr),
         .clk(sys_clk), .wr_en(temperature_wr_en), .wr_addr(temperature_wr_addr),
         .wr_data(temperature_wr_data), .rd_addr(temperature_rd_addr),
         .wr_data(temperature_wr_data), .rd_addr(temperature_rd_addr),
         .rd_data(temperature_rd_data)
         .rd_data(temperature_rd_data)
@@ -210,7 +212,7 @@ module prod2u_p4_normal_v3_top (
 
 
     frame_tx u_frame_tx (
     frame_tx u_frame_tx (
         .clk(sys_clk), .rst_n(sys_rst_n), .start(tx_start), .frame_type(8'h82),
         .clk(sys_clk), .rst_n(sys_rst_n), .start(tx_start), .frame_type(8'h82),
-        .payload_length(8'h1B), .busy(frame_tx_busy),
+        .payload_length(`P4_TEMPERATURE_COUNT_BYTE), .busy(frame_tx_busy),
         .byte_valid(frame_tx_byte_valid), .byte_data(frame_tx_byte_data),
         .byte_valid(frame_tx_byte_valid), .byte_data(frame_tx_byte_data),
         .byte_ready(frame_tx_byte_ready), .payload_addr(frame_tx_payload_addr),
         .byte_ready(frame_tx_byte_ready), .payload_addr(frame_tx_payload_addr),
         .payload_data(temperature_rd_data), .done(tx_done)
         .payload_data(temperature_rd_data), .done(tx_done)

+ 82 - 81
tools/generate_project.py

@@ -9,8 +9,11 @@ import re
 from pathlib import Path
 from pathlib import Path
 from typing import Any, Mapping
 from typing import Any, Mapping
 
 
+from jsonschema import Draft202012Validator
+
 
 
 PROFILE = "prod2u-normal-multiproject-115200-v1"
 PROFILE = "prod2u-normal-multiproject-115200-v1"
+SCHEMA_PATH = Path(__file__).resolve().parents[1] / "schemas" / "project.schema.json"
 
 
 ACTIVE_SOURCE_PATHS = (
 ACTIVE_SOURCE_PATHS = (
     "src/generated/prod2u_door_temp_params.vh",
     "src/generated/prod2u_door_temp_params.vh",
@@ -35,25 +38,6 @@ ACTIVE_SOURCE_PATHS = (
     "src/top/prod2u_p4_normal_v3_top.v",
     "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 = {
 _TOP_LEVEL_KEYS = {
     "project_id",
     "project_id",
     "profile",
     "profile",
@@ -65,7 +49,7 @@ _TOP_LEVEL_KEYS = {
     "limits",
     "limits",
     "temperature",
     "temperature",
     "pins",
     "pins",
-    "resources",
+    "resource_policy",
     "protocol",
     "protocol",
     "timeouts",
     "timeouts",
     "watchdog",
     "watchdog",
@@ -114,36 +98,30 @@ def _validate_channel(channel: Any, index: int, kind: str) -> None:
     _require(re.fullmatch(r"[A-Z][0-9]+", str(item["ball"])) is not None, f"invalid {kind} ball 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}")
     _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)
     _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:
 def _validate_project(payload: Mapping[str, Any]) -> None:
     _keys(payload, _TOP_LEVEL_KEYS, "project")
     _keys(payload, _TOP_LEVEL_KEYS, "project")
     _require(re.fullmatch(r"[a-z0-9-]+", str(payload["project_id"])) is not None, "invalid project_id")
     _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["profile"], str) and payload["profile"], "invalid project profile")
     _require(isinstance(payload["display_name"], str) and payload["display_name"], "invalid display_name")
     _require(isinstance(payload["display_name"], str) and payload["display_name"], "invalid display_name")
 
 
     device = _object(payload["device"], "device")
     device = _object(payload["device"], "device")
     _keys(device, {"family", "part", "clock_hz", "clock_ball"}, "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")
+    _require(isinstance(device["family"], str) and device["family"], "invalid device family")
+    _require(isinstance(device["part"], str) and device["part"], "invalid device part")
+    _integer(device["clock_hz"], "device.clock_hz", minimum=1)
+    _require(re.fullmatch(r"[A-Z][0-9]+", str(device["clock_ball"])) is not None, "invalid clock ball")
 
 
     uart = _object(payload["uart"], "uart")
     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")
     _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")
+    _integer(uart["baud"], "uart.baud", minimum=1)
+    _integer(uart["data_bits"], "uart.data_bits", minimum=1)
+    _integer(uart["stop_bits"], "uart.stop_bits", minimum=1)
+    _integer(uart["clks_per_bit"], "uart.clks_per_bit", minimum=1)
+    _require(uart["parity"] in {"N", "E", "O"}, "invalid UART parity")
+    _require(isinstance(uart["flow_control"], str), "invalid UART flow control")
+    _integer(uart["inter_byte_timeout_ms"], "uart.inter_byte_timeout_ms", minimum=1)
 
 
     outputs = _object(payload["outputs"], "outputs")
     outputs = _object(payload["outputs"], "outputs")
     _keys(
     _keys(
@@ -170,20 +148,25 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
         },
         },
         "outputs",
         "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")
+    _integer(outputs["ptc_count"], "outputs.ptc_count", minimum=1)
+    _integer(outputs["fan_count"], "outputs.fan_count", minimum=1)
+    _require(outputs["ptc_count"] == len(outputs["ptc_channels"]), "PTC count/list mismatch")
+    _require(outputs["fan_count"] == len(outputs["fan_channels"]), "FAN count/list mismatch")
     for index, channel in enumerate(outputs["ptc_channels"]):
     for index, channel in enumerate(outputs["ptc_channels"]):
         _validate_channel(channel, index, "ptc")
         _validate_channel(channel, index, "ptc")
     for index, channel in enumerate(outputs["fan_channels"]):
     for index, channel in enumerate(outputs["fan_channels"]):
         _validate_channel(channel, index, "fan")
         _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")
+    _integer(outputs["pwm_bits"], "outputs.pwm_bits", minimum=1)
+    _integer(outputs["pwm_internal_width"], "outputs.pwm_internal_width", minimum=1)
+    _integer(outputs["pwm_max_duty"], "outputs.pwm_max_duty", minimum=0)
+    _require(outputs["pwm_max_duty"] < (1 << outputs["pwm_bits"]), "PWM maximum exceeds protocol width")
+    _integer(outputs["pwm_phase_count"], "outputs.pwm_phase_count", minimum=1)
+    _integer(outputs["pwm_slot_clks"], "outputs.pwm_slot_clks", minimum=1)
+    _number(outputs["pwm_frequency_hz"], "outputs.pwm_frequency_hz")
+    _number(outputs["pwm_actual_frequency_hz"], "outputs.pwm_actual_frequency_hz")
     _require(outputs["ptc_polarity"] == "active_high" and outputs["fan_polarity"] == "active_low", "PWM polarity 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(0 <= outputs["ptc_default"] <= outputs["pwm_max_duty"], "invalid PTC boot target")
+    _require(0 <= outputs["fan_default"] <= outputs["pwm_max_duty"], "invalid FAN boot target")
     _require(outputs["fan_connector_active_level"] == "high" and outputs["fan_board_inverts"] is True, "FAN board metadata 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")
     boot_targets = _object(outputs["boot_targets"], "outputs.boot_targets")
     _keys(boot_targets, {"ptc", "fan"}, "outputs.boot_targets")
     _keys(boot_targets, {"ptc", "fan"}, "outputs.boot_targets")
@@ -209,11 +192,17 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
         },
         },
         "motors",
         "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")
+    _integer(motors["count"], "motors.count", minimum=1)
+    _require(len(motors["order"]) == motors["count"] and all(isinstance(axis, str) and axis for axis in motors["order"]), "motor order mismatch")
+    _require(isinstance(motors["role"], str) and motors["role"], "invalid motor role")
+    _require(motors["execution"] in {"overlap", "serial"}, "invalid motor execution")
+    _integer(motors["busy_wait_ms"], "motors.busy_wait_ms", minimum=0)
+    _integer(motors["fixed_steps"], "motors.fixed_steps", minimum=1)
+    _integer(motors["step_rate_hz"], "motors.step_rate_hz", minimum=1)
+    _integer(motors["step_half_cycles"], "motors.step_half_cycles", minimum=1)
+    _integer(motors["dir_setup_cycles"], "motors.dir_setup_cycles", minimum=0)
+    _require(isinstance(motors["command_values"], list) and motors["command_values"], "invalid motor commands")
+    _require(motors["heartbeat_value"] in motors["command_values"], "motor heartbeat is not a command")
     mapping = _object(motors["mapping"], "motors.mapping")
     mapping = _object(motors["mapping"], "motors.mapping")
     _keys(mapping, {"x", "y"}, "motors.mapping")
     _keys(mapping, {"x", "y"}, "motors.mapping")
     for axis in ("x", "y"):
     for axis in ("x", "y"):
@@ -250,9 +239,14 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
         },
         },
         "temperature",
         "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")
+    _integer(temperature["value_count"], "temperature.value_count", minimum=1)
+    _require(temperature["value_count"] == len(temperature["device_addresses"]) * len(temperature["registers"]), "temperature count/list mismatch")
+    _require(all(isinstance(value, int) and 0 <= value < 128 for value in temperature["device_addresses"]), "invalid temperature address")
+    _require(all(isinstance(value, int) and 0 <= value <= 255 for value in temperature["registers"]), "invalid temperature register")
+    _require(isinstance(temperature["device"], str) and temperature["device"], "invalid temperature device")
+    _integer(temperature["invalid_value"], "temperature.invalid_value", minimum=0)
+    _require(temperature["invalid_value"] <= 255, "temperature.invalid_value exceeds byte")
+    _integer(temperature["maximum_celsius"], "temperature.maximum_celsius", minimum=0)
     conversion = _object(temperature["conversion"], "temperature.conversion")
     conversion = _object(temperature["conversion"], "temperature.conversion")
     _keys(conversion, {"profile", "raw_shift", "raw_width", "reject_sign_bit"}, "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")
     _require(conversion == {"profile": "ct7428-msb-integer", "raw_shift": 7, "raw_width": 9, "reject_sign_bit": True}, "temperature conversion mismatch")
@@ -281,8 +275,7 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
     _require(pins["temp_scl"] == temperature["scl_ball"] and pins["temp_sda"] == temperature["sda_ball"], "I2C 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(pins["ptc_pwm"] == [item["ball"] for item in outputs["ptc_channels"]], "PTC pin/list mismatch")
     _require(
     _require(
-        len(pins["fan_pwm"]) == outputs["fan_count"]
-        and set(pins["fan_pwm"]) == {item["ball"] for item in outputs["fan_channels"]},
+        pins["fan_pwm"] == [item["ball"] for item in outputs["fan_channels"]],
         "FAN pin/list mismatch",
         "FAN pin/list mismatch",
     )
     )
     _require(pins["motor_en_n"] == enable["ball"], "motor enable pin mismatch")
     _require(pins["motor_en_n"] == enable["ball"], "motor enable pin mismatch")
@@ -290,7 +283,7 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
     _require(pins["y_step"] == mapping["y"]["step_ball"] and pins["y_dir"] == mapping["y"]["dir_ball"], "Y 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")
     _require([pins["x_limit_raw"], pins["y_limit_raw"]] == [item["ball"] for item in limits["channels"]], "limit pin mismatch")
 
 
-    resources = _object(payload["resources"], "resources")
+    resources = _object(payload["resource_policy"], "resource_policy")
     _keys(
     _keys(
         resources,
         resources,
         {
         {
@@ -302,13 +295,14 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
             "shared_motor_executors",
             "shared_motor_executors",
             "shared_i2c_readers",
             "shared_i2c_readers",
         },
         },
-        "resources",
+        "resource_policy",
     )
     )
-    _require(resources["shared_pwm_comparators"] == 1 and resources["shared_motor_executors"] == 1 and resources["shared_i2c_readers"] == 1, "shared resource contract mismatch")
+    for key, value in resources.items():
+        _integer(value, f"resource_policy.{key}", minimum=0)
 
 
     protocol = _object(payload["protocol"], "protocol")
     protocol = _object(payload["protocol"], "protocol")
     _keys(protocol, {"header_hex", "crc", "commands", "set_all", "temperature_data"}, "protocol")
     _keys(protocol, {"header_hex", "crc", "commands", "set_all", "temperature_data"}, "protocol")
-    _require(protocol["header_hex"] == "A55A", "frame header mismatch")
+    _require(isinstance(protocol["header_hex"], str) and protocol["header_hex"], "frame header missing")
     crc = _object(protocol["crc"], "protocol.crc")
     crc = _object(protocol["crc"], "protocol.crc")
     _keys(crc, {"name", "polynomial", "initial", "reflect_input", "reflect_output", "xor_output", "coverage", "wire_order"}, "protocol.crc")
     _keys(crc, {"name", "polynomial", "initial", "reflect_input", "reflect_output", "xor_output", "coverage", "wire_order"}, "protocol.crc")
     _require(
     _require(
@@ -325,37 +319,33 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
         },
         },
         "CRC contract mismatch",
         "CRC contract mismatch",
     )
     )
-    _require(protocol["commands"] == {"set_all": 1, "get_temperature": 2, "temperature_data": 130}, "protocol type mismatch")
+    _require(set(protocol["commands"]) == {"set_all", "get_temperature", "temperature_data"}, "protocol command keys mismatch")
     set_all = _object(protocol["set_all"], "protocol.set_all")
     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")
     _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",
-    )
+    _require(set_all["ptc_offset"] == 0, "SET_ALL PTC offset mismatch")
+    _require(set_all["fan_offset"] == outputs["ptc_count"], "SET_ALL FAN offset mismatch")
+    _require(set_all["motor_x_offset"] == outputs["ptc_count"] + outputs["fan_count"], "SET_ALL X offset mismatch")
+    _require(set_all["motor_y_offset"] == set_all["motor_x_offset"] + 1, "SET_ALL Y offset mismatch")
+    _require(set_all["payload_length"] == set_all["motor_y_offset"] + 1, "SET_ALL length mismatch")
+    _require(set_all["duty_min"] <= set_all["duty_max"], "SET_ALL duty range mismatch")
+    _require(isinstance(set_all["motor_values"], list) and set_all["heartbeat"] == [motors["heartbeat_value"]] * len(motors["order"]), "SET_ALL motor contract mismatch")
     temperature_data = _object(protocol["temperature_data"], "protocol.temperature_data")
     temperature_data = _object(protocol["temperature_data"], "protocol.temperature_data")
     _keys(temperature_data, {"payload_length", "frame_length"}, "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")
+    _require(temperature_data["payload_length"] == temperature["value_count"], "temperature payload length mismatch")
+    _require(temperature_data["frame_length"] == temperature_data["payload_length"] + 6, "temperature frame length mismatch")
 
 
     timeouts = _object(payload["timeouts"], "timeouts")
     timeouts = _object(payload["timeouts"], "timeouts")
     _keys(timeouts, {"frame_inter_byte_ms", "host_get_response_ms"}, "timeouts")
     _keys(timeouts, {"frame_inter_byte_ms", "host_get_response_ms"}, "timeouts")
-    _require(timeouts["frame_inter_byte_ms"] == 10, "frame timeout mismatch")
+    _integer(timeouts["frame_inter_byte_ms"], "timeouts.frame_inter_byte_ms", minimum=1)
+    _integer(timeouts["host_get_response_ms"], "timeouts.host_get_response_ms", minimum=1)
 
 
     watchdog = _object(payload["watchdog"], "watchdog")
     watchdog = _object(payload["watchdog"], "watchdog")
     _keys(watchdog, {"timeout_seconds", "tick_us", "tick_clks", "timeout_ticks", "target"}, "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")
+    _integer(watchdog["timeout_seconds"], "watchdog.timeout_seconds", minimum=1)
+    _integer(watchdog["tick_us"], "watchdog.tick_us", minimum=1)
+    _integer(watchdog["tick_clks"], "watchdog.tick_clks", minimum=1)
     _require(watchdog["tick_clks"] == device["clock_hz"] * watchdog["tick_us"] // 1_000_000, "watchdog tick clock mismatch")
     _require(watchdog["tick_clks"] == device["clock_hz"] * watchdog["tick_us"] // 1_000_000, "watchdog tick clock mismatch")
+    _integer(watchdog["timeout_ticks"], "watchdog.timeout_ticks", minimum=1)
     _require(watchdog["timeout_ticks"] == watchdog["timeout_seconds"] * 1_000_000 // watchdog["tick_us"], "watchdog tick count mismatch")
     _require(watchdog["timeout_ticks"] == watchdog["timeout_seconds"] * 1_000_000 // watchdog["tick_us"], "watchdog tick count mismatch")
     target = _object(watchdog["target"], "watchdog.target")
     target = _object(watchdog["target"], "watchdog.target")
     _keys(target, {"ptc", "fan"}, "watchdog.target")
     _keys(target, {"ptc", "fan"}, "watchdog.target")
@@ -366,6 +356,11 @@ def load_project(path: Path) -> dict[str, Any]:
     project_path = Path(path)
     project_path = Path(path)
     payload = json.loads(project_path.read_text(encoding="utf-8"))
     payload = json.loads(project_path.read_text(encoding="utf-8"))
     _require(isinstance(payload, dict), "project root must be an object")
     _require(isinstance(payload, dict), "project root must be an object")
+    schema = json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))
+    errors = sorted(Draft202012Validator(schema).iter_errors(payload), key=lambda error: list(error.absolute_path))
+    if errors:
+        location = ".".join(str(part) for part in errors[0].absolute_path) or "project"
+        raise ValueError(f"project schema violation at {location}: {errors[0].message}")
     _validate_project(payload)
     _validate_project(payload)
     return payload
     return payload
 
 
@@ -465,6 +460,9 @@ def _render_params(project: Mapping[str, Any]) -> str:
     temperature = project["temperature"]
     temperature = project["temperature"]
     uart = project["uart"]
     uart = project["uart"]
     watchdog = project["watchdog"]
     watchdog = project["watchdog"]
+    _require(motors["dir_setup_cycles"] % watchdog["tick_clks"] == 0, "motor direction setup is not an integral tick count")
+    motor_dir_setup_ticks = motors["dir_setup_cycles"] // watchdog["tick_clks"]
+    frame_inter_byte_timeout_cycles = project["device"]["clock_hz"] * project["timeouts"]["frame_inter_byte_ms"] // 1000
     lines = [
     lines = [
         "// Generated from project.json. Do not edit.",
         "// Generated from project.json. Do not edit.",
         f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
         f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
@@ -480,13 +478,16 @@ def _render_params(project: Mapping[str, Any]) -> str:
         f"`define P4_PWM_FREQUENCY_HZ {outputs['pwm_frequency_hz']}",
         f"`define P4_PWM_FREQUENCY_HZ {outputs['pwm_frequency_hz']}",
         f"`define P4_PWM_SLOT_CLKS {outputs['pwm_slot_clks']}",
         f"`define P4_PWM_SLOT_CLKS {outputs['pwm_slot_clks']}",
         f"`define P4_SET_ALL_PAYLOAD_LENGTH {project['protocol']['set_all']['payload_length']}",
         f"`define P4_SET_ALL_PAYLOAD_LENGTH {project['protocol']['set_all']['payload_length']}",
+        f"`define P4_FRAME_INTER_BYTE_TIMEOUT_CYCLES {frame_inter_byte_timeout_cycles}",
         f"`define P4_FIXED_MOTOR_STEPS {motors['fixed_steps']}",
         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_RATE_HZ {motors['step_rate_hz']}",
         f"`define P4_MOTOR_STEP_HALF_CYCLES {motors['step_half_cycles']}",
         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_DIR_SETUP_CYCLES {motors['dir_setup_cycles']}",
+        f"`define P4_MOTOR_DIR_SETUP_TICKS {motor_dir_setup_ticks}",
         f"`define P4_MOTOR_HEARTBEAT_COMMAND 2'd{motors['heartbeat_value']}",
         f"`define P4_MOTOR_HEARTBEAT_COMMAND 2'd{motors['heartbeat_value']}",
         f"`define P4_TEMPERATURE_COUNT {temperature['value_count']}",
         f"`define P4_TEMPERATURE_COUNT {temperature['value_count']}",
         f"`define P4_TEMPERATURE_COUNT_BYTE 8'h{temperature['value_count']:02X}",
         f"`define P4_TEMPERATURE_COUNT_BYTE 8'h{temperature['value_count']:02X}",
+        f"`define P4_TEMPERATURE_FRAME_LENGTH {temperature['value_count'] + 6}",
         f"`define P4_TEMP_MAX_CELSIUS {temperature['maximum_celsius']}",
         f"`define P4_TEMP_MAX_CELSIUS {temperature['maximum_celsius']}",
         f"`define P4_PTC_ACTIVE_HIGH {1 if outputs['ptc_polarity'] == 'active_high' else 0}",
         f"`define P4_PTC_ACTIVE_HIGH {1 if outputs['ptc_polarity'] == 'active_high' else 0}",
         f"`define P4_FAN_ACTIVE_HIGH {1 if outputs['fan_polarity'] == 'active_high' else 0}",
         f"`define P4_FAN_ACTIVE_HIGH {1 if outputs['fan_polarity'] == 'active_high' else 0}",