OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.storage/] [sdram2hibi/] [1.0/] [tb/] [tb_agent.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : tb_agent
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : tb_agent.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 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
    comm_out     : out std_logic_vector(2 downto 0);
42
    data_out     : out std_logic_vector(data_width_g - 1 downto 0);
43
    addr_out     : out std_logic_vector(addr_width_g - 1 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;
67
 
68
architecture behavioral of tb_agent is
69
 
70
  type state_vec_type is (idle,
71
                          req_write_port, req_read_port,
72
                          wait_write_port, wait_read_port,
73
                          conf_write_port, conf_read_port,
74
                          send_write_data);
75
  signal state_r : state_vec_type;
76
 
77
  type conf_state_type is (conf_dst_addr, conf_src_addr,
78
                           conf_amount, conf_height_offset,
79
                           conf_ret_addr);
80
  signal wr_conf_state : conf_state_type;
81
  signal rd_conf_state : conf_state_type;
82
  signal rd_port_addr  : std_logic_vector(data_width_g - 1 downto 0);
83
  signal wr_port_addr  : std_logic_vector(data_width_g - 1 downto 0);
84
 
85
  type chk_state_vec is (run_test, test_finished);
86
  signal chk_state_r : chk_state_vec;
87
  signal msg_we_r    : std_logic;
88
  signal we_r        : std_logic;
89
 
90
  signal dst_addr_r  : std_logic_vector(addr_width_g - 1 downto 0);
91
  signal src_addr_r  : std_logic_vector(addr_width_g - 1 downto 0);
92
  signal wr_amount_r : std_logic_vector(data_width_g - 1 downto 0);
93
  signal rd_amount_r : std_logic_vector(data_width_g - 1 downto 0);
94
  signal wr_count_r  : std_logic_vector(data_width_g - 1 downto 0);
95
  signal rd_count_r  : std_logic_vector(data_width_g - 1 downto 0);
96
 
97
  signal wr_data_r : std_logic_vector(data_width_g - 1 downto 0);
98
 
99
  signal chk_count_r  : std_logic_vector(data_width_g - 1 downto 0);
100
  signal chk_amount_r : std_logic_vector(data_width_g - 1 downto 0);
101
 
102
begin  -- behavioral
103
 
104
  msg_we_out <= msg_we_r;
105
  we_out     <= we_r;
106
 
107
  check_results : process (clk, rst_n)
108
  begin  -- process check_results
109
 
110
    if rst_n = '0' then                 -- asynchronous reset (active low)
111
      re_out       <= '1';
112
      msg_re_out   <= '1';
113
      rd_count_r   <= (others => '0');
114
      chk_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
115
      chk_count_r  <= std_logic_vector(to_unsigned(1, data_width_g));
116
 
117
      chk_state_r <= run_test;
118
 
119
    elsif clk'event and clk = '1' then  -- rising clock edge
120
 
121
      re_out     <= '1';
122
      msg_re_out <= '1';
123
 
124
      case chk_state_r is
125
        when run_test =>
126
          if empty_in = '0' then
127
            -- check incoming addr
128
            assert to_integer(unsigned(addr_in)) = own_addr_g
129
              report "ERROR: tb_ag(lo) 0x" &
130
              str(own_addr_g, 16) &
131
              " got addr: 0x" & str(to_integer(unsigned(addr_in)), 16) severity failure;
132
            -- check incoming data
133
            assert std_logic_vector(to_unsigned(own_addr_g, data_width_g) + unsigned(rd_count_r)) = data_in
134
              report "ERROR: data corrupted exp: 0x" &
135
              str(to_integer(unsigned(rd_count_r)) + own_addr_g, 16) & " got: 0x" &
136
              str(to_integer(unsigned(data_in)), 16) severity failure;
137
 
138
            assert std_logic_vector(to_unsigned(own_addr_g, data_width_g) + unsigned(rd_count_r)) /= data_in
139
              report "data ok got: 0x" &
140
              str(to_integer(unsigned(data_in)), 16) severity note;
141
 
142
            rd_count_r <= std_logic_vector(unsigned(rd_count_r) + 1);
143
 
144
            if chk_count_r = chk_amount_r then
145
              assert false report "ag: 0x" & str(own_addr_g, 16) &
146
                " read OK (length=" & str(to_integer(unsigned(chk_amount_r)), 16) & ")"
147
                severity note;
148
              chk_amount_r <= std_logic_vector(unsigned(chk_amount_r) + 1);
149
              chk_count_r  <= std_logic_vector(to_unsigned(1, data_width_g));
150
 
151
              if unsigned(chk_amount_r) >= 255 then
152
 
153
                assert unsigned(chk_amount_r) < 255 report "++++++++ ag: 0x" & str(own_addr_g, 16) &
154
                  " TEST SUCCESFUL ++++++++++++++++++++"
155
                  severity failure;
156
                chk_state_r <= test_finished;
157
              end if;
158
            else
159
              chk_amount_r <= chk_amount_r;
160
              chk_count_r  <= std_logic_vector(unsigned(chk_count_r) + 1);
161
            end if;
162
 
163
          end if;
164
          -- check incoming msg addr
165
          if msg_empty_in = '0' then
166
            assert to_integer(unsigned(msg_addr_in)) = own_addr_g
167
              report "ERROR: tb_ag(msg) 0x" &
168
              str(own_addr_g, 16) &
169
              " got addr: 0x" & str(to_integer(unsigned(msg_addr_in)), 16) severity failure;
170
          end if;
171
        when test_finished =>
172
          null;
173
        when others =>
174
          assert false report "Illegal test state" severity failure;
175
      end case;
176
    end if;
177
  end process check_results;
178
 
179
  data_out <= wr_data_r;
180
 
181
  update_wr_data : process (clk, rst_n)
182
  begin  -- process update_wr_count
183
    if rst_n = '0' then
184
      wr_data_r <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));  --(others => '0');
