Просмотр исходного кода

fix legacy shared-crc lint and cocotb runner

root 3 месяцев назад
Родитель
Сommit
a67ae51c3f

+ 26 - 6
src/top/prod2u_p4_normal_v3_top.v

@@ -1,7 +1,10 @@
 `timescale 1ns/1ps
 `timescale 1ns/1ps
 `include "src/generated/prod2u_door_temp_params.vh"
 `include "src/generated/prod2u_door_temp_params.vh"
 
 
-module prod2u_p4_normal_v3_top (
+module prod2u_p4_normal_v3_top #(
+    parameter integer SHARED_TICK_CLOCK_HZ = `P4_CLOCK_HZ,
+    parameter integer MOTION_SERVICE_CLKS = `P4_MOTION_SERVICE_CLKS
+) (
     input  wire       sys_clk,
     input  wire       sys_clk,
     input  wire       host_uart_rx,
     input  wire       host_uart_rx,
     output wire       host_uart_tx,
     output wire       host_uart_tx,
@@ -123,6 +126,12 @@ module prod2u_p4_normal_v3_top (
     wire [2:0] calibrated_mask;
     wire [2:0] calibrated_mask;
     wire [2:0] fault_mask;
     wire [2:0] fault_mask;
     wire watchdog_feed;
     wire watchdog_feed;
+    wire frame_rx_crc_start_unused;
+    wire frame_rx_crc_data_valid_unused;
+    wire [7:0] frame_rx_crc_data_unused;
+    wire frame_tx_crc_start_unused;
+    wire frame_tx_crc_data_valid_unused;
+    wire [7:0] frame_tx_crc_data_unused;
 
 
     assign temp_scl = i2c_scl_drive_low ? 1'b0 : 1'bz;
     assign temp_scl = i2c_scl_drive_low ? 1'b0 : 1'bz;
     assign temp_sda = i2c_sda_drive_low ? 1'b0 : 1'bz;
     assign temp_sda = i2c_sda_drive_low ? 1'b0 : 1'bz;
@@ -217,7 +226,7 @@ module prod2u_p4_normal_v3_top (
     );
     );
 
 
     shared_500us_tick #(
     shared_500us_tick #(
-        .CLOCK_HZ(`P4_CLOCK_HZ), .TICK_US(`P4_WATCHDOG_TICK_US)
+        .CLOCK_HZ(SHARED_TICK_CLOCK_HZ), .TICK_US(`P4_WATCHDOG_TICK_US)
     ) u_shared_tick (
     ) u_shared_tick (
         .clk(sys_clk), .rst_n(sys_rst_n), .tick(tick_500us)
         .clk(sys_clk), .rst_n(sys_rst_n), .tick(tick_500us)
     );
     );
@@ -246,7 +255,11 @@ module prod2u_p4_normal_v3_top (
         .frame_ready(frame_ready), .frame_type(frame_type), .frame_length(frame_length),
         .frame_ready(frame_ready), .frame_type(frame_type), .frame_length(frame_length),
         .payload_read_addr(payload_read_addr), .payload_read_data(payload_read_data),
         .payload_read_addr(payload_read_addr), .payload_read_data(payload_read_data),
         .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr),
         .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr),
-        .payload_wr_data(payload_wr_data)
+        .payload_wr_data(payload_wr_data),
+        .crc_start_o(frame_rx_crc_start_unused),
+        .crc_data_valid_o(frame_rx_crc_data_valid_unused),
+        .crc_data_o(frame_rx_crc_data_unused),
+        .crc_busy_i(1'b0), .crc_data_done_i(1'b0), .crc_value_i(16'hFFFF)
     );
     );
 
 
     payload_ram #(.DEPTH(`P4_SET_ALL_PAYLOAD_LENGTH), .ADDR_WIDTH(8)) u_payload_ram (
     payload_ram #(.DEPTH(`P4_SET_ALL_PAYLOAD_LENGTH), .ADDR_WIDTH(8)) u_payload_ram (
@@ -300,7 +313,7 @@ module prod2u_p4_normal_v3_top (
         .DIR_SETUP_TICKS(`P4_MOTOR_DIR_SETUP_TICKS),
         .DIR_SETUP_TICKS(`P4_MOTOR_DIR_SETUP_TICKS),
         .PERCENT_MAX(`P4_DOOR_PERCENT_MAX),
         .PERCENT_MAX(`P4_DOOR_PERCENT_MAX),
         .STATUS_PAYLOAD_LENGTH(`P4_MOTOR_STATUS_PAYLOAD_LENGTH),
         .STATUS_PAYLOAD_LENGTH(`P4_MOTOR_STATUS_PAYLOAD_LENGTH),
-        .MOTION_SERVICE_CLKS(`P4_MOTION_SERVICE_CLKS),
+        .MOTION_SERVICE_CLKS(MOTION_SERVICE_CLKS),
         .PHASE_FACTOR(`P4_PHASE_FACTOR),
         .PHASE_FACTOR(`P4_PHASE_FACTOR),
         .CAL_RAMP_UNIT(`P4_CAL_RAMP_UNIT)
         .CAL_RAMP_UNIT(`P4_CAL_RAMP_UNIT)
     ) u_door_motion (
     ) u_door_motion (
@@ -392,7 +405,11 @@ module prod2u_p4_normal_v3_top (
         .busy(frame_tx_busy),
         .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(frame_tx_payload_data), .done(tx_done)
+        .payload_data(frame_tx_payload_data), .done(tx_done),
+        .crc_start_o(frame_tx_crc_start_unused),
+        .crc_data_valid_o(frame_tx_crc_data_valid_unused),
+        .crc_data_o(frame_tx_crc_data_unused),
+        .crc_busy_i(1'b0), .crc_data_done_i(1'b0), .crc_value_i(16'hFFFF)
     );
     );
 
 
     uart_tx_byte #(.CLKS_PER_BIT(`P4_UART_CLKS_PER_BIT)) u_uart_tx (
     uart_tx_byte #(.CLKS_PER_BIT(`P4_UART_CLKS_PER_BIT)) u_uart_tx (
@@ -404,5 +421,8 @@ module prod2u_p4_normal_v3_top (
 
 
     wire unused_inputs = &{1'b0, uart_framing_error, frame_tx_busy, adapter_busy,
     wire unused_inputs = &{1'b0, uart_framing_error, frame_tx_busy, adapter_busy,
         i2c_busy, temperature_busy, uart_tx_byte_done, tick_500us,
         i2c_busy, temperature_busy, uart_tx_byte_done, tick_500us,
-        watchdog_timeout_event, calibrated_mask, fault_mask};
+        watchdog_timeout_event, calibrated_mask, fault_mask,
+        frame_rx_crc_start_unused, frame_rx_crc_data_valid_unused,
+        frame_rx_crc_data_unused, frame_tx_crc_start_unused,
+        frame_tx_crc_data_valid_unused, frame_tx_crc_data_unused};
 endmodule
 endmodule

+ 5 - 15
tests/cocotb/prod2u_door_temp_uart_top.v

@@ -1,6 +1,6 @@
 `timescale 1ns/1ps
 `timescale 1ns/1ps
 
 
-// Simulation wrapper: real UART bit timing; accelerated 500us tick.
+// Simulation wrapper: real UART bit timing; accelerated control enables.
 module prod2u_door_temp_uart_top (
 module prod2u_door_temp_uart_top (
     input  wire       host_uart_rx,
     input  wire       host_uart_rx,
     output wire       host_uart_tx,
     output wire       host_uart_tx,
@@ -25,19 +25,10 @@ module prod2u_door_temp_uart_top (
     reg sys_clk = 1'b0;
     reg sys_clk = 1'b0;
     always #20 sys_clk = ~sys_clk;
     always #20 sys_clk = ~sys_clk;
 
 
-    reg [6:0] tick_div = 7'd0;
-    reg fast_tick = 1'b0;
-    always @(posedge sys_clk) begin
-        if (tick_div + 1'b1 >= 7'd100) begin
-            tick_div <= 7'd0;
-            fast_tick <= 1'b1;
-        end else begin
-            tick_div <= tick_div + 1'b1;
-            fast_tick <= 1'b0;
-        end
-    end
-
-    prod2u_p4_normal_v3_top u_dut (
+    prod2u_p4_normal_v3_top #(
+        .SHARED_TICK_CLOCK_HZ(200_000),
+        .MOTION_SERVICE_CLKS(1)
+    ) u_dut (
         .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
         .sys_clk(sys_clk), .host_uart_rx(host_uart_rx), .host_uart_tx(host_uart_tx),
         .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out),
         .ptc_pwm_out(ptc_pwm_out), .fan_pwm_out(fan_pwm_out),
         .motor_en_n(motor_en_n),
         .motor_en_n(motor_en_n),
@@ -50,7 +41,6 @@ module prod2u_door_temp_uart_top (
     );
     );
 
 
     initial begin
     initial begin
-        force u_dut.tick_500us = fast_tick;
 `ifdef COCOTB_WAVES
 `ifdef COCOTB_WAVES
         $dumpfile("cocotb_debug.vcd");
         $dumpfile("cocotb_debug.vcd");
         $dumpvars(0, prod2u_door_temp_uart_top);
         $dumpvars(0, prod2u_door_temp_uart_top);

+ 34 - 1
tests/cocotb/run_prod2u_door_temp_uart_e2e.py

@@ -95,6 +95,10 @@ def _select_python() -> Path:
     if configured:
     if configured:
         candidates.append(Path(configured).expanduser())
         candidates.append(Path(configured).expanduser())
     candidates.append(DEFAULT_VERIFY_PYTHON)
     candidates.append(DEFAULT_VERIFY_PYTHON)
+    # The persistent OSS Python wrapper carries the matching shared library
+    # and bundled cocotb.  Prefer its non-tabbypy3 entrypoint before falling
+    # back to a poisoned sys.executable reported by the vendor wrapper.
+    candidates.append(Path("/data/prod2u/oss-cad-suite/latest/py3bin/python3.11"))
     # Prefer configured/verify venv over a possibly poisoned sys.executable.
     # Prefer configured/verify venv over a possibly poisoned sys.executable.
     seen: set[str] = set()
     seen: set[str] = set()
     for candidate in candidates:
     for candidate in candidates:
@@ -129,6 +133,10 @@ def _tool_bin_dirs(shim_dir: Path | None = None, python_exe: Path | None = None)
         oss_top = Path("/data/prod2u/oss-cad-suite/latest")
         oss_top = Path("/data/prod2u/oss-cad-suite/latest")
         for name in ("iverilog", "vvp"):
         for name in ("iverilog", "vvp"):
             resolved = shutil.which(name)
             resolved = shutil.which(name)
+            # A controlled Python re-exec preserves this run's shim directory
+            # on PATH.  Never regenerate a shim that execs itself.
+            if resolved and Path(resolved).parent.resolve() == shim_dir.resolve():
+                resolved = None
             if not resolved:
             if not resolved:
                 for candidate in (
                 for candidate in (
                     oss_top / "bin" / name,
                     oss_top / "bin" / name,
@@ -254,6 +262,14 @@ def _ensure_running_under(python_exe: Path, build_dir: Path) -> None:
     PYTHONEXECUTABLE poisons sys.executable for the whole process lifetime; the
     PYTHONEXECUTABLE poisons sys.executable for the whole process lifetime; the
     only fix is a clean execve before cocotb_tools/VPI start.
     only fix is a clean execve before cocotb_tools/VPI start.
     """
     """
+    if os.environ.get("PROD2U_COCOTB_REEXEC_DONE") == "1":
+        # OSS CAD's selected wrapper legitimately injects these again while
+        # launching libexec/python.  The marker proves the one controlled
+        # re-exec already happened; clear the wrapper residue here instead of
+        # recursively execing the same wrapper forever.
+        for key in _OSS_CAD_POISON:
+            os.environ.pop(key, None)
+        return
     need_reexec = False
     need_reexec = False
     if "tabbypy3" in Path(sys.executable).name:
     if "tabbypy3" in Path(sys.executable).name:
         need_reexec = True
         need_reexec = True
@@ -301,7 +317,10 @@ def main() -> int:
             file=sys.stderr,
             file=sys.stderr,
         )
         )
         return 2
         return 2
-    if "tabbypy3" in Path(sys.executable).name:
+    if (
+        "tabbypy3" in Path(sys.executable).name
+        and os.environ.get("PROD2U_COCOTB_REEXEC_DONE") != "1"
+    ):
         print(f"error: sys.executable is OSS CAD tabbypy3: {sys.executable}", file=sys.stderr)
         print(f"error: sys.executable is OSS CAD tabbypy3: {sys.executable}", file=sys.stderr)
         return 2
         return 2
     if any(_is_oss_cad_bin(part) for part in os.environ.get("PATH", "").split(os.pathsep)):
     if any(_is_oss_cad_bin(part) for part in os.environ.get("PATH", "").split(os.pathsep)):
@@ -312,6 +331,20 @@ def main() -> int:
 
 
     runner = get_runner("icarus")
     runner = get_runner("icarus")
 
 
+    # cocotb_tools hard-codes -g2012 before user build_args.  Replace that
+    # single dialect selection so the command exactly matches the passing
+    # Legacy Icarus lane instead of passing two conflicting -g options.
+    _orig_build_command = runner._build_command
+
+    def _build_command_g2005_sv():
+        commands = _orig_build_command()
+        return [
+            ["-g2005-sv" if arg == "-g2012" else arg for arg in command]
+            for command in commands
+        ]
+
+    runner._build_command = _build_command_g2005_sv  # type: ignore[method-assign]
+
     _orig_set_env_common = runner._set_env_common
     _orig_set_env_common = runner._set_env_common
 
 
     def _set_env_common_without_oss_cad_poison() -> None:
     def _set_env_common_without_oss_cad_poison() -> None:

+ 13 - 21
tests/cocotb/test_prod2u_door_temp_uart_e2e.py

@@ -138,32 +138,24 @@ async def wait_measure_rises_then_open(
     min_rises: int = 2,
     min_rises: int = 2,
 ) -> int:
 ) -> int:
     """Serial-cal friendly: wait for this axis's measure-open STEP rises, then hit open only."""
     """Serial-cal friendly: wait for this axis's measure-open STEP rises, then hit open only."""
-    rises = {"n": 0}
-
-    async def count_rises():
-        while True:
-            await RisingEdge(step_sig)
-            rises["n"] += 1
-
-    counter = cocotb.start_soon(count_rises())
-    # Up to ~62.5M clocks (~2.5s sim @25MHz) per axis; service tick is 625 clks.
-    for _ in range(100_000):
-        await clocks(dut, 625)
-        if rises["n"] >= min_rises:
-            break
-    else:
-        counter.kill()
-        raise AssertionError(
-            f"insufficient measure rises axis={axis_name} rises={rises['n']} "
-            f"sim_time={_sim_time_ns()}"
+    # Let the simulator advance directly to STEP activity.  Iterating every
+    # sys_clk edge here made the same bounded check take hundreds of seconds
+    # of Python/VPI wall time despite only needing to observe two rises.
+    rises = 0
+    for rise_index in range(min_rises):
+        await wait_for_stage(
+            RisingEdge(step_sig),
+            5000,
+            f"cal_measure_{axis_name}",
+            rise_index,
         )
         )
+        rises += 1
     limit_hs.value = 1
     limit_hs.value = 1
     limit_ls.value = 0
     limit_ls.value = 0
-    checkpoint(f"cal_open_{axis_name}", rises=rises["n"])
+    checkpoint(f"cal_open_{axis_name}", rises=rises)
     # Allow limit sync + terminal handoff before the next axis starts.
     # Allow limit sync + terminal handoff before the next axis starts.
     await clocks(dut, 4000)
     await clocks(dut, 4000)
-    counter.kill()
-    return rises["n"]
+    return rises
 
 
 
 
 @cocotb.test()
 @cocotb.test()

+ 5 - 0
tests/verilator_waivers.vlt

@@ -20,3 +20,8 @@ lint_off -rule MULTIDRIVENPROC -file "*/src/modules/door_axis_controller.v"
 // builders; the sequential scheduler itself only consumes rate/threshold.
 // builders; the sequential scheduler itself only consumes rate/threshold.
 // Narrow match: only unused TRAVEL_WIDTH, not other UNUSEDPARAM in the file.
 // Narrow match: only unused TRAVEL_WIDTH, not other UNUSEDPARAM in the file.
 lint_off -rule UNUSEDPARAM -file "*/src/modules/door_shared_dda_scheduler.v" -match "*TRAVEL_WIDTH*"
 lint_off -rule UNUSEDPARAM -file "*/src/modules/door_shared_dda_scheduler.v" -match "*TRAVEL_WIDTH*"
+
+// The POR output intentionally serves as the asynchronous reset for the
+// design and is also sampled by synchronous logic.  Keep this waiver scoped
+// to the single POR register rather than suppressing SYNCASYNCNET globally.
+lint_off -rule SYNCASYNCNET -file "*/src/rtl/prod2u_por.v" -match "*por_reset_n*"