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_sdram2hibi.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
-------------------------------------------------------------------------------
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
 
13
use work.txt_util.all;
14
 
15
entity tb_sdram2hibi is
16
end tb_sdram2hibi;
17
 
18
architecture behavioral of tb_sdram2hibi is
19
 
20
  component fifo
21
    generic (
22
      data_width_g : integer := 0;
23
      depth_g      : integer := 0
24
      );
25
 
26
    port (
27
      clk       : in  std_logic;
28
      rst_n     : in  std_logic;
29
      data_In   : in  std_logic_vector (data_width_g - 1 downto 0);
30
      we_in     : in  std_logic;
31
      one_p_out : out std_logic;
32
      full_out  : out std_logic;
33
      data_out  : out std_logic_vector (data_width_g - 1 downto 0);
34
      re_in     : in  std_logic;
35
      empty_out : out std_logic;
36
      one_d_out : out std_logic
37
      );
38
  end component;
39
 
40
  component sdram2hibi
41
    generic (
42
      hibi_data_width_g    : integer := 0;
43
      mem_data_width_g     : integer := 0;
44
      mem_addr_width_g     : integer := 0;
45
      comm_width_g         : integer := 0;
46
      input_fifo_depth_g   : integer := 0;
47
      num_of_read_ports_g  : integer := 0;
48
      num_of_write_ports_g : integer := 0;
49
      offset_width_g       : integer := 16;
50
      rq_fifo_depth_g      : integer := 3
51
      );
52
    port (
53
      clk   : in std_logic;
54
      rst_n : in std_logic;
55
 
56
      hibi_data_in  : in  std_logic_vector (hibi_data_width_g - 1 downto 0);
57
      hibi_addr_in  : in  std_logic_vector (hibi_data_width_g - 1 downto 0);
58
      hibi_comm_in  : in  std_logic_vector (comm_width_g - 1 downto 0);
59
      hibi_empty_in : in  std_logic;
60
      hibi_re_out   : out std_logic;
61
 
62
      hibi_data_out : out std_logic_vector (hibi_data_width_g - 1 downto 0);
63
      hibi_addr_out : out std_logic_vector (hibi_data_width_g - 1 downto 0);
64
      hibi_comm_out : out std_logic_vector (comm_width_g - 1 downto 0);
65
      hibi_full_in  : in  std_logic;
66
      hibi_we_out   : out std_logic;
67
 
68
      hibi_msg_data_in  : in  std_logic_vector (hibi_data_width_g - 1 downto 0);
69
      hibi_msg_addr_in  : in  std_logic_vector (hibi_data_width_g - 1 downto 0);
70
      hibi_msg_comm_in  : in  std_logic_vector (comm_width_g - 1 downto 0);
71
      hibi_msg_empty_in : in  std_logic;
72
      hibi_msg_re_out   : out std_logic;
73
 
74
      hibi_msg_data_out : out std_logic_vector (hibi_data_width_g - 1 downto 0);
75
      hibi_msg_addr_out : out std_logic_vector (hibi_data_width_g - 1 downto 0);
76
      hibi_msg_comm_out : out std_logic_vector (comm_width_g - 1 downto 0);
77
      hibi_msg_full_in  : in  std_logic;
78
      hibi_msg_we_out   : out std_logic;
79
 
80
      sdram_ctrl_write_on_in     : in  std_logic;
81
      sdram_ctrl_comm_out        : out std_logic_vector(1 downto 0);
82
      sdram_ctrl_addr_out        : out std_logic_vector(21 downto 0);
83
      sdram_ctrl_data_amount_out : out std_logic_vector(mem_addr_width_g - 1
84
                                                        downto 0);
85
      sdram_ctrl_input_empty_out : out std_logic;
86
      sdram_ctrl_input_one_d_out : out std_logic;
87
      sdram_ctrl_output_full_out : out std_logic;
88
      sdram_ctrl_busy_in         : in  std_logic;
89
      sdram_ctrl_re_in           : in  std_logic;
90
      sdram_ctrl_we_in           : in  std_logic;
91
      sdram_ctrl_data_out        : out std_logic_vector(31 downto 0);
92
      sdram_ctrl_data_in         : in  std_logic_vector(31 downto 0);
93
      sdram_ctrl_byte_select_out : out std_logic_vector(3 downto 0)
94
      );
95
  end component;  --sdram2hibi;
96
 
97
  component sdram_controller
98
    generic (
99
      clk_freq_mhz_g      : integer;
100
      mem_addr_width_g    : integer;
101
      block_read_length_g : integer);
102
    port (
103
      clk                    : in    std_logic;
104
      rst_n                  : in    std_logic;
105
      command_in             : in    std_logic_vector(1 downto 0);
106
      address_in             : in    std_logic_vector(21 downto 0);
107
      data_amount_in         : in    std_logic_vector(mem_addr_width_g - 1
108
                                                      downto 0);
109
      byte_select_in         : in    std_logic_vector(3 downto 0);
110
      input_empty_in         : in    std_logic;
111
      input_one_d_in         : in    std_logic;
112
      output_full_in         : in    std_logic;
113
      data_in                : in    std_logic_vector(31 downto 0);
114
      write_on_out           : out   std_logic;
115
      busy_out               : out   std_logic;
116
      output_we_out          : out   std_logic;
117
      input_re_out           : out   std_logic;
118
      data_to_sdram2hibi_out : out   std_logic_vector(31 downto 0);
119
      sdram_data_inout       : inout std_logic_vector(31 downto 0);
120
      sdram_cke_out          : out   std_logic;
121
      sdram_cs_n_out         : out   std_logic;
122
      sdram_we_n_out         : out   std_logic;
123
      sdram_ras_n_out        : out   std_logic;
124
      sdram_cas_n_out        : out   std_logic;
125
      sdram_dqm_out          : out   std_logic_vector(3 downto 0);
126
      sdram_ba_out           : out   std_logic_vector(1 downto 0);
127
      sdram_address_out      : out   std_logic_vector(11 downto 0));