185
    elsif clk = '1' and clk'event then
186
      if we_r = '1' and full_in = '0' then
187
        wr_data_r <= std_logic_vector(unsigned(wr_data_r) + 1);
188
      end if;
189
    end if;
190
  end process update_wr_data;
191
 
192
  process (clk, rst_n)
193
  begin  -- process
194
 
195
    if rst_n = '0' then                 -- asynchronous reset (active low)
196
 
197
      req_out      <= '0';
198
      hold_out     <= '0';
199
      msg_req_out  <= '0';
200
      msg_hold_out <= '0';
201
      comm_out     <= "010";
202
      addr_out     <= (others => '0');
203
      msg_data_out <= (others => '0');
204
      msg_addr_out <= (others => '0');
205
      we_r         <= '0';
206
      msg_we_r     <= '0';
207
      rd_port_addr <= (others => '0');
208
      wr_port_addr <= (others => '0');
209
      src_addr_r   <= std_logic_vector(to_unsigned(own_addr_g, addr_width_g));
210
      dst_addr_r   <= std_logic_vector(to_unsigned(own_addr_g, addr_width_g));
211
      rd_amount_r  <= std_logic_vector(to_unsigned(1, data_width_g));
212
      wr_amount_r  <= std_logic_vector(to_unsigned(1, data_width_g));
213
      wr_count_r   <= std_logic_vector(to_unsigned(1, data_width_g));  --(others => '0');
214
      state_r      <= idle;
215
 
216
    elsif clk'event and clk = '1' then  -- rising clock edge
217
 
218
      if chk_state_r = test_finished then
219
        msg_req_out  <= '0';
220
        msg_hold_out <= '0';
221
        req_out      <= '0';
222
        hold_out     <= '0';
223
      else
224
        case state_r is
225
 
226
          when idle =>
227
            req_out       <= '0';
228
            hold_out      <= '0';
229
            msg_req_out   <= '0';
230
            msg_hold_out  <= '0';
231
            wr_conf_state <= conf_dst_addr;
232
            rd_conf_state <= conf_src_addr;
233
            state_r       <= req_write_port;
234
 
235
          when req_write_port =>
236
            msg_req_out  <= '1';
237
            msg_hold_out <= '1';
238
            msg_addr_out <= std_logic_vector(to_unsigned(1, addr_width_g));
239
            msg_data_out <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));
240
            if msg_grant_in = '1' and msg_full_in = '0' then
241
              msg_we_r <= '1';
242
              state_r  <= wait_write_port;
