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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [designs/] [leon3-gr-cpci-ax/] [testbench.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
-----------------------------------------------------------------------------
2
--  LEON3 Demonstration design test bench
3
--  Copyright (C) 2004 Jiri Gaisler, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
------------------------------------------------------------------------------
15
 
16
library ieee;
17
use ieee.std_logic_1164.all;
18
library gaisler;
19
use gaisler.libdcom.all;
20
use gaisler.sim.all;
21
use gaisler.ambatest.all;
22
use gaisler.pcitb.all;
23
library techmap;
24
use techmap.gencomp.all;
25
library grlib;
26
use grlib.stdlib.all;
27
library micron;
28
use micron.components.all;
29
 
30
use work.config.all;    -- configuration
31
use work.debug.all;
32
use std.textio.all;
33
 
34
entity testbench is
35
  generic (
36
    fabtech   : integer := CFG_FABTECH;
37
    memtech   : integer := CFG_MEMTECH;
38
    padtech   : integer := CFG_PADTECH;
39
    clktech   : integer := CFG_CLKTECH;
40
    disas     : integer := CFG_DISAS;   -- Enable disassembly to console
41
    dbguart   : integer := CFG_DUART;   -- Print UART on console
42
    pclow     : integer := CFG_PCLOW;
43
 
44
    clkperiod : integer := 100;         -- system clock period
45
    romwidth  : integer := 8;           -- rom data width (8/32)
46
    romdepth  : integer := 23;          -- rom address depth
47
    sramwidth  : integer := 32;         -- ram data width (8/16/32)
48
    sramdepth  : integer := 20;         -- ram address depth
49
    srambanks  : integer := 2           -- number of ram banks
50
  );
51
end;
52
 
53
architecture behav of testbench is
54
 
55
constant promfile  : string := "prom.srec";  -- rom contents
56
constant sramfile  : string := "sram.srec";  -- ram contents
57
constant sdramfile : string := "sdram.srec"; -- sdram contents
58
 
59
component leon3ax
60
--    generic (
61
--      fabtech  : integer := CFG_FABTECH;
62
--      memtech  : integer := CFG_MEMTECH;
63
--      padtech  : integer := CFG_PADTECH;
64
--      clktech  : integer := CFG_CLKTECH;
65
--      disas     : integer := CFG_DISAS;       -- Enable disassembly to console
66
--      dbguart   : integer := CFG_DUART;       -- Print UART on console
67
--      pclow     : integer := CFG_PCLOW
68
--    );
69
  port (
70
    resetn        : in     std_logic;
71
    clk           : in     std_logic;
72
 
73
    errorn        : out    std_logic;
74
 
75
    sa            : out    std_logic_vector(15 downto 0);-- {sa(15) unused}
76
    sd            : inout  std_logic_vector(63 downto 0);
77
    scb           : inout  std_logic_vector(7 downto 0);
78
    sdclkfb       : in     std_logic;                   -- {unused by default}
79
    sdcsn         : out    std_logic_vector(1 downto 0); -- SDRAM chip select
80
    sdwen         : out    std_logic;                   -- SDRAM write enable
81
    sdrasn        : out    std_logic;                   -- SDRAM RAS
82
    sdcasn        : out    std_logic;                   -- SDRAM CAS
83
    sddqm         : out    std_logic_vector(7 downto 0); -- SDRAM DQM
84
 
85
    dsutx         : out    std_logic;                   -- DSU tx data
86
    dsurx         : in     std_logic;                   -- DSU rx data
87
    dsuen         : in     std_logic;
88
    dsubre        : in     std_logic;
89
    dsuact        : out    std_logic;
90
    txd           : out    std_logic_vector(1 to 2);     -- UART tx data
91
    rxd           : in     std_logic_vector(1 to 2);     -- UART rx data
92
    rtsn          : out    std_logic_vector(1 to 2);     -- UART rtsn
93
    ctsn          : in     std_logic_vector(1 to 2);     -- UART ctsn
94
 
95
    address       : out    std_logic_vector(27 downto 0);
96
    data          : inout  std_logic_vector(31 downto 0);
97
 
98
    ramsn         : out    std_logic_vector(4 downto 0);
99
    ramoen        : out    std_logic_vector(4 downto 0);
100
    rwen          : out    std_logic_vector(3 downto 0);
101
    ramben        : out    std_logic_vector(3 downto 0);
102
    oen           : out    std_logic;
103
    writen        : out    std_logic;
104
    read          : out    std_logic;
105
    iosn          : out    std_logic;
106
    romsn         : out    std_logic_vector(1 downto 0);
107
 
108
    cb            : inout  std_logic_vector(7 downto 0); -- {unused by default}
109
    bexcn         : in     std_logic;                    -- {unused by default}
110
    brdyn         : in     std_logic;                    -- {unused by default}
111
 
112
    gpio          : inout  std_logic_vector(15 downto 0);-- {unused by default}
113
    pciio         : inout  std_logic_vector(31 downto 0);-- {unused by default}
114
 
115
    pci_rst       : inout  std_logic;                   -- PCI bus
116
    pci_clk       : in     std_logic;
117
 
118
    pci_gnt       : in     std_logic;
119
    pci_idsel     : in     std_logic;
120
    pci_lock      : inout  std_logic;
121
    pci_ad        : inout  std_logic_vector(63 downto 0);
122
    pci_cbe       : inout  std_logic_vector(7 downto 0);
123
    pci_frame     : inout  std_logic;
124
    pci_irdy      : inout  std_logic;
125
    pci_trdy      : inout  std_logic;
126
    pci_devsel    : inout  std_logic;
127
    pci_stop      : inout  std_logic;
128
    pci_perr      : inout  std_logic;
129
    pci_par       : inout  std_logic;
130
    pci_req       : inout  std_logic;
131
    pci_serr      : inout  std_logic;
132
    pci_host      : in     std_logic;
133
    pci_66        : in     std_logic;
134
 
135
    --pci_arb_gnt   : out    std_logic_vector(7 downto 0);
136
    pci_arb_req   : in     std_logic_vector(7 downto 0);
137
 
138
    pci_ack64n    : inout  std_logic;                    -- {unused by default}
139
    pci_par64     : inout  std_logic;                    -- {unused by default}
140
    pci_req64n    : inout  std_logic;                    -- {unused by default}
141
    pci_en64      : in     std_logic                     -- {unused by default}
142
  );
143
end component;
144
 
145
signal clk    : std_logic := '0';
146
signal Rst    : std_logic := '0';                        -- Reset
147
constant ct     : integer := clkperiod/2;
148
 
149
signal address  : std_logic_vector(27 downto 0);
150
signal data     : std_logic_vector(31 downto 0);
151
 
152
signal ramsn    : std_logic_vector(4 downto 0);
153
signal ramoen   : std_logic_vector(4 downto 0);
154
signal rwen     : std_logic_vector(3 downto 0);
155
signal romsn    : std_logic_vector(1 downto 0);
156
signal iosn     : std_logic;
157
signal oen      : std_logic;
158
signal read     : std_logic;
159
signal writen   : std_logic;
160
signal brdyn    : std_logic;
161
signal bexcn    : std_logic;
162
signal dsuen, dsutx, dsurx, dsubre, dsuact : std_logic;
163
signal dsurst   : std_logic;
164
signal error    : std_logic;
165
signal GND      : std_logic := '0';
166
signal VCC      : std_logic := '1';
167
 
168
signal sdcke    : std_logic_vector ( 1 downto 0);  -- clk en
169
signal sdcsn    : std_logic_vector ( 1 downto 0);  -- chip sel
170
signal sdwen    : std_logic;                       -- write en
171
signal sdrasn   : std_logic;                       -- row addr stb
172
signal sdcasn   : std_logic;                       -- col addr stb
173
signal sddqm    : std_logic_vector ( 7 downto 0);  -- data i/o mask
174
 
175
signal pci_rst  : Std_Logic := '0';      -- PCI bus
176
signal pci_clk  : std_logic := '0';
177
 
178
constant lresp : boolean := false;
179
 
180
signal sa       : std_logic_vector(15 downto 0);
181
signal sd       : std_logic_vector(63 downto 0);
182
 
183
signal   sdclkfb       : Std_ULogic;                   -- {unused by default}
184
 
185
signal txd, rxd : std_logic_vector(1 to 2);
186
signal rtsn, ctsn : std_logic_vector(1 to 2);
187
 
188
signal   ramben        : std_logic_vector(3 downto 0); -- {unused by default}
189
signal   cb            : std_logic_vector(7 downto 0); -- {unused by default}
190
signal   gpio          : std_logic_vector(15 downto 0);-- {unused by default}
191
signal   pciio         : std_logic_vector(31 downto 0);-- {unused by default}
192
 
193
-- PCI signals
194
 
195
constant tval : time := 7 ns;
196
constant slots : integer := 1;
197
 
198
constant ad_const2 : pci_ad_type := (
199
          ad => (others => 'Z'),
200
          cbe => (others => 'L'),
201
          par => 'Z');
202
constant pci_idle2 : pci_type := ( ad_const2, ifc_const, err_const, arb_const,
203
  syst_const, ext64_const, int_const, cache_const);
204
 
205
signal pci     : pci_type;
206
signal rsttrig : std_logic;
207
signal tbi     : tbi_array_type;
208
signal tbo     : tbo_array_type;
209
 
210
signal pci_cbe  : std_logic_vector(7 downto 4);
211
signal pci_ad   : std_logic_vector(63 downto 32);
212
signal pci_host : std_logic;
213
signal pci_66   : std_logic;
214
signal pci_en64 : std_logic;
215
 
216
begin
217
 
218
-- clock and reset
219
 
220
  clk <= not clk after ct * 1 ns;
221
  rst <= dsurst;
222
  dsuen <= '1'; dsubre <= '0'; rxd(1) <= '1';
223
  sdcke <= "11";
224
  pci_clk <= not pci_clk after 25 ns;
225
  pci_rst <= '0', '1' after 500 ns;
226
 
227
  data <= buskeep(data) after 5 ns;
228
 
229
  leon3ax_0 : leon3ax
230
   port map(
231
   resetn     => rst,
232
   clk        => clk,
233
   errorn     => error,            --##errorn
234
   sa         => sa,
235
   sd         => sd(63 downto 0),
236
   scb        => cb(7 downto 0),
237
   sdclkfb    => sdclkfb,
238
   sdcsn      => sdcsn,
239
   sdwen      => sdwen,
240
   sdrasn     => sdrasn,
241
   sdcasn     => sdcasn,
242
   sddqm      => sddqm,
243
   dsutx      => dsutx,
244
   dsurx      => dsurx,
245
   dsuen      => dsuen,
246
   dsubre     => dsubre,
247
   dsuact     => dsuact,
248
   txd        => txd,
249
   rxd        => rxd,
250
   rtsn       => rtsn,
251
   ctsn       => ctsn,
252
   address    => address(27 downto 0),
253
   data       => data,
254
   ramsn      => ramsn,
255
   ramoen     => ramoen,
256
   rwen       => rwen,
257
   ramben     => ramben,
258
   oen        => oen,
259
   writen     => writen,
260
   read       => read,
261
   iosn       => iosn,
262
   romsn      => romsn,
263
   cb         => cb,
264
   bexcn      => bexcn,
265
   brdyn      => brdyn,
266
   gpio       => gpio,
267
   pciio      => pciio,
268
   pci_rst    => pci.syst.rst,
269
   pci_clk    => pci.syst.clk,
270
   pci_gnt    => pci.arb.gnt(20),
271
   pci_idsel            => pci.ifc.idsel(0),
272
   pci_lock             => pci.ifc.lock,
273
   pci_ad(31 downto 0)  => pci.ad.ad,
274
   pci_ad(63 downto 32) => pci_ad,
275
   pci_cbe(3 downto 0)  => pci.ad.cbe,
276
   pci_cbe(7 downto 4)  => pci_cbe,
277
   pci_frame            => pci.ifc.frame,
278
   pci_irdy             => pci.ifc.irdy,
279
   pci_trdy             => pci.ifc.trdy,
280
   pci_devsel           => pci.ifc.devsel,
281
   pci_stop             => pci.ifc.stop,
282
   pci_perr             => pci.err.perr,
283
   pci_par              => pci.ad.par,
284
   pci_req              => pci.arb.req(20),
285
   pci_serr             => pci.err.serr,
286
   pci_host             => pci_host,
287
   pci_66               => pci_66,
288
   --pci_arb_gnt,
289
   pci_arb_req          => pci.arb.req(7 downto 0),
290
   pci_ack64n           => pci.ext64.ack64,
291
   pci_par64            => pci.ext64.par64,
292
   pci_req64n           => pci.ext64.req64,
293
   pci_en64             => pci_en64);
294
 
295
-- testmodule
296
 
297
  test0 :  grtestmod
298
    port map ( rst, clk, error, address(21 downto 2), data,
299
               iosn, oen, writen, brdyn);
300
 
301
-- PCI tests
302
 
303
  pci <= pci_idle2;
304
 
305
  pci_66 <= '1'; pci_host <= '1'; pci_en64 <= '1';
306
  pci.ifc.idsel(slots-1 downto 0) <= pci.ad.ad(31 downto (32-slots));
307
  pci_cbe <= (others => 'Z'); pci_ad <= (others => 'Z');
308
 
309
  clkgen : pcitb_clkgen
310
    generic map(mhz66 => false, rstclocks => 20)
311
    port map(rsttrig => rsttrig, systclk => pci.syst);
312
 
313
  arbiter : pcitb_arb
314
    generic map(slots => slots, tval => tval)
315
    port map(systclk => pci.syst, ifcin => pci.ifc, arbin => pci.arb, arbout => pci.arb);
316
 
317
  monitor : pcitb_monitor
318
    generic map(dbglevel => 5)
319
    port map(pciin => pci);
320
 
321
  master : pcitb_master
322
    generic map(tval => tval, dbglevel => 5)
323
    port map(pciin => pci, pciout => pci, tbi => tbi(0), tbo => tbo(0));
324
 
325
  stimgen : pcitb_stimgen
326
    generic map(slots => slots, dbglevel => 5)
327
    port map(rsttrig => rsttrig, tbi => tbi, tbo => tbo);
328
 
329
 
330
-- optional sdram
331
 
332
  sd1 : if (CFG_SDEN = 1) generate
333
    u0: mt48lc16m16a2 generic map (index => 0, fname => sdramfile)
334
        PORT MAP(
335
            Dq => sd(31 downto 16), Addr => sa(12 downto 0),
336
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
337
            Cs_n => sdcsn(0), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
338
            Dqm => sddqm(3 downto 2));
339
    u1: mt48lc16m16a2 generic map (index => 16, fname => sdramfile)
340
        PORT MAP(
341
            Dq => sd(15 downto 0), Addr => sa(12 downto 0),
342
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
343
            Cs_n => sdcsn(0), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
344
            Dqm => sddqm(1 downto 0));
345
    u2: mt48lc16m16a2 generic map (index => 0, fname => sdramfile)
346
        PORT MAP(
347
            Dq => sd(31 downto 16), Addr => sa(12 downto 0),
348
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
349
            Cs_n => sdcsn(1), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
350
            Dqm => sddqm(3 downto 2));
351
    u3: mt48lc16m16a2 generic map (index => 16, fname => sdramfile)
352
        PORT MAP(
353
            Dq => sd(15 downto 0), Addr => sa(12 downto 0),
354
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
355
            Cs_n => sdcsn(1), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
356
            Dqm => sddqm(1 downto 0));
357
    u4: mt48lc16m16a2 generic map (index => 0, fname => sdramfile)
358
        PORT MAP(
359
            Dq => sd(63 downto 48), Addr => sa(12 downto 0),
360
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
361
            Cs_n => sdcsn(0), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
362
            Dqm => sddqm(7 downto 6));
363
    u5: mt48lc16m16a2 generic map (index => 16, fname => sdramfile)
364
        PORT MAP(
365
            Dq => sd(47 downto 32), Addr => sa(12 downto 0),
366
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
367
            Cs_n => sdcsn(0), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
368
            Dqm => sddqm(5 downto 4));
369
    u6: mt48lc16m16a2 generic map (index => 0, fname => sdramfile)
370
        PORT MAP(
371
            Dq => sd(63 downto 48), Addr => sa(12 downto 0),
372
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
373
            Cs_n => sdcsn(1), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
374
            Dqm => sddqm(7 downto 6));
375
    u7: mt48lc16m16a2 generic map (index => 16, fname => sdramfile)
376
        PORT MAP(
377
            Dq => sd(47 downto 32), Addr => sa(12 downto 0),
378
            Ba => sa(14 downto 13), Clk => clk, Cke => sdcke(0),
379
            Cs_n => sdcsn(1), Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
380
            Dqm => sddqm(5 downto 4));
381
  end generate;
382
 
383
  prom0 : sram generic map (index => 6, abits => romdepth, fname => promfile)
384
        port map (address(romdepth-1 downto 0), data(31 downto 24),
385
                  romsn(0), rwen(0), oen);
386
 
387
  sram0 : sram16 generic map (index => 0, abits => sramdepth, fname => sramfile)
388
        port map (address(sramdepth+1 downto 2), data(31 downto 16),
389
                ramben(0), ramben(1), ramsn(0), writen, ramoen(0));
390
  sram1 : sram16 generic map (index => 2, abits => sramdepth, fname => sramfile)
391
        port map (address(sramdepth+1 downto 2), data(15 downto 0),
392
                ramben(2), ramben(3), ramsn(0), writen, ramoen(0));
393
  sram2 : sram16 generic map (index => 0, abits => sramdepth, fname => sramfile)
394
        port map (address(sramdepth+1 downto 2), data(31 downto 16),
395
                ramben(0), ramben(1), ramsn(1), writen, ramoen(1));
396
  sram3 : sram16 generic map (index => 2, abits => sramdepth, fname => sramfile)
397
        port map (address(sramdepth+1 downto 2), data(15 downto 0),
398
                ramben(2), ramben(3), ramsn(1), writen, ramoen(1));
399
 
400
 
401
 
402
   error <= 'H';                          -- ERROR pull-up
403
 
404
   iuerr : process
405
   begin
406
     wait for 2000 ns;
407
     if to_x01(error) = '1' then wait on error; end if;
408
     assert (to_x01(error) = '1')
409
       report "*** IU in error mode, simulation halted ***"
410
         severity failure ;
411
   end process;
412
 
413
  data <= buskeep(data), (others => 'H') after 25 ns;
414
  sd <= buskeep(sd), (others => 'H') after 25 ns;
415
 
416
  dsucom : process
417
    procedure dsucfg(signal dsurx : in std_logic; signal dsutx : out std_logic) is
418
    variable w32 : std_logic_vector(31 downto 0);
419
    variable c8  : std_logic_vector(7 downto 0);
420
    constant txp : time := 160 * 1 ns;
421
    begin
422
    dsutx <= '1';
423
    dsurst <= '0';
424
    wait for 500 ns;
425
    dsurst <= '1';
426
    wait;
427
    wait for 5000 ns;
428
    txc(dsutx, 16#55#, txp);            -- sync uart
429
 
430
    txc(dsutx, 16#c0#, txp);
431
    txa(dsutx, 16#90#, 16#00#, 16#00#, 16#00#, txp);
432
    txa(dsutx, 16#00#, 16#00#, 16#00#, 16#ef#, txp);
433
 
434
    txc(dsutx, 16#c0#, txp);
435
    txa(dsutx, 16#90#, 16#00#, 16#00#, 16#20#, txp);
436
    txa(dsutx, 16#00#, 16#00#, 16#ff#, 16#ff#, txp);
437
 
438
    txc(dsutx, 16#c0#, txp);
439
    txa(dsutx, 16#90#, 16#40#, 16#00#, 16#48#, txp);
440
    txa(dsutx, 16#00#, 16#00#, 16#00#, 16#12#, txp);
441
 
442
    txc(dsutx, 16#c0#, txp);
443
    txa(dsutx, 16#90#, 16#40#, 16#00#, 16#60#, txp);
444
    txa(dsutx, 16#00#, 16#00#, 16#12#, 16#10#, txp);
445
 
446
    txc(dsutx, 16#80#, txp);
447
    txa(dsutx, 16#90#, 16#00#, 16#00#, 16#00#, txp);
448
    rxi(dsurx, w32, txp, lresp);
449
 
450
    txc(dsutx, 16#a0#, txp);
451
    txa(dsutx, 16#40#, 16#00#, 16#00#, 16#00#, txp);
452
    rxi(dsurx, w32, txp, lresp);
453
 
454
    end;
455
 
456
  begin
457
 
458
    dsucfg(dsutx, dsurx);
459
 
460
    wait;
461
  end process;
462
 
463
    sdclkfb       <= clk;
464
 
465
    rxd(2)        <= '1';
466
    ctsn(1)       <= '0';
467
    ctsn(2)       <= '0';
468
 
469
    cb            <= (others => 'H');
470
    bexcn         <= '1';
471
 
472
    gpio          <= (others => 'H');
473
    pciio         <= (others => 'H');
474
 
475
end;
476
 

powered by: WebSVN 2.1.0

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