128
  end component;
129
 
130
  constant hibi_data_width : integer := 32;
131
  constant mem_data_width  : integer := 32;
132
  constant mem_addr_width  : integer := 22;
133
  constant comm_width      : integer := 3;
134
  constant depth           : integer := 10;
135
  constant PERIOD          : time    := 10 ns;
136
  constant clk_freq_c      : integer := 100;
137
 
138
  constant num_of_r_ports_g : integer := 4;
139
  constant num_of_w_ports_g : integer := 4;
140
 
141
  -----------------------------------------------------------------------------
142
  -- 
143
  --  _____                        ________      ________________
144
  -- |     |                      |        |    |                |    
145
  -- |     |   <- msg tx fifo <-  |        |    |                | <-
146
  -- |     |   <-     tx_fifo <-  |        | <- | sdram 50MHz    |       tb
147
  -- |  tb |                      | ctrl   |    | cas 3          |
148
  -- |     |   ->     rx_fifo ->  | (dut)  |    |                | ->
149
  -- |     |   -> msg rx fifo ->  |        | -> |                |
150
  -- | ____|                      |________|    |________________|
151
  --                                  A
152
  --                                  |__ tb?
153
  --
154
  -----------------------------------------------------------------------------
155
 
156
 
157
  -- Testbench signals
158
  signal Test_Phase : integer range 0 to 100;
159
  signal clk        : std_logic;
160
  signal rst_n      : std_logic;
161
 
162
  type   check_state_type is (wait_comm, wait_busy);
163
  signal check_state : check_state_type;
164
 
165
  -- Signals tb -> rxfifo
166
  signal c_a_d_tb_rxfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
167
  signal data_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
168
  signal addr_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
169
  signal comm_tb_rxfifo  : std_logic_vector (comm_width-1 downto 0);
170
  signal we_tb_rxfifo    : std_logic;
171
 
172
  -- Signals rxfifo -> tb
173
  signal full_rxfifo_tb  : std_logic;
174
  signal one_p_rxfifo_tb : std_logic;
175
 
176
  -- Signals tb -> msg_rxfifo
177
  signal msg_c_a_d_tb_rxfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
178
  signal msg_data_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
179
  signal msg_addr_tb_rxfifo  : std_logic_vector (hibi_data_width-1 downto 0);
180
  signal msg_comm_tb_rxfifo  : std_logic_vector (comm_width-1 downto 0);
181
  signal msg_we_tb_rxfifo    : std_logic;
182
 
183
  -- Signals msg_rxfifo -> tb
184
  signal msg_full_rxfifo_tb  : std_logic;
185
  signal msg_one_p_rxfifo_tb : std_logic;
186
 
187
  -- Signals tb -> txfifo
188
  signal re_tb_txfifo : std_logic;
189
 
190
  -- Signals txfifo -> tb
191
  signal c_a_d_txfifo_tb : std_logic_vector(hibi_data_width+hibi_data_width+comm_width - 1 downto 0);
192
  signal data_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
193
  signal addr_txfifo_tb  : std_logic_vector(hibi_data_width -1 downto 0);
194
  signal comm_txfifo_tb  : std_logic_vector(comm_width - 1 downto 0);
195
  signal empty_txfifo_tb : std_logic;
196
  signal one_d_txfifo_tb : std_logic;
197
 
198
  -- Signals tb -> msg_txfifo
199
  signal msg_re_tb_txfifo : std_logic;
200
 
201
  -- Signals msg_txfifo -> tb
202
  signal msg_c_a_d_txfifo_tb : std_logic_vector(hibi_data_width+hibi_data_width+comm_width - 1 downto 0);
203
  signal msg_data_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
204
  signal msg_addr_txfifo_tb  : std_logic_vector(hibi_data_width - 1 downto 0);
205
  signal msg_comm_txfifo_tb  : std_logic_vector(comm_width - 1 downto 0);
206
  signal msg_empty_txfifo_tb : std_logic;
207
  signal msg_one_d_txfifo_tb : std_logic;
208
 
209
  -- Signals rxfifo -> dut
210
  signal c_a_d_rxfifo_dut : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
211
  signal addr_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
212
  signal data_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
213
  signal comm_rxfifo_dut  : std_logic_vector(comm_width - 1 downto 0);
214
  signal empty_rxfifo_dut : std_logic;
215
 
216
  -- Signals dut -> rxfifo
217
  signal re_dut_rxfifo : std_logic;
218
 
219
  -- Signals txfifo -> dut
220
  signal full_txfifo_dut  : std_logic;
221
  signal one_p_txfifo_dut : std_logic;
222
 
223
  -- Signals dut -> txfifo
224
  signal c_a_d_dut_txfifo : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
225
  signal addr_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
226
  signal data_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
227
  signal comm_dut_txfifo  : std_logic_vector(comm_width - 1 downto 0);
228
  signal we_dut_txfifo    : std_logic;
