|
|
@@ -14,29 +14,7 @@ from jsonschema import Draft202012Validator
|
|
|
|
|
|
PROFILE = "prod2u-normal-multiproject-115200-v1"
|
|
|
SCHEMA_PATH = Path(__file__).resolve().parents[1] / "schemas" / "project.schema.json"
|
|
|
-
|
|
|
-ACTIVE_SOURCE_PATHS = (
|
|
|
- "src/generated/prod2u_door_temp_params.vh",
|
|
|
- "src/common/uart_rx_byte.v",
|
|
|
- "src/common/uart_tx_byte.v",
|
|
|
- "src/common/crc16_serial.v",
|
|
|
- "src/common/frame_rx.v",
|
|
|
- "src/common/frame_tx.v",
|
|
|
- "src/common/payload_ram.v",
|
|
|
- "src/modules/output_target_ram.v",
|
|
|
- "src/modules/pwm_scheduler.v",
|
|
|
- "src/modules/shared_500us_tick.v",
|
|
|
- "src/modules/host_watchdog.v",
|
|
|
- "src/modules/door_motor_engine.v",
|
|
|
- "src/modules/i2c_word_reader.v",
|
|
|
- "src/modules/temperature_reader.v",
|
|
|
- "src/modules/temperature_ram.v",
|
|
|
- "src/project/command_controller.v",
|
|
|
- "src/project/project_adapter.v",
|
|
|
- "src/rtl/prod2u_por.v",
|
|
|
- "src/rtl/prod2u_p4_i2c_stop_start_read.v",
|
|
|
- "src/top/prod2u_p4_normal_v3_top.v",
|
|
|
-)
|
|
|
+SOURCE_CLOSURE_PATH = Path(__file__).resolve().parents[1] / "config" / "source_closure.json"
|
|
|
|
|
|
_TOP_LEVEL_KEYS = {
|
|
|
"project_id",
|
|
|
@@ -61,6 +39,28 @@ def _require(condition: bool, message: str) -> None:
|
|
|
raise ValueError(message)
|
|
|
|
|
|
|
|
|
+def _load_source_closure() -> tuple[str, ...]:
|
|
|
+ payload = json.loads(SOURCE_CLOSURE_PATH.read_text(encoding="utf-8"))
|
|
|
+ _require(isinstance(payload, Mapping), "source closure root must be an object")
|
|
|
+ _require(payload.get("schema") == "prod2u-source-closure-v1", "source closure schema mismatch")
|
|
|
+ _require(payload.get("project_id") == "prod2u-door-temp", "source closure project_id mismatch")
|
|
|
+ sources = payload.get("sources")
|
|
|
+ _require(isinstance(sources, list) and sources, "source closure must contain a non-empty sources list")
|
|
|
+ normalized = []
|
|
|
+ for value in sources:
|
|
|
+ _require(isinstance(value, str) and value, "source closure entry must be a non-empty string")
|
|
|
+ parts = Path(value).parts
|
|
|
+ _require(".." not in parts and not Path(value).is_absolute(), "source closure entry must be a relative safe path")
|
|
|
+ normalized.append(value)
|
|
|
+ _require(len(normalized) == len(set(normalized)), "source closure contains duplicate paths")
|
|
|
+ missing = [path for path in normalized if not (SOURCE_CLOSURE_PATH.parents[1] / path).is_file()]
|
|
|
+ _require(not missing, f"source closure references missing files: {missing}")
|
|
|
+ return tuple(normalized)
|
|
|
+
|
|
|
+
|
|
|
+ACTIVE_SOURCE_PATHS = _load_source_closure()
|
|
|
+
|
|
|
+
|
|
|
def _object(value: Any, name: str) -> Mapping[str, Any]:
|
|
|
_require(isinstance(value, dict), f"{name} must be an object")
|
|
|
return value
|
|
|
@@ -214,9 +214,19 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_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")
|
|
|
+ _keys(limits, {"limit_count", "active_level", "functional_use", "startup", "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")
|
|
|
+ _require(limits["active_level"] == "high" and limits["functional_use"] is True, "limit policy mismatch")
|
|
|
+ startup = _object(limits["startup"], "limits.startup")
|
|
|
+ _keys(startup, {"enabled", "direction_value", "direction_meaning", "burst_step_count", "burst_step_rate_hz", "inter_burst_ms", "max_bursts", "axis_order"}, "limits.startup")
|
|
|
+ _require(startup["enabled"] is True, "startup must be enabled")
|
|
|
+ _require(startup["direction_meaning"] == "close", "startup direction must be close")
|
|
|
+ _integer(startup["direction_value"], "limits.startup.direction_value", minimum=0)
|
|
|
+ _integer(startup["burst_step_count"], "limits.startup.burst_step_count", minimum=1)
|
|
|
+ _integer(startup["burst_step_rate_hz"], "limits.startup.burst_step_rate_hz", minimum=1)
|
|
|
+ _integer(startup["inter_burst_ms"], "limits.startup.inter_burst_ms", minimum=0)
|
|
|
+ _integer(startup["max_bursts"], "limits.startup.max_bursts", minimum=1)
|
|
|
+ _require(len(startup["axis_order"]) == limits["limit_count"], "startup axis order mismatch")
|
|
|
for index, item in enumerate(limits["channels"]):
|
|
|
entry = _object(item, f"limits.channels[{index}]")
|
|
|
_keys(entry, {"name", "ball"}, f"limits.channels[{index}]")
|
|
|
@@ -463,12 +473,17 @@ def _frame_hex(frame_type: int, payload: bytes) -> str:
|
|
|
def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
outputs = project["outputs"]
|
|
|
motors = project["motors"]
|
|
|
+ limits = project["limits"]
|
|
|
+ startup = limits["startup"]
|
|
|
temperature = project["temperature"]
|
|
|
uart = project["uart"]
|
|
|
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
|
|
|
+ startup_inter_burst_ticks = startup["inter_burst_ms"] * 1000 // watchdog["tick_us"]
|
|
|
+ startup_dir_bit = startup["direction_value"]
|
|
|
+ startup_dir_mask = f"2'b{startup_dir_bit}{startup_dir_bit}"
|
|
|
lines = [
|
|
|
"// Generated from project.json. Do not edit.",
|
|
|
f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
|
|
|
@@ -505,6 +520,11 @@ def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
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}",
|
|
|
+ f"`define P4_STARTUP_ENABLED {1 if startup['enabled'] else 0}",
|
|
|
+ f"`define P4_STARTUP_DIR_MASK {startup_dir_mask}",
|
|
|
+ f"`define P4_STARTUP_BURST_STEPS {startup['burst_step_count']}",
|
|
|
+ f"`define P4_STARTUP_MAX_BURSTS {startup['max_bursts']}",
|
|
|
+ f"`define P4_STARTUP_INTER_BURST_TICKS {startup_inter_burst_ticks}",
|
|
|
]
|
|
|
lines.extend(
|
|
|
f"`define P4_TEMP_DEVICE_ADDR_{index} 7'h{address:02X}"
|
|
|
@@ -579,7 +599,7 @@ def generate_project(project_path: Path, output_root: Path) -> dict[str, Any]:
|
|
|
{
|
|
|
"schema": "prod2u-simple-source-manifest-template-v1",
|
|
|
"project_id": project["project_id"],
|
|
|
- "sources": list(ACTIVE_SOURCE_PATHS),
|
|
|
+ "sources": list(_load_source_closure()),
|
|
|
"generated_from": "project.json",
|
|
|
"contract": {
|
|
|
"uart": project["uart"],
|