-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_top.vhdl
179 lines (144 loc) · 4.01 KB
/
example_top.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
-- Example for cmd_proc: the simple command processor
-- Copyright 2019, 2020 Marc Joosen
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity example_top is
port (
clk: in std_logic;
cmd_txd: out std_logic;
cmd_rxd: in std_logic;
output: out std_logic_vector(7 downto 0)
);
end;
architecture rtl of example_top is
signal logic_0: std_logic := '0';
signal reset: std_logic := '0';
signal temp: std_logic_vector(31 downto 0) := (others => '0');
signal count: unsigned(31 downto 0) := (others => '0');
signal out_i: std_logic_vector(7 downto 0) := (others => '0');
-- UART interface
signal tx_data: std_logic_vector(7 downto 0);
signal tx_req: std_logic := '0';
signal tx_brk: std_logic := '0';
signal tx_busy: std_logic;
signal rx_data: std_logic_vector(7 downto 0);
signal rx_data_valid: std_logic := '0';
signal rx_brk: std_logic;
signal rx_err: std_logic;
-- command processor
signal cmd_proc_reset: std_logic;
signal rd_data: std_logic_vector(31 downto 0);
signal wr_data: std_logic_vector(31 downto 0);
signal address: std_logic_vector(15 downto 0);
-- signal read_req: std_logic;
signal write_req: std_logic;
begin
logic_0 <= '0';
reset <= '0';
-- register interface -------------------------------------------------
read_multiplexer: process(all)
begin
rd_data <= (others => '0');
case address is
when x"0000" =>
rd_data <= x"01020304"; -- version
when x"0001" =>
rd_data(7 downto 0) <= out_i; -- debug pins
when x"0002" =>
rd_data <= temp; -- test
when x"0100" =>
rd_data <= std_logic_vector(count); -- clock cycle counter
when others =>
rd_data <= (others => '0');
end case;
end process;
-- infer all registers here
write_decoder: process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
output <= (others => '0');
else
if write_req = '1' then
case address is
when x"0001" =>
out_i <= wr_data(7 downto 0);
when x"0002" =>
temp <= wr_data;
when others =>
null;
end case;
end if;
end if;
end if;
end process;
-- counter ------------------------------------------------------------
counter: process(clk)
begin
if rising_edge(clk) then
if reset = '1' then
count <= (others => '0');
else
count <= count + 1;
end if;
end if;
end process;
output <= out_i;
-- command interface --------------------------------------------------
cmd_uart: entity work.fluart
generic map(
CLK_FREQ => 50_000_000, -- main frequency (Hz)
SER_FREQ => 115200, -- bit rate (bps)
BRK_LEN => 10
)
port map (
clk => clk,
reset => reset,
txd => cmd_txd,
rxd => cmd_rxd,
tx_data => tx_data,
tx_req => tx_req,
tx_brk => logic_0,
tx_busy => tx_busy,
tx_end => open,
rx_data => rx_data,
rx_data_valid => rx_data_valid,
rx_brk => rx_brk,
rx_err => rx_err
);
cmd_proc_reset <= reset or rx_brk or rx_err;
cmd_proc: entity work.cmd_proc
generic map (
ADDR_SIZE => 16,
DATA_SIZE => 32
)
port map (
clk => clk,
reset => cmd_proc_reset,
-- UART interface
rx_data => rx_data,
rx_data_valid => rx_data_valid,
tx_data => tx_data,
tx_req => tx_req,
tx_busy => tx_busy,
-- user logic interface
address => address,
rd_data => rd_data,
wr_data => wr_data,
read_req => open,
write_req => write_req
);
end architecture;