229
 
230
  -- Signals msg_rxfifo -> dut
231
  signal msg_c_a_d_rxfifo_dut : std_logic_vector (hibi_data_width+hibi_data_width+comm_width-1 downto 0);
232
  signal msg_addr_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
233
  signal msg_data_rxfifo_dut  : std_logic_vector(hibi_data_width - 1 downto 0);
234
  signal msg_comm_rxfifo_dut  : std_logic_vector(comm_width - 1 downto 0);
235
  signal msg_empty_rxfifo_dut : std_logic;
236
  signal msg_one_d_rxfifo_dut : std_logic;
237
 
238
  -- Signals dut -> msg_rxfifo
239
  signal msg_re_dut_rxfifo : std_logic;
240
 
241
  -- Signals msg_txfifo -> dut
242
  signal msg_full_txfifo_dut  : std_logic;
243
  signal msg_one_p_txfifo_dut : std_logic;
244
 
245
  -- Signals dut -> msg_txfifo
246
  signal msg_c_a_d_dut_txfifo : std_logic_vector(hibi_data_width + hibi_data_width + comm_width - 1 downto 0);
247
  signal msg_addr_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
248
  signal msg_data_dut_txfifo  : std_logic_vector(hibi_data_width - 1 downto 0);
249
  signal msg_comm_dut_txfifo  : std_logic_vector(comm_width - 1 downto 0);
250
  signal msg_we_dut_txfifo    : std_logic;
251
 
252
  -- signals sdram_controller -> dut
253
  signal write_on_tb_dut : std_logic;
254
  signal busy_tb_dut     : std_logic;
255
  signal re_tb_dut       : std_logic;
256
  signal we_tb_dut       : std_logic;
257
  signal data_tb_dut     : std_logic_vector(31 downto 0);
258
 
259
  -- sdram_ctrl
260
  signal sdram_data_inout : std_logic_vector(31 downto 0);
261
  signal sdram_cke_out    : std_logic;
262
  signal sdram_cs_n_out   : std_logic;
263
  signal sdram_we_n_out   : std_logic;
264
  signal sdram_ras_n_out  : std_logic;
265
  signal sdram_cas_n_out  : std_logic;
266
  signal sdram_dqm_out    : std_logic_vector(3 downto 0);
267
  signal sdram_ba_out     : std_logic_vector(1 downto 0);
268
  signal sdram_addr_out   : std_logic_vector(11 downto 0);
269
 
270
  -- signals dut -> sdram_controller
271
  signal comm_dut_tb   : std_logic_vector(1 downto 0);
272
  signal addr_dut_tb   : std_logic_vector(21 downto 0);
273
  signal amount_dut_tb : std_logic_vector(21 downto 0);
274
 
275
  signal byte_sel_dut_tb : std_logic_vector(3 downto 0);
276
  signal empty_dut_tb    : std_logic;
277
  signal one_d_dut_tb    : std_logic;
278
  signal full_dut_tb     : std_logic;
279
  signal data_dut_tb     : std_logic_vector(31 downto 0);
280
 
281
  type   write_integer_array is array (0 to num_of_w_ports_g - 1) of integer;
282
  signal wr_dst_addr : write_integer_array;
283
  signal wr_amount   : write_integer_array;
284
  signal wr_reserved : std_logic_vector(num_of_w_ports_g - 1 downto 0);
285
  signal wr_valid    : std_logic_vector(num_of_w_ports_g - 1 downto 0);
286
  signal wr_count    : write_integer_array;
287
  signal wr_offset   : write_integer_array;
288
  signal wr_ret_addr : write_integer_array;
289
 
290
  type   read_integer_array is array (0 to num_of_r_ports_g - 1) of integer;
291
  signal rd_src_addr : read_integer_array;
292
  signal rd_amount   : read_integer_array;
293
  signal rd_reserved : std_logic_vector(num_of_r_ports_g - 1 downto 0);
294
  signal rd_valid    : std_logic_vector(num_of_r_ports_g - 1 downto 0);
295
  signal rd_count    : read_integer_array;
296
  signal rd_ret_addr : read_integer_array;
297
  signal rd_offset   : read_integer_array;
298
 
299
  signal msg_empty_txfifo : std_logic;
300
  signal msg_full_rxfifo  : std_logic;
301
  signal full_rxfifo      : std_logic;
302
 
303
  signal data_counter      : read_integer_array;
304
  signal single_counter_r  : integer;
305
  signal valid_write_ports : std_logic_vector(num_of_w_ports_g - 1 downto 0);
306
 
307
  signal empty_txfifo : std_logic;
308
 
309
begin  -- behavioral
310
 
311
 
312
  -- Concurrent assignments
313
  -- tb -> rx_fifo
314
  c_a_d_tb_rxfifo     <= comm_tb_rxfifo & addr_tb_rxfifo & data_tb_rxfifo;
315
  msg_c_a_d_tb_rxfifo <= msg_comm_tb_rxfifo & msg_addr_tb_rxfifo & msg_data_tb_rxfifo;
316
 
317
  -- rx_fifo -> dut
318
  comm_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
319
                     when empty_rxfifo_dut = '0' else (others => 'Z');
320
  addr_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
321
                     when empty_rxfifo_dut = '0' else (others => 'Z');
322
  data_rxfifo_dut <= c_a_d_rxfifo_dut (hibi_data_width -1 downto 0)
323
                     when empty_rxfifo_dut = '0' else (others => 'Z');
