-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_axi_gcr.vhd
188 lines (152 loc) · 5.14 KB
/
tb_axi_gcr.vhd
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
180
181
182
183
184
185
186
187
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std_unsigned.all;
entity tb_axi_gcr is
end entity tb_axi_gcr;
architecture simulation of tb_axi_gcr is
constant C_CLK_PERIOD : time := 10 ns;
signal clk : std_logic;
signal rst : std_logic;
signal s_enc_ready : std_logic;
signal s_enc_valid : std_logic;
signal s_enc_data : std_logic_vector(7 downto 0);
signal m_enc_ready : std_logic;
signal m_enc_valid : std_logic;
signal m_enc_data : std_logic_vector(7 downto 0);
signal s_dec_ready : std_logic;
signal s_dec_valid : std_logic;
signal s_dec_data : std_logic_vector(7 downto 0);
signal m_dec_ready : std_logic;
signal m_dec_valid : std_logic;
signal m_dec_data : std_logic_vector(7 downto 0);
signal resp_ready : std_logic;
signal resp_valid : std_logic;
signal resp_data : std_logic_vector(7 downto 0);
signal tb_error : std_logic;
signal rand_idx : std_logic_vector(4 downto 0);
signal lfsr_update_s : std_logic;
signal lfsr_output_s : std_logic_vector(31 downto 0);
signal lfsr_random_s : std_logic_vector(31 downto 0);
signal lfsr_reverse_s : std_logic_vector(31 downto 0);
begin
---------------------------------------------------------
-- Controller clock and reset
---------------------------------------------------------
p_clk : process
begin
clk <= '1';
wait for C_CLK_PERIOD/2;
clk <= '0';
wait for C_CLK_PERIOD/2;
if tb_error = '1' then
report "Test ERROR";
wait;
end if;
end process p_clk;
p_rst : process
begin
rst <= '1';
wait for 10*C_CLK_PERIOD;
wait until clk = '1';
rst <= '0';
wait;
end process p_rst;
--------------------------------------
-- Provide input stimuli
-- TBD: Add some random pauses here
--------------------------------------
s_enc_valid <= '1';
s_enc_data <= lfsr_random_s(7 downto 0);
lfsr_update_s <= s_enc_valid and s_enc_ready;
--------------------------------------
-- Copy input to FIFO
--------------------------------------
i_axi_fifo_small : entity work.axi_fifo_small
generic map (
G_RAM_WIDTH => 8,
G_RAM_DEPTH => 16
)
port map (
clk_i => clk,
rst_i => rst,
s_ready_o => open, -- Just ignore this, because the FIFO is plenty big enough
s_valid_i => s_enc_valid and s_enc_ready,
s_data_i => s_enc_data,
m_ready_i => resp_ready,
m_valid_o => resp_valid,
m_data_o => resp_data
); -- i_axi_fifo_small
--------------------------------------
-- Connect encoder and decoder
-- TBD: Add some random pauses here
--------------------------------------
s_dec_valid <= m_enc_valid;
s_dec_data <= m_enc_data;
m_enc_ready <= s_dec_ready;
--------------------------------------
-- Check output results
-- TBD: Add some random pauses here
--------------------------------------
m_dec_ready <= resp_valid and lfsr_random_s(to_integer(rand_idx));
resp_ready <= m_dec_valid and lfsr_random_s(to_integer(rand_idx));
p_verify : process (clk)
begin
if rising_edge(clk) then
rand_idx <= rand_idx + 1;
if resp_valid = '1' and resp_ready = '1' then
if m_dec_data /= resp_data then
tb_error <= '1';
end if;
end if;
if rst = '1' then
tb_error <= '0';
rand_idx <= (others => '0');
end if;
end if;
end process p_verify;
---------------------------------------------------------
-- Instantiate DUT
---------------------------------------------------------
i_axi_gcr : entity work.axi_gcr
port map (
clk_i => clk,
rst_i => rst,
s_enc_ready_o => s_enc_ready,
s_enc_valid_i => s_enc_valid,
s_enc_data_i => s_enc_data,
s_enc_sync_i => '0',
m_enc_ready_i => m_enc_ready,
m_enc_valid_o => m_enc_valid,
m_enc_data_o => m_enc_data,
s_dec_ready_o => s_dec_ready,
s_dec_valid_i => s_dec_valid,
s_dec_data_i => s_dec_data,
m_dec_ready_i => m_dec_ready,
m_dec_valid_o => m_dec_valid,
m_dec_data_o => m_dec_data,
m_dec_sync_o => open
); -- i_axi_gcr
--------------------------------------
-- Instantiate randon number generator
--------------------------------------
i_lfsr : entity work.lfsr
generic map (
G_WIDTH => 32,
G_TAPS => X"0000000080000EA6" -- See https://users.ece.cmu.edu/~koopman/lfsr/32.txt
)
port map (
clk_i => clk,
rst_i => rst,
update_i => lfsr_update_s,
load_i => '0',
load_val_i => (others => '1'),
output_o => lfsr_output_s
); -- i_lfsr
p_reverse : process(all)
begin
for i in lfsr_output_s'low to lfsr_output_s'high loop
lfsr_reverse_s(lfsr_output_s'high - i) <= lfsr_output_s(i);
end loop;
end process p_reverse;
lfsr_random_s <= lfsr_output_s + lfsr_reverse_s;
end architecture simulation;