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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [bplib/] [nxcramlib/] [tb/] [tb_nx_cram_memctl.vhd] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 wfjm
-- $Id: tb_nx_cram_memctl.vhd 802 2016-08-27 19:00:23Z mueller $
2 16 wfjm
--
3
-- Copyright 2010-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    tb_nx_cram_memctl - sim
16
-- Description:    Test bench for nx_cram_memctl
17
--
18
-- Dependencies:   vlib/simlib/simclk
19 17 wfjm
--                 vlib/simlib/simclkcnt
20 16 wfjm
--                 bplib/micron/mt45w8mw16b
21
--                 tbd_nx_cram_memctl        [UUT, abstact]
22
--
23
-- To test:        nx_cram_memctl_as  (via tbd_nx_cram_memctl_as)
24
--                 
25
-- Target Devices: generic
26 29 wfjm
-- Tool versions:  xst 11.4-14.7; ghdl 0.26-0.31
27 16 wfjm
-- Revision History: 
28
-- Date         Rev Version  Comment
29 17 wfjm
-- 2011-12-23   444   1.4    use new simclk/simclkcnt
30 16 wfjm
-- 2011-11-26   433   1.3    renamed from tb_n2_cram_memctl
31
-- 2011-11-21   432   1.2    now numeric_std clean; update O_FLA_CE_N usage
32
-- 2010-05-30   297   1.1    use abstact uut tbd_nx_cram_memctl
33
-- 2010-05-23   293   1.0    Initial version (derived from tb_s3_sram_memctl)
34
------------------------------------------------------------------------------
35
 
36
library ieee;
37
use ieee.std_logic_1164.all;
38
use ieee.numeric_std.all;
39
use ieee.std_logic_textio.all;
40
use std.textio.all;
41
 
42
use work.slvtypes.all;
43
use work.simlib.all;
44
 
45
entity tb_nx_cram_memctl is
46
end tb_nx_cram_memctl;
47
 
48
architecture sim of tb_nx_cram_memctl is
49
 
50
component tbd_nx_cram_memctl is         -- CRAM driver (abstract) [tb design]
51
  port (
52
    CLK : in slbit;                     -- clock
53
    RESET : in slbit;                   -- reset
54
    REQ   : in slbit;                   -- request
55
    WE    : in slbit;                   -- write enable
56
    BUSY : out slbit;                   -- controller busy
57
    ACK_R : out slbit;                  -- acknowledge read
58
    ACK_W : out slbit;                  -- acknowledge write
59
    ACT_R : out slbit;                  -- signal active read
60
    ACT_W : out slbit;                  -- signal active write
61
    ADDR : in slv22;                    -- address  (32 bit word address)
62
    BE : in slv4;                       -- byte enable
63
    DI : in slv32;                      -- data in  (memory view)
64
    DO : out slv32;                     -- data out (memory view)
65
    O_MEM_CE_N : out slbit;             -- cram: chip enable   (act.low)
66
    O_MEM_BE_N : out slv2;              -- cram: byte enables  (act.low)
67
    O_MEM_WE_N : out slbit;             -- cram: write enable  (act.low)
68
    O_MEM_OE_N : out slbit;             -- cram: output enable (act.low)
69
    O_MEM_ADV_N : out slbit;            -- cram: address valid (act.low)
70
    O_MEM_CLK : out slbit;              -- cram: clock
71
    O_MEM_CRE : out slbit;              -- cram: command register enable
72
    I_MEM_WAIT : in slbit;              -- cram: mem wait
73
    O_MEM_ADDR  : out slv23;            -- cram: address lines
74
    IO_MEM_DATA : inout slv16           -- cram: data lines
75
  );
76
end component;
77
 
78
  signal CLK   : slbit := '0';
79
  signal RESET : slbit := '0';
80
  signal REQ   : slbit := '0';
81
  signal WE    : slbit := '0';
82
  signal BUSY  : slbit := '0';