324
 
325
  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)
326
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
327
  msg_addr_rxfifo_dut <= msg_c_a_d_rxfifo_dut (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
328
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
329
  msg_data_rxfifo_dut <= msg_c_a_d_rxfifo_dut (hibi_data_width -1 downto 0)
330
                         when msg_empty_rxfifo_dut = '0' else (others => 'Z');
331
 
332
  -- dut -> tx_fifo
333
  c_a_d_dut_txfifo     <= comm_dut_txfifo & addr_dut_txfifo & data_dut_txfifo;
334
  msg_c_a_d_dut_txfifo <= msg_comm_dut_txfifo & msg_addr_dut_txfifo & msg_data_dut_txfifo;
335
 
336
 
337
  -- tx_fifo -> tb
338
  comm_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width + hibi_data_width + comm_width-1 downto hibi_data_width + hibi_data_width)
339
                    when empty_txfifo_tb = '0' else (others => 'Z');
340
  addr_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
341
                    when empty_txfifo_tb = '0' else (others => 'Z');
342
  data_txfifo_tb <= c_a_d_txfifo_tb (hibi_data_width -1 downto 0)
343
                    when empty_txfifo_tb = '0' else (others => 'Z');
344
 
345
  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)
346
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
347
  msg_addr_txfifo_tb <= msg_c_a_d_txfifo_tb (hibi_data_width + hibi_data_width -1 downto hibi_data_width)
348
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
349
  msg_data_txfifo_tb <= msg_c_a_d_txfifo_tb (hibi_data_width -1 downto 0)
350
                        when msg_empty_txfifo_tb = '0' else (others => 'Z');
351
 
352
  full_rxfifo      <= full_rxfifo_tb or (one_p_rxfifo_tb and we_tb_rxfifo);
353
  empty_txfifo     <= empty_txfifo_tb or (one_d_txfifo_tb and re_tb_txfifo);
354
  msg_full_rxfifo  <= msg_full_rxfifo_tb or (msg_one_p_rxfifo_tb and msg_we_tb_rxfifo);
355
  msg_empty_txfifo <= msg_empty_txfifo_tb or (msg_one_d_txfifo_tb and msg_re_tb_txfifo);
356
 
357
  -- 1) PROC
358
  Generate_input : process
359
    -----------------------------------------------------------------------------
360
    -- Three procedures for writing to and for reading the fifo
361
    -----------------------------------------------------------------------------
362
    procedure WriteToFifo (
363
      addr_to_fifo : in integer;
364
      data_to_fifo : in integer;
365
      comm_to_fifo : in integer;
366
      wait_time    : in integer) is
367
 
368
    begin  --procedure
369
 
370
      if clk = '0' then
371
        wait until clk = '1';
372
        wait for PERIOD / 5;
373
      end if;
374
 
375
      while full_rxfifo = '1' loop
376
        wait for PERIOD;
377
      end loop;
378
      --assert false report "Fifo full. Cannot write" severity note;
379
 
380
      data_tb_rxfifo <= std_logic_vector(to_unsigned (data_to_fifo, hibi_data_width));
381
      comm_tb_rxfifo <= std_logic_vector(to_unsigned (comm_to_fifo, comm_width));
382
      addr_tb_rxfifo <= std_logic_vector(to_unsigned (addr_to_fifo, hibi_data_width));
383
      we_tb_rxfifo   <= '1';
384
 
385
      wait for PERIOD/5;
386
      wait for PERIOD;
387
      --if wait_time > 0 then      
388
      we_tb_rxfifo   <= '0';
389
      data_tb_rxfifo <= (others => 'Z');
390
      comm_tb_rxfifo <= (others => 'Z');
391
      addr_tb_rxfifo <= (others => 'Z');
392
      wait for (wait_time)* PERIOD;
393
      --end if;
394
 
395
    end WriteToFifo;
396
 
397
    procedure WriteToMsgFifo (
398
      addr_to_fifo : in integer;
399
      data_to_fifo : in integer;
400
      comm_to_fifo : in integer;
401
      wait_time    : in integer) is
402
 
403
    begin  --procedure
404
 
405
      if clk = '0' then
406
        wait until clk = '1';
407
        wait for PERIOD / 5;
408
      end if;
409
 
410
      while msg_full_rxfifo = '1' loop
411
        wait for PERIOD;
412
      end loop;
413
 
414
      --assert false report "Fifo full. Cannot write" severity note;
415
      msg_addr_tb_rxfifo <= std_logic_vector(to_unsigned (addr_to_fifo, hibi_data_width));
416
      msg_data_tb_rxfifo <= std_logic_vector(to_unsigned (data_to_fifo, hibi_data_width));
417
      msg_comm_tb_rxfifo <= std_logic_vector(to_unsigned (comm_to_fifo, comm_width));
418
      msg_we_tb_rxfifo   <= '1';
419
 
420
 
421
      wait for PERIOD/5;
422
      wait for PERIOD;
423
      --if wait_time > 0 then      
424
      msg_addr_tb_rxfifo <= (others => 'Z');
425
      msg_data_tb_rxfifo <= (others => 'Z');
426
      msg_comm_tb_rxfifo <= (others => 'Z');
427
      msg_we_tb_rxfifo   <= '0';
428
      wait for (wait_time)* PERIOD;
429
      --end if;
430
 
431
    end WriteToMsgFifo;
432
 
433
    procedure request_read_port (
434
      agent_number : in integer) is
435
 
436
    begin
