prod2u_p4_cdc_sync_depth_tb.v 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. `timescale 1ns/1ps
  2. module prod2u_p4_cdc_sync_depth_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg limit_raw = 1'b0;
  6. always #5 clk = ~clk;
  7. prod2u_p4_axis_executor #(
  8. .STANDARD_STEPS(4),
  9. .LIMIT_CONFIRM_US(8),
  10. .DIR_SETUP_US(2),
  11. .SPEED0_HALF_US(2),
  12. .SPEED1_HALF_US(2),
  13. .SPEED2_HALF_US(2),
  14. .SPEED3_HALF_US(2)
  15. ) dut (
  16. .clk(clk),
  17. .rst_n(rst_n),
  18. .tick_1us(1'b1),
  19. .force_stop(1'b0),
  20. .limit_raw(limit_raw),
  21. .jog_start(1'b0),
  22. .jog_dir(1'b0),
  23. .jog_speed_code(2'd0),
  24. .jog_steps(16'd1),
  25. .standard_start(1'b0),
  26. .standard_target_open(1'b0),
  27. .step_out(),
  28. .dir_out(),
  29. .busy(),
  30. .drive_active(),
  31. .position_valid(),
  32. .current_aperture(),
  33. .target_aperture()
  34. );
  35. task expect_pipe;
  36. input [2:0] expected;
  37. input [8*48-1:0] label_text;
  38. begin
  39. @(posedge clk);
  40. #1;
  41. if (dut.limit_sync_pipe !== expected) begin
  42. $display("CDC_FAIL %0s pipe=%03b expected=%03b",
  43. label_text, dut.limit_sync_pipe, expected);
  44. $fatal(1);
  45. end
  46. end
  47. endtask
  48. initial begin
  49. repeat (3) @(negedge clk);
  50. rst_n = 1'b1;
  51. expect_pipe(3'b000, "reset low");
  52. @(negedge clk);
  53. limit_raw = 1'b1;
  54. expect_pipe(3'b001, "rise stage 1");
  55. expect_pipe(3'b011, "rise stage 2");
  56. expect_pipe(3'b111, "rise stage 3");
  57. @(negedge clk);
  58. limit_raw = 1'b0;
  59. expect_pipe(3'b110, "fall stage 1");
  60. expect_pipe(3'b100, "fall stage 2");
  61. expect_pipe(3'b000, "fall stage 3");
  62. $display("PASS: prod2u_p4_cdc_sync_depth_tb");
  63. $finish;
  64. end
  65. endmodule