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_sdram2hibiv7.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : tb_sdram2hibi.vhd
3
-- Description : Testbench for SDRAM (block transfer) ctrl
4
-- Author      : Erno Salminen
5
-- Date        : 29.10.2004
6
-- Modified    : 
7
--
8
-- Every agent can have only one port at a time, so at least 2 agents are needed
9
-- to test concurrent read and write!!!
10
--
11
-- Supports blocking and non-blocking requests
12
-- Supports old and new sdram2hibi config methods
13
-- 
14
-------------------------------------------------------------------------------
15
library ieee;
16
use ieee.std_logic_1164.all;
17
use ieee.numeric_std.all;
18
 
19
use work.txt_util.all;
20
 
21
entity tb_sdram2hibi is
22
  generic (
23
    dut_ver_g        : integer := 7;    -- Sdram2hibi version
24
    rq_fifo_depth_g  : integer := 3;  -- Request fifo depth(0=non-blocking others=blocking)
25
    num_of_r_ports_g : integer := 4;    -- Number of read ports
26
    num_of_w_ports_g : integer := 4);   -- Number of write ports
27
end tb_sdram2hibi;
28
 
29
architecture behavioral of tb_sdram2hibi is
30
 
31
  -- NUM OF TB AGENTS
32
  constant n_agents_c : integer := 16;
33
  type read_integer_array is array (n_agents_c + 1 downto 0) of integer;
34
 
35
  signal old_config_method : integer;
36
 
37
  -- TESTBENCH AGENT ADDRESSES
38
  signal agent_addrs_r : read_integer_array;
39
 
40
  constant re_delay_c        : integer := 5;
41
  constant msg_rx_depth_c    : integer := 20;
42
  constant rx_depth_c        : integer := 20;
43
  constant msg_tx_depth_c    : integer := 3;
44
  constant tx_depth_c        : integer := 2;
45
  constant rq_timeout_c      : integer := 1000;  -- Timeout for request response
46
  constant hibi_data_width   : integer := 32;
47
  constant mem_data_width    : integer := 32;
48
  constant mem_addr_width    : integer := 22;
49
  constant comm_width        : integer := 3;
50
  constant depth             : integer := 10;
51
  constant period_c          : time    := 10 ns;
52
  constant clk_freq_c        : integer := 100;
53
  constant sdram_hibi_addr_c : integer := 16#09000000#;
54
 
55
  -----------------------------------------------------------------------------
56
  -- 
57
  --  _____                        ________      ________________
58
  -- |     |                      |        |    |                |    
59
  -- |     |   <- msg tx fifo <-  |        |    |                | <-
60
  -- |     |   <-     tx_fifo <-  |        | <- | sdram 50MHz    |       tb
61
  -- |  tb |                      | ctrl   |    | cas 3          |
62
  -- |     |   ->     rx_fifo ->  | (dut)  |    |                | ->
63
  -- |     |   -> msg rx fifo ->  |        | -> |                |
64
  -- | ____|                      |________|    |________________|
65
  --                                  A
66
  --                                  |__ tb?
67
  --
68
  -----------------------------------------------------------------------------
69
 
70
 
71
  -- Testbench signals
72
  signal clk   : std_logic;
73
  signal rst_n : std_logic;
74
 
75
  type check_state_type is (wait_comm, wait_busy);
76
  signal check_state : check_state_type;
77
 
78
  type state_type is (idle, read_state, write_state);
79
  signal state_r : state_type;
80
 
81
  type tb_state_type is (rst, rq_wr, conf_wr, rq_rd, conf_rd, send_wr_data,
82
                         wait_pending, conf_pending);
83
  signal tb_state : tb_state_type;
84
 
85
  type port_offset_array is array(n_agents_c + 1 downto 0) of integer;
86
  signal port_offsets_r  : port_offset_array;
87
  signal rd_wr_rq        : std_logic_vector(n_agents_c + 1 downto 0);
88
  type write_integer_array is array (n_agents_c + 1 downto 0) of integer;
89
  signal wr_dst_addr     : write_integer_array;
90
  signal wr_data_r        : write_integer_array;
91
  signal wr_data_check_r : write_integer_array;
92
  signal wr_offset       : write_integer_array;
93
 
94
  signal rd_src_addr : read_integer_array;
95
 
96
  constant single_write_c : integer := n_agents_c;
97
  constant single_read_c : integer  := n_agents_c + 1;
98
 
99
  signal tb_sdram_write   : std_logic;
100
  signal re_cnt_r         : integer;
101
  signal test_num         : integer;
102
  signal iteration        : integer;
103
  signal i_dbg            : integer;
104
  -- Signals for port request checking
105
  signal rq_timeout_cnt_r : integer;
106
  signal rq_port          : std_logic;
107
  signal got_resp         : std_logic;
108
  signal got_resp_vec     : std_logic_vector(n_agents_c - 1 downto 0);
109
  signal wait_resp_vec    : std_logic_vector(n_agents_c - 1 downto 0);
110
  signal rq_vec           : std_logic_vector(n_agents_c - 1 downto 0);
111
  signal pending_rqs      : integer;
112
 
113
  signal single_op_addr  : integer;
114
  signal single_op_wr_addr  : integer;
115
  signal new_rd_conf     : std_logic;
116
  signal new_rd_idx      : integer;
117
  signal new_rd_addr     : integer;
118
  signal new_rd_amount   : integer;
119
  signal new_wr_conf     : std_logic;
120
  signal new_wr_idx      : integer;
121
  signal new_wr_addr     : integer;
122
  signal new_wr_amount   : integer;
123
  signal wr_addrs_r      : port_offset_array;
124
  signal rd_addrs_r      : port_offset_array;
125
  signal rd_amounts_r    : port_offset_array;
126
  signal wr_amounts_r    : port_offset_array;
127
  signal curr_rd_ag_r    : integer;
128
  signal curr_wr_ag_r    : integer;
129
  signal clr_offset_r    : std_logic;
130
  signal clr_idx_r       : integer;
131
  signal n_free_rd_ports : integer;
132
  signal n_free_wr_ports : integer;
133
  signal sending_data    : std_logic_vector(n_agents_c - 1 downto 0);
134
  signal data_sent       : std_logic_vector(n_agents_c - 1 downto 0);
135
 
136
  -- Signals tb <-> rxfifo
137
  signal c_a_d_tb_rxfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
138
  signal data_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
139
  signal addr_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
140
  signal comm_tb_rxfifo  : std_logic_vector (comm_width-1 downto 0);
141
  signal we_tb_rxfifo    : std_logic;
142
  signal full_rxfifo_tb  : std_logic;
143
  signal one_p_rxfifo_tb : std_logic;
144
 
145
  -- Signals tb <-> msg_rxfifo
146
  signal msg_c_a_d_tb_rxfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
147
  signal msg_data_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
148
  signal msg_addr_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
149
  signal msg_comm_tb_rxfifo  : std_logic_vector (comm_width-1 downto 0);
150
  signal msg_we_tb_rxfifo    : std_logic;
151
  signal msg_full_rxfifo_tb  : std_logic;
152
  signal msg_one_p_rxfifo_tb : std_logic;
153
 
154
  -- Signals tb <-> txfifo
155
  signal re_tb_txfifo    : std_logic;
156
  signal c_a_d_txfifo_tb : std_logic_vector(hibi_data_width+hibi_data_width+comm_width - 1 downto 0);
157
  signal data_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
158
  signal addr_txfifo_tb  : std_logic_vector(hibi_data_width -1 downto 0);
159
  signal comm_txfifo_tb  : std_logic_vector(comm_width - 1 downto 0);
160
  signal empty_txfifo_tb : std_logic;
161
  signal one_d_txfifo_tb : std_logic;
162
 
163
  -- Signals tb <-> msg_txfifo
164
  signal msg_re_tb_txfifo    : std_logic;
165
  signal msg_c_a_d_txfifo_tb : std_logic_vector(hibi_data_width+hibi_data_width+comm_width - 1 downto 0);
166
  signal msg_data_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
167
  signal msg_addr_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
168
  signal msg_comm_txfifo_tb  : std_logic_vector(comm_width - 1 downto 0);
169
  signal msg_empty_txfifo_tb : std_logic;
170
  signal msg_one_d_txfifo_tb : std_logic;
171
 
172
  -- Signals rxfifo <-> dut
173
  signal c_a_d_rxfifo_dut : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
174
  signal addr_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
175
  signal data_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
176
  signal comm_rxfifo_dut  : std_logic_vector(comm_width - 1 downto 0);
177
  signal empty_rxfifo_dut : std_logic;
178
  signal re_dut_rxfifo    : std_logic;
179
 
180
  -- Signals txfifo <-> dut
181
  signal full_txfifo_dut  : std_logic;
182
  signal one_p_txfifo_dut : std_logic;
183
  signal c_a_d_dut_txfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