83
  signal ACK_R : slbit := '0';
84
  signal ACK_W : slbit := '0';
85
  signal ACT_R : slbit := '0';
86
  signal ACT_W : slbit := '0';
87
  signal ADDR : slv22 := (others=>'0');
88
  signal BE : slv4  := (others=>'0');
89
  signal DI : slv32 := (others=>'0');
90
  signal DO : slv32 := (others=>'0');
91
  signal O_MEM_CE_N : slbit  := '0';
92
  signal O_MEM_BE_N : slv2   := (others=>'0');
93
  signal O_MEM_WE_N : slbit  := '0';
94
  signal O_MEM_OE_N : slbit  := '0';
95
  signal O_MEM_ADV_N : slbit  := '0';
96
  signal O_MEM_CLK : slbit  := '0';
97
  signal O_MEM_CRE : slbit  := '0';
98
  signal I_MEM_WAIT : slbit  := '0';
99
  signal O_MEM_ADDR  : slv23 := (others=>'0');
100
  signal IO_MEM_DATA : slv16 := (others=>'0');
101
 
102
  signal R_MEMON : slbit  := '0';
103
  signal N_CHK_DATA : slbit  := '0';
104
  signal N_REF_DATA : slv32 := (others=>'0');
105
  signal N_REF_ADDR : slv22 := (others=>'0');
106
  signal R_CHK_DATA_AL : slbit  := '0';
107
  signal R_REF_DATA_AL : slv32 := (others=>'0');
108
  signal R_REF_ADDR_AL : slv22 := (others=>'0');
109
  signal R_CHK_DATA_DL : slbit  := '0';
110
  signal R_REF_DATA_DL : slv32 := (others=>'0');
111
  signal R_REF_ADDR_DL : slv22 := (others=>'0');
112
 
113
  signal CLK_STOP : slbit := '0';
114 17 wfjm
  signal CLK_CYCLE : integer := 0;
115 16 wfjm
 
116 37 wfjm
  constant clock_period : Delay_length :=  20 ns;  -- when changed update also
117
                                                   -- READ0DELAY ect delays !!
118
  constant clock_offset : Delay_length := 200 ns;
119
  constant setup_time : Delay_length :=  7.5 ns;   -- compatible ucf for
120
  constant c2out_time : Delay_length := 12.0 ns;   -- tbd_nx_cram_memctl_as
121 16 wfjm
 
122
begin
123
 
124 17 wfjm
  CLKGEN : simclk
125 16 wfjm
    generic map (
126
      PERIOD => clock_period,
127
      OFFSET => clock_offset)
128
    port map (
129
      CLK => CLK,
130
      CLK_STOP => CLK_STOP
131
    );
132
 
133 17 wfjm
  CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
134
 
135 16 wfjm
  MEM : entity work.mt45w8mw16b
136
    port map (
137
      CLK   => O_MEM_CLK,
138
      CE_N  => O_MEM_CE_N,
139
      OE_N  => O_MEM_OE_N,
140
      WE_N  => O_MEM_WE_N,
141
      UB_N  => O_MEM_BE_N(1),
142
      LB_N  => O_MEM_BE_N(0),
143
      ADV_N => O_MEM_ADV_N,
144
      CRE   => O_MEM_CRE,
145
      MWAIT => I_MEM_WAIT,
146
      ADDR  => O_MEM_ADDR,
147
      DATA  => IO_MEM_DATA
148
    );
149
 
150
  UUT : tbd_nx_cram_memctl
