door_action_dispatcher_tb.v 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. `timescale 1ns/1ps
  2. // 3-axis dispatcher: byte8=Z, byte9=X, byte10=Y; 00/01/02; busy ignores new start.
  3. module door_action_dispatcher_tb;
  4. reg clk = 1'b0;
  5. reg rst_n = 1'b0;
  6. reg door_action_valid = 1'b0;
  7. reg [1:0] z_door_cmd = 2'd0;
  8. reg [1:0] exhaust_x_cmd = 2'd0;
  9. reg [1:0] exhaust_y_cmd = 2'd0;
  10. reg watchdog_abort = 1'b0;
  11. reg motor_busy = 1'b0;
  12. wire motor_start;
  13. wire [2:0] motor_active_mask;
  14. wire [2:0] motor_dir_mask;
  15. always #1 clk = ~clk;
  16. door_action_dispatcher #(.OPEN_DIR(0), .CLOSE_DIR(1), .AXIS_COUNT(3)) dut (
  17. .clk(clk), .rst_n(rst_n),
  18. .door_action_valid(door_action_valid),
  19. .z_door_cmd(z_door_cmd),
  20. .exhaust_x_cmd(exhaust_x_cmd),
  21. .exhaust_y_cmd(exhaust_y_cmd),
  22. .watchdog_abort(watchdog_abort),
  23. .motor_start(motor_start),
  24. .motor_active_mask(motor_active_mask),
  25. .motor_dir_mask(motor_dir_mask),
  26. .motor_busy(motor_busy)
  27. );
  28. task pulse_action;
  29. input [1:0] z_cmd;
  30. input [1:0] x_cmd;
  31. input [1:0] y_cmd;
  32. begin
  33. @(negedge clk);
  34. z_door_cmd = z_cmd;
  35. exhaust_x_cmd = x_cmd;
  36. exhaust_y_cmd = y_cmd;
  37. door_action_valid = 1'b1;
  38. @(posedge clk);
  39. @(negedge clk);
  40. door_action_valid = 1'b0;
  41. end
  42. endtask
  43. initial begin
  44. repeat (3) @(posedge clk);
  45. rst_n = 1'b1;
  46. pulse_action(2'd1, 2'd1, 2'd1);
  47. if (!motor_start) $fatal(1, "open all: missing motor_start");
  48. if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b000)
  49. $fatal(1, "open all mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  50. pulse_action(2'd2, 2'd2, 2'd2);
  51. if (!motor_start) $fatal(1, "close all: missing motor_start");
  52. if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b111)
  53. $fatal(1, "close all mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  54. pulse_action(2'd1, 2'd2, 2'd1);
  55. if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b001)
  56. $fatal(1, "mixed open/close mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  57. pulse_action(2'd0, 2'd0, 2'd0);
  58. if (motor_start) $fatal(1, "idle 00/00 must not start when not busy");
  59. // Z-only open: bit2 active, DIR=0.
  60. pulse_action(2'd1, 2'd0, 2'd0);
  61. if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
  62. $fatal(1, "Z open mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  63. // Busy ignores new command (mask/dir unchanged).
  64. motor_busy = 1'b1;
  65. pulse_action(2'd2, 2'd0, 2'd0);
  66. if (motor_start) $fatal(1, "busy must not re-pulse motor_start");
  67. if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
  68. $fatal(1, "busy must ignore new command mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  69. watchdog_abort = 1'b1;
  70. @(posedge clk);
  71. @(negedge clk);
  72. if (motor_active_mask !== 3'b000) $fatal(1, "watchdog abort must clear active_mask");
  73. $display("door_action_dispatcher_tb PASS");
  74. $finish;
  75. end
  76. endmodule