243
            else
244
              msg_we_r <= '0';
245
              state_r  <= req_write_port;
246
            end if;
247
 
248
          when wait_write_port =>
249
 
250
            if msg_we_r = '1' and msg_full_in = '1' then
251
              state_r <= wait_write_port;
252
            else
253
              msg_we_r     <= '0';
254
              msg_req_out  <= '0';
255
              msg_hold_out <= '0';
256
              msg_addr_out <= (others => '0');
257
              msg_data_out <= (others => '0');
258
 
259
              if msg_empty_in = '0'
260
                and msg_data_in = std_logic_vector(to_unsigned(0, data_width_g)) then
261
                state_r <= req_write_port;
262
 
263
              elsif msg_empty_in = '0'
264
                and msg_data_in /= std_logic_vector(to_unsigned(0, data_width_g)) then
265
                wr_port_addr <= msg_data_in;
266
                state_r      <= conf_write_port;
267
              else
268
                wr_port_addr <= (others => '0');
269
                state_r      <= wait_write_port;
270
              end if;
271
 
272
            end if;
273
 
274
          when conf_write_port =>
275
 
276
            msg_req_out  <= '1';
277
            msg_hold_out <= '1';
278
 
279
            if msg_grant_in = '1' and msg_full_in = '0' then
280
 
281
              if msg_we_r = '1' and msg_full_in = '1' then
282
                wr_conf_state <= wr_conf_state;
283
                state_r       <= state_r;
284
 
285
              else
286
 
287
                msg_we_r <= '1';
288
 
289
                case wr_conf_state is
290
 
291
                  when conf_dst_addr =>
292
                    msg_addr_out <= wr_port_addr;
293
                    msg_data_out <= dst_addr_r;
294
                    dst_addr_r <= std_logic_vector(unsigned(dst_addr_r) +
295
                                                   unsigned(wr_amount_r));
296
                    wr_conf_state <= conf_amount;
297
 
298
                  when conf_amount =>
299
                    msg_addr_out  <= std_logic_vector(unsigned(wr_port_addr) + 1);
300
                    msg_data_out  <= wr_amount_r;
301
                    wr_conf_state <= conf_height_offset;
302
 
303
                  when conf_height_offset =>
304
                    msg_req_out  <= '1';
305
                    msg_hold_out <= '1';
306
                    msg_we_r     <= '1';
307
                    msg_addr_out <= std_logic_vector(unsigned(wr_port_addr) + 2);
308
                    msg_data_out <= std_logic_vector(to_unsigned(1, data_width_g/2)) &
309
                                    std_logic_vector(to_unsigned(1, data_width_g/2));
310
                    wr_conf_state <= conf_dst_addr;
311
                    state_r       <= send_write_data;
312
 
313
                  when others =>
314
                    assert false report "tb_agent: 0x" & str(own_addr_g, 16) &
315
                      " illegal rd_conf_state" severity failure;
316
                end case;
317
 
318
              end if;
319
 
320
            end if;
321
 
322
          when send_write_data =>
323
 
324
            if msg_we_r = '1' and msg_full_in = '1' then
325
              state_r <= send_write_data;
326
            else
327
              msg_we_r     <= '0';
328
              msg_req_out  <= '0';
329
              msg_hold_out <= '0';
330
 
331
              req_out  <= '1';
332
              hold_out <= '1';
333
 
334
              addr_out <= std_logic_vector(unsigned(wr_port_addr) + 3);
335
              we_r     <= '1';
336
 
337
              if grant_in = '1' and full_in = '0' then
338
                if wr_count_r = std_logic_vector(unsigned(wr_amount_r)) then
339
                  req_out    <= '0';
340
                  hold_out   <= '0';
341
                  we_r       <= '0';
342
                  wr_count_r <= std_logic_vector(to_unsigned(1, data_width_g));  --(others => '0');
343
 
344
                  if to_integer(unsigned(wr_amount_r)) = 255 then
345
                    wr_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
346
                  else
347
                    wr_amount_r <= std_logic_vector(unsigned(wr_amount_r) + 1);
348
                  end if;
349
                  state_r <= req_read_port;
350
                else
351
                  wr_count_r <= std_logic_vector(unsigned(wr_count_r) + 1);