184
  signal addr_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
185
  signal data_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
186
  signal comm_dut_txfifo  : std_logic_vector(comm_width - 1 downto 0);
187
  signal we_dut_txfifo    : std_logic;
188
 
189
  -- Signals msg_rxfifo <-> dut
190
  signal msg_c_a_d_rxfifo_dut : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
191
  signal msg_addr_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
192
  signal msg_data_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
193
  signal msg_comm_rxfifo_dut  : std_logic_vector(comm_width - 1 downto 0);
194
  signal msg_empty_rxfifo_dut : std_logic;
195
  signal msg_one_d_rxfifo_dut : std_logic;
196
  signal msg_re_dut_rxfifo    : std_logic;
197
 
198
  -- Signals msg_txfifo <-> dut
199
  signal msg_full_txfifo_dut  : std_logic;
200
  signal msg_one_p_txfifo_dut : std_logic;
201
  signal msg_c_a_d_dut_txfifo : std_logic_vector(hibi_data_width + hibi_data_width + comm_width - 1 downto 0);
202
  signal msg_addr_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
203
  signal msg_data_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
204
  signal msg_comm_dut_txfifo  : std_logic_vector(comm_width - 1 downto 0);
205
  signal msg_we_dut_txfifo    : std_logic;
206
 
207
  -- Signals dut <-> sdram_controller
208
  signal write_on_tb_dut : std_logic;
209
  signal busy_tb_dut     : std_logic;
210
  signal re_tb_dut       : std_logic;
211
  signal we_tb_dut       : std_logic;
212
  signal data_tb_dut     : std_logic_vector(31 downto 0);
213
  signal comm_dut_tb     : std_logic_vector(1 downto 0);
214
  signal addr_dut_tb     : std_logic_vector(21 downto 0);
215
  signal amount_dut_tb   : std_logic_vector(21 downto 0);
216
 
217
  signal byte_sel_dut_tb : std_logic_vector(3 downto 0);
218
  signal empty_dut_tb    : std_logic;
219
  signal one_d_dut_tb    : std_logic;
220
  signal full_dut_tb     : std_logic;
221
  signal data_dut_tb     : std_logic_vector(31 downto 0);
222
 
223
  -- sdram_ctrl <-> tb
224
  signal sdram_data_inout : std_logic_vector(31 downto 0);
225
  signal sdram_cke_out    : std_logic;
226
  signal sdram_cs_n_out   : std_logic;
227
  signal sdram_we_n_out   : std_logic;
228
  signal sdram_ras_n_out  : std_logic;
229
  signal sdram_cas_n_out  : std_logic;
230
  signal sdram_dqm_out    : std_logic_vector(3 downto 0);
231
  signal sdram_ba_out     : std_logic_vector(1 downto 0);
232
  signal sdram_addr_out   : std_logic_vector(11 downto 0);
233
  signal was_busy_r       : std_logic;
234
 
235
  signal hibi_addr_mask : std_logic_vector(mem_addr_width - 1 downto 0) := (others => '1');
236
 
237
begin  -- behavioral
238
 
239
  sel_old_config_method : if dut_ver_g < 7 generate
240
    old_config_method <= 1;
241
  end generate sel_old_config_method;
242
  sel_new_config_method : if dut_ver_g >= 7 generate
243
    old_config_method <= 0;
244
  end generate sel_new_config_method;
245
 
246
  -- Generate addresses fo testbench agents.
247
  -- First agent's address is 1000
248
  -- Second's 2000 and so on...
249
  gen_tb_agent_addrs : for i in 0 to n_agents_c + 1 generate
250
    agent_addrs_r(i) <= 16#01000000# * (i+1) + 16#1000# * (i+1);
251
  end generate;  -- gen_tb_agent_addrs
252
 
253
  -- Concurrent assignments
254
  -- tb -> rx_fifo
255
  c_a_d_tb_rxfifo     <= comm_tb_rxfifo & addr_tb_rxfifo & data_tb_rxfifo;
256
  msg_c_a_d_tb_rxfifo <= msg_comm_tb_rxfifo & msg_addr_tb_rxfifo & msg_data_tb_rxfifo;
257
 
258
  -- rx_fifo -> dut
259
  comm_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
260
                     when empty_rxfifo_dut = '0' else (others => 'Z');
261
  addr_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
262
                     when empty_rxfifo_dut = '0' else (others => 'Z');
263
  data_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width -1 downto 0)
264
                     when empty_rxfifo_dut = '0' else (others => 'Z');
265
 
266
  msg_comm_rxfifo_dut <= msg_c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
267
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
268
  msg_addr_rxfifo_dut <= msg_c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
269
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
270
  msg_data_rxfifo_dut <= msg_c_a_d_rxfifo_dut (hibi_data_width -1 downto 0)
271
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
272
 
273
  -- dut -> tx_fifo
274
  c_a_d_dut_txfifo     <= comm_dut_txfifo & addr_dut_txfifo & data_dut_txfifo;
275
  msg_c_a_d_dut_txfifo <= msg_comm_dut_txfifo & msg_addr_dut_txfifo & msg_data_dut_txfifo;
276
 
277
  -- tx_fifo -> tb
278
  comm_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
279
                    when empty_txfifo_tb = '0' else (others => 'Z');
280
  addr_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
281
                    when empty_txfifo_tb = '0' else (others => 'Z');
282
  data_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width -1 downto 0)
283
                    when empty_txfifo_tb = '0' else (others => 'Z');
284
 
