|
@@ -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}",
|