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.

123 lines
2.7 KiB

  1. -- Simple UART loop with UART RX & TX units and FIFO buffer
  2. -- between. It's working at baudrate 9600.
  3. library ieee ;
  4. use ieee.std_logic_1164.all;
  5. use ieee.numeric_std.all;
  6. library gatemate;
  7. use gatemate.components.all;
  8. entity uart_loop is
  9. port (
  10. clk_i : in std_logic; -- 10 MHz clock
  11. rst_n_i : in std_logic; -- SW3 button
  12. uart_rx_i : in std_logic; -- PMODA IO3
  13. uart_tx_o : out std_logic -- PMODA IO5
  14. );
  15. end entity uart_loop;
  16. architecture rtl of uart_loop is
  17. signal s_pll_clk : std_logic;
  18. signal s_pll_lock : std_logic;
  19. signal s_rst_n : std_logic;
  20. signal s_usr_rstn : std_logic;
  21. signal s_uart_rx_tdata : std_logic_vector(7 downto 0);
  22. signal s_uart_rx_tvalid : std_logic;
  23. signal s_uart_rx_tready : std_logic;
  24. signal s_uart_tx_tdata : std_logic_vector(7 downto 0);
  25. signal s_uart_tx_tvalid : std_logic;
  26. signal s_uart_tx_tready : std_logic;
  27. begin
  28. pll : CC_PLL
  29. generic map (
  30. REF_CLK => "10",
  31. OUT_CLK => "10",
  32. PERF_MD => "SPEED"
  33. )
  34. port map (
  35. CLK_REF => clk_i,
  36. CLK_FEEDBACK => '0',
  37. USR_CLK_REF => '0',
  38. USR_LOCKED_STDY_RST => '0',
  39. USR_PLL_LOCKED_STDY => open,
  40. USR_PLL_LOCKED => s_pll_lock,
  41. CLK270 => open,
  42. CLK180 => open,
  43. CLK0 => s_pll_clk,
  44. CLK90 => open,
  45. CLK_REF_OUT => open
  46. );
  47. cc_usr_rstn_inst : CC_USR_RSTN
  48. port map (
  49. USR_RSTN => s_usr_rstn
  50. );
  51. uart_rx : entity work.uart_rx
  52. generic map (
  53. CLK_DIV => 1040
  54. )
  55. port map (
  56. -- globals
  57. rst_n_i => s_rst_n,
  58. clk_i => s_pll_clk,
  59. -- axis user interface
  60. tdata_o => s_uart_rx_tdata,
  61. tvalid_o => s_uart_rx_tvalid,
  62. tready_i => s_uart_rx_tready,
  63. -- uart interface
  64. rx_i => uart_rx_i
  65. );
  66. axis_fifo : entity work.axis_fifo
  67. generic map (
  68. DEPTH => 32,
  69. WIDTH => 8
  70. )
  71. port map (
  72. -- globals
  73. rst_n_i => s_rst_n,
  74. clk_i => s_pll_clk,
  75. -- uart rx interface
  76. tdata_i => s_uart_rx_tdata,
  77. tvalid_i => s_uart_rx_tvalid,
  78. tready_o => s_uart_rx_tready,
  79. -- uart tx interface
  80. tdata_o => s_uart_tx_tdata,
  81. tvalid_o => s_uart_tx_tvalid,
  82. tready_i => s_uart_tx_tready
  83. );
  84. -- s_uart_tx_tdata <= s_uart_rx_tdata;
  85. -- s_uart_tx_tvalid <= s_uart_rx_tvalid;
  86. -- s_uart_rx_tready <= s_uart_tx_tready;
  87. uart_tx : entity work.uart_tx
  88. generic map (
  89. CLK_DIV => 1040
  90. )
  91. port map (
  92. -- globals
  93. rst_n_i => s_rst_n,
  94. clk_i => s_pll_clk,
  95. -- axis user interface
  96. tdata_i => s_uart_tx_tdata,
  97. tvalid_i => s_uart_tx_tvalid,
  98. tready_o => s_uart_tx_tready,
  99. -- uart interface
  100. tx_o => uart_tx_o
  101. );
  102. s_rst_n <= rst_n_i and s_pll_lock and s_usr_rstn;
  103. end architecture;