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.

155 lines
3.8 KiB

  1. -- This design implements a AES-CTR unit which 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 AES-CTR registers.
  6. library ieee ;
  7. use ieee.std_logic_1164.all;
  8. use ieee.numeric_std.all;
  9. library gatemate;
  10. use gatemate.components.all;
  11. library cryptocores;
  12. use work.uart_aes_types.all;
  13. entity uart_aes is
  14. port (
  15. clk_i : in std_logic; -- 10 MHz clock
  16. rst_n_i : in std_logic; -- SW3 button
  17. uart_rx_i : in std_logic; -- PMODA IO3
  18. uart_tx_o : out std_logic; -- PMODA IO5
  19. led_n_o : out std_logic_vector(3 downto 0)
  20. );
  21. end entity uart_aes;
  22. architecture rtl of uart_aes 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_usr_rstn : std_logic;
  27. signal s_uart_rx_tdata : std_logic_vector(7 downto 0);
  28. signal s_uart_rx_tvalid : std_logic;
  29. signal s_uart_rx_tready : std_logic;
  30. signal s_uart_tx_tdata : std_logic_vector(7 downto 0);
  31. signal s_uart_tx_tvalid : std_logic;
  32. signal s_uart_tx_tready : std_logic;
  33. signal s_ctrl_aes_m2s : t_axis_ctrl_aes_m2s;
  34. signal s_ctrl_aes_s2m : t_axis_s2m;
  35. signal s_aes_ctrl_m2s : t_axis_aes_ctrl_m2s;
  36. signal s_aes_ctrl_s2m : t_axis_s2m;
  37. begin
  38. pll : CC_PLL
  39. generic map (
  40. REF_CLK => "10",
  41. OUT_CLK => "10",
  42. PERF_MD => "SPEED"
  43. )
  44. port map (
  45. CLK_REF => clk_i,
  46. CLK_FEEDBACK => '0',
  47. USR_CLK_REF => '0',
  48. USR_LOCKED_STDY_RST => '0',
  49. USR_PLL_LOCKED_STDY => open,
  50. USR_PLL_LOCKED => s_pll_lock,
  51. CLK270 => open,
  52. CLK180 => open,
  53. CLK0 => s_pll_clk,
  54. CLK90 => open,
  55. CLK_REF_OUT => open
  56. );
  57. cc_usr_rstn_inst : CC_USR_RSTN
  58. port map (
  59. USR_RSTN => s_usr_rstn
  60. );
  61. uart_rx : entity work.uart_rx
  62. generic map (
  63. CLK_DIV => 1040
  64. )
  65. port map (
  66. -- globals
  67. rst_n_i => s_rst_n,
  68. clk_i => s_pll_clk,
  69. -- axis user interface
  70. tdata_o => s_uart_rx_tdata,
  71. tvalid_o => s_uart_rx_tvalid,
  72. tready_i => s_uart_rx_tready,
  73. -- uart interface
  74. rx_i => uart_rx_i
  75. );
  76. uart_ctrl : entity work.uart_ctrl
  77. port map (
  78. -- globals
  79. rst_n_i => s_rst_n,
  80. clk_i => s_pll_clk,
  81. -- uart rx interface
  82. tdata_i => s_uart_rx_tdata,
  83. tvalid_i => s_uart_rx_tvalid,
  84. tready_o => s_uart_rx_tready,
  85. -- uart tx interface
  86. tdata_o => s_uart_tx_tdata,
  87. tvalid_o => s_uart_tx_tvalid,
  88. tready_i => s_uart_tx_tready,
  89. -- aes out
  90. ctrl_aes_o => s_ctrl_aes_m2s,
  91. ctrl_aes_i => s_ctrl_aes_s2m,
  92. -- aes in
  93. aes_ctrl_i => s_aes_ctrl_m2s,
  94. aes_ctrl_o => s_aes_ctrl_s2m
  95. );
  96. aes_inst : entity cryptocores.ctraes
  97. port map (
  98. reset_i => s_rst_n,
  99. clk_i => s_pll_clk,
  100. start_i => s_ctrl_aes_m2s.tuser.start,
  101. nonce_i => s_ctrl_aes_m2s.tuser.nonce,
  102. key_i => s_ctrl_aes_m2s.tuser.key,
  103. data_i => s_ctrl_aes_m2s.tdata,
  104. valid_i => s_ctrl_aes_m2s.tvalid,
  105. accept_o => s_ctrl_aes_s2m.tready,
  106. data_o => s_aes_ctrl_m2s.tdata,
  107. valid_o => s_aes_ctrl_m2s.tvalid,
  108. accept_i => s_aes_ctrl_s2m.tready
  109. );
  110. uart_tx : entity work.uart_tx
  111. generic map (
  112. CLK_DIV => 1040
  113. )
  114. port map (
  115. -- globals
  116. rst_n_i => s_rst_n,
  117. clk_i => s_pll_clk,
  118. -- axis user interface
  119. tdata_i => s_uart_tx_tdata,
  120. tvalid_i => s_uart_tx_tvalid,
  121. tready_o => s_uart_tx_tready,
  122. -- uart interface
  123. tx_o => uart_tx_o
  124. );
  125. s_rst_n <= rst_n_i and s_pll_lock and s_usr_rstn;
  126. -- Lets some LEDs blink
  127. led_n_o(0) <= rst_n_i; -- reset button
  128. led_n_o(1) <= s_uart_rx_tready and s_uart_tx_tvalid; -- uart ctrl ready
  129. led_n_o(2) <= not s_uart_rx_tready; -- uart received
  130. led_n_o(3) <= not s_uart_tx_tvalid; -- uart send
  131. end architecture;