437
      if agent_number < num_of_r_ports_g then
438
 
439
        -- request read port
440
        for r in 0 to num_of_r_ports_g - 1 loop
441
          if r = agent_number then
442
            WriteToMsgFifo(0, rd_ret_addr(r), 3, 1);
443
          end if;
444
        end loop;  -- r
445
 
446
        while msg_empty_txfifo = '1' loop
447
          wait for PERIOD;
448
        end loop;
449
 
450
        assert to_integer(unsigned(msg_data_txfifo_tb)) /= 0 report "No free read ports!"
451
          severity note;
452
 
453
        for r in 0 to num_of_r_ports_g - 1 loop
454
          if r = agent_number then
455
            assert to_integer(unsigned(msg_addr_txfifo_tb)) = rd_ret_addr(r) report "Own HIBI address corrupted when requesting read port" severity failure;
456
          end if;
457
        end loop;  -- r
458
 
459
        assert false report "Read agent offset read" severity note;
460
 
461
        for r in 0 to num_of_r_ports_g - 1 loop
462
          if r = agent_number then
463
            rd_offset(r) <= to_integer(unsigned(msg_data_txfifo_tb));
464
          end if;
465
        end loop;  -- r
466
 
467
        msg_re_tb_txfifo <= '1';
468
        wait for PERIOD;
469
        msg_re_tb_txfifo <= '0';
470
 
471
      end if;
472
    end procedure;
473
 
474
    procedure request_write_port (
475
      agent_number : in integer) is
476
 
477
    begin
478
 
479
      if agent_number < num_of_w_ports_g then
480
 
481
        -- request write port
482
        for w in 0 to num_of_w_ports_g - 1 loop
483
          if agent_number = w then
484
            WriteToMsgFifo(1, wr_ret_addr(w), 3, 1);
485
          end if;
486
        end loop;  -- w
487
 
488
        while msg_empty_txfifo = '1' loop
489
          wait for PERIOD;
490
        end loop;
491
 
492
        if to_integer(unsigned(msg_data_txfifo_tb)) = 0 then
493
          valid_write_ports(agent_number) <= '0';
494
        else
495
          valid_write_ports(agent_number) <= '1';
496
        end if;
497
 
498
 
499
        assert msg_comm_txfifo_tb = "011" report "hibi_msg_comm corrupted"
500
          severity failure;
501
 
502
        assert to_integer(unsigned(msg_data_txfifo_tb)) /= 0 report "No free write ports"
503
          severity note;
504
 
505
        for w in 0 to num_of_w_ports_g - 1 loop
506
          if agent_number = w then
507
            assert to_integer(unsigned(msg_addr_txfifo_tb)) = wr_ret_addr(w) report "Own HIBI address corrupted when requesting write port" severity failure;
508
          end if;
509
        end loop;  -- w
510
 
511
        assert false report "Write port offset read" severity note;
512
 
513
        for w in 0 to num_of_w_ports_g - 1 loop
514
          if agent_number = w then
515
            wr_offset(w) <= to_integer(unsigned(msg_data_txfifo_tb));
516
          end if;
517
        end loop;  -- w
518
 
519
        msg_re_tb_txfifo <= '1';
520
        wait for PERIOD;
521
        msg_re_tb_txfifo <= '0';
522
      end if;
523
 
524
    end procedure;
525
 
526
    procedure configure_read_port (
527
      agent_number : in integer;
528
      amount       : in integer) is
529
 
530
    begin
531
 
532
      if agent_number < num_of_r_ports_g then
533
 
534
        wait for PERIOD;
535
 
536
        for r in 0 to num_of_r_ports_g - 1 loop
537
          if r = agent_number then
538
            if rd_offset(r) /= 0 then
539
              assert false report "Configure read agent" severity note;
540
              WriteToMsgFifo(rd_offset(r), rd_src_addr(r), 3, 1);
541
              WriteToMsgFifo(rd_offset(r)+1, amount, 3, 1);
542
              WriteToMsgFifo(rd_offset(r)+3, rd_ret_addr(r), 3, 1);
543
              WriteToMsgFifo(rd_offset(r)+2, 1, 3, 1);
544
              rd_src_addr(r) <= rd_src_addr(r) + amount;
545
            else
546
              assert false report "No valid read ports. Didn't configure" severity warning;
547
            end if;
548
          end if;
549
        end loop;  -- r
550
 
551
      end if;
552
    end procedure;
553
 
554
    procedure configure_write_port (
555
      agent_number : in integer;
556
      amount       : in integer) is
557
 
558
    begin
559
 
560
      if agent_number < num_of_w_ports_g then
561
 
562
        wait for PERIOD;
563
 
564
        if valid_write_ports(agent_number) = '1' then
565
 
566
 
567
          for w in 0 to num_of_w_ports_g - 1 loop
568
 
569
            if w = agent_number then
570
              WriteToMsgFifo(wr_offset(w), wr_dst_addr(w), 3, 1);
571
              WriteToMsgFifo(wr_offset(w)+1, amount, 3, 1);
572
              WriteToMsgFifo(wr_offset(w)+2, 1, 3, 1);
573
              wr_dst_addr(w) <= wr_dst_addr(w) + amount;  --write_amount(w);
574
            end if;
575
          end loop;  -- w
576
 
577
        end if;
578
      end if;
579
    end procedure;
580
 
581
    procedure write_input_data (
582
      agent_number : in integer;
583
      amount       : in integer) is
584
 
