|
|
@@ -56,6 +56,10 @@ def load_project(path: Path) -> dict[str, Any]:
|
|
|
_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")
|
|
|
@@ -70,11 +74,34 @@ 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
|
|
|
+ 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
|
|
|
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_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,
|
|
|
@@ -108,6 +135,11 @@ 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
|
|
|
+ )))
|
|
|
lines = [
|
|
|
"// Generated from project.json. Do not edit.",
|
|
|
f"`define P4_CLOCK_HZ {project['device']['clock_hz']}",
|
|
|
@@ -115,6 +147,8 @@ 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_FREQUENCY_HZ {outputs['pwm_frequency_hz']}",
|
|
|
+ f"`define P4_PWM_SLOT_CLKS {pwm_slot_clks}",
|
|
|
f"`define P4_FIXED_MOTOR_STEPS {motors['fixed_steps']}",
|
|
|
f"`define P4_MOTOR_STEP_HALF_CYCLES {motors['step_half_cycles']}",
|
|
|
f"`define P4_MOTOR_DIR_SETUP_CYCLES {motors['dir_setup_cycles']}",
|
|
|
@@ -123,6 +157,8 @@ def _render_params(project: Mapping[str, Any]) -> str:
|
|
|
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_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}",
|
|
|
]
|
|
|
lines.extend(
|
|
|
f"`define P4_TEMP_DEVICE_ADDR_{index} 7'h{address:02X}"
|