|
| 1 | +-------------------------------------------------------------------------------- |
| 2 | +-- PROJECT: SIMPLE UART FOR FPGA |
| 3 | +-------------------------------------------------------------------------------- |
| 4 | +-- AUTHORS: Jakub Cabal <jakubcabal@gmail.com> |
| 5 | +-- LICENSE: The MIT License, please read LICENSE file |
| 6 | +-- WEBSITE: https://github.com/jakubcabal/uart-for-fpga |
| 7 | +-------------------------------------------------------------------------------- |
| 8 | + |
| 9 | +library IEEE; |
| 10 | +use IEEE.STD_LOGIC_1164.ALL; |
| 11 | +use IEEE.NUMERIC_STD.ALL; |
| 12 | + |
| 13 | +-- TOP MODULE OF UART 2 WISHBONE EXAMPLE FOR CYC1000 BOARD |
| 14 | +-- ======================================================= |
| 15 | + |
| 16 | +entity UART2WB_FPGA_CYC1000 is |
| 17 | + Port ( |
| 18 | + CLK_12M : in std_logic; -- system clock 12 MHz |
| 19 | + RST_BTN_N : in std_logic; -- low active reset button |
| 20 | + -- UART INTERFACE |
| 21 | + UART_RXD : in std_logic; |
| 22 | + UART_TXD : out std_logic |
| 23 | + ); |
| 24 | +end entity; |
| 25 | + |
| 26 | +architecture RTL of UART2WB_FPGA_CYC1000 is |
| 27 | + |
| 28 | + signal rst_btn : std_logic; |
| 29 | + signal reset : std_logic; |
| 30 | + |
| 31 | + signal wb_cyc : std_logic; |
| 32 | + signal wb_stb : std_logic; |
| 33 | + signal wb_we : std_logic; |
| 34 | + signal wb_addr : std_logic_vector(15 downto 0); |
| 35 | + signal wb_dout : std_logic_vector(31 downto 0); |
| 36 | + signal wb_stall : std_logic; |
| 37 | + signal wb_ack : std_logic; |
| 38 | + signal wb_din : std_logic_vector(31 downto 0); |
| 39 | + |
| 40 | + signal debug_reg_sel : std_logic; |
| 41 | + signal debug_reg_we : std_logic; |
| 42 | + signal debug_reg : std_logic_vector(31 downto 0); |
| 43 | + |
| 44 | +begin |
| 45 | + |
| 46 | + rst_btn <= not RST_BTN_N; |
| 47 | + |
| 48 | + rst_sync_i : entity work.RST_SYNC |
| 49 | + port map ( |
| 50 | + CLK => CLK_12M, |
| 51 | + ASYNC_RST => rst_btn, |
| 52 | + SYNCED_RST => reset |
| 53 | + ); |
| 54 | + |
| 55 | + uart2wbm_i : entity work.UART2WBM |
| 56 | + generic map ( |
| 57 | + CLK_FREQ => 12e6, |
| 58 | + BAUD_RATE => 9600 |
| 59 | + ) |
| 60 | + port map ( |
| 61 | + CLK => CLK_12M, |
| 62 | + RST => reset, |
| 63 | + -- UART INTERFACE |
| 64 | + UART_TXD => UART_TXD, |
| 65 | + UART_RXD => UART_RXD, |
| 66 | + -- WISHBONE MASTER INTERFACE |
| 67 | + WB_CYC => wb_cyc, |
| 68 | + WB_STB => wb_stb, |
| 69 | + WB_WE => wb_we, |
| 70 | + WB_ADDR => wb_addr, |
| 71 | + WB_DOUT => wb_dout, |
| 72 | + WB_STALL => wb_stall, |
| 73 | + WB_ACK => wb_ack, |
| 74 | + WB_DIN => wb_din |
| 75 | + ); |
| 76 | + |
| 77 | + debug_reg_sel <= '1' when (wb_addr = X"0004") else '0'; |
| 78 | + debug_reg_we <= wb_stb and wb_we and debug_reg_sel; |
| 79 | + |
| 80 | + debug_reg_p : process (CLK_12M) |
| 81 | + begin |
| 82 | + if (rising_edge(CLK_12M)) then |
| 83 | + if (debug_reg_we = '1') then |
| 84 | + debug_reg <= wb_din; |
| 85 | + end if; |
| 86 | + end if; |
| 87 | + end process; |
| 88 | + |
| 89 | + wb_stall <= '0'; |
| 90 | + |
| 91 | + wb_ack_reg_p : process (CLK_12M) |
| 92 | + begin |
| 93 | + if (rising_edge(CLK_12M)) then |
| 94 | + wb_ack <= wb_cyc and wb_stb; |
| 95 | + end if; |
| 96 | + end process; |
| 97 | + |
| 98 | + wb_dout_reg_p : process (CLK_12M) |
| 99 | + begin |
| 100 | + if (rising_edge(CLK_12M)) then |
| 101 | + case wb_addr is |
| 102 | + when X"0000" => |
| 103 | + wb_dout <= X"20210406"; |
| 104 | + when X"0004" => |
| 105 | + wb_dout <= debug_reg; |
| 106 | + when others => |
| 107 | + wb_dout <= X"DEADCAFE"; |
| 108 | + end case; |
| 109 | + end if; |
| 110 | + end process; |
| 111 | + |
| 112 | +end architecture; |
0 commit comments