151
    port map (
152
      CLK     => CLK,
153
      RESET   => RESET,
154
      REQ     => REQ,
155
      WE      => WE,
156
      BUSY    => BUSY,
157
      ACK_R   => ACK_R,
158
      ACK_W   => ACK_W,
159
      ACT_R   => ACT_R,
160
      ACT_W   => ACT_W,
161
      ADDR    => ADDR,
162
      BE      => BE,
163
      DI      => DI,
164
      DO      => DO,
165
      O_MEM_CE_N  => O_MEM_CE_N,
166
      O_MEM_BE_N  => O_MEM_BE_N,
167
      O_MEM_WE_N  => O_MEM_WE_N,
168
      O_MEM_OE_N  => O_MEM_OE_N,
169
      O_MEM_CLK   => O_MEM_CLK,
170
      O_MEM_ADV_N => O_MEM_ADV_N,
171
      O_MEM_CRE   => O_MEM_CRE,
172
      I_MEM_WAIT  => I_MEM_WAIT,
173
      O_MEM_ADDR  => O_MEM_ADDR,
174
      IO_MEM_DATA => IO_MEM_DATA
175
    );
176
 
177
  proc_stim: process
178
    file fstim : text open read_mode is "tb_nx_cram_memctl_stim";
179
    variable iline : line;
180
    variable oline : line;
181
    variable ok : boolean;
182
    variable dname : string(1 to 6) := (others=>' ');
183
    variable idelta : integer := 0;
184
    variable iaddr : slv22 := (others=>'0');
185
    variable idata : slv32 := (others=>'0');
186
    variable ibe   : slv4 := (others=>'0');
187
    variable ival  : slbit := '0';
188
    variable nbusy : integer := 0;
189
 
190
  begin
191
 
192
    wait for clock_offset - setup_time;
193
 
194
    file_loop: while not endfile(fstim) loop
195
 
196
      readline (fstim, iline);
197
 
198
      readcomment(iline, ok);
199
      next file_loop when ok;
200
 
201
      readword(iline, dname, ok);
202
      if ok then
203
        case dname is
204
          when ".memon" =>              -- .memon
205
            read_ea(iline, ival);
206
            R_MEMON <= ival;
207
            wait for 2*clock_period;
208
 
209
          when ".reset" =>              -- .reset 