285
  msg_comm_txfifo_tb <= msg_c_a_d_txfifo_tb (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
286
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
287
  msg_addr_txfifo_tb <= msg_c_a_d_txfifo_tb (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
288
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
289
  msg_data_txfifo_tb <= msg_c_a_d_txfifo_tb (hibi_data_width -1 downto 0)
290
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
291
 
292
  -- 1) PROC
293
  Generate_input : postponed process
294
 
295
    ---------------------------------------------------------------------------
296
    -- Write to rx_fifo
297
    ---------------------------------------------------------------------------
298
    procedure WriteToFifo (
299
      addr_to_fifo : in integer;
300
      data_to_fifo : in integer;
301
      comm_to_fifo : in integer) is
302
 
303
    begin  --procedure
304
 
305
      while full_rxfifo_tb = '1' loop
306
        wait for period_c;
307
      end loop;
308
 
309
      data_tb_rxfifo <= std_logic_vector(to_unsigned (data_to_fifo, hibi_data_width));
310
      comm_tb_rxfifo <= std_logic_vector(to_unsigned (comm_to_fifo, comm_width));
311
      addr_tb_rxfifo <= std_logic_vector(to_unsigned (addr_to_fifo, hibi_data_width));
312
      we_tb_rxfifo   <= '1';
313
 
314
      wait for period_c;
315
 
316
      we_tb_rxfifo   <= '0';
317
      data_tb_rxfifo <= (others => 'Z');
318
      comm_tb_rxfifo <= (others => 'Z');
319
      addr_tb_rxfifo <= (others => 'Z');
320
 
321
    end WriteToFifo;
322
 
323
    ---------------------------------------------------------------------------
324
    -- Write to msg_rx_fifo
325
    ---------------------------------------------------------------------------
326
    procedure WriteToMsgFifo (
327
      addr_to_fifo : in integer;
328
      data_to_fifo : in integer;
329
      comm_to_fifo : in integer) is
330
 
331
    begin  --procedure
332
 
333
      while msg_full_rxfifo_tb = '1' loop
334
        wait for period_c;
335
      end loop;
336
 
337
      msg_addr_tb_rxfifo <= std_logic_vector(to_unsigned (addr_to_fifo, hibi_data_width));
338
      msg_data_tb_rxfifo <= std_logic_vector(to_unsigned (data_to_fifo, hibi_data_width));
339
      msg_comm_tb_rxfifo <= std_logic_vector(to_unsigned (comm_to_fifo, comm_width));
340
      msg_we_tb_rxfifo   <= '1';
341
 
342
      wait for period_c;
343
 
344
      msg_addr_tb_rxfifo <= (others => 'Z');
345
      msg_data_tb_rxfifo <= (others => 'Z');
346
      msg_comm_tb_rxfifo <= (others => 'Z');
347
      msg_we_tb_rxfifo   <= '0';
348
 
349
    end WriteToMsgFifo;
350
 
351
    ---------------------------------------------------------------------------
352
    -- Request read port from DUT
353
    --
354
    -- If agent has a port offset /= 0, we assume that the previous operation
355
    -- hasn't completed and we wait until it is finished and port_offset reset
356
    ---------------------------------------------------------------------------
357
    procedure rq_read_port (
358
      agent_number : in integer) is
359
 
360
    begin
361
 
362
--      assert n_free_rd_ports /= 0 report "Waiting for free read ports" severity note;
363
--      while n_free_rd_ports = 0 loop
364
--        wait for period_c;
365
--      end loop;
366
 
367
      assert port_offsets_r(agent_number) = 0
368
        report "TB: agent " & str(agent_number)
369
        & " waiting for previous operation before reserving new read port"
370
        severity note;
371
 
372
      while port_offsets_r(agent_number) /= 0 loop
373
        wait for period_c;
374
      end loop;
375
 
376
      while msg_full_rxfifo_tb = '1' loop
377
        wait for period_c;
378
      end loop;
379
 
380
      if clr_idx_r /= agent_number or clr_offset_r = '0' then
381
 
382
        rq_port                <= '1';
383
        rd_wr_rq(agent_number) <= '0';
384
        rq_vec(agent_number)   <= '1';
385
        msg_addr_tb_rxfifo     <= std_logic_vector(to_unsigned (0, hibi_data_width));
386
        msg_data_tb_rxfifo     <= std_logic_vector(to_unsigned (agent_addrs_r(agent_number), hibi_data_width));
387
        msg_comm_tb_rxfifo     <= std_logic_vector(to_unsigned (3, comm_width));
388
        msg_we_tb_rxfifo       <= '1';
389
 
390
        wait for period_c;
391
--      assert false
392
--        report "Agent " & str(agent_number) & " requested read port"
393
--        severity note;
394
        rq_port              <= '0';
395
        rq_vec(agent_number) <= '0';
396
 
397
        msg_addr_tb_rxfifo <= (others => 'Z');
398
        msg_data_tb_rxfifo <= (others => 'Z');
399
        msg_comm_tb_rxfifo <= (others => 'Z');
400
        msg_we_tb_rxfifo   <= '0';
401
      end if;
402
 
403
    end procedure;  -- rq_read_port
404
 
405
    ---------------------------------------------------------------------------
406
    -- Request write port from DUT
407
    --
408
    -- If agent has a port offset /= 0, we assume that the previous operation
409
    -- hasn't completed and we wait until it is finished and port_offset reset
410
    ---------------------------------------------------------------------------
411
    procedure rq_write_port (
412
      agent_number : in integer) is
413
    begin
414
 
415
--      assert n_free_wr_ports /= 0 report "Waiting for free write ports" severity note;
416
--      while n_free_wr_ports = 0 loop
417
--        wait for period_c;
418
--      end loop;
419
 
420
      assert port_offsets_r(agent_number) = 0
421
        report "TB: agent " & str(agent_number)
422
        & " waiting for previous operation before reserving new write port"
423
        severity note;
424
 
425
      while port_offsets_r(agent_number) /= 0 loop
426
        wait for period_c;
427
      end loop;
428
 
429
      while msg_full_rxfifo_tb = '1' loop
430
        wait for period_c;
431
      end loop;
432
 
433
      rq_port                <= '1';
434
      rq_vec(agent_number)   <= '1';
435
      rd_wr_rq(agent_number) <= '1';
436
      --assert false report "Fifo full. Cannot write" severity note;
437
      msg_addr_tb_rxfifo     <= std_logic_vector(to_unsigned (1, hibi_data_width));
438
      msg_data_tb_rxfifo     <= std_logic_vector(to_unsigned (agent_addrs_r(agent_number), hibi_data_width));
439
      msg_comm_tb_rxfifo     <= std_logic_vector(to_unsigned (3, comm_width));
440
      msg_we_tb_rxfifo       <= '1';
441
 
442
      wait for period_c;
443
--      assert false
444
--        report "Agent " & str(agent_number) & " requested write port"
445
--        severity note;
446
      rq_port              <= '0';
447
      rq_vec(agent_number) <= '0';
448
 
449
      msg_addr_tb_rxfifo <= (others => 'Z');
450
      msg_data_tb_rxfifo <= (others => 'Z');
451
      msg_comm_tb_rxfifo <= (others => 'Z');
452
      msg_we_tb_rxfifo   <= '0';
453
 
454
    end procedure;  -- rq_write_port
455
 
456
    ---------------------------------------------------------------------------
457
    -- Configure read port
458
    --
459
    -- If previous read operation hasn't finished, asserts failure
460
    -- If we haven't got response for port request, we wait for it.
461
    -- If we get zero response(i.e. ports not available), we skip configuring
462
    ---------------------------------------------------------------------------
463
    procedure configure_read_port (
464
      agent_number : in integer;
465
      amount       : in integer) is
466
    begin
467
 
468
      assert rd_amounts_r(agent_number) = 0
469
        report "TB ERROR: Tried to configure valid read port"
470
        severity failure;
471
 
472
      assert got_resp_vec(agent_number) = '1'
473
        report "Waiting for port offset before configuring read port"
474
        severity note;
475
      while got_resp_vec(agent_number) = '0' loop
476
        wait for period_c;
477
      end loop;
478
 
479
      assert port_offsets_r(agent_number) /= 0
480
        report "Agent " & str(agent_number) & " No reserved read port, can not configure"
481
        severity note;
482
 
483
      if port_offsets_r(agent_number) /= 0 then
484
 
485
--        assert false report "Configure read agent" severity note;
486
        -- src addr
487
        WriteToMsgFifo(port_offsets_r(agent_number), agent_addrs_r(agent_number), 3);
488
        -- amount/width
489
        WriteToMsgFifo(port_offsets_r(agent_number)+old_config_method*1, amount, 3);
490
 
491
        -- height&offset
492
        WriteToMsgFifo(port_offsets_r(agent_number)+old_config_method*2, 0, 3);
493
 
494
        -- Signal to check_sdram_addrs process that we have configured a read port
495
        new_rd_conf   <= '1';
496
        new_rd_idx    <= agent_number;
497
        new_rd_addr   <= agent_addrs_r(agent_number);
498
        new_rd_amount <= amount;
499
        wait for period_c;
500
        new_rd_conf   <= '0';
501
        new_rd_idx    <= 0;
502
        new_rd_addr   <= 0;
503
        new_rd_amount <= 0;
504
 
505
        -- return address
506
        WriteToMsgFifo(port_offsets_r(agent_number)+old_config_method*3, 1, 3);
507
        rd_src_addr(agent_number) <= rd_src_addr(agent_number) + amount;
508
      end if;
509
 
510
    end procedure;
511
 
512
    ---------------------------------------------------------------------------
513
    -- Configure write port
514
    --
515
    -- If previous write operation hasn't finished, asserts failure
516
    -- If we haven't got response for port request, we wait for it.
517
    -- If we get zero response(i.e. ports not available) we skip configuring
518
    ---------------------------------------------------------------------------
519
    procedure configure_write_port (
520
      agent_number : in integer;
521
      amount       : in integer) is
522
    begin
523
 
524
      assert wr_amounts_r(agent_number) = 0
525
        report "TB ERROR: Tried to configure valid write port"
526
        severity failure;
527
 
528
      assert got_resp_vec(agent_number) = '1'
529
        report "Waiting for port offset before configuring write port"
530
        severity note;
531
      while got_resp_vec(agent_number) = '0' loop
532
        wait for period_c;
533
      end loop;
534
 
535
      assert port_offsets_r(agent_number) /= 0
536
        report "Agent " & str(agent_number) & " No reserved write port, can not configure"
537
        severity note;
538
 
539
      if port_offsets_r(agent_number) /= 0 then
540
        -- dst_addr
541
        WriteToMsgFifo(port_offsets_r(agent_number), agent_addrs_r(agent_number), 3);
542
        -- amount/width
543
        WriteToMsgFifo(port_offsets_r(agent_number)+old_config_method*1, amount, 3);
544
 
545
        -- height&offset
546
        WriteToMsgFifo(port_offsets_r(agent_number)+old_config_method*2, 0, 3);
547
 
548
        -- Signal to check_sdram_addrs process that we have configured a read port
549
        new_wr_conf   <= '1';
550
        new_wr_idx    <= agent_number;
551
        new_wr_addr   <= agent_addrs_r(agent_number);
552
        new_wr_amount <= amount;
553
        wait for period_c;
554
--        assert false
555
--          report "Agent " & str(agent_number) & " configure write port"
556
--          severity note;
557
        new_wr_conf   <= '0';
558
        new_wr_idx    <= 0;
559
        new_wr_addr   <= 0;
560
        new_wr_amount <= 0;
561
 
562
        wr_dst_addr(agent_number) <= wr_dst_addr(agent_number) + amount;  --write_amount(w);
563
 
564
      end if;
565
    end procedure;
566
 
567
    procedure single_op (
568
      constant r_w    : in std_logic;
569
      constant amount : in integer) is
570
    begin  -- single_op
571
 
572
      if r_w = '1' then
573
        new_wr_conf    <= '1';
574
        new_wr_idx     <= single_write_c;
575
        new_wr_addr    <= agent_addrs_r(single_write_c);
576
        new_wr_amount  <= amount;
577
        single_op_addr <= agent_addrs_r(single_write_c);
578
      else
579
        new_rd_conf    <= '1';
580
        new_rd_idx     <= single_read_c;
581
        new_rd_addr    <= agent_addrs_r(single_read_c);
582
        new_rd_amount  <= amount;
583
        single_op_addr <= agent_addrs_r(single_read_c);
584
      end if;
585
 
586
      wait for period_c;
587
 
588
      new_rd_conf   <= '0';
589
      new_rd_idx    <= 0;
590
      new_rd_addr   <= 0;
591
      new_rd_amount <= 0;
592
      new_wr_conf   <= '0';
593
      new_wr_idx    <= 0;
594
      new_wr_addr   <= 0;
595
      new_wr_amount <= 0;
596
 
597
      if r_w = '1' then
598
        -- write
599
        for i in 0 to amount - 1 loop
600
 
601
      while full_rxfifo_tb = '1' loop
602
        wait for period_c;
603
      end loop;
604
 
605
      data_tb_rxfifo <= std_logic_vector(to_unsigned(
606
        wr_data_r(single_write_c), hibi_data_width));
607
      comm_tb_rxfifo <= std_logic_vector(to_unsigned(2, comm_width));
608
      addr_tb_rxfifo <= std_logic_vector(to_unsigned(
609
        single_op_addr, hibi_data_width));
610
      we_tb_rxfifo   <= '1';
611
 
612
      wr_data_r(single_write_c) <= wr_data_r(single_write_c) + 1;
613
      single_op_addr <= single_op_addr + 1;
614
      wait for period_c;
615
 
616
      we_tb_rxfifo   <= '0';
617
      data_tb_rxfifo <= (others => 'Z');
618
      comm_tb_rxfifo <= (others => 'Z');
619
      addr_tb_rxfifo <= (others => 'Z');
620
--          WriteToFifo(single_op_addr, wr_data_r(single_write_c), 2);
621
        end loop;  -- i
622
      else
623
        -- read
624
        for i in 0 to amount - 1 loop
625
          while full_rxfifo_tb = '1' loop
626
            wait for period_c;
627
          end loop;
628
 
629
      data_tb_rxfifo <= std_logic_vector(to_unsigned(
630
        agent_addrs_r(single_read_c), hibi_data_width));
631
      comm_tb_rxfifo <= std_logic_vector(to_unsigned(0, comm_width));
632
      addr_tb_rxfifo <= std_logic_vector(to_unsigned(
633
        single_op_addr, hibi_data_width));
634
      we_tb_rxfifo   <= '1';
635
 
636
      single_op_addr <= single_op_addr + 1;
637
      wait for period_c;
638
 
639
      we_tb_rxfifo   <= '0';
640
      data_tb_rxfifo <= (others => 'Z');
641
      comm_tb_rxfifo <= (others => 'Z');
642
      addr_tb_rxfifo <= (others => 'Z');
643
--          WriteToFifo(single_op_addr, agent_addrs_r(single_read_c), 0);
644
        end loop;  -- i        
645
      end if;
646
    end single_op;
647
    ---------------------------------------------------------------------------
648
    -- Writes write data to rx fifo
649
    ---------------------------------------------------------------------------
650
    procedure write_input_data (
651
      agent_number : in integer;
652
      amount       : in integer) is
653
    begin
654
 
655
      for i in 0 to amount - 1 loop
656
        sending_data(agent_number) <= '1';
657
 
658
        while full_rxfifo_tb = '1' loop
659
          wait for period_c;
660
        end loop;
661
 
662
        data_tb_rxfifo <= std_logic_vector(to_unsigned(
663
          wr_data_r(agent_number), hibi_data_width));
664
 
665
        comm_tb_rxfifo <= std_logic_vector(to_unsigned(2, comm_width));
666
        addr_tb_rxfifo <= std_logic_vector(to_unsigned(
667
          port_offsets_r(agent_number)+3*old_config_method, hibi_data_width));
668
 
669
        we_tb_rxfifo   <= '1';
670
 
671
        wr_data_r(agent_number)    <= wr_data_r(agent_number) + 1;
672
        wait for period_c;
673
 
674
--        WriteToFifo(port_offsets_r(agent_number)+3*old_config_method, wr_data_r(agent_number), 2);
675
      end loop;  -- i
676
      we_tb_rxfifo   <= '0';
677
      data_tb_rxfifo <= (others => 'Z');
678
      comm_tb_rxfifo <= (others => 'Z');
679
      addr_tb_rxfifo <= (others => 'Z');
680
      sending_data(agent_number) <= '0';
681
 
682
    end procedure;
683
 
684
-------------------------------------------------------------------------------
685
-- TESTBENCH
686
-------------------------------------------------------------------------------
687
    variable j : integer;
688
  begin  -- process Generate_input
689
 
690
    -- test sequence
691
    -- 0 wait for reset
692
    -- 1 write to empty fifo and read so that it is empty again
693
    -- 2 write to fifo until there is only one place left
694
    -- Wait for reset
695
 
696
    -- reset
697
    data_tb_rxfifo     <= (others => 'Z');
698
    addr_tb_rxfifo     <= (others => 'Z');
699
    comm_tb_rxfifo     <= (others => 'Z');
700
    we_tb_rxfifo       <= '0';
701
    msg_data_tb_rxfifo <= (others => 'Z');
702
    msg_addr_tb_rxfifo <= (others => 'Z');
703
    msg_comm_tb_rxfifo <= (others => 'Z');
704
    msg_we_tb_rxfifo   <= '0';
705
    wr_offset          <= (others => 0);
706
    rq_port            <= '0';
707
    new_rd_conf        <= '0';
708
    new_rd_idx         <= 0;
709
    new_rd_addr        <= 0;
710
    new_rd_amount      <= 0;
711
    new_wr_conf        <= '0';
712
    new_wr_idx         <= 0;
713
    new_wr_addr        <= 0;
714
    new_wr_amount      <= 0;
715
    rd_wr_rq           <= (others => '0');
716
    rq_vec             <= (others => '0');
717
    tb_state           <= rst;
718
    test_num           <= 0;
719
    iteration          <= 0;
720
    sending_data       <= (others => '0');
721
    for i in 0 to n_agents_c loop
722
      rd_src_addr(i) <= i * 4096;       --X"1000";
723
    end loop;  -- i
724
 
725
    for i in 0 to n_agents_c loop
726
      wr_dst_addr(i) <= i * 4096;       --X"1000";
727
      wr_data_r(i)   <= i * 100;
728
    end loop;  -- i
729
 
730
 
731
    wait for period_c/2;
732
    wait for period_c/5;
733
 
734
    if rst_n = '0' then
735
      wait until rst_n = '1';
736
    end if;
737
 
738
    wait for period_c/2;
739
    wait for period_c/5;
740
 
741
    wait for period_c;
742
    while true loop
743
 
744
      tb_state <= rq_wr;
745
 
746
      -- TEST 1, request n_agents_c write ports and
747
      --         configure num_of_write_ports write ports
748
      --         send write data
749
      test_num  <= 1;
750
      iteration <= 0;
751
 
752
 
753
      for iter in 0 to 1000 loop
754
        tb_state <= rq_wr;
755
        for i in 0 to n_agents_c/2 - 1 loop
756
          -- request write port if agent is not waiting for response and
757
          -- has no valid port
758
          if wait_resp_vec(i) = '0'
759
            and port_offsets_r(i) = 0 then
760
            i_dbg <= i;
761
            rq_write_port(i);
762
          end if;
763
        end loop;  -- i
764
 
765
        -- single op reads, if previous single op reads have been completed
766
        if rd_amounts_r(single_read_c) = 0 then
767
          single_op('0', 5);
768
        end if;
769
 
770
        -- single op writes, if previous single op writes have been completed
771
        if wr_amounts_r(single_write_c) = 0 then
772
          single_op('1', 5);
773
        end if;
774
        for i in n_agents_c/2 to n_agents_c - 1 loop
775
          -- request read port if agent is not waiting for response and
776
          -- has no valid port
777
          if wait_resp_vec(i) = '0'
778
            and port_offsets_r(i) = 0 then
779
            i_dbg <= i;
780
            rq_read_port(i);
781
          end if;
782
        end loop;  -- i
783
 
784
        -- single op writes, if previous single op writes have been completed
785
        if wr_amounts_r(single_write_c) = 0 then
786
          single_op('1', 5);
787
        end if;
788
        -- single op reads, if previous single op reads have been completed
789
        if rd_amounts_r(single_read_c) = 0 then
790
          single_op('0', 5);
791
        end if;
792
        tb_state  <= conf_wr;
793
        iteration <= iteration + 1;
794
        for i in 0 to n_agents_c/2 - 1 loop
795
          -- configure write port if agent has got port offset and
796
          -- hasn't been configured yet
797
          if port_offsets_r(i) /= 0
798
            and wr_amounts_r(i) = 0
799
            and not(clr_idx_r = i and clr_offset_r = '1') then
800
            i_dbg <= i;
801
            configure_write_port(i, 1+i*2);
802
          end if;
803
        end loop;  -- i
804
 
805
        -- single op reads, if previous single op reads have been completed
806
        if rd_amounts_r(single_read_c) = 0 then
807
          single_op('0', 5);
808
        end if;
809
        -- single op writes, if previous single op writes have been completed
810
        if wr_amounts_r(single_write_c) = 0 then
811
          single_op('1', 5);
812
        end if;
813
        for i in n_agents_c/2 to n_agents_c - 1 loop
814
          -- configure read port if agent has got port offset and
815
          -- hasn't been configured yet
816
          if port_offsets_r(i) /= 0
817
            and rd_amounts_r(i) = 0
818
            and not(clr_idx_r = i and clr_offset_r = '1') then
819
            i_dbg <= i;
820
            configure_read_port(i, 1+i*2);
821
          end if;
822
        end loop;  -- i
823
 
824
        tb_state <= send_wr_data;
825
        for i in 0 to n_agents_c/2 - 1 loop
826
          -- send write data if agent has configured write port
827
          -- and write data hasn't been sent
828
          if wr_amounts_r(i) /= 0 and data_sent(i) = '0' then
829
            i_dbg <= i;
830
            write_input_data(i, 1+i*2);
831
          end if;
832
        end loop;  -- i
833
        wait for period_c;
834
      end loop;  -- iter
835
 
836
      -- finish test 1 by completing unfinished operations
837
      for i in n_agents_c/2 - 1 downto 0 loop
838
 
839
        wait for period_c;
840
        tb_state <= conf_wr;
841
        for i in 0 to n_agents_c/2 - 1 loop
842
          -- configure write port if agent has got port offset and
843
          -- hasn't been configured yet
844
          if port_offsets_r(i) /= 0 and wr_amounts_r(i) = 0
845
            and not(clr_idx_r = i and clr_offset_r = '1') then
846
            i_dbg <= i;
847
            configure_write_port(i, 1+i*2);
848
          end if;
849
        end loop;  -- i
850
        tb_state <= send_wr_data;
851
 
852
        for i in 0 to n_agents_c/2 - 1 loop
853
          -- send write data if agent has configured write port
854
          -- and doesn't have write data
855
          if wr_amounts_r(i) /= 0 and data_sent(i) = '0' then
856
            i_dbg <= i;
857
            write_input_data(i, 1+i*2);
858
          end if;
859
        end loop;  -- i
860
        wait for period_c*20;
861
      end loop;  -- i
862
 
863
      wait for period_c*50;
864
 
865
-------------------------------------------------------------------------------
866
-- Test 2:
867
-- Port operations of length 1
868
-------------------------------------------------------------------------------
869
      test_num  <= 2;
870
      iteration <= 0;
871
 
872
      for iter in 0 to 1000 loop
873
 
874
        for i in 0 to n_agents_c/2 - 1 loop
875
 
876
          -- single op reads, if previous single op reads have been completed
877
          if rd_amounts_r(single_read_c) = 0 then
878
            single_op('0', 1);
879
          end if;
880
          -- single op writes, if previous single op writes have been completed
881
          if wr_amounts_r(single_write_c) = 0 then
882
            single_op('1', 1);
883
          end if;
884
 
885
          tb_state <= rq_rd;
886
          -- request read port if agent is not waiting for response and
887
          -- has no valid port
888
          if wait_resp_vec(i+n_agents_c/2) = '0'
889
            and port_offsets_r(i+n_agents_c/2) = 0 then
890
            i_dbg <= i;
891
            rq_read_port(i+n_agents_c/2);
892
          end if;
893
 
894
          tb_state <= rq_wr;
895
          -- request write port if agent is not waiting for response and
896
          -- has no valid port
897
          if wait_resp_vec(i) = '0'
898
            and port_offsets_r(i) = 0 then
899
            i_dbg <= i;
900
            rq_write_port(i);
901
          end if;
902
 
903
          -- single op reads, if previous single op reads have been completed
904
          if rd_amounts_r(single_read_c) = 0 then
905
            single_op('0', 1);
906
          end if;
907
          -- single op writes, if previous single op writes have been completed
908
          if wr_amounts_r(single_write_c) = 0 then
909
            single_op('1', 1);
910
          end if;
911
 
912
          -- configure read port if agent has got port offset and
913
          -- hasn't been configured yet
914
          tb_state  <= conf_rd;
915
          if port_offsets_r(i+n_agents_c/2) /= 0 and rd_amounts_r(i+n_agents_c/2) = 0
916
            and not(clr_idx_r = i+n_agents_c/2 and clr_offset_r = '1') then
917
            i_dbg <= i;
918
            configure_read_port(i+n_agents_c/2, 1);
919
          end if;
920
 
921
          wait for period_c;
922
 
923
          tb_state  <= conf_wr;
924
          if port_offsets_r(i) /= 0
925
            and wr_amounts_r(i) = 0
926
            and not(clr_idx_r = i and clr_offset_r = '1') then
927
            configure_write_port(i, 1);
928
          end if;
929
 
930
          -- single op reads, if previous single op reads have been completed
931
          if rd_amounts_r(single_read_c) = 0 then
932
            single_op('0', 1);
933
          end if;
934
          -- single op writes, if previous single op writes have been completed
935
          if wr_amounts_r(single_write_c) = 0 then
936
            single_op('1', 1);
937
          end if;
938
          -- send write data
939
          tb_state <= send_wr_data;
940
          if wr_amounts_r(i) /= 0 and data_sent(i) = '0' then
941
            i_dbg <= i;
942
            write_input_data(i, 1);
943
          end if;
944
        end loop;  -- i
945
        iteration <= iteration + 1;
946
      end loop;  -- iter
947
 
948
 
949
      -- finish test 2 by completing unfinished operations
950
      for i in n_agents_c/2 - 1 downto 0 loop
951
 
952
        wait for period_c;
953
        tb_state <= conf_rd;
954
        for i in 0 to n_agents_c/2 - 1 loop
955
          -- configure read port if agent has got port offset but
956
          -- hasn't been configured yet
957
          if port_offsets_r(i+n_agents_c/2) /= 0 and rd_amounts_r(i+n_agents_c/2) = 0
958
            and not(clr_idx_r = i+n_agents_c/2 and clr_offset_r = '1') then
959
            i_dbg <= i;
960
            configure_read_port(i+n_agents_c/2, 1);
961
          end if;
962
          if port_offsets_r(i) /= 0 and wr_amounts_r(i) = 0
963
            and not(clr_idx_r = i and clr_offset_r = '1') then
964
            i_dbg <= i;
965
            configure_write_port(i, 1);
966
          end if;
967
          if wr_amounts_r(i) /= 0 and data_sent(i) = '0' then
968
            i_dbg <= i;
969
            write_input_data(i, 1);
970
          end if;
971
        end loop;  -- i
972
 
973
        wait for period_c*50;
974
      end loop;  -- i
975
 
976
      -- wait for previous test
977
      for i in 0 to n_agents_c - 1 loop
978
        while port_offsets_r(i) /= 0 loop
979
          wait for period_c;
980
        end loop;
981
      end loop;  -- i
982
 
983
      wait for 20*period_c;
984
 
985
      for i in n_agents_c - 1 downto 0 loop
986
        assert port_offsets_r(i) = 0
987
          report "Transfers not finished" severity failure;
988
        assert wait_resp_vec(i) = '0'
989
          report "Waiting for port offset" severity failure;
990
      end loop;  -- i
991
      assert false report "++++++++++++++" severity note;
992
      assert false report "Test completed" severity note;
993
      assert false report "++++++++++++++" severity failure;
994
    end loop;
995
 
996
    wait;
997
  end process Generate_input;
998
 
999
 
1000
-------------------------------------------------------------------------------
1001
-- Check that we get responses for port requests
1002
-------------------------------------------------------------------------------
1003
  count_rqs_and_resps : process(clk, rst_n)
1004
  begin  -- count_rqs_and_resps
1005
    if rst_n = '0' then
1006
      pending_rqs      <= 0;
1007
      rq_timeout_cnt_r <= 0;
1008
    elsif clk'event and clk = '1' then
1009
 
1010
      -- Keep count of port requests and responses
1011
      if rq_port = '1' and got_resp = '0' then
1012
        pending_rqs <= pending_rqs + 1;
1013
      elsif rq_port = '0' and got_resp = '1' then
1014
        pending_rqs <= pending_rqs - 1;
1015
      else
1016
        pending_rqs <= pending_rqs;
1017
      end if;
1018
 
1019
      -- How long have we waited for response?
1020
      if pending_rqs > 0 and got_resp = '0' then
1021
        rq_timeout_cnt_r <= rq_timeout_cnt_r + 1;
1022
      else
1023
        rq_timeout_cnt_r <= 0;
1024
      end if;
1025
 
1026
      -- Check that we don't get more responses than requested
1027
      assert pending_rqs >= 0
1028
        report "Got more ports than requested"
1029
        severity failure;
1030
 
1031
      -- Check that we get responses for requests
1032
--      assert rq_timeout_cnt_r < rq_timeout_c
1033
--        report "Didn't get response for port request"
1034
--        severity failure;
1035
 
1036
    end if;
1037
  end process;
1038
 
1039
-------------------------------------------------------------------------------
1040
-- Read port request responses and store port offsets
1041
-------------------------------------------------------------------------------
1042
  rd_rq_resps : process (clk, rst_n)
1043
    variable check_resp_addr_v : std_logic := '0';
1044
    variable n_free_r_ports_v  : integer;
1045
    variable n_free_w_ports_v  : integer;
1046
  begin  -- process rd_rq_resps
1047
    if rst_n = '0' then                 -- asynchronous reset (active low)
1048
      msg_re_tb_txfifo <= '0';
1049
      got_resp         <= '0';
1050
      port_offsets_r   <= (others => 0);
1051
      n_free_rd_ports  <= num_of_r_ports_g;
1052
      n_free_wr_ports  <= num_of_w_ports_g;
1053
      got_resp_vec     <= (others => '0');
1054
      wait_resp_vec    <= (others => '0');
1055
      re_cnt_r         <= 0;
1056
 
1057
    elsif clk'event and clk = '1' then  -- rising clock edge
1058
 
1059
      -- Delay reading to test DUT when msg_tx_fifo is full
1060
      if msg_empty_txfifo_tb = '0' then
1061
        if re_cnt_r = re_delay_c then
1062
          msg_re_tb_txfifo <= '1';
1063
          re_cnt_r         <= 0;
1064
        else
1065
          msg_re_tb_txfifo <= '0';
1066
          re_cnt_r         <= re_cnt_r + 1;
1067
        end if;
1068
      end if;
1069
 
1070
      n_free_r_ports_v := n_free_rd_ports;
1071
      n_free_w_ports_v := n_free_wr_ports;
1072
 
1073
      check_resp_addr_v := '0';
1074
 
1075
      -- Clear got_resp, when new request is issued
1076
      got_resp_vec <= got_resp_vec and not(rq_vec);
1077
 
1078
 
1079
      for i in n_agents_c - 1 downto 0 loop
1080
        if rq_vec(i) = '1' then
1081
          -- Set wait_resp_vec, when agent requests port
1082
          wait_resp_vec(i) <= '1';
1083
        else
1084
          -- Clear wait_resp when we get a response
1085
          wait_resp_vec(i) <= wait_resp_vec(i) and not(got_resp_vec(i));
1086
        end if;
1087
      end loop;  -- i
1088
 
1089
      -- Check that we don't get more read ports than
1090
      -- the actual number of read ports
1091
      assert n_free_rd_ports >= 0
1092
        report "Got more read ports than num_of_r_ports"
1093
        severity failure;
1094
      assert n_free_rd_ports <= num_of_r_ports_g
1095
                                report "More free read ports than num_of_r_ports"
1096
                                severity failure;
1097
 
1098
      -- Check that we don't get more write ports than
1099
      -- the actual number of write ports
1100
      assert n_free_wr_ports >= 0
1101
        report "Got more write ports than num_of_w_ports"
1102
        severity failure;
1103
      assert n_free_wr_ports <= num_of_w_ports_g
1104
                                report "More free write ports than num_of_w_ports"
1105
                                severity failure;
1106
 
1107
      -- If operation finishes we must clear the port offset and
1108
      -- increase the number of free ports
1109
      if clr_offset_r = '1'
1110
        and clr_idx_r /= single_read_c and clr_idx_r /= single_write_c then
1111
        assert false report "Agent " & str(clr_idx_r) & " operation finished" severity note;
1112
        port_offsets_r(clr_idx_r) <= 0;
1113
        if rd_wr_rq(clr_idx_r) = '0' then
1114
          n_free_r_ports_v := n_free_r_ports_v + 1;
1115
        else
1116
          n_free_w_ports_v := n_free_w_ports_v + 1;
1117
        end if;
1118
      end if;
1119
 
1120
      -- Read DUT responses from msg_tx_fifo
1121
      if msg_empty_txfifo_tb = '0' and msg_re_tb_txfifo = '1' then
1122
 
1123
        -- Fifo not empty so we got a response
1124
        got_resp <= '1';
1125
 
1126
        -- zero is a valid response(no ports available)
1127
        if to_integer(unsigned(msg_addr_txfifo_tb)) = 0 then
1128
          check_resp_addr_v := '1';
1129
        end if;
1130
 
1131
        -- Check which testbench agent got response
1132
        for i in 0 to n_agents_c - 1 loop
1133
          if to_integer(unsigned(msg_addr_txfifo_tb)) = agent_addrs_r(i) then
1134
            check_resp_addr_v := '1';   -- response to valid address
1135
            got_resp_vec(i)   <= '1';
1136
            port_offsets_r(i) <= to_integer(unsigned(msg_data_txfifo_tb));
1137
            assert false
1138
              report "Agent " & str(i) & " got port offset "
1139
              & str(to_integer(unsigned(msg_data_txfifo_tb)))
1140
              severity note;
1141
 
1142
            -- Was this a response to read or write port request?
1143
            if rd_wr_rq(i) = '0' and to_integer(unsigned(msg_data_txfifo_tb)) /= 0 then
1144
 
1145
              -- Response to read port request,
1146
              -- reduce the number of free read ports
1147
              n_free_r_ports_v := n_free_r_ports_v - 1;
1148
            elsif rd_wr_rq(i) = '1' and to_integer(unsigned(msg_data_txfifo_tb)) /= 0 then
1149
 
1150
              -- Response to write port request,
1151
              -- reduce the number of free write ports
1152
              n_free_w_ports_v := n_free_w_ports_v - 1;
1153
            end if;
1154
          end if;
1155
 
1156
        end loop;  -- i
1157
 
1158
        -- Check that the response address is one of the agent addresses
1159
        assert check_resp_addr_v = '1'
1160
          report "Got port rq response to illegal address"
1161
          severity failure;
1162
 
1163
      else
1164
 
1165
        -- Fifo was empty so no responses this time
1166
        got_resp <= '0';
1167
 
1168
      end if;
1169
 
1170
      n_free_rd_ports <= n_free_r_ports_v;
1171
      n_free_wr_ports <= n_free_w_ports_v;
1172
 
1173
    end if;
1174
  end process rd_rq_resps;
1175
 
1176
-------------------------------------------------------------------------------
1177
-- Monitors SDRAM operations and checks the amounts and addresses of SDRAM
1178
-- reads and writes. Signals to other processes if port operations finish
1179
-------------------------------------------------------------------------------
1180
  check_sdram_addrs : process (clk, rst_n)
1181
    variable check_addr_v : std_logic;
1182
    variable data_sent_v  : std_logic_vector(n_agents_c - 1 downto 0);
1183
    variable agent_addr_v : std_logic_vector(mem_addr_width - 1 downto 0);
1184
  begin  -- process check_sdram_addrs
1185
    if rst_n = '0' then                 -- asynchronous reset (active low)
1186
      rd_addrs_r      <= (others => 0);
1187
      wr_addrs_r      <= (others => 0);
1188
      rd_amounts_r    <= (others => 0);
1189
      wr_amounts_r    <= (others => 0);
1190
      curr_rd_ag_r    <= 0;
1191
      curr_wr_ag_r    <= 0;
1192
      state_r         <= idle;
1193
      clr_offset_r    <= '0';
1194
      clr_idx_r       <= 0;
1195
      was_busy_r      <= '0';
1196
      for i in 0 to n_agents_c loop
1197
        wr_data_check_r(i) <= i * 100;
1198
      end loop;  -- i
1199
      data_sent       <= (others => '0');
1200
      agent_addr_v    := (others => '0');
1201
    elsif clk'event and clk = '1' then  -- rising clock edge
1202
 
1203
      data_sent_v := data_sent or sending_data;
1204
 
1205
      clr_offset_r <= '0';
1206
      clr_idx_r    <= 0;
1207
 
1208
      check_addr_v := '0';
1209
 
1210
      was_busy_r <= busy_tb_dut;
1211
 
1212
      if new_rd_conf = '1' then
1213
 
1214
        -- configure read port procedure has configured a read port,
1215
        -- store read address and amount
1216
        rd_addrs_r(new_rd_idx)   <= new_rd_addr;
1217
        rd_amounts_r(new_rd_idx) <= new_rd_amount;
1218
 
1219
      elsif new_wr_conf = '1' then
1220
 
1221
        -- configure write port procedure has configured a write port
1222
        -- store write address and amount
1223
        wr_addrs_r(new_wr_idx)   <= new_wr_addr;
1224
        wr_amounts_r(new_wr_idx) <= new_wr_amount;
1225
      end if;
1226
 
1227
      case state_r is
1228
 
1229
        when idle =>
1230
 
1231
          if busy_tb_dut = '1' and was_busy_r = '0' then
1232
 
1233
            case comm_dut_tb is
1234
 
1235
              when "00" =>
1236
 
1237
                -- nop
1238
                state_r <= idle;
1239
 
1240
              when "01" =>
1241
 
1242
                -- read command to SDRAM
1243
                -- check which port is used
1244
                for i in 0 to n_agents_c - 1 loop
1245
 
1246
                  -- mask out the HIBI part of agent addr
1247
                  agent_addr_v := std_logic_vector(
1248
                    to_unsigned(rd_addrs_r(i), mem_addr_width));
1249
                  if addr_dut_tb = agent_addr_v then
1250
--                  if to_integer(unsigned(addr_dut_tb)) = rd_addrs_r(i) then
1251
                    check_addr_v := '1';
1252
                    curr_rd_ag_r <= i;
1253
                    -- amount must be > 0
1254
                    assert rd_amounts_r(i) /= 0
1255
                      report "Agent " & str(i) & " Read with amount 0"
1256
                      severity failure;
1257
                    assert rd_amounts_r(i) = to_integer(unsigned(amount_dut_tb))
1258
                      report "Agent " & str(i) & " Read amount corrupted"
1259
                      severity failure;
1260
                  end if;
1261
                end loop;  -- i
1262
 
1263
                -- check if this is single op read
1264
                agent_addr_v := std_logic_vector(
1265
                  to_unsigned(rd_addrs_r(single_read_c), mem_addr_width));
1266
                if addr_dut_tb = agent_addr_v then
1267
                  check_addr_v := '1';
1268
                  curr_rd_ag_r <= single_read_c;
1269
                  -- amount must be = 1
1270
                  assert 1 = to_integer(unsigned(amount_dut_tb))
1271
                    report "Single op read with amount /= 1"
1272
                    severity failure;
1273
                end if;
1274
                -- did we find a corresponding read port?
1275
 
1276
                assert check_addr_v = '1'
1277
                  report "Unexpected read. Addr: " & str(to_integer(unsigned(addr_dut_tb)))
1278
                  severity failure;
1279
                state_r <= read_state;
1280
 
1281
              when "10" =>
1282
 
1283
                -- write command to SDRAM
1284
                -- check which port is used
1285
                for i in 0 to n_agents_c - 1 loop
1286
                  agent_addr_v := std_logic_vector(
1287
                    to_unsigned(wr_addrs_r(i), mem_addr_width));
1288
                  if addr_dut_tb = agent_addr_v then
1289
--                  if to_integer(unsigned(addr_dut_tb)) = wr_addrs_r(i) then
1290
                    check_addr_v := '1';
1291
                    curr_wr_ag_r <= i;
1292
                    -- amount must be > 0
1293
                    -- amount must be > 0
1294
                    assert wr_amounts_r(i) /= 0
1295
                      report "Agent " & str(i) & " write with amount 0"
1296
                      severity failure;
1297
                    assert wr_amounts_r(i) = to_integer(unsigned(amount_dut_tb))
1298
                      report "Agent " & str(i) & " write amount corrupted"
1299
                      severity failure;
1300
                  end if;
1301
                end loop;  -- i
1302
 
1303
                -- check if this is single op write
1304
                agent_addr_v := std_logic_vector(
1305
                  to_unsigned(wr_addrs_r(single_write_c), mem_addr_width));
1306
                if addr_dut_tb = agent_addr_v then
1307
                  check_addr_v := '1';
1308
                  curr_wr_ag_r <= single_write_c;
1309
                  -- amount must be = 1
1310
                  assert 1 = to_integer(unsigned(amount_dut_tb))
1311
                    report "Single op write with amount /= 1"
1312
                    severity failure;
1313
                end if;
1314
 
1315
                -- did we find a corresponding write port?
1316
                assert check_addr_v = '1'
1317
                  report "Unexpected write. Addr: " & str(to_integer(unsigned(addr_dut_tb)))
1318
                  severity failure;
1319
                state_r <= write_state;
1320
 
1321
              when others =>
1322
                assert false report "Illegal command to ctrl" severity failure;
1323
                state_r <= idle;
1324
            end case;
1325
          end if;
1326
 
1327
        when read_state =>
1328
 
1329
          if we_tb_dut = '1' then
1330
 
1331
            -- SDRAM controller writes read data to DUT
1332
            -- check that DUT doesn't get data when amount is 0
1333
            if curr_rd_ag_r < n_agents_c then
1334
 
1335
              assert rd_amounts_r(curr_rd_ag_r) /= 0
1336
                report "Agent: " & str(curr_rd_ag_r) & " read while amount 0"
1337
                severity failure;
1338
            elsif curr_rd_ag_r = single_read_c then
1339
              assert rd_amounts_r(curr_rd_ag_r) /= 0
1340
                report "Unexpected single op read"
1341
                severity failure;
1342
            else
1343
              assert false report "Unexpected read" severity failure;
1344
            end if;
1345
 
1346
            if rd_amounts_r(curr_rd_ag_r) = 1 and curr_rd_ag_r /= n_agents_c then
1347
              -- Read operation finishes
1348
              -- signal to rd_rq_resps process that operation finishes
1349
              clr_idx_r    <= curr_rd_ag_r;
1350
              clr_offset_r <= '1';
1351
            end if;
1352
 
1353
            -- Update address and amount
1354
            rd_addrs_r(curr_rd_ag_r)   <= rd_addrs_r(curr_rd_ag_r) + 1;
1355
            rd_amounts_r(curr_rd_ag_r) <= rd_amounts_r(curr_rd_ag_r) - 1;
1356
          end if;
1357
 
1358
          -- Does SDRAM operation continue?
1359
          if busy_tb_dut = '0' then
1360
            -- SDRAM operation finishes
1361
            state_r <= idle;
1362
          else
1363
            -- SDRAM operation continues
1364
            state_r <= state_r;
1365
          end if;
1366
 
1367
        when write_state =>
1368
 
1369
          if write_on_tb_dut = '1' then
1370
 
1371
            -- SDRAM controller write
1372
            -- Check that we don't do too many writes
1373
            if curr_wr_ag_r < n_agents_c then
1374
 
1375
              assert wr_amounts_r(curr_wr_ag_r) /= 0
1376
                report "Agent: " & str(curr_wr_ag_r) & " write while amount 0"
1377
                severity failure;
1378
            else
1379
              assert wr_amounts_r(curr_wr_ag_r) /= 0
1380
                report "Unexpected single op write"
1381
                severity failure;
1382
            end if;
1383
 
1384
            if wr_amounts_r(curr_wr_ag_r) = 1 and curr_wr_ag_r /= n_agents_c then
1385
              -- Write operation finishes
1386
              -- signal to rd_rq_resps process that operation finishes and
1387
              -- clear data_sent of corresponding port
1388
              clr_idx_r                 <= curr_wr_ag_r;
1389
              clr_offset_r              <= '1';
1390
              data_sent_v(curr_wr_ag_r) := '0';
1391
            end if;
1392
 
1393
            -- Update address, amount check
1394
            wr_addrs_r(curr_wr_ag_r)   <= wr_addrs_r(curr_wr_ag_r) + 1;
1395
            wr_amounts_r(curr_wr_ag_r) <= wr_amounts_r(curr_wr_ag_r) - 1;
1396
          end if;
1397
 
1398
          if sdram_cs_n_out = '0' and sdram_ras_n_out = '1' and
1399
            sdram_cas_n_out = '0' and sdram_we_n_out = '0' then
1400
            -- SDRAM write
1401
            if curr_wr_ag_r < n_agents_c then
1402
 
1403
              assert wr_data_check_r(curr_wr_ag_r) = to_integer(unsigned(sdram_data_inout))
1404
                report "Agent " & str(curr_wr_ag_r) & " Write data corrupted"
1405
                severity failure;
1406
            elsif curr_wr_ag_r = single_write_c then
1407
              assert wr_data_check_r(curr_wr_ag_r) = to_integer(unsigned(sdram_data_inout))
1408
                report "Agent " & str(curr_wr_ag_r) & " Single op write data corrupted"
1409
                severity failure;
1410
            else
1411
              assert false report "Unexcpected write" severity failure;
1412
            end if;
1413
            -- update data check
1414
            wr_data_check_r(curr_wr_ag_r) <= wr_data_check_r(curr_wr_ag_r) + 1;
1415
          end if;
1416
            -- Does SDRAM operation continue?
1417
          if busy_tb_dut = '0' then
1418
            -- SDRAM operation finishes
1419
            state_r <= idle;
1420
          else
1421
            -- SDRAM operation continues
1422
            state_r <= state_r;
1423
          end if;
1424
      end case;
1425
      data_sent <= data_sent_v;
1426
 
1427
    end if;
1428
 
1429
  end process check_sdram_addrs;
1430
 
1431
  -- 4) PROC (ASYNC)
