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.

80 lines
1.8 KiB

  1. library ieee ;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use std.env.all;
  5. entity tb_uart_trng is
  6. end entity tb_uart_trng;
  7. architecture sim of tb_uart_trng is
  8. signal s_clk : std_logic := '1';
  9. signal s_rst_n : std_logic := '0';
  10. signal s_uart_tx : std_logic;
  11. constant c_baudrate : natural := 9600;
  12. constant c_period_ns : time := 1000000000 / c_baudrate * ns;
  13. procedure uart_send ( data : in std_logic_vector(7 downto 0);
  14. signal tx : out std_logic) is
  15. begin
  16. report "UART send: 0x" & to_hstring(data);
  17. tx <= '0';
  18. wait for c_period_ns;
  19. for i in 0 to 7 loop
  20. tx <= data(i);
  21. wait for c_period_ns;
  22. end loop;
  23. tx <= '1';
  24. wait for c_period_ns;
  25. end procedure;
  26. procedure uart_recv ( data : out std_logic_vector(7 downto 0);
  27. signal rx : in std_logic) is
  28. begin
  29. wait until not rx;
  30. wait for c_period_ns; -- Skip start bit
  31. wait for c_period_ns/2;
  32. for i in 0 to 7 loop
  33. data(i) := rx;
  34. wait for c_period_ns;
  35. end loop;
  36. report "UART recv: 0x" & to_hstring(data);
  37. end procedure;
  38. begin
  39. dut : entity work.uart_trng
  40. generic map (
  41. SIM => 1
  42. )
  43. port map (
  44. clk_i => s_clk,
  45. rst_n_i => s_rst_n,
  46. uart_tx_o => s_uart_tx
  47. );
  48. s_rst_n <= '1' after 120 ns;
  49. s_clk <= not s_clk after 50 ns;
  50. ReceiveP : process is
  51. type t_exp is array (0 to 7) of std_logic_vector(7 downto 0);
  52. variable v_exp : t_exp;
  53. variable v_data : std_logic_vector(7 downto 0);
  54. begin
  55. wait until s_rst_n;
  56. wait until rising_edge(s_clk);
  57. -- First read all registers
  58. for i in 0 to 7 loop
  59. uart_recv(v_data, s_uart_tx);
  60. end loop;
  61. wait for 200 us;
  62. report "Simulation finished :-)";
  63. stop(0);
  64. end process;
  65. end architecture;