1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 | use ieee.std_logic_unsigned.all;
|
5 |
|
6 | entity sram_rx_tx is
|
7 | port( clk : in std_logic;
|
8 | ledr : out std_logic_vector (7 downto 0);
|
9 | sw : in std_logic_vector (2 downto 0);
|
10 | sram_adr : out std_logic_vector (17 downto 0);
|
11 | sram_io : inout std_logic_vector (15 downto 0);
|
12 | ub : out std_logic;
|
13 | lb : out std_logic;
|
14 | oe : out std_logic;
|
15 | ce : out std_logic;
|
16 | we : out std_logic;
|
17 | rxd : in std_logic;
|
18 | txd : out std_logic
|
19 | );
|
20 | end sram_rx_tx;
|
21 |
|
22 | architecture behavioral of sram_rx_tx is
|
23 |
|
24 | signal zustand : std_logic_vector (2 downto 0) := "000";
|
25 | signal data_read : std_logic_vector (15 downto 0) := "0000000000000000";
|
26 | signal data_write : std_logic_vector (15 downto 0) := "0000000000000000";
|
27 | signal read_write : std_logic := '0'; --(read = '1', write ='0')
|
28 |
|
29 | signal sr_adr : std_logic_vector (17 downto 0) := "000000000000000000";
|
30 | signal data_w : std_logic_vector (7 downto 0) := "00000000";
|
31 | signal data_r : std_logic_vector (7 downto 0) := "00000000";
|
32 |
|
33 | signal rx_en : std_logic;
|
34 | signal rx_data : std_logic_vector (7 downto 0);
|
35 |
|
36 | signal tx_start : std_logic;
|
37 | signal tx_data : std_logic_vector (7 downto 0);
|
38 |
|
39 | signal cnt : integer range 0 to 50000000;
|
40 | signal test : std_logic;
|
41 |
|
42 | component rs232_rx port(
|
43 | clk : in std_logic;
|
44 | rxd : in std_logic;
|
45 | rx_en : out std_logic;
|
46 | rx_data : out std_logic_vector (7 downto 0)
|
47 | );
|
48 | end component;
|
49 |
|
50 | component rs232_tx port(
|
51 | clk : in std_logic;
|
52 | txd : out std_logic;
|
53 | tx_start : in std_logic;
|
54 | tx_data : in std_logic_vector (7 downto 0)
|
55 | );
|
56 | end component;
|
57 |
|
58 | begin
|
59 | rx: rs232_rx
|
60 | port map(
|
61 | clk => clk,
|
62 | rxd => rxd,
|
63 | rx_en => rx_en,
|
64 | rx_data => rx_data
|
65 | );
|
66 |
|
67 | tx: rs232_tx
|
68 | port map(
|
69 | clk => clk,
|
70 | txd => txd,
|
71 | tx_start => tx_start,
|
72 | tx_data => tx_data
|
73 | );
|
74 |
|
75 | sram_io <= data_write when read_write='0' else (others=>'Z');
|
76 | data_read <= sram_io;
|
77 |
|
78 | ub <= '0';
|
79 | lb <= '0';
|
80 |
|
81 | process (clk)
|
82 | begin
|
83 | if rising_edge (clk) then
|
84 | if (zustand = "001") then
|
85 | sram_adr <= sr_adr;
|
86 | oe <= '0';
|
87 | ce <= '1';
|
88 | we <= '1';
|
89 |
|
90 | read_write <= '0';
|
91 | data_write <= "00000000" & data_w;
|
92 | zustand <= "010";
|
93 | elsif (zustand = "010") then
|
94 | sram_adr <= sr_adr;
|
95 | oe <= '0';
|
96 | ce <= '0';
|
97 | we <= '0';
|
98 |
|
99 | read_write <= '0';
|
100 | data_write <= "00000000" & data_w;
|
101 | zustand <= "000";
|
102 | end if;
|
103 |
|
104 | if (zustand = "011") then
|
105 | sram_adr <= sr_adr;
|
106 | oe <= '0';
|
107 | ce <= '0';
|
108 | we <= '1';
|
109 |
|
110 | read_write <= '1';
|
111 | zustand <= "100";
|
112 | elsif (zustand = "100") then
|
113 | sram_adr <= sr_adr;
|
114 | oe <= '0';
|
115 | ce <= '1';
|
116 | we <= '1';
|
117 |
|
118 | read_write <= '0';
|
119 | data_r <= data_read(7 downto 0);
|
120 | zustand <= "000";
|
121 | end if;
|
122 |
|
123 | if rx_en='1' then
|
124 | sr_adr <= sr_adr + 1;
|
125 | data_w <= rx_data;
|
126 | ledr <= rx_data;
|
127 | zustand <= "001";
|
128 | end if;
|
129 |
|
130 | if sw(0) = '1' then
|
131 | sram_io <= (others => 'Z');
|
132 | sram_adr <= (others => '0');
|
133 | we <= '1';
|
134 | ce <= '1';
|
135 | oe <= '1';
|
136 | end if;
|
137 |
|
138 | if sw(1) = '1' then
|
139 | sr_adr <= (others => '0');
|
140 | data_w <= (others => '0');
|
141 | data_r <= (others => '0');
|
142 | end if;
|
143 |
|
144 | if sw(2)='1' and test='1' and sr_adr < 255 then
|
145 | tx_start <= '1';
|
146 | zustand <= "011";
|
147 | sr_adr <= sr_adr+1;
|
148 | tx_data <= data_r;
|
149 | test <= '0';
|
150 | else
|
151 | tx_start<='0';
|
152 | end if;
|
153 |
|
154 | if (cnt > 1000000) then
|
155 | cnt <= 0;
|
156 | test <= '1';
|
157 | else
|
158 | cnt <= cnt + 1;
|
159 | end if;
|
160 |
|
161 | end if;
|
162 | end process;
|
163 | end behavioral;
|