host_port_selector_tb.v 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. `timescale 1ns/1ps
  2. module host_port_selector_tb;
  3. reg clk = 0;
  4. reg rst_n = 0;
  5. reg rs_rx = 1;
  6. reg ttl_rx = 1;
  7. reg tx = 1;
  8. reg done = 0;
  9. wire selected_rx;
  10. wire rs_tx;
  11. wire ttl_tx;
  12. wire locked;
  13. wire select;
  14. wire rs_sync;
  15. wire ttl_sync;
  16. always #5 clk = ~clk;
  17. host_port_selector dut (
  18. .clk(clk), .rst_n(rst_n), .rs232_rx_async(rs_rx), .ttl_rx_async(ttl_rx),
  19. .shared_tx(tx), .transaction_done(done), .selected_rx(selected_rx),
  20. .rs232_tx(rs_tx), .ttl_tx(ttl_tx), .locked(locked), .port_sel(select),
  21. .rs232_rx_sync(rs_sync), .ttl_rx_sync(ttl_sync)
  22. );
  23. initial begin
  24. repeat (3) @(negedge clk);
  25. rst_n = 1;
  26. rs_rx = 0;
  27. repeat (4) @(negedge clk);
  28. if (!locked || select) $fatal;
  29. tx = 0;
  30. @(negedge clk);
  31. if (rs_tx !== 0 || ttl_tx !== 1) $fatal;
  32. rs_rx = 1;
  33. done = 1;
  34. repeat (4) @(negedge clk);
  35. done = 0;
  36. if (locked) $fatal;
  37. ttl_rx = 0;
  38. repeat (4) @(negedge clk);
  39. if (!locked || !select) $fatal;
  40. tx = 0;
  41. if (rs_tx !== 1 || ttl_tx !== 0) $fatal;
  42. $display("PASS: host_port_selector_tb");
  43. $finish;
  44. end
  45. endmodule