1432
  CLOCK1 : process                      -- generate clock signal for design
1433
  begin
1434
    clk <= '1';
1435
    wait for period_c/2;
1436
    clk <= '0';
1437
    wait for period_c/2;
1438
  end process CLOCK1;
1439
 
1440
  -- 5) PROC (ASYNC)
1441
  RESET : process
1442
  begin
1443
    rst_n <= '0';                       -- Reset the testsystem
1444
    wait for 6*period_c;                -- Wait 
1445
    rst_n <= '1';                       -- de-assert reset
1446
    wait;
1447
  end process RESET;
1448
 
1449
  DUT : entity work.sdram2hibi
1450
 
1451
    generic map(
1452
      hibi_data_width_g    => hibi_data_width,
1453
      mem_data_width_g     => mem_data_width,
1454
      mem_addr_width_g     => mem_addr_width,
1455
      comm_width_g         => comm_width,
1456
      input_fifo_depth_g   => 5,
1457
      num_of_read_ports_g  => num_of_r_ports_g,
1458
      num_of_write_ports_g => num_of_w_ports_g,
1459
      rq_fifo_depth_g      => rq_fifo_depth_g
1460
      )
1461
    port map(
1462
      clk   => clk,
1463
      rst_n => rst_n,
1464
 
1465
      hibi_addr_in  => addr_rxfifo_dut,
1466
      hibi_data_in  => data_rxfifo_dut,
1467
      hibi_comm_in  => comm_rxfifo_dut,
1468
      hibi_empty_in => empty_rxfifo_dut,
1469
      hibi_re_out   => re_dut_rxfifo,
1470
 
1471
      hibi_addr_out => addr_dut_txfifo,
1472
      hibi_data_out => data_dut_txfifo,
1473
      hibi_comm_out => comm_dut_txfifo,
1474
      hibi_full_in  => full_txfifo_dut,
1475
      hibi_we_out   => we_dut_txfifo,
1476
 
1477
      hibi_msg_addr_in  => msg_addr_rxfifo_dut,
1478
      hibi_msg_data_in  => msg_data_rxfifo_dut,
1479
      hibi_msg_comm_in  => msg_comm_rxfifo_dut,
1480
      hibi_msg_empty_in => msg_empty_rxfifo_dut,
1481
      hibi_msg_re_out   => msg_re_dut_rxfifo,
1482
 
1483
      hibi_msg_addr_out => msg_addr_dut_txfifo,
1484
      hibi_msg_data_out => msg_data_dut_txfifo,
1485
      hibi_msg_comm_out => msg_comm_dut_txfifo,
1486
      hibi_msg_full_in  => msg_full_txfifo_dut,
1487
      hibi_msg_we_out   => msg_we_dut_txfifo,
1488
 
1489
      sdram_ctrl_write_on_in     => write_on_tb_dut,
1490
      sdram_ctrl_comm_out        => comm_dut_tb,
1491
      sdram_ctrl_addr_out        => addr_dut_tb,
1492
      sdram_ctrl_data_amount_out => amount_dut_tb,
1493
      sdram_ctrl_input_empty_out => empty_dut_tb,
1494
      sdram_ctrl_input_one_d_out => one_d_dut_tb,
1495
      sdram_ctrl_output_full_out => full_dut_tb,
1496
      sdram_ctrl_busy_in         => busy_tb_dut,
1497
      sdram_ctrl_re_in           => re_tb_dut,
1498
      sdram_ctrl_we_in           => we_tb_dut,
1499
      sdram_ctrl_data_out        => data_dut_tb,
1500
      sdram_ctrl_data_in         => data_tb_dut,
1501
      sdram_ctrl_byte_select_out => byte_sel_dut_tb
1502
      );