585
    begin
586
 
587
      if agent_number < num_of_w_ports_g then
588
 
589
        if valid_write_ports(agent_number) = '1' then
590
 
591
          for w in 0 to num_of_w_ports_g - 1 loop
592
            if agent_number = w then
593
              for i in 0 to amount - 1 loop
594
                wr_count(w) <= wr_count(w) + 1;
595
                WriteToFifo(wr_offset(w)+3, wr_count(w), 2, 1);
596
              end loop;  -- i
597
            end if;
598
          end loop;  -- w
599
 
600
        end if;
601
      end if;
602
    end procedure;
603
 
604
 
605
  begin  -- process Generate_input
606
 
607
    -- test sequence
608
    -- 0 wait for reset
609
    -- 1 write to empty fifo and read so that it is empty again
610
    -- 2 write to fifo until there is only one place left
611
    -- Wait for reset
612
 
613
    data_tb_rxfifo <= (others => 'Z');
614
    addr_tb_rxfifo <= (others => 'Z');
615
    comm_tb_rxfifo <= (others => 'Z');
616
    we_tb_rxfifo   <= '0';
617
 
618
    msg_data_tb_rxfifo <= (others => 'Z');
619
    msg_addr_tb_rxfifo <= (others => 'Z');
620
    msg_comm_tb_rxfifo <= (others => 'Z');
621
    msg_we_tb_rxfifo   <= '0';
622
    msg_re_tb_txfifo   <= '0';
623
 
624
    for i in 0 to num_of_r_ports_g - 1 loop
625
      rd_src_addr(i) <= i * 4096;       --X"1000";
626
    end loop;  -- i
627
    for i in 0 to num_of_w_ports_g - 1 loop
628
      wr_dst_addr(i) <= i * 4096;       --X"1000";
629
    end loop;  -- i
630
 
631
    wr_count <= (others => 0);
632
 
633
    for w in 0 to num_of_w_ports_g - 1 loop
634
      wr_ret_addr(w) <= (w+1)*100;
635
    end loop;  -- w
636
 
637
    for r in 0 to num_of_r_ports_g - 1 loop
638
      rd_ret_addr(r) <= (r+1)* 4096;    -- X"1000";
639
    end loop;  -- r
640
 
641
    wr_offset <= (others => 0);
642
    rd_offset <= (others => 0);
643
 
644
    single_counter_r <= 100;
645
    Test_Phase       <= 0;
646
 
647
    valid_write_ports <= (others => '0');
648
 
649
    wait for (6 + 2)*PERIOD;
650
    wait for PERIOD/2;
651
    wait for PERIOD/3;
652
 
653
    -- 0) At the beginning
654
    assert empty_txfifo_tb = '1' report "0      : Empty does not work" severity error;
655
    assert full_rxfifo_tb = '0' report "0       : Full does not work" severity error;
656
 
657
--    while busy_tb_dut = '1' loop
658
    wait for PERIOD;
659
--    end loop;
660
    while true loop
661
 
662
      -- request write port
663
      request_write_port(0);
664
      -- request write port
665
      request_write_port(1);
666
      -- request write port
667
      request_write_port(2);
668
 
669
      -- configure write port
670
      configure_write_port(0, 100);
671
      configure_write_port(1, 5);
672
      configure_write_port(2, 1);
673
 
674
      wait for 20*period;
675
 
676
      -- write data to rxfifo
677
      write_input_data(0, 10);
678
      -- write data to rxfifo
679
      write_input_data(1, 5);
680
      -- write data to rxfifo
681
      write_input_data(2, 1);
682
 
683
      wait for 40*PERIOD;
684
 
685
      -- request read port
686
      request_read_port(0);
687
 
688
      -- configure read port
689
--    read_amount(0) <= 2;
690
      configure_read_port(0, 10);
691
 
692
      wait for 20*period;
693
 
694
      assert false report "Start filling single op with write" severity note;
695
      -- fill single_op_fifo
696
      for i in 0 to 50 loop
697
        WriteToFifo(single_counter_r + i, single_counter_r + i, 2, 0);
698
      end loop;  -- i
699
      assert false report "Single op filled with write, start filling with read"
700
        severity note;
701
      write_input_data(0, 45);
702
 
703
      -- single read
704
      for i in 0 to 50 loop
705
        single_counter_r <= single_counter_r + 1;
706
        WriteToFifo(single_counter_r, 123, 4, 0);
707
      end loop;  -- i
708
      write_input_data(0, 45);
709
 
710
      assert false report "Single op filled with read" severity note;
711
 
712
      -- request read port
713
      request_read_port(1);
714
 
715
      -- request read port
716
      request_read_port(2);
717
 
718
      -- configure read port
719
--    read_amount(1) <= 10;
720
      configure_read_port(1, 10);
721
 
722
      -- configure read port
723
--    read_amount(2) <= 3;
724
      configure_read_port(2, 3);
725
 
726
      wait for 20*period;
727
 
728
      assert false report "++++++++++++++" severity note;
729
      assert false report "Test completed" severity note;
730
      assert false report "++++++++++++++" severity note;
731
    end loop;
732
 
733
    wait;
734
  end process Generate_input;
735
 
736
  check_output : process (clk, rst_n)
737
 
738
    variable addr_int     : integer := 0;
739
    variable addr_tmp     : std_logic_vector(21 downto 0);
740
    variable addr_tmp_int : integer := 0;
741
    variable port_num     : integer := 0;