352
                  state_r    <= send_write_data;
353
                end if;
354
              end if;
355
 
356
            end if;
357
 
358
          when req_read_port =>
359
            req_out      <= '0';
360
            hold_out     <= '0';
361
            we_r         <= '0';
362
            msg_req_out  <= '1';
363
            msg_hold_out <= '1';
364
            msg_addr_out <= (others => '0');
365
            msg_data_out <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));
366
            if msg_grant_in = '1' and msg_full_in = '0' then
367
              msg_we_r <= '1';
368
              state_r  <= wait_read_port;
369
            else
370
              msg_we_r <= '0';
371
              state_r  <= req_read_port;
372
            end if;
373
 
374
 
375
          when wait_read_port =>
376
            msg_we_r     <= '0';
377
            msg_req_out  <= '0';
378
            msg_hold_out <= '0';
379
            msg_addr_out <= (others => '0');
380
            msg_data_out <= (others => '0');
381
 
382
            if msg_empty_in = '0'
383
              and msg_data_in = std_logic_vector(to_unsigned(0, data_width_g)) then
384
              state_r <= req_read_port;
385
            elsif msg_empty_in = '0'
386
              and msg_data_in /= std_logic_vector(to_unsigned(0, data_width_g)) then
387
              rd_port_addr <= msg_data_in;
388
              state_r      <= conf_read_port;
389
            else
390
              rd_port_addr <= (others => '0');
391
              state_r      <= wait_read_port;
392
            end if;
393
 
394
          when conf_read_port =>
395
 
396
            if msg_we_r = '1' then
397
 
398
              -- this is here to allow other agents get grants and use
399
              -- msg fifo during configuring
400
              msg_req_out  <= '0';
401
              msg_hold_out <= '0';
402
              msg_we_r     <= '0';
403
            else
404
 
405
              msg_req_out  <= '1';
406
              msg_hold_out <= '1';
407
 
408
              if msg_grant_in = '1' and msg_full_in = '0' then
409
 
410
                msg_we_r <= '1';
411
 
412
                case rd_conf_state is
413
 
414
                  when conf_src_addr =>
415
                    msg_addr_out <= rd_port_addr;
416
                    msg_data_out <= src_addr_r;
417
                    src_addr_r <= std_logic_vector(unsigned(src_addr_r) +
418
                                                   unsigned(rd_amount_r));
419
                    rd_conf_state <= conf_amount;
420
 
421
                  when conf_amount =>
422
                    msg_addr_out <= std_logic_vector(unsigned(rd_port_addr) + 1);
423
                    msg_data_out <= rd_amount_r;
424
                    if to_integer(unsigned(rd_amount_r)) = 255 then
425
                      rd_amount_r <= std_logic_vector(to_unsigned(1, data_width_g));
426
                    else
427
                      rd_amount_r <= std_logic_vector(unsigned(rd_amount_r) + 1);
428
                    end if;
429
                    rd_conf_state <= conf_ret_addr;
430
 
431
                  when conf_ret_addr =>
432
                    msg_addr_out  <= std_logic_vector(unsigned(rd_port_addr) + 3);
433
                    msg_data_out  <= std_logic_vector(to_unsigned(own_addr_g, data_width_g));
434
                    rd_conf_state <= conf_height_offset;
435
 
436
                  when conf_height_offset =>
437
                    msg_addr_out <= std_logic_vector(unsigned(rd_port_addr) + 2);
438
                    msg_data_out <= std_logic_vector(to_unsigned(1, data_width_g/2)) &
439
                                    std_logic_vector(to_unsigned(1, data_width_g/2));
440
                    rd_conf_state <= conf_src_addr;
441
                    state_r       <= req_write_port;
442
 
443
                  when others =>
444
                    assert false report "tb_agent: 0x" & str(own_addr_g, 16) &
445
                      " illegal rd_conf_state" severity failure;
446
                end case;
447
              else
448
                msg_we_r <= '0';
449
              end if;
450
            end if;
451
 
452
          when others =>
453
            assert false report "tb_agent: 0x" & str(own_addr_g, 16) &
454
              " illegal state" severity failure;
455
        end case;
456
 
457
      end if;
458
    end if;
459
  end process;
460
 
461
end behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.