|
|
@@ -30,8 +30,16 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
|
|
|
reg fast_tick;
|
|
|
|
|
|
integer host_x_steps;
|
|
|
+ integer host_y_steps;
|
|
|
+ integer host_z_steps;
|
|
|
+ integer post_limit_rise;
|
|
|
reg prev_x_step;
|
|
|
+ reg prev_y_step;
|
|
|
+ reg prev_z_step;
|
|
|
reg startup_done_seen = 1'b0;
|
|
|
+ reg count_y_steps = 1'b0;
|
|
|
+ reg count_z_steps = 1'b0;
|
|
|
+ reg watch_x_rises = 1'b0;
|
|
|
|
|
|
always #1 sys_clk = ~sys_clk;
|
|
|
|
|
|
@@ -66,8 +74,17 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
|
|
|
|
|
|
always @(posedge sys_clk) begin
|
|
|
prev_x_step <= x_step;
|
|
|
- if (startup_done_seen && !prev_x_step && x_step)
|
|
|
+ prev_y_step <= y_step;
|
|
|
+ prev_z_step <= z_step;
|
|
|
+ if (startup_done_seen && !prev_x_step && x_step) begin
|
|
|
host_x_steps <= host_x_steps + 1;
|
|
|
+ if (watch_x_rises)
|
|
|
+ post_limit_rise <= post_limit_rise + 1;
|
|
|
+ end
|
|
|
+ if (startup_done_seen && count_y_steps && !prev_y_step && y_step)
|
|
|
+ host_y_steps <= host_y_steps + 1;
|
|
|
+ if (startup_done_seen && count_z_steps && !prev_z_step && z_step)
|
|
|
+ host_z_steps <= host_z_steps + 1;
|
|
|
end
|
|
|
|
|
|
task wait_for_startup_done;
|
|
|
@@ -136,6 +153,7 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
|
|
|
$fatal(1, "runtime LS stop failed to truncate X before 450, got %0d", host_x_steps);
|
|
|
if (host_x_steps < 1)
|
|
|
$fatal(1, "X never stepped before runtime LS stop");
|
|
|
+ $display("PASS_SECTION_X_LS steps=%0d", host_x_steps);
|
|
|
|
|
|
// Wrong-side HS while closing must not stop X.
|
|
|
host_x_steps = 0;
|
|
|
@@ -151,6 +169,7 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
|
|
|
release_host_motor();
|
|
|
if (host_x_steps !== HOST_STEPS)
|
|
|
$fatal(1, "expected full 450 with wrong-side HS held, got %0d", host_x_steps);
|
|
|
+ $display("PASS_SECTION_WRONG_HS steps=%0d", host_x_steps);
|
|
|
|
|
|
// Host open on X (DIR=0): assert HS mid-move -> truncate before 450.
|
|
|
host_x_steps = 0;
|
|
|
@@ -168,26 +187,132 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
|
|
|
release_host_motor();
|
|
|
if (host_x_steps >= HOST_STEPS)
|
|
|
$fatal(1, "runtime HS stop failed to truncate X before 450, got %0d", host_x_steps);
|
|
|
+ $display("PASS_SECTION_X_HS steps=%0d", host_x_steps);
|
|
|
+
|
|
|
+ // Target limit already high before start -> zero external rising edges.
|
|
|
+ host_x_steps = 0;
|
|
|
+ prev_x_step = 1'b0;
|
|
|
+ x_limit_ls = 1'b1;
|
|
|
+ x_limit_hs = 1'b0;
|
|
|
+ drain_limit_sync();
|
|
|
+ start_host_motor(3'b001, 3'b001);
|
|
|
+ // Engine may finish immediately or ignore start when target limit already high.
|
|
|
+ repeat (400) @(posedge sys_clk);
|
|
|
+ if (dut.u_motor_engine.busy) begin
|
|
|
+ force dut.watchdog_timeout_event = 1'b1;
|
|
|
+ @(posedge sys_clk);
|
|
|
+ force dut.watchdog_timeout_event = 1'b0;
|
|
|
+ repeat (20) @(posedge sys_clk);
|
|
|
+ end
|
|
|
+ if (dut.u_motor_engine.busy)
|
|
|
+ $fatal(1, "pre-asserted LS left X engine busy");
|
|
|
+ release_host_motor();
|
|
|
+ if (host_x_steps !== 0)
|
|
|
+ $fatal(1, "pre-asserted LS should yield zero X rising edges, got %0d", host_x_steps);
|
|
|
+ $display("PASS_SECTION_PREASSERTED steps=%0d", host_x_steps);
|
|
|
+
|
|
|
+ // Y truncate on LS while Z continues to full 450 (axis independence).
|
|
|
+ host_y_steps = 0;
|
|
|
+ host_z_steps = 0;
|
|
|
+ prev_y_step = 1'b0;
|
|
|
+ prev_z_step = 1'b0;
|
|
|
+ count_y_steps = 1'b1;
|
|
|
+ count_z_steps = 1'b1;
|
|
|
+ x_limit_ls = 1'b0;
|
|
|
+ y_limit_ls = 1'b0;
|
|
|
+ z_limit_ls = 1'b0;
|
|
|
+ y_limit_hs = 1'b0;
|
|
|
+ z_limit_hs = 1'b0;
|
|
|
+ drain_limit_sync();
|
|
|
+ start_host_motor(3'b110, 3'b110);
|
|
|
+ begin : wait_y_steps
|
|
|
+ integer guard;
|
|
|
+ guard = 0;
|
|
|
+ while (host_y_steps < 5) begin
|
|
|
+ @(posedge sys_clk);
|
|
|
+ guard = guard + 1;
|
|
|
+ if (guard > 200000)
|
|
|
+ $fatal(1, "timeout waiting for Y steps before LS truncate");
|
|
|
+ end
|
|
|
+ end
|
|
|
+ y_limit_ls = 1'b1;
|
|
|
+ drain_limit_sync();
|
|
|
+ if (y_step !== 1'b0)
|
|
|
+ $fatal(1, "runtime LS truncate failed on Y");
|
|
|
+ begin : wait_z_continue
|
|
|
+ integer z_before;
|
|
|
+ integer guard;
|
|
|
+ z_before = host_z_steps;
|
|
|
+ guard = 0;
|
|
|
+ while (host_z_steps < z_before + 8) begin
|
|
|
+ @(posedge sys_clk);
|
|
|
+ guard = guard + 1;
|
|
|
+ if (guard > 200000)
|
|
|
+ $fatal(1, "Z did not continue after Y LS truncate");
|
|
|
+ end
|
|
|
+ end
|
|
|
+ // Abort remaining Z motion instead of waiting for full 450 (wall-time).
|
|
|
+ @(negedge sys_clk);
|
|
|
+ force dut.watchdog_timeout_event = 1'b1;
|
|
|
+ @(posedge sys_clk);
|
|
|
+ @(negedge sys_clk);
|
|
|
+ force dut.watchdog_timeout_event = 1'b0;
|
|
|
+ release_host_motor();
|
|
|
+ count_y_steps = 1'b0;
|
|
|
+ count_z_steps = 1'b0;
|
|
|
+ if (host_y_steps >= HOST_STEPS)
|
|
|
+ $fatal(1, "Y not truncated before 450, got %0d", host_y_steps);
|
|
|
+ $display("PASS_SECTION_YZ_INDEP y=%0d z=%0d", host_y_steps, host_z_steps);
|
|
|
|
|
|
- // Watchdog abort: external STEP low; EN remains permanent_high.
|
|
|
+ // After synced target limit, no new X rising edges.
|
|
|
host_x_steps = 0;
|
|
|
+ post_limit_rise = 0;
|
|
|
prev_x_step = 1'b0;
|
|
|
x_limit_ls = 1'b0;
|
|
|
x_limit_hs = 1'b0;
|
|
|
+ y_limit_ls = 1'b0;
|
|
|
drain_limit_sync();
|
|
|
start_host_motor(3'b001, 3'b001);
|
|
|
+ while (host_x_steps < 4) @(posedge sys_clk);
|
|
|
+ x_limit_ls = 1'b1;
|
|
|
+ drain_limit_sync();
|
|
|
+ watch_x_rises = 1'b1;
|
|
|
+ repeat (200) @(posedge sys_clk);
|
|
|
+ watch_x_rises = 1'b0;
|
|
|
+ if (post_limit_rise !== 0)
|
|
|
+ $fatal(1, "new X rising edges after synced LS: %0d", post_limit_rise);
|
|
|
+ force dut.watchdog_timeout_event = 1'b1;
|
|
|
+ @(posedge sys_clk);
|
|
|
+ force dut.watchdog_timeout_event = 1'b0;
|
|
|
+ release_host_motor();
|
|
|
+ $display("PASS_SECTION_NO_RISE post=%0d", post_limit_rise);
|
|
|
+
|
|
|
+ // Watchdog abort: all external STEP low; EN remains permanent_high.
|
|
|
+ host_x_steps = 0;
|
|
|
+ host_y_steps = 0;
|
|
|
+ host_z_steps = 0;
|
|
|
+ prev_x_step = 1'b0;
|
|
|
+ count_y_steps = 1'b1;
|
|
|
+ count_z_steps = 1'b1;
|
|
|
+ x_limit_ls = 1'b0;
|
|
|
+ y_limit_ls = 1'b0;
|
|
|
+ z_limit_ls = 1'b0;
|
|
|
+ drain_limit_sync();
|
|
|
+ start_host_motor(3'b111, 3'b111);
|
|
|
while (host_x_steps < 3) @(posedge sys_clk);
|
|
|
@(negedge sys_clk);
|
|
|
force dut.watchdog_timeout_event = 1'b1;
|
|
|
@(posedge sys_clk);
|
|
|
#1;
|
|
|
- if (x_step !== 1'b0)
|
|
|
- $fatal(1, "watchdog abort left x_step high");
|
|
|
+ if (x_step !== 1'b0 || y_step !== 1'b0 || z_step !== 1'b0)
|
|
|
+ $fatal(1, "watchdog abort left STEP high xyz=%b%b%b", x_step, y_step, z_step);
|
|
|
if (motor_en_n !== 1'b1)
|
|
|
$fatal(1, "motor_en_n dropped after watchdog (expected permanent_high)");
|
|
|
@(negedge sys_clk);
|
|
|
force dut.watchdog_timeout_event = 1'b0;
|
|
|
release_host_motor();
|
|
|
+ count_y_steps = 1'b0;
|
|
|
+ count_z_steps = 1'b0;
|
|
|
|
|
|
if (!dut.startup_done)
|
|
|
$fatal(1, "startup_done was not sticky through runtime limit stops");
|