1503
 
1504
 
1505
  rx_fifo : entity work.fifo
1506
    generic map (
1507
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
1508
      depth_g      => rx_depth_c
1509
      )
1510
    port map (
1511
      clk       => clk,
1512
      rst_n     => rst_n,
1513
      data_in   => c_a_d_tb_rxfifo,
1514
      we_in     => we_tb_rxfifo,
1515
      full_out  => full_rxfifo_tb,
1516
      one_p_out => one_p_rxfifo_tb,
1517
 
1518
      data_out  => c_a_d_rxfifo_dut,
1519
      re_in     => re_dut_rxfifo,
1520
      empty_out => empty_rxfifo_dut
1521
 
1522
      );
1523
 
1524
  msg_rx_fifo : entity work.fifo
1525
    generic map (
1526
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
1527
      depth_g      => msg_rx_depth_c
1528
      )
1529
    port map (
1530
      clk       => clk,
1531
      rst_n     => rst_n,
1532
      data_in   => msg_c_a_d_tb_rxfifo,
1533
      we_in     => msg_we_tb_rxfifo,
1534
      full_out  => msg_full_rxfifo_tb,
1535
      one_p_out => msg_one_p_rxfifo_tb,
1536
 
1537
      data_out  => msg_c_a_d_rxfifo_dut,
1538
      re_in     => msg_re_dut_rxfifo,
1539
      empty_out => msg_empty_rxfifo_dut,
1540
      one_d_out => msg_one_d_rxfifo_dut
1541
 
1542
      );