742
  begin  -- process check_output
743
 
744
    if rst_n = '0' then                 -- asynchronous reset (active low)
745
      addr_int     := 0;
746
      addr_tmp     := (others => '0');
747
      addr_tmp_int := 0;
748
      port_num     := 0;
749
      check_state  <= wait_comm;
750
    elsif clk'event and clk = '1' then  -- rising clock edge
751
 
752
      case check_state is
753
 
754
        when wait_comm =>
755
 
756
          if busy_tb_dut = '0' then
757
 
758
            case comm_dut_tb is
759
 
760
              when "00" =>
761
                -- NOP
762
                check_state <= wait_comm;
763
 
764
              when "01" =>
765
                -- READ
766
                addr_int               := to_integer(unsigned(addr_dut_tb));
767
                addr_tmp(21 downto 12) := addr_dut_tb(21 downto 12);
768
                addr_tmp(11 downto 0)  := (others => '0');
769
                addr_int               := to_integer(unsigned(addr_tmp));
770
                port_num               := 0;
771
                addr_tmp_int           := addr_int;
772
                while addr_tmp_int > 0 loop
773
                  port_num     := port_num + 1;
774
                  addr_tmp_int := addr_tmp_int - 4096;  --X"1000";
775
                end loop;
776
                report "----- Read command to ctrl -----";
777
                report "Addr: 0x" & str(addr_int, 16);
778
                report "Port: " & str(port_num);
779
                report "Amount: " & str(to_integer(unsigned(amount_dut_tb))) severity note;
780
                check_state <= wait_busy;
781
 
782
              when "10" =>
783
                -- WRITE
784
                addr_int               := to_integer(unsigned(addr_dut_tb));
785
                addr_tmp(21 downto 12) := addr_dut_tb(21 downto 12);
786
                addr_tmp(11 downto 0)  := (others => '0');
787
                addr_int               := to_integer(unsigned(addr_tmp));
788
                port_num               := 0;
789
                addr_tmp_int           := addr_int;
790
                while addr_tmp_int > 0 loop
791
                  port_num     := port_num + 1;
792
                  addr_tmp_int := addr_tmp_int - 4096;  --X"1000";
793
                end loop;
794
                report "----- Write command to ctrl -----";
795
                report "Addr: 0x" & str(addr_int, 16);
796
                report "Port: " & str(port_num);
797
                report "Amount: " & str(to_integer(unsigned(amount_dut_tb))) severity note;
798
                check_state <= wait_busy;
799
 
800
              when others =>
801
                assert false report "Illegal command to ctrl" severity failure;
802
                check_state <= wait_comm;
803
            end case;
804
          end if;
805
 
806
        when wait_busy =>
807
          if busy_tb_dut = '0' then
808
            check_state <= wait_busy;
809
          else
810
            check_state <= wait_comm;
811
          end if;
812
        when others =>
813
          assert false report "Illegal check state" severity failure;
814
      end case;
815
 
816
    end if;
817
  end process check_output;
818
 
819
 
820
  -- 4) PROC (ASYNC)
821
  CLOCK1 : process                      -- generate clock signal for design
822
  begin
823
    clk <= '1';
824
    wait for PERIOD/2;
825
    clk <= '0';
826
    wait for PERIOD/2;
827
  end process CLOCK1;
828
 
829
  -- 5) PROC (ASYNC)
830
  RESET : process
831
  begin
832
    rst_n <= '0';                       -- Reset the testsystem
833
    wait for 6*PERIOD;                  -- Wait 
834
    rst_n <= '1';                       -- de-assert reset
835
    wait;
836
  end process RESET;
837
 
838
  DUT : sdram2hibi
839
 
840
    generic map(
841
      hibi_data_width_g    => hibi_data_width,
842
      mem_data_width_g     => mem_data_width,
843
      mem_addr_width_g     => mem_addr_width,
844
      comm_width_g         => comm_width,
845
      input_fifo_depth_g   => 5,
846
      num_of_read_ports_g  => num_of_r_ports_g,
847
      num_of_write_ports_g => num_of_w_ports_g
848
      )
849
    port map(
850
      clk   => clk,
851
      rst_n => rst_n,
852
 
853
      hibi_addr_in  => addr_rxfifo_dut,
854
      hibi_data_in  => data_rxfifo_dut,
855
      hibi_comm_in  => comm_rxfifo_dut,
856
      hibi_empty_in => empty_rxfifo_dut,
857
      hibi_re_out   => re_dut_rxfifo,
858
 
859
      hibi_addr_out => addr_dut_txfifo,
860
      hibi_data_out => data_dut_txfifo,
861
      hibi_comm_out => comm_dut_txfifo,
862
      hibi_full_in  => full_txfifo_dut,
863
      hibi_we_out   => we_dut_txfifo,
864
 
865
      hibi_msg_addr_in  => msg_addr_rxfifo_dut,
866
      hibi_msg_data_in  => msg_data_rxfifo_dut,
867
      hibi_msg_comm_in  => msg_comm_rxfifo_dut,
868
      hibi_msg_empty_in => msg_empty_rxfifo_dut,
869
      hibi_msg_re_out   => msg_re_dut_rxfifo,
870
 
871
      hibi_msg_addr_out => msg_addr_dut_txfifo,
872
      hibi_msg_data_out => msg_data_dut_txfifo,
873
      hibi_msg_comm_out => msg_comm_dut_txfifo,
874
      hibi_msg_full_in  => msg_full_txfifo_dut,
875
      hibi_msg_we_out   => msg_we_dut_txfifo,
876
 
877
      sdram_ctrl_write_on_in     => write_on_tb_dut,
878
      sdram_ctrl_comm_out        => comm_dut_tb,
879
      sdram_ctrl_addr_out        => addr_dut_tb,
880
      sdram_ctrl_data_amount_out => amount_dut_tb,
881
      sdram_ctrl_input_empty_out => empty_dut_tb,
882
      sdram_ctrl_input_one_d_out => one_d_dut_tb,
883
      sdram_ctrl_output_full_out => full_dut_tb,
884
      sdram_ctrl_busy_in         => busy_tb_dut,
885
      sdram_ctrl_re_in           => re_tb_dut,
886
      sdram_ctrl_we_in           => we_tb_dut,
887
      sdram_ctrl_data_out        => data_dut_tb,
888
      sdram_ctrl_data_in         => data_tb_dut,
889
      sdram_ctrl_byte_select_out => byte_sel_dut_tb
890
      );
