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.

137 lines
3.0 KiB

  1. -- This design implements a register file which can
  2. -- be accessed by an UART with 9600 baud
  3. --
  4. -- See into uart_ctrl.vhd for documentation of the protocol
  5. -- used to read / write the register file.
  6. library ieee ;
  7. use ieee.std_logic_1164.all;
  8. use ieee.numeric_std.all;
  9. use ieee.math_real.all;
  10. library gatemate;
  11. use gatemate.components.all;
  12. entity uart_trng is
  13. generic (
  14. SIM : natural := 0
  15. );
  16. port (
  17. clk_i : in std_logic; -- 10 MHz clock
  18. rst_n_i : in std_logic; -- SW3 button
  19. uart_tx_o : out std_logic -- PMODA IO5
  20. );
  21. end entity uart_trng;
  22. architecture rtl of uart_trng is
  23. signal s_pll_clk : std_logic;
  24. signal s_pll_lock : std_logic;
  25. signal s_rst_n : std_logic;
  26. signal s_cfg_end : std_logic;
  27. signal s_uart_tx_tdata : std_logic_vector(7 downto 0);
  28. signal s_uart_tx_tvalid : std_logic;
  29. signal s_uart_tx_tready : std_logic;
  30. signal s_firo_run : std_logic;
  31. signal s_firo_data : std_logic;
  32. begin
  33. pll : CC_PLL
  34. generic map (
  35. REF_CLK => "10",
  36. OUT_CLK => "10",
  37. PERF_MD => "SPEED"
  38. )
  39. port map (
  40. CLK_REF => clk_i,
  41. CLK_FEEDBACK => '0',
  42. USR_CLK_REF => '0',
  43. USR_LOCKED_STDY_RST => '0',
  44. USR_PLL_LOCKED_STDY => open,
  45. USR_PLL_LOCKED => s_pll_lock,
  46. CLK270 => open,
  47. CLK180 => open,
  48. CLK0 => s_pll_clk,
  49. CLK90 => open,
  50. CLK_REF_OUT => open
  51. );
  52. cfg_end_inst : CC_CFG_END
  53. port map (
  54. CFG_END => s_cfg_end
  55. );
  56. firo_ctrl : entity work.firo_ctrl
  57. generic map (
  58. EXTRACT => true
  59. )
  60. port map (
  61. -- system
  62. rst_n_i => s_rst_n,
  63. clk_i => s_pll_clk,
  64. -- axis in
  65. tvalid_i => '1',
  66. tready_o => open,
  67. -- axis out
  68. tdata_o => s_uart_tx_tdata,
  69. tvalid_o => s_uart_tx_tvalid,
  70. tready_i => s_uart_tx_tready,
  71. -- firo
  72. frun_o => s_firo_run,
  73. fdata_i => s_firo_data
  74. );
  75. SIMULATION : if (SIM /= 0) generate
  76. -- simple random bit generator
  77. RandomGenP : process (s_pll_clk, s_firo_run) is
  78. variable v_seed1, v_seed2 : positive := 1;
  79. variable v_real_rand : real;
  80. begin
  81. if (not s_firo_run) then
  82. s_firo_data <= '0';
  83. elsif (s_pll_clk'event) then
  84. uniform(v_seed1, v_seed2, v_real_rand);
  85. if (v_real_rand < 0.5) then
  86. s_firo_data <= '0';
  87. else
  88. s_firo_data <= '1';
  89. end if;
  90. end if;
  91. end process RandomGenP;
  92. else generate
  93. firo : entity work.firo
  94. generic map (
  95. TOGGLE => true
  96. )
  97. port map (
  98. frun_i => s_firo_run,
  99. fdata_o => s_firo_data
  100. );
  101. end generate;
  102. uart_tx : entity work.uart_tx
  103. generic map (
  104. CLK_DIV => 1040
  105. )
  106. port map (
  107. -- globals
  108. rst_n_i => s_rst_n,
  109. clk_i => s_pll_clk,
  110. -- axis user interface
  111. tdata_i => s_uart_tx_tdata,
  112. tvalid_i => s_uart_tx_tvalid,
  113. tready_o => s_uart_tx_tready,
  114. -- uart interface
  115. tx_o => uart_tx_o
  116. );
  117. s_rst_n <= rst_n_i and s_pll_lock and s_cfg_end;
  118. end architecture;