|
@@ -88,6 +88,18 @@ def _list(value: Any, name: str, length: int | None = None) -> list[Any]:
|
|
|
return value
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _axis_mask_literal(values: list[Any], axis_count: int) -> str:
|
|
|
|
|
+ """Build AXIS_COUNT'b... with bit0=X (LSB / rightmost), index0=X,1=Y,2=Z."""
|
|
|
|
|
+ _require(len(values) == axis_count, "axis mask length mismatch")
|
|
|
|
|
+ bits_lsb_first: list[str] = []
|
|
|
|
|
+ for value in values:
|
|
|
|
|
+ if isinstance(value, bool):
|
|
|
|
|
+ bits_lsb_first.append("1" if value else "0")
|
|
|
|
|
+ else:
|
|
|
|
|
+ bits_lsb_first.append("1" if int(value) else "0")
|
|
|
|
|
+ return f"{axis_count}'b" + "".join(reversed(bits_lsb_first))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _validate_channel(channel: Any, index: int, kind: str) -> None:
|
|
def _validate_channel(channel: Any, index: int, kind: str) -> None:
|
|
|
item = _object(channel, f"{kind}_channels[{index}]")
|
|
item = _object(channel, f"{kind}_channels[{index}]")
|
|
|
_keys(item, {"index", "name", "signal", "board_signal", "ball", "connector", "connector_pin", "polarity"}, f"{kind}_channels[{index}]")
|
|
_keys(item, {"index", "name", "signal", "board_signal", "ball", "connector", "connector_pin", "polarity"}, f"{kind}_channels[{index}]")
|
|
@@ -206,6 +218,7 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
"heartbeat_value",
|
|
"heartbeat_value",
|
|
|
"open_dir_value",
|
|
"open_dir_value",
|
|
|
"close_dir_value",
|
|
"close_dir_value",
|
|
|
|
|
+ "dir_close_level",
|
|
|
"mapping",
|
|
"mapping",
|
|
|
"enable_n",
|
|
"enable_n",
|
|
|
},
|
|
},
|
|
@@ -222,6 +235,15 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_integer(motors["dir_setup_cycles"], "motors.dir_setup_cycles", minimum=0)
|
|
_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(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")
|
|
_require(motors["heartbeat_value"] in motors["command_values"], "motor heartbeat is not a command")
|
|
|
|
|
+ _integer(motors["open_dir_value"], "motors.open_dir_value", minimum=0)
|
|
|
|
|
+ _integer(motors["close_dir_value"], "motors.close_dir_value", minimum=0)
|
|
|
|
|
+ _require(motors["open_dir_value"] == 0, "logical open_dir_value must be 0")
|
|
|
|
|
+ _require(motors["close_dir_value"] == 1, "logical close_dir_value must be 1")
|
|
|
|
|
+ dir_close_level = _list(motors["dir_close_level"], "motors.dir_close_level", length=motors["count"])
|
|
|
|
|
+ for index, level in enumerate(dir_close_level):
|
|
|
|
|
+ _require(isinstance(level, int) and not isinstance(level, bool) and level in (0, 1),
|
|
|
|
|
+ f"motors.dir_close_level[{index}] must be 0 or 1")
|
|
|
|
|
+ _require(dir_close_level == [1, 1, 1], "production dir_close_level must be [1,1,1]")
|
|
|
mapping = _object(motors["mapping"], "motors.mapping")
|
|
mapping = _object(motors["mapping"], "motors.mapping")
|
|
|
_require(motors["count"] == 3 and motors["order"] == ["x", "y", "z"], "production motor count/order must be x,y,z")
|
|
_require(motors["count"] == 3 and motors["order"] == ["x", "y", "z"], "production motor count/order must be x,y,z")
|
|
|
_keys(mapping, {"x", "y", "z"}, "motors.mapping")
|
|
_keys(mapping, {"x", "y", "z"}, "motors.mapping")
|
|
@@ -237,10 +259,35 @@ def _validate_project(payload: Mapping[str, Any]) -> None:
|
|
|
_require(enable["policy"] == "permanent_high", "motor enable policy must be permanent_high")
|
|
_require(enable["policy"] == "permanent_high", "motor enable policy must be permanent_high")
|
|
|
|
|
|
|
|
limits = _object(payload["limits"], "limits")
|
|
limits = _object(payload["limits"], "limits")
|
|
|
- _keys(limits, {"limit_count", "active_level", "functional_use", "runtime_use", "startup", "channels"}, "limits")
|
|
|
|
|
|
|
+ _keys(
|
|
|
|
|
+ limits,
|
|
|
|
|
+ {
|
|
|
|
|
+ "limit_count",
|
|
|
|
|
+ "active_level",
|
|
|
|
|
+ "limit_active_high",
|
|
|
|
|
+ "close_limit_is_ls",
|
|
|
|
|
+ "functional_use",
|
|
|
|
|
+ "runtime_use",
|
|
|
|
|
+ "startup",
|
|
|
|
|
+ "channels",
|
|
|
|
|
+ },
|
|
|
|
|
+ "limits",
|
|
|
|
|
+ )
|
|
|
_require(limits["limit_count"] == len(limits["channels"]) == 6, "limit count/list mismatch")
|
|
_require(limits["limit_count"] == len(limits["channels"]) == 6, "limit count/list mismatch")
|
|
|
_require(limits["active_level"] == "high" and limits["functional_use"] is True, "limit policy mismatch")
|
|
_require(limits["active_level"] == "high" and limits["functional_use"] is True, "limit policy mismatch")
|
|
|
_require(limits["runtime_use"] is True, "runtime limit use must be true")
|
|
_require(limits["runtime_use"] is True, "runtime limit use must be true")
|
|
|
|
|
+ limit_active_high = _list(limits["limit_active_high"], "limits.limit_active_high", length=motors["count"])
|
|
|
|
|
+ for index, active_high in enumerate(limit_active_high):
|
|
|
|
|
+ _require(isinstance(active_high, bool), f"limits.limit_active_high[{index}] must be a boolean")
|
|
|
|
|
+ _require(limit_active_high == [True, True, True], "production limit_active_high must be [true,true,true]")
|
|
|
|
|
+ close_limit_is_ls = _list(limits["close_limit_is_ls"], "limits.close_limit_is_ls", length=motors["count"])
|
|
|
|
|
+ for index, close_is_ls in enumerate(close_limit_is_ls):
|
|
|
|
|
+ _require(isinstance(close_is_ls, bool), f"limits.close_limit_is_ls[{index}] must be a boolean")
|
|
|
|
|
+ _require(close_limit_is_ls == [True, True, True], "production close_limit_is_ls must be [true,true,true]")
|
|
|
|
|
+ _require(
|
|
|
|
|
+ all(limit_active_high) == (limits["active_level"] == "high"),
|
|
|
|
|
+ "limits.active_level must match limit_active_high aggregate",
|
|
|
|
|
+ )
|
|
|
startup = _object(limits["startup"], "limits.startup")
|
|
startup = _object(limits["startup"], "limits.startup")
|
|
|
_keys(
|
|
_keys(
|
|
|
startup,
|
|
startup,
|
|
@@ -570,11 +617,17 @@ def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
frame_inter_byte_timeout_cycles = project["device"]["clock_hz"] * project["timeouts"]["frame_inter_byte_ms"] // 1000
|
|
frame_inter_byte_timeout_cycles = project["device"]["clock_hz"] * project["timeouts"]["frame_inter_byte_ms"] // 1000
|
|
|
startup_dir_bit = startup["direction_value"]
|
|
startup_dir_bit = startup["direction_value"]
|
|
|
startup_dir_mask = f"{axis_count}'b" + (str(startup_dir_bit) * axis_count)
|
|
startup_dir_mask = f"{axis_count}'b" + (str(startup_dir_bit) * axis_count)
|
|
|
|
|
+ limit_active_high_mask = _axis_mask_literal(limits["limit_active_high"], axis_count)
|
|
|
|
|
+ dir_close_level_mask = _axis_mask_literal(motors["dir_close_level"], axis_count)
|
|
|
|
|
+ close_limit_is_ls_mask = _axis_mask_literal(limits["close_limit_is_ls"], axis_count)
|
|
|
lines = [
|
|
lines = [
|
|
|
"// Generated from project.json. Do not edit.",
|
|
"// Generated from project.json. Do not edit.",
|
|
|
f"`define P4_AXIS_COUNT {axis_count}",
|
|
f"`define P4_AXIS_COUNT {axis_count}",
|
|
|
f"`define P4_LIMIT_COUNT {limits['limit_count']}",
|
|
f"`define P4_LIMIT_COUNT {limits['limit_count']}",
|
|
|
f"`define P4_RUNTIME_LIMIT_USE {1 if limits['runtime_use'] else 0}",
|
|
f"`define P4_RUNTIME_LIMIT_USE {1 if limits['runtime_use'] else 0}",
|
|
|
|
|
+ f"`define P4_LIMIT_ACTIVE_HIGH_MASK {limit_active_high_mask}",
|
|
|
|
|
+ f"`define P4_DIR_CLOSE_LEVEL_MASK {dir_close_level_mask}",
|
|
|
|
|
+ f"`define P4_CLOSE_LIMIT_IS_LS_MASK {close_limit_is_ls_mask}",
|
|
|
f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
|
|
f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
|
|
|
f"`define P4_UART_BAUD {uart['baud']}",
|
|
f"`define P4_UART_BAUD {uart['baud']}",
|
|
|
f"`define P4_UART_CLKS_PER_BIT {uart['clks_per_bit']}",
|
|
f"`define P4_UART_CLKS_PER_BIT {uart['clks_per_bit']}",
|