door_action_dispatcher_axis3_tb.v 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. `timescale 1ns/1ps
  2. // AXIS_COUNT=3: intake on bit2, exhaust X/Y on bits 0/1. Byte8 semantics via
  3. // intake_door_cmd: 00 stop, 01 DIR=0, 02 DIR=1; latest wins.
  4. module door_action_dispatcher_axis3_tb;
  5. reg clk = 1'b0;
  6. reg rst_n = 1'b0;
  7. reg door_action_valid = 1'b0;
  8. reg [1:0] intake_door_cmd = 2'd0;
  9. reg [1:0] exhaust_x_cmd = 2'd0;
  10. reg [1:0] exhaust_y_cmd = 2'd0;
  11. reg watchdog_abort = 1'b0;
  12. reg motor_busy = 1'b0;
  13. wire motor_start;
  14. wire [2:0] motor_active_mask;
  15. wire [2:0] motor_dir_mask;
  16. always #1 clk = ~clk;
  17. door_action_dispatcher #(.OPEN_DIR(0), .CLOSE_DIR(1), .AXIS_COUNT(3)) dut (
  18. .clk(clk), .rst_n(rst_n),
  19. .door_action_valid(door_action_valid),
  20. .intake_door_cmd(intake_door_cmd),
  21. .exhaust_x_cmd(exhaust_x_cmd),
  22. .exhaust_y_cmd(exhaust_y_cmd),
  23. .watchdog_abort(watchdog_abort),
  24. .motor_start(motor_start),
  25. .motor_active_mask(motor_active_mask),
  26. .motor_dir_mask(motor_dir_mask),
  27. .motor_busy(motor_busy)
  28. );
  29. task pulse_action;
  30. input [1:0] intake_cmd;
  31. input [1:0] x_cmd;
  32. input [1:0] y_cmd;
  33. begin
  34. @(negedge clk);
  35. intake_door_cmd = intake_cmd;
  36. exhaust_x_cmd = x_cmd;
  37. exhaust_y_cmd = y_cmd;
  38. door_action_valid = 1'b1;
  39. @(posedge clk);
  40. @(negedge clk);
  41. door_action_valid = 1'b0;
  42. end
  43. endtask
  44. initial begin
  45. repeat (3) @(posedge clk);
  46. rst_n = 1'b1;
  47. // Intake open only -> bit2 active, DIR=0.
  48. pulse_action(2'd1, 2'd0, 2'd0);
  49. if (!motor_start) $fatal(1, "intake open missing motor_start");
  50. if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
  51. $fatal(1, "intake open mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  52. // Intake close.
  53. pulse_action(2'd2, 2'd0, 2'd0);
  54. if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b100)
  55. $fatal(1, "intake close mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  56. // All three axes mixed.
  57. pulse_action(2'd1, 2'd2, 2'd1);
  58. if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b001)
  59. $fatal(1, "mixed 3-axis mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
  60. // Latest-wins stop while busy.
  61. motor_busy = 1'b1;
  62. pulse_action(2'd0, 2'd0, 2'd0);
  63. if (!motor_start) $fatal(1, "busy stop missing motor_start");
  64. if (motor_active_mask !== 3'b000)
  65. $fatal(1, "busy stop active_mask=%b", motor_active_mask);
  66. $display("door_action_dispatcher_axis3_tb PASS");
  67. $finish;
  68. end
  69. endmodule