You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.1 KiB

  1. `timescale 1 ns/10 ps // time-unit = 1 ns, precision = 10 ps
  2. // simplified CC_PLL model
  3. module CC_PLL #(
  4. parameter REF_CLK = "", // e.g. "10.0"
  5. parameter OUT_CLK = "", // e.g. "50.0"
  6. parameter PERF_MD = "", // LOWPOWER, ECONOMY, SPEED
  7. parameter LOW_JITTER = 1,
  8. parameter CI_FILTER_CONST = 2,
  9. parameter CP_FILTER_CONST = 4
  10. )(
  11. input CLK_REF, CLK_FEEDBACK, USR_CLK_REF,
  12. input USR_LOCKED_STDY_RST, USR_SET_SEL,
  13. output USR_PLL_LOCKED_STDY, USR_PLL_LOCKED,
  14. output CLK270, CLK180, CLK90, CLK0, CLK_REF_OUT
  15. );
  16. reg r_pll_clk;
  17. reg r_user_pll_locked;
  18. // OUT_FREQ = 1 MHz
  19. integer clk_half_period = 50;
  20. initial begin
  21. r_pll_clk = 1'b0;
  22. r_user_pll_locked = 1'b1;
  23. end
  24. always #clk_half_period r_pll_clk = ~r_pll_clk;
  25. assign CLK0 = r_pll_clk;
  26. assign USR_PLL_LOCKED = r_user_pll_locked;
  27. endmodule
  28. // simplified CC_CFG_END model
  29. module CC_CFG_END (
  30. output CFG_END
  31. );
  32. assign CFG_END = 1'b1;
  33. endmodule
  34. module tb_uart_trng;
  35. // DUT in/out
  36. reg clk = 1'b0;
  37. reg rst_n = 1'b1;
  38. reg uart_tx;
  39. // Testbench variables
  40. reg [7:0] tx_data = 8'h0;
  41. reg [7:0] rx_data = 8'h0;
  42. // Testbench 1/2 clock period
  43. localparam clk_half_period = 50;
  44. // UART period calculation (9600 baud)
  45. localparam uart_bit_period = 1000000000 / 9600;
  46. localparam uart_bit_half_period = uart_bit_period/2;
  47. uart_trng UUT (.clk_i(clk), .rst_n_i(rst_n), .uart_tx_o(uart_tx));
  48. // set dumpfile
  49. initial begin
  50. $dumpfile ("tb_uart_trng.fst");
  51. $dumpvars (0, tb_uart_trng);
  52. end
  53. // Setup simulation
  54. initial begin
  55. #1 rst_n = 1'b0;
  56. #120 rst_n = 1'b1;
  57. end
  58. // Generate 10 mhz clock
  59. always #clk_half_period clk = !clk;
  60. // Checker
  61. initial begin
  62. @(posedge rst_n)
  63. for (reg [7:0] rx = 0; rx < 32; rx = rx + 1) begin
  64. @(negedge uart_tx)
  65. #uart_bit_period;
  66. #uart_bit_half_period;
  67. for (integer i = 0; i < 7; i = i + 1) begin
  68. rx_data[i] = uart_tx;
  69. #uart_bit_period;
  70. end
  71. $display ("UART recv: 0x%h", rx_data);
  72. end
  73. $display ("UART tests finished");
  74. $finish;
  75. end
  76. endmodule