891
 
892
 
893
  rx_fifo : fifo
894
    generic map (
895
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
896
      depth_g      => 5
897
      )
898
    port map (
899
      clk       => clk,
900
      rst_n     => rst_n,
901
      data_in   => c_a_d_tb_rxfifo,
902
      we_in     => we_tb_rxfifo,
903
      full_out  => full_rxfifo_tb,
904
      one_p_out => one_p_rxfifo_tb,
905
 
906
      data_out  => c_a_d_rxfifo_dut,
907
      re_in     => re_dut_rxfifo,
908
      empty_out => empty_rxfifo_dut
909
 
910
      );
911
 
912
  msg_rx_fifo : fifo
913
    generic map (
914
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
915
      depth_g      => 5
916
      )
917
    port map (
918
      clk       => clk,
919
      rst_n     => rst_n,
920
      data_in   => msg_c_a_d_tb_rxfifo,
921
      we_in     => msg_we_tb_rxfifo,
922
      full_out  => msg_full_rxfifo_tb,
923
      one_p_out => msg_one_p_rxfifo_tb,
924
 
925
      data_out  => msg_c_a_d_rxfifo_dut,
926
      re_in     => msg_re_dut_rxfifo,
927
      empty_out => msg_empty_rxfifo_dut,
928
      one_d_out => msg_one_d_rxfifo_dut
929
 
930
      );
931
 
932
 
933
  tx_fifo : fifo
934
    generic map (
935
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
936
      depth_g      => 5
937
      )
938
    port map (
939
      clk     => clk,
940
      rst_n   => rst_n,
941
      data_in => c_a_d_dut_txfifo,
942
      we_in   => we_dut_txfifo,
943
 
944
      full_out  => full_txfifo_dut,
945
      one_p_out => one_p_txfifo_dut,
946
 
947
      data_out  => c_a_d_txfifo_tb,
948
      re_in     => re_tb_txfifo,
949
      empty_out => empty_txfifo_tb,
950
      one_d_out => one_d_txfifo_tb
951
      );
952
 
953
  msg_tx_fifo : fifo
954
    generic map (
955
      data_width_g => hibi_data_width+hibi_data_width+comm_width,
956
      depth_g      => 5
957
      )
958
    port map (
959
      clk     => clk,
960
      rst_n   => rst_n,
961
      data_in => msg_c_a_d_dut_txfifo,
962
      we_in   => msg_we_dut_txfifo,
963
 
964
      full_out  => msg_full_txfifo_dut,
965
      one_p_out => msg_one_p_txfifo_dut,
966
 
967
      data_out  => msg_c_a_d_txfifo_tb,
968
      re_in     => msg_re_tb_txfifo,
969
      empty_out => msg_empty_txfifo_tb,
970
      one_d_out => msg_one_d_txfifo_tb
971
 
972
      );
973
 
974
  sdram_controller_1 : sdram_controller
975
    generic map (
976
      clk_freq_mhz_g      => clk_freq_c,
977
      mem_addr_width_g    => 22,
978
      block_read_length_g => 640)
979
    port map (
980
      clk                    => clk,
981
      rst_n                  => rst_n,
982
      command_in             => comm_dut_tb,
983
      address_in             => addr_dut_tb,
984
      data_amount_in         => amount_dut_tb,
985
      byte_select_in         => byte_sel_dut_tb,
986
      input_empty_in         => empty_dut_tb,
987
      input_one_d_in         => one_d_dut_tb,
988
      output_full_in         => full_dut_tb,
989
      data_in                => data_dut_tb,
990
      write_on_out           => write_on_tb_dut,
991
      busy_out               => busy_tb_dut,
992
      output_we_out          => we_tb_dut,
993
      input_re_out           => re_tb_dut,
994
      data_to_sdram2hibi_out => data_tb_dut,
995
      sdram_data_inout       => sdram_data_inout,
996
      sdram_cke_out          => sdram_cke_out,
997
      sdram_cs_n_out         => sdram_cs_n_out,
998
      sdram_we_n_out         => sdram_we_n_out,
999
      sdram_ras_n_out        => sdram_ras_n_out,
1000
      sdram_cas_n_out        => sdram_cas_n_out,
1001
      sdram_dqm_out          => sdram_dqm_out,
1002
      sdram_ba_out           => sdram_ba_out,
1003
      sdram_address_out      => sdram_addr_out);
1004
 
1005
end behavioral;

powered by: WebSVN 2.1.0

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