intake_solenoid_adapter_tb.v 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. `timescale 1ns/1ps
  2. module intake_solenoid_adapter_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg door_action_valid = 1'b0;
  6. reg [1:0] intake_door_cmd = 2'd0;
  7. reg watchdog_inactive = 1'b0;
  8. wire solenoid_out;
  9. always #1 clk = ~clk;
  10. intake_solenoid_adapter #(.OPEN_LEVEL(1'b1), .CLOSED_LEVEL(1'b0), .INACTIVE_LEVEL(1'b0)) dut (
  11. .clk(clk), .rst_n(rst_n), .door_action_valid(door_action_valid),
  12. .intake_door_cmd(intake_door_cmd), .watchdog_inactive(watchdog_inactive),
  13. .solenoid_out(solenoid_out)
  14. );
  15. task pulse_cmd;
  16. input [1:0] cmd;
  17. begin
  18. @(negedge clk);
  19. intake_door_cmd = cmd;
  20. door_action_valid = 1'b1;
  21. @(posedge clk);
  22. @(negedge clk);
  23. door_action_valid = 1'b0;
  24. end
  25. endtask
  26. initial begin
  27. repeat (3) @(posedge clk);
  28. rst_n = 1'b1;
  29. pulse_cmd(2'd1);
  30. if (solenoid_out !== 1'b1) $fatal(1, "open level");
  31. pulse_cmd(2'd0);
  32. if (solenoid_out !== 1'b1) $fatal(1, "hold open");
  33. pulse_cmd(2'd2);
  34. if (solenoid_out !== 1'b0) $fatal(1, "closed level");
  35. watchdog_inactive = 1'b1;
  36. @(posedge clk);
  37. @(negedge clk);
  38. if (solenoid_out !== 1'b0) $fatal(1, "watchdog inactive");
  39. $display("intake_solenoid_adapter_tb PASS");
  40. $finish;
  41. end
  42. endmodule