1543
 
1544
 
1545
  tx_fifo : entity work.fifo
1546
    generic map (
1547
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
1548
      depth_g      => tx_depth_c
1549
      )
1550
    port map (
1551
      clk     => clk,
1552
      rst_n   => rst_n,
1553
      data_in => c_a_d_dut_txfifo,
1554
      we_in   => we_dut_txfifo,
1555
 
1556
      full_out  => full_txfifo_dut,
1557
      one_p_out => one_p_txfifo_dut,
1558
 
1559
      data_out  => c_a_d_txfifo_tb,
1560
      re_in     => re_tb_txfifo,
1561
      empty_out => empty_txfifo_tb,
1562
      one_d_out => one_d_txfifo_tb
1563
      );
1564
 
1565
  msg_tx_fifo : entity work.fifo
1566
    generic map (
1567
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
1568
      depth_g      => msg_tx_depth_c
1569
      )
1570
    port map (
1571
      clk     => clk,
1572
      rst_n   => rst_n,
1573
      data_in => msg_c_a_d_dut_txfifo,
1574
      we_in   => msg_we_dut_txfifo,
1575
 
1576
      full_out  => msg_full_txfifo_dut,
1577
      one_p_out => msg_one_p_txfifo_dut,
1578
 
1579
      data_out  => msg_c_a_d_txfifo_tb,
1580
      re_in     => msg_re_tb_txfifo,
1581
      empty_out => msg_empty_txfifo_tb,
1582
      one_d_out => msg_one_d_txfifo_tb
1583
 
1584
      );
