1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : tb_agent_so
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : tb_agent_so.vhd
|
6 |
|
|
-- Author :
|
7 |
|
|
-- Company :
|
8 |
|
|
-- Created : 2006-10-03
|
9 |
|
|
-- Last update: 2006-10-24
|
10 |
|
|
-- Platform :
|
11 |
|
|
-- Standard : VHDL'87
|
12 |
|
|
-------------------------------------------------------------------------------
|
13 |
|
|
-- Description: Agent that sends request to sdram2hibi
|
14 |
|
|
-------------------------------------------------------------------------------
|
15 |
|
|
-- Copyright (c) 2006
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-- Revisions :
|
18 |
|
|
-- Date Version Author Description
|
19 |
|
|
-- 2006-10-03 1.0 penttin5 Created
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
library ieee;
|
23 |
|
|
use ieee.std_logic_1164.all;
|
24 |
|
|
use ieee.numeric_std.all;
|
25 |
|
|
use work.txt_util.all;
|
26 |
|
|
|
27 |
|
|
entity tb_agent_so is
|
28 |
|
|
|
29 |
|
|
generic (
|
30 |
|
|
own_addr_g : integer;
|
31 |
|
|
check_rd_data : integer := 0;
|
32 |
|
|
data_width_g : integer;
|
33 |
|
|
addr_width_g : integer
|
34 |
|
|
);
|
35 |
|
|
port (
|
36 |
|
|
clk : in std_logic;
|
37 |
|
|
rst_n : in std_logic;
|
38 |
|
|
req_out : out std_logic;
|
39 |
|
|
hold_out : out std_logic;
|
40 |
|
|
grant_in : in std_logic;
|
41 |
|
|
data_out : out std_logic_vector(data_width_g - 1 downto 0);
|
42 |
|
|
addr_out : out std_logic_vector(addr_width_g - 1 downto 0);
|
43 |
|
|
comm_out : out std_logic_vector(2 downto 0);
|
44 |
|
|
re_out : out std_logic;
|
45 |
|
|
we_out : out std_logic;
|
46 |
|
|
full_in : in std_logic;
|
47 |
|
|
one_p_in : in std_logic;
|
48 |
|
|
data_in : in std_logic_vector(data_width_g - 1 downto 0);
|
49 |
|
|
addr_in : in std_logic_vector(data_width_g - 1 downto 0);
|
50 |
|
|
empty_in : in std_logic;
|
51 |
|
|
one_d_in : in std_logic;
|
52 |
|
|
msg_req_out : out std_logic;
|
53 |
|
|
msg_hold_out : out std_logic;
|
54 |
|
|
msg_grant_in : in std_logic;
|
55 |
|
|
msg_full_in : in std_logic;
|
56 |
|
|
msg_one_p_in : in std_logic;
|
57 |
|
|
msg_data_in : in std_logic_vector(data_width_g - 1 downto 0);
|
58 |
|
|
msg_addr_in : in std_logic_vector(data_width_g - 1 downto 0);
|
59 |
|
|
msg_empty_in : in std_logic;
|
60 |
|
|
msg_one_d_in : in std_logic;
|
61 |
|
|
msg_data_out : out std_logic_vector(data_width_g - 1 downto 0);
|
62 |
|
|
msg_addr_out : out std_logic_vector(addr_width_g - 1 downto 0);
|
63 |
|
|
msg_re_out : out std_logic;
|
64 |
|
|
msg_we_out : out std_logic
|
65 |
|
|
);
|
66 |
|
|
end tb_agent_so;
|
67 |
|
|
|
68 |
|
|
architecture behavioral of tb_agent_so is
|
69 |
|
|
|
70 |
|
|
type state_vec_type is (idle,
|
71 |
|
|
single_read, single_write);
|
72 |
|
|
signal state_r : state_vec_type;
|
73 |
|
|
|
74 |
|
|
type conf_state_type is (conf_dst_addr, conf_src_addr,
|
75 |
|
|
conf_amount, conf_height_offset,
|
76 |
|
|
conf_ret_addr);
|
77 |
|
|
signal wr_conf_state : conf_state_type;
|
78 |
|
|
signal rd_conf_state : conf_state_type;
|
79 |
|
|
signal rd_port_addr : std_logic_vector(data_width_g - 1 downto 0);
|
80 |
|
|
signal wr_port_addr : std_logic_vector(data_width_g - 1 downto 0);
|
81 |
|
|
|
82 |
|
|
type chk_state_vec is (run_test, test_finished);
|
83 |
|
|
signal chk_state_r : chk_state_vec;
|
84 |
|
|
signal msg_we_r : std_logic;
|
85 |
|
|
signal we_r : std_logic;
|
86 |
|
|
|
87 |
|
|
signal dst_addr_r : std_logic_vector(addr_width_g - 1 downto 0);
|
88 |
|
|
signal src_addr_r : std_logic_vector(addr_width_g - 1 downto 0);
|
89 |
|
|
signal wr_amount_r : std_logic_vector(data_width_g - 1 downto 0);
|
90 |
|
|
signal rd_amount_r : std_logic_vector(data_width_g - 1 downto 0);
|
91 |
|
|
signal wr_count_r : std_logic_vector(data_width_g - 1 downto 0);
|
92 |
|
|
signal rd_count_r : std_logic_vector(data_width_g - 1 downto 0);
|
93 |
|
|
|
94 |
|
|
signal wr_data_r : std_logic_vector(data_width_g - 1 downto 0);
|
95 |
|
|
|
96 |
|
|
signal chk_count_r : std_logic_vector(data_width_g - 1 downto 0);
|
97 |
|
|
signal chk_amount_r : std_logic_vector(data_width_g - 1 downto 0);
|
98 |
|
|
|
99 |
|
|
begin -- behavioral
|
100 |
|
|
|
101 |
|
|
msg_we_out <= msg_we_r;
|
102 |
|
|
we_out <= we_r;
|
103 |
|
|
|
104 |
|
|
check_results : process (clk, rst_n)
|
105 |
|
|
begin -- process check_results
|
106 |
|
|
|
107 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
108 |
|
|
re_out <= '1';
|
109 |
|
|
msg_re_out <= '0';
|
110 |
|
|
rd_count_r <= (others => '0');
|
111 |
|
|
chk_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
|
112 |
|
|
chk_count_r <= std_logic_vector(to_unsigned(1, data_width_g));
|
113 |
|
|
|
114 |
|
|
chk_state_r <= run_test;
|
115 |
|
|
|
116 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
117 |
|
|
|
118 |
|
|
re_out <= '1';
|
119 |
|
|
|
120 |
|
|
case chk_state_r is
|
121 |
|
|
when run_test =>
|
122 |
|
|
|
123 |
|
|
if empty_in = '0' then
|
124 |
|
|
|
125 |
|
|
-- check incoming addr
|
126 |
|
|
assert to_integer(unsigned(addr_in)) = own_addr_g
|
127 |
|
|
report "ERROR: tb_ag(lo) 0x" &
|
128 |
|
|
str(own_addr_g, 16) &
|
129 |
|
|
" got addr: 0x" & str(to_integer(unsigned(addr_in)), 16) severity failure;
|
130 |
|
|
|
131 |
|
|
-- check incoming data
|
132 |
|
|
assert std_logic_vector(to_unsigned(own_addr_g, data_width_g) + unsigned(rd_count_r)) = data_in
|
133 |
|
|
report "ERROR: data corrupted exp: 0x" &
|
134 |
|
|
str(to_integer(unsigned(rd_count_r)) + own_addr_g, 16) & " got: 0x" &
|
135 |
|
|
str(to_integer(unsigned(data_in)), 16) severity failure;
|
136 |
|
|
assert std_logic_vector(to_unsigned(own_addr_g, data_width_g) + unsigned(rd_count_r)) /= data_in
|
137 |
|
|
report "data ok got: 0x" &
|
138 |
|
|
str(to_integer(unsigned(data_in)), 16) severity note;
|
139 |
|
|
|
140 |
|
|
rd_count_r <= std_logic_vector(unsigned(rd_count_r) + 1);
|
141 |
|
|
|
142 |
|
|
if unsigned(rd_count_r) >= 255 then
|
143 |
|
|
|
144 |
|
|
assert unsigned(rd_count_r) < 255 report "++++++++ ag: 0x" & str(own_addr_g, 16) &
|
145 |
|
|
" TEST SUCCESFUL ++++++++++++++++++++"
|
146 |
|
|
severity failure;
|
147 |
|
|
chk_state_r <= test_finished;
|
148 |
|
|
end if;
|
149 |
|
|
|
150 |
|
|
else
|
151 |
|
|
chk_state_r <= chk_state_r;
|
152 |
|
|
end if;
|
153 |
|
|
|
154 |
|
|
-- check incoming msg addr
|
155 |
|
|
if msg_empty_in = '0' then
|
156 |
|
|
assert to_integer(unsigned(msg_addr_in)) = own_addr_g
|
157 |
|
|
report "ERROR: tb_ag(msg) 0x" &
|
158 |
|
|
str(own_addr_g, 16) &
|
159 |
|
|
" got addr: 0x" & str(to_integer(unsigned(msg_addr_in)), 16) severity failure;
|
160 |
|
|
end if;
|
161 |
|
|
when test_finished =>
|
162 |
|
|
null;
|
163 |
|
|
when others =>
|
164 |
|
|
assert false report "Illegal test state" severity failure;
|
165 |
|
|
end case;
|
166 |
|
|
end if;
|
167 |
|
|
end process check_results;
|
168 |
|
|
|
169 |
|
|
process (clk, rst_n)
|
170 |
|
|
begin -- process
|
171 |
|
|
|
172 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
173 |
|
|
|
174 |
|
|
req_out <= '0';
|
175 |
|
|
hold_out <= '0';
|
176 |
|
|
msg_req_out <= '0';
|
177 |
|
|
msg_hold_out <= '0';
|
178 |
|
|
comm_out <= (others => '0');
|
179 |
|
|
addr_out <= (others => '0');
|
180 |
|
|
data_out <= (others => '0');
|
181 |
|
|
msg_data_out <= (others => '0');
|
182 |
|
|
msg_addr_out <= (others => '0');
|
183 |
|
|
we_r <= '0';
|
184 |
|
|
msg_we_r <= '0';
|
185 |
|
|
rd_port_addr <= (others => '0');
|
186 |
|
|
wr_port_addr <= (others => '0');
|
187 |
|
|
src_addr_r <= std_logic_vector(to_unsigned(own_addr_g, addr_width_g));
|
188 |
|
|
dst_addr_r <= std_logic_vector(to_unsigned(own_addr_g, addr_width_g));
|
189 |
|
|
rd_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
|
190 |
|
|
wr_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
|
191 |
|
|
wr_count_r <= std_logic_vector(to_unsigned(1, data_width_g)); --(others => '0');
|
192 |
|
|
state_r <= idle;
|
193 |
|
|
|
194 |
|
|
wr_data_r <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));
|
195 |
|
|
|
196 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
197 |
|
|
|
198 |
|
|
if chk_state_r = test_finished then
|
199 |
|
|
msg_req_out <= '0';
|
200 |
|
|
msg_hold_out <= '0';
|
201 |
|
|
req_out <= '0';
|
202 |
|
|
hold_out <= '0';
|
203 |
|
|
else
|
204 |
|
|
|
205 |
|
|
if chk_state_r = run_test then
|
206 |
|
|
|
207 |
|
|
case state_r is
|
208 |
|
|
|
209 |
|
|
when idle =>
|
210 |
|
|
if full_in = '1' and we_r = '1' then
|
211 |
|
|
state_r <= idle;
|
212 |
|
|
else
|
213 |
|
|
we_r <= '0';
|
214 |
|
|
req_out <= '0';
|
215 |
|
|
hold_out <= '0';
|
216 |
|
|
msg_req_out <= '0';
|
217 |
|
|
msg_hold_out <= '0';
|
218 |
|
|
state_r <= single_write;
|
219 |
|
|
end if;
|
220 |
|
|
|
221 |
|
|
when single_write =>
|
222 |
|
|
|
223 |
|
|
if full_in = '1' and we_r = '1' then
|
224 |
|
|
state_r <= single_write;
|
225 |
|
|
else
|
226 |
|
|
req_out <= '1';
|
227 |
|
|
hold_out <= '1';
|
228 |
|
|
comm_out <= "010"; -- write
|
229 |
|
|
addr_out <= dst_addr_r;
|
230 |
|
|
data_out <= wr_data_r;
|
231 |
|
|
|
232 |
|
|
if grant_in = '1' and full_in = '0' then
|
233 |
|
|
we_r <= '1';
|
234 |
|
|
req_out <= '0';
|
235 |
|
|
dst_addr_r <= std_logic_vector(unsigned(dst_addr_r) + 1);
|
236 |
|
|
wr_data_r <= std_logic_vector(unsigned(wr_data_r) + 1);
|
237 |
|
|
state_r <= single_read;
|
238 |
|
|
else
|
239 |
|
|
we_r <= '0';
|
240 |
|
|
state_r <= single_write;
|
241 |
|
|
end if;
|
242 |
|
|
end if;
|
243 |
|
|
when single_read =>
|
244 |
|
|
if full_in = '1' and we_r = '1' then
|
245 |
|
|
state_r <= single_read;
|
246 |
|
|
else
|
247 |
|
|
req_out <= '1';
|
248 |
|
|
hold_out <= '1';
|
249 |
|
|
comm_out <= "001"; -- read
|
250 |
|
|
addr_out <= src_addr_r;
|
251 |
|
|
data_out <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));
|
252 |
|
|
|
253 |
|
|
if grant_in = '1' and full_in = '0' then
|
254 |
|
|
we_r <= '1';
|
255 |
|
|
req_out <= '0';
|
256 |
|
|
src_addr_r <= std_logic_vector(unsigned(src_addr_r) + 1);
|
257 |
|
|
state_r <= idle;
|
258 |
|
|
else
|
259 |
|
|
we_r <= '0';
|
260 |
|
|
state_r <= single_read;
|
261 |
|
|
end if;
|
262 |
|
|
end if;
|
263 |
|
|
when others =>
|
264 |
|
|
assert false report "tb_agent_so: 0x" & str(own_addr_g, 16) &
|
265 |
|
|
" illegal state" severity failure;
|
266 |
|
|
end case;
|
267 |
|
|
|
268 |
|
|
else
|
269 |
|
|
req_out <= '0';
|
270 |
|
|
hold_out <= '0';
|
271 |
|
|
we_r <= '0';
|
272 |
|
|
end if;
|
273 |
|
|
end if;
|
274 |
|
|
end if;
|
275 |
|
|
end process;
|
276 |
|
|
|
277 |
|
|
end behavioral;
|