210
            write(oline, string'(".reset"));
211
            writeline(output, oline);
212
            RESET <= '1';
213
            wait for clock_period;
214
            RESET <= '0';
215
            wait for 9*clock_period;
216
 
217
          when ".wait " =>              -- .wait
218
            read_ea(iline, idelta);
219
            wait for idelta*clock_period;
220
 
221
          when "read  " =>              -- read
222
            readgen_ea(iline, iaddr, 16);
223
            readgen_ea(iline, idata, 16);
224
            ADDR <= iaddr;
225
            REQ <= '1';
226
            WE  <= '0';
227
 
228
            writetimestamp(oline, CLK_CYCLE, ": stim read ");
229
            writegen(oline, iaddr, right, 7, 16);
230
            write(oline, string'("     "));
231
            writegen(oline, idata, right, 9, 16);
232
 
233
            nbusy := 0;
234
            while BUSY='1' loop
235
              nbusy := nbusy + 1;
236
              wait for clock_period;
237
            end loop;
238
 
239
            write(oline, string'("  nbusy="));
240
            write(oline, nbusy, right, 2);
241
            writeline(output, oline);
242
 
243
            N_CHK_DATA <= '1', '0' after clock_period;
244
            N_REF_DATA <= idata;
245
            N_REF_ADDR <= iaddr;
246
 
247
            wait for clock_period;
248
            REQ <= '0';
249
 
250
          when "write " =>              -- write
251
            readgen_ea(iline, iaddr, 16);
252
            read_ea(iline, ibe);
253
            readgen_ea(iline, idata, 16);
254
            ADDR <= iaddr;
255
            BE   <= ibe;
256
            DI   <= idata;
257
            REQ  <= '1';
258
            WE   <= '1';
259
 
260
            writetimestamp(oline, CLK_CYCLE, ": stim write");
261
            writegen(oline, iaddr, right, 7, 16);
262
            writegen(oline, ibe  , right, 5,  2);
263
            writegen(oline, idata, right, 9, 16);
264
 
265
            nbusy := 0;
266
            while BUSY = '1' loop
267
              nbusy := nbusy + 1;
268
              wait for clock_period;
269
            end loop;
270
 
271
            write(oline, string'("  nbusy="));
272
            write(oline, nbusy, right, 2);
273
            writeline(output, oline);
274
 
275
            wait for clock_period;
276
            REQ <= '0';
277
 
278
          when others =>                -- bad directive
279
            write(oline, string'("?? unknown directive: "));
280
            write(oline, dname);
281
            writeline(output, oline);
282
            report "aborting" severity failure;
283
        end case;
284
      else
285
        report "failed to find command" severity failure;
286
 
287
      end if;
288
 
289
      testempty_ea(iline);
290
 
291
    end loop; -- file fstim
292
 
293
    wait for 10*clock_period;
294
 
295
    writetimestamp(oline, CLK_CYCLE, ": DONE ");
296
    writeline(output, oline);
297
 
298
    CLK_STOP <= '1';
299
 
300
    wait;                               -- suspend proc_stim forever
301
                                        -- clock is stopped, sim will end
302
 
303
  end process proc_stim;
304
 
305
 
306
  proc_moni: process
307
    variable oline : line;
308
  begin
309
 
310
    loop
311
      wait until rising_edge(CLK);
312
 
313
      if ACK_R = '1' then
314
        writetimestamp(oline, CLK_CYCLE, ": moni ");
315
        writegen(oline, DO, right, 9, 16);
316
        if R_CHK_DATA_DL = '1' then
317
          write(oline, string'("  CHECK"));
318
          if R_REF_DATA_DL = DO then
319
            write(oline, string'(" OK"));
320
          else
321
            write(oline, string'(" FAIL, exp="));
322
            writegen(oline, R_REF_DATA_DL, right, 9, 16);
323
            write(oline, string'(" for a="));
324
            writegen(oline, R_REF_ADDR_DL, right, 5, 16);
325
          end if;
326
          R_CHK_DATA_DL <= '0';
327
        end if;
328
        writeline(output, oline);
329
      end if;
330
 
331
      if R_CHK_DATA_AL = '1' then
332
        R_CHK_DATA_DL <= R_CHK_DATA_AL;
333
        R_REF_DATA_DL <= R_REF_DATA_AL;
334
        R_REF_ADDR_DL <= R_REF_ADDR_AL;
335
        R_CHK_DATA_AL <= '0';
336
      end if;
337
      if N_CHK_DATA = '1' then
338
        R_CHK_DATA_AL <= N_CHK_DATA;
339
        R_REF_DATA_AL <= N_REF_DATA;
340
        R_REF_ADDR_AL <= N_REF_ADDR;
341
      end if;
342
 
343
    end loop;
344
 
345
  end process proc_moni;
346
 
347
 
348
  proc_memon: process
349
    variable oline : line;
350
  begin
351
 
352
    loop
353
      wait until rising_edge(CLK);
354
 
355
      if R_MEMON = '1' then
356
        writetimestamp(oline, CLK_CYCLE, ": mem  ");
357
        write(oline, string'(" ce="));
358
        write(oline, not O_MEM_CE_N, right, 2);
359
        write(oline, string'(" be="));
360
        write(oline, not O_MEM_BE_N, right, 4);
361
        write(oline, string'(" we="));
362
        write(oline, not O_MEM_WE_N, right);
363
        write(oline, string'(" oe="));
364
        write(oline, not O_MEM_OE_N, right);
365
        write(oline, string'(" a="));
366
        writegen(oline, O_MEM_ADDR, right, 6, 16);
367
        write(oline, string'(" d="));
368
        writegen(oline, IO_MEM_DATA, right, 4, 16);
369
        writeline(output, oline);
370
      end if;
371
 
372
    end loop;
373
 
374
  end process proc_memon;
375
 
376
 
377
end sim;

powered by: WebSVN 2.1.0

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