1585
 
1586
  tb_sdram_write <= not(sdram_cs_n_out) and sdram_ras_n_out and
1587
                    not(sdram_cas_n_out) and not(sdram_we_n_out);
1588
 
1589
  sdram_controller_1 : entity work.sdram_controller
1590
    generic map (
1591
      clk_freq_mhz_g      => clk_freq_c,
1592
      mem_addr_width_g    => mem_addr_width,
1593
      block_read_length_g => 640,
1594
      sim_ena_g           => 1)
1595
    port map (
1596
      clk                    => clk,
1597
      rst_n                  => rst_n,
1598
      command_in             => comm_dut_tb,
1599
      address_in             => addr_dut_tb,
1600
      data_amount_in         => amount_dut_tb,
1601
      byte_select_in         => byte_sel_dut_tb,
1602
      input_empty_in         => empty_dut_tb,
1603
      input_one_d_in         => one_d_dut_tb,
1604
      output_full_in         => full_dut_tb,
1605
      data_in                => data_dut_tb,
1606
      write_on_out           => write_on_tb_dut,
1607
      busy_out               => busy_tb_dut,
1608
      output_we_out          => we_tb_dut,
1609
      input_re_out           => re_tb_dut,
1610
      data_to_sdram2hibi_out => data_tb_dut,
1611
      sdram_data_inout       => sdram_data_inout,
1612
      sdram_cke_out          => sdram_cke_out,
1613
      sdram_cs_n_out         => sdram_cs_n_out,
1614
      sdram_we_n_out         => sdram_we_n_out,
1615
      sdram_ras_n_out        => sdram_ras_n_out,
1616
      sdram_cas_n_out        => sdram_cas_n_out,
1617
      sdram_dqm_out          => sdram_dqm_out,
1618
      sdram_ba_out           => sdram_ba_out,
1619
      sdram_address_out      => sdram_addr_out);
1620
 
1621
end behavioral;

powered by: WebSVN 2.1.0

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