1 |
5 |
sergeykhbr |
-----------------------------------------------------------------------------
|
2 |
|
|
--! @file
|
3 |
|
|
--! @copyright Copyright 2017 GNSS Sensor Ltd. All right reserved.
|
4 |
|
|
--! @author Sergey Khabarov - sergeykhbr@gmail.com
|
5 |
|
|
--! @brief Testbench file for the TAP via UART
|
6 |
|
|
------------------------------------------------------------------------------
|
7 |
|
|
|
8 |
|
|
library ieee;
|
9 |
|
|
use ieee.std_logic_1164.all;
|
10 |
|
|
library std;
|
11 |
|
|
use std.textio.all;
|
12 |
|
|
library commonlib;
|
13 |
|
|
use commonlib.types_common.all;
|
14 |
|
|
use commonlib.types_util.all;
|
15 |
|
|
--! Technology definition library.
|
16 |
|
|
library techmap;
|
17 |
|
|
--! Technology constants definition.
|
18 |
|
|
use techmap.gencomp.all;
|
19 |
|
|
--! AMBA system bus specific library
|
20 |
|
|
library ambalib;
|
21 |
|
|
--! AXI4 configuration constants.
|
22 |
|
|
use ambalib.types_amba4.all;
|
23 |
|
|
--! Rocket-chip specific library
|
24 |
|
|
library misclib;
|
25 |
|
|
--! SOC top-level component declaration.
|
26 |
|
|
use misclib.types_misc.all;
|
27 |
|
|
--! Top-level implementaion library
|
28 |
|
|
library work;
|
29 |
|
|
--! Target dependable configuration: RTL, FPGA or ASIC.
|
30 |
|
|
use work.config_target.all;
|
31 |
|
|
--! Target independable configuration.
|
32 |
|
|
use work.config_common.all;
|
33 |
|
|
|
34 |
|
|
entity tap_uart_tb is
|
35 |
|
|
constant INCR_TIME : time := 3571 ps;--100 ns;--3571 ps;
|
36 |
|
|
end tap_uart_tb;
|
37 |
|
|
|
38 |
|
|
architecture behavior of tap_uart_tb is
|
39 |
|
|
constant UART_BIN_SIZE : integer := 24;
|
40 |
|
|
|
41 |
|
|
-- input/output signals:
|
42 |
|
|
signal i_rst : std_logic := '1';
|
43 |
|
|
signal i_nrst : std_logic;
|
44 |
|
|
signal i_clk : std_logic;
|
45 |
|
|
signal i_uart1_ctsn : std_logic := '0';
|
46 |
|
|
signal i_uart1_rd : std_logic := '1';
|
47 |
|
|
signal o_uart1_td : std_logic;
|
48 |
|
|
signal o_uart1_rtsn : std_logic;
|
49 |
|
|
|
50 |
|
|
signal uart_wr_str : std_logic;
|
51 |
|
|
signal uart_instr : string(1 to 256);
|
52 |
|
|
signal uart_busy : std_logic;
|
53 |
|
|
signal uart_bin_data : std_logic_vector(8*UART_BIN_SIZE-1 downto 0);
|
54 |
|
|
signal uart_bin_bytes_sz : integer;
|
55 |
|
|
|
56 |
|
|
signal aximi : nasti_master_in_vector;
|
57 |
|
|
signal aximo : nasti_master_out_vector;
|
58 |
|
|
signal axisi : nasti_slave_in_vector;
|
59 |
|
|
signal axiso : nasti_slaves_out_vector;
|
60 |
|
|
signal slv_cfg : nasti_slave_cfg_vector;
|
61 |
|
|
|
62 |
|
|
signal uarti : uart_in_type;
|
63 |
|
|
signal uarto : uart_out_type;
|
64 |
|
|
|
65 |
|
|
signal clk_cur: std_logic := '1';
|
66 |
|
|
signal check_clk_bus : std_logic := '0';
|
67 |
|
|
signal iClkCnt : integer := 0;
|
68 |
|
|
signal iErrCnt : integer := 0;
|
69 |
|
|
signal iErrCheckedCnt : integer := 0;
|
70 |
|
|
|
71 |
|
|
component uart_sim is
|
72 |
|
|
generic (
|
73 |
|
|
clock_rate : integer := 10;
|
74 |
|
|
binary_bytes_max : integer := 8;
|
75 |
|
|
use_binary : boolean := false
|
76 |
|
|
);
|
77 |
|
|
port (
|
78 |
|
|
rst : in std_logic;
|
79 |
|
|
clk : in std_logic;
|
80 |
|
|
wr_str : in std_logic;
|
81 |
|
|
instr : in string;
|
82 |
|
|
bin_data : in std_logic_vector(8*binary_bytes_max-1 downto 0);
|
83 |
|
|
bin_bytes_sz : in integer;
|
84 |
|
|
td : in std_logic;
|
85 |
|
|
rtsn : in std_logic;
|
86 |
|
|
rd : out std_logic;
|
87 |
|
|
ctsn : out std_logic;
|
88 |
|
|
busy : out std_logic
|
89 |
|
|
);
|
90 |
|
|
end component;
|
91 |
|
|
|
92 |
|
|
begin
|
93 |
|
|
|
94 |
|
|
clk_cur <= not clk_cur after 12.5 ns;
|
95 |
|
|
-- Process of reading
|
96 |
|
|
-- procReadingFile : process
|
97 |
|
|
-- variable clk_next: std_logic;
|
98 |
|
|
-- begin
|
99 |
|
|
|
100 |
|
|
-- wait for INCR_TIME;
|
101 |
|
|
|
102 |
|
|
-- while true loop
|
103 |
|
|
-- clk_next := not clk_cur;
|
104 |
|
|
-- if (clk_next = '1' and clk_cur = '0') then
|
105 |
|
|
-- check_clk_bus <= '1';
|
106 |
|
|
-- end if;
|
107 |
|
|
|
108 |
|
|
-- wait for 1 ps;
|
109 |
|
|
-- check_clk_bus <= '0';
|
110 |
|
|
-- clk_cur <= clk_next;
|
111 |
|
|
|
112 |
|
|
-- wait for INCR_TIME;
|
113 |
|
|
-- if clk_cur = '1' then
|
114 |
|
|
-- iClkCnt <= iClkCnt + 1;
|
115 |
|
|
-- end if;
|
116 |
|
|
|
117 |
|
|
-- end loop;
|
118 |
|
|
-- report "Total clocks checked: " & tost(iErrCheckedCnt) & " Errors: " & tost(iErrCnt);
|
119 |
|
|
-- wait for 1 sec;
|
120 |
|
|
-- end process procReadingFile;
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
i_clk <= clk_cur;
|
124 |
|
|
|
125 |
|
|
procSignal : process (i_clk, iClkCnt)
|
126 |
|
|
|
127 |
|
|
begin
|
128 |
|
|
if rising_edge(i_clk) then
|
129 |
|
|
|
130 |
|
|
--! @note to make sync. reset of the logic that are clocked by
|
131 |
|
|
--! htif_clk which is clock/512 by default.
|
132 |
|
|
if iClkCnt = 15 then
|
133 |
|
|
i_rst <= '0';
|
134 |
|
|
end if;
|
135 |
|
|
end if;
|
136 |
|
|
end process procSignal;
|
137 |
|
|
i_nrst <= not i_rst;
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
udatagen0 : process (i_clk, iClkCnt)
|
141 |
|
|
begin
|
142 |
|
|
-- 0x31 - magic number at the beginning of packet
|
143 |
|
|
if falling_edge(i_clk) then
|
144 |
|
|
uart_wr_str <= '0';
|
145 |
|
|
if iClkCnt = 82000 then
|
146 |
|
|
-- initialize baudrate detector
|
147 |
|
|
uart_wr_str <= '1';
|
148 |
|
|
uart_bin_data(8*UART_BIN_SIZE-1 downto 8*(UART_BIN_SIZE-3)) <= X"555555";
|
149 |
|
|
uart_bin_bytes_sz <= 3;
|
150 |
|
|
elsif iClkCnt = 108000 then
|
151 |
|
|
uart_wr_str <= '1';
|
152 |
|
|
-- read 4 bytes at address: 0x00000000.10000004 => 04 00 00 10.00 00 00 00
|
153 |
|
|
uart_bin_data(8*UART_BIN_SIZE-1 downto 8*(UART_BIN_SIZE-10)) <= X"31_80_0400001000000000";
|
154 |
|
|
uart_bin_bytes_sz <= 10;
|
155 |
|
|
elsif iClkCnt = 168000 then
|
156 |
|
|
uart_wr_str <= '1';
|
157 |
|
|
-- read 16 bytes at address: 0x00000000.10000020 => 20 00 00 10.00 00 00 00
|
158 |
|
|
uart_bin_data(8*UART_BIN_SIZE-1 downto 8*(UART_BIN_SIZE-10)) <= X"31_83_2000001000000000";
|
159 |
|
|
uart_bin_bytes_sz <= 10;
|
160 |
|
|
elsif iClkCnt = 288000 then
|
161 |
|
|
uart_wr_str <= '1';
|
162 |
|
|
-- write 4 bytes at address: 0x00000000.10000024 => 31_24 00 00 10.00 00 00 00
|
163 |
|
|
-- wdata : 0xfeedface => ce fa ed fe
|
164 |
|
|
uart_bin_data(8*UART_BIN_SIZE-1 downto 8*(UART_BIN_SIZE-14)) <= X"31_c0_2400001000000000_cefaedfe";
|
165 |
|
|
uart_bin_bytes_sz <= 14;
|
166 |
|
|
elsif iClkCnt = 348000 then
|
167 |
|
|
uart_wr_str <= '1';
|
168 |
|
|
-- write 8 bytes at address: 0x00000000.10000104 => 04 01 00 10.00 00 00 00
|
169 |
|
|
-- wdata : [0xfeedface, 0xdeadbeef] => ce fa ed fe.ef be ad de
|
170 |
|
|
uart_bin_data(8*UART_BIN_SIZE-1 downto 8*(UART_BIN_SIZE-18)) <= X"31_c1_0401001000000000_cefaedfeefbeadde";
|
171 |
|
|
uart_bin_bytes_sz <= 18;
|
172 |
|
|
end if;
|
173 |
|
|
end if;
|
174 |
|
|
end process;
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
uart0 : uart_sim generic map (
|
178 |
|
|
clock_rate => (40000000/115200),
|
179 |
|
|
binary_bytes_max => UART_BIN_SIZE,
|
180 |
|
|
use_binary => true
|
181 |
|
|
) port map (
|
182 |
|
|
rst => i_rst,
|
183 |
|
|
clk => i_clk,
|
184 |
|
|
wr_str => uart_wr_str,
|
185 |
|
|
instr => uart_instr,
|
186 |
|
|
bin_data => uart_bin_data,
|
187 |
|
|
bin_bytes_sz => uart_bin_bytes_sz,
|
188 |
|
|
td => o_uart1_td,
|
189 |
|
|
rtsn => o_uart1_rtsn,
|
190 |
|
|
rd => i_uart1_rd,
|
191 |
|
|
ctsn => i_uart1_ctsn,
|
192 |
|
|
busy => uart_busy
|
193 |
|
|
);
|
194 |
|
|
|
195 |
|
|
aximo(CFG_NASTI_MASTER_UNCACHED) <= nasti_master_out_none;
|
196 |
|
|
aximo(CFG_NASTI_MASTER_ETHMAC) <= nasti_master_out_none;
|
197 |
|
|
aximo(CFG_NASTI_MASTER_MSTUART) <= nasti_master_out_none;
|
198 |
|
|
|
199 |
|
|
axiso(CFG_NASTI_SLAVE_BOOTROM) <= nasti_slave_out_none;
|
200 |
|
|
axiso(CFG_NASTI_SLAVE_ROMIMAGE) <= nasti_slave_out_none;
|
201 |
|
|
--axiso(CFG_NASTI_SLAVE_SRAM) <= nasti_slave_out_none;
|
202 |
|
|
axiso(CFG_NASTI_SLAVE_UART1) <= nasti_slave_out_none;
|
203 |
|
|
axiso(CFG_NASTI_SLAVE_GPIO) <= nasti_slave_out_none;
|
204 |
|
|
axiso(CFG_NASTI_SLAVE_IRQCTRL) <= nasti_slave_out_none;
|
205 |
|
|
axiso(CFG_NASTI_SLAVE_SPI_FLASH) <= nasti_slave_out_none;
|
206 |
|
|
axiso(CFG_NASTI_SLAVE_ETHMAC) <= nasti_slave_out_none;
|
207 |
|
|
axiso(CFG_NASTI_SLAVE_DSU) <= nasti_slave_out_none;
|
208 |
|
|
axiso(CFG_NASTI_SLAVE_GPTIMERS) <= nasti_slave_out_none;
|
209 |
|
|
axiso(CFG_NASTI_SLAVE_PNP) <= nasti_slave_out_none;
|
210 |
|
|
|
211 |
|
|
slv_cfg(CFG_NASTI_SLAVE_BOOTROM) <= nasti_slave_config_none;
|
212 |
|
|
slv_cfg(CFG_NASTI_SLAVE_ROMIMAGE) <= nasti_slave_config_none;
|
213 |
|
|
--slv_cfg(CFG_NASTI_SLAVE_SRAM) <= nasti_slave_config_none;
|
214 |
|
|
slv_cfg(CFG_NASTI_SLAVE_UART1) <= nasti_slave_config_none;
|
215 |
|
|
slv_cfg(CFG_NASTI_SLAVE_GPIO) <= nasti_slave_config_none;
|
216 |
|
|
slv_cfg(CFG_NASTI_SLAVE_IRQCTRL) <= nasti_slave_config_none;
|
217 |
|
|
slv_cfg(CFG_NASTI_SLAVE_SPI_FLASH) <= nasti_slave_config_none;
|
218 |
|
|
slv_cfg(CFG_NASTI_SLAVE_ETHMAC) <= nasti_slave_config_none;
|
219 |
|
|
slv_cfg(CFG_NASTI_SLAVE_DSU) <= nasti_slave_config_none;
|
220 |
|
|
slv_cfg(CFG_NASTI_SLAVE_GPTIMERS) <= nasti_slave_config_none;
|
221 |
|
|
slv_cfg(CFG_NASTI_SLAVE_PNP) <= nasti_slave_config_none;
|
222 |
|
|
|
223 |
|
|
ctrl0 : axictrl generic map (
|
224 |
|
|
watchdog_memop => 0
|
225 |
|
|
) port map (
|
226 |
|
|
i_clk => i_clk,
|
227 |
|
|
i_nrst => i_nrst,
|
228 |
|
|
i_slvcfg => slv_cfg,
|
229 |
|
|
i_slvo => axiso,
|
230 |
|
|
i_msto => aximo,
|
231 |
|
|
o_slvi => axisi,
|
232 |
|
|
o_msti => aximi,
|
233 |
|
|
o_miss_irq => open,
|
234 |
|
|
o_miss_addr => open,
|
235 |
|
|
o_bus_util_w => open,
|
236 |
|
|
o_bus_util_r => open
|
237 |
|
|
);
|
238 |
|
|
|
239 |
|
|
-- signal parsment and assignment
|
240 |
|
|
uarti.cts <= not i_uart1_ctsn;
|
241 |
|
|
uarti.rd <= i_uart1_rd;
|
242 |
|
|
tt : uart_tap port map (
|
243 |
|
|
nrst => i_nrst,
|
244 |
|
|
clk => i_clk,
|
245 |
|
|
i_uart => uarti,
|
246 |
|
|
o_uart => uarto,
|
247 |
|
|
i_msti => aximi(CFG_NASTI_MASTER_CACHED),
|
248 |
|
|
o_msto => aximo(CFG_NASTI_MASTER_CACHED),
|
249 |
|
|
o_mstcfg => open
|
250 |
|
|
);
|
251 |
|
|
o_uart1_td <= uarto.td;
|
252 |
|
|
o_uart1_rtsn <= not uarto.rts;
|
253 |
|
|
|
254 |
|
|
sram0 : nasti_sram generic map (
|
255 |
|
|
memtech => 0,
|
256 |
|
|
xaddr => 16#10000#,
|
257 |
|
|
xmask => 16#fff80#, -- 512 KB mask
|
258 |
|
|
abits => (10 + log2(512)), -- 512 KB address
|
259 |
|
|
init_file => CFG_SIM_FWIMAGE_HEX -- Used only for inferred
|
260 |
|
|
) port map (
|
261 |
|
|
clk => i_clk,
|
262 |
|
|
nrst => i_nrst,
|
263 |
|
|
cfg => slv_cfg(CFG_NASTI_SLAVE_SRAM),
|
264 |
|
|
i => axisi(CFG_NASTI_SLAVE_SRAM),
|
265 |
|
|
o => axiso(CFG_NASTI_SLAVE_SRAM)
|
266 |
|
|
);
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
procCheck : process (i_rst, clk_cur)
|
271 |
|
|
begin
|
272 |
|
|
if rising_edge(clk_cur) then
|
273 |
|
|
iClkCnt <= iClkCnt + 1;
|
274 |
|
|
end if;
|
275 |
|
|
end process procCheck;
|
276 |
|
|
|
277 |
|
|
end;
|