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 work.debug.all;
|
22 |
|
|
library techmap;
|
23 |
|
|
use techmap.gencomp.all;
|
24 |
|
|
library micron;
|
25 |
|
|
use micron.components.all;
|
26 |
|
|
|
27 |
|
|
use work.config.all; -- configuration
|
28 |
|
|
|
29 |
|
|
entity testbench is
|
30 |
|
|
generic (
|
31 |
|
|
fabtech : integer := CFG_FABTECH;
|
32 |
|
|
memtech : integer := CFG_MEMTECH;
|
33 |
|
|
padtech : integer := CFG_PADTECH;
|
34 |
|
|
clktech : integer := CFG_CLKTECH;
|
35 |
|
|
disas : integer := CFG_DISAS; -- Enable disassembly to console
|
36 |
|
|
dbguart : integer := CFG_DUART; -- Print UART on console
|
37 |
|
|
pclow : integer := CFG_PCLOW;
|
38 |
|
|
clkperiod : integer := 16; -- system clock period
|
39 |
|
|
comboard : integer := 1 -- Comms. adapter board attached
|
40 |
|
|
);
|
41 |
|
|
port (
|
42 |
|
|
pci_rst : out std_logic;
|
43 |
|
|
pci_clk : in std_logic;
|
44 |
|
|
pci_gnt : in std_logic;
|
45 |
|
|
pci_idsel : in std_logic;
|
46 |
|
|
pci_lock : inout std_logic;
|
47 |
|
|
pci_ad : inout std_logic_vector(31 downto 0);
|
48 |
|
|
pci_cbe : inout std_logic_vector(3 downto 0);
|
49 |
|
|
pci_frame : inout std_logic;
|
50 |
|
|
pci_irdy : inout std_logic;
|
51 |
|
|
pci_trdy : inout std_logic;
|
52 |
|
|
pci_devsel : inout std_logic;
|
53 |
|
|
pci_stop : inout std_logic;
|
54 |
|
|
pci_perr : inout std_logic;
|
55 |
|
|
pci_par : inout std_logic;
|
56 |
|
|
pci_req : inout std_logic;
|
57 |
|
|
pci_serr : inout std_logic;
|
58 |
|
|
pci_host : in std_logic;
|
59 |
|
|
pci_66 : in std_logic
|
60 |
|
|
);
|
61 |
|
|
end;
|
62 |
|
|
|
63 |
|
|
architecture behav of testbench is
|
64 |
|
|
|
65 |
|
|
constant promfile : string := "prom.srec"; -- rom contents
|
66 |
|
|
constant sramfile : string := "sram.srec"; -- ram contents
|
67 |
|
|
constant sdramfile : string := "sdram.srec"; -- sdram contents
|
68 |
|
|
|
69 |
|
|
component leon3mp
|
70 |
|
|
generic (
|
71 |
|
|
fabtech : integer := CFG_FABTECH;
|
72 |
|
|
memtech : integer := CFG_MEMTECH;
|
73 |
|
|
padtech : integer := CFG_PADTECH;
|
74 |
|
|
clktech : integer := CFG_CLKTECH;
|
75 |
|
|
disas : integer := CFG_DISAS; -- Enable disassembly to console
|
76 |
|
|
dbguart : integer := CFG_DUART; -- Print UART on console
|
77 |
|
|
pclow : integer := CFG_PCLOW;
|
78 |
|
|
mezz : integer := CFG_ADS_DAU_MEZZ
|
79 |
|
|
);
|
80 |
|
|
port (
|
81 |
|
|
clk_66mhz : in std_logic;
|
82 |
|
|
clk_socket : in std_logic;
|
83 |
|
|
leds : out std_logic_vector(7 downto 0);
|
84 |
|
|
switches : in std_logic_vector(5 downto 0);
|
85 |
|
|
|
86 |
|
|
sram_a : out std_logic_vector(24 downto 0);
|
87 |
|
|
sram_ben_l : out std_logic_vector(0 to 3);
|
88 |
|
|
sram_cs_l : out std_logic_vector(1 downto 0);
|
89 |
|
|
sram_oe_l : out std_logic;
|
90 |
|
|
sram_we_l : out std_logic;
|
91 |
|
|
sram_dq : inout std_logic_vector(31 downto 0);
|
92 |
|
|
flash_cs_l : out std_logic;
|
93 |
|
|
flash_rst_l : out std_logic;
|
94 |
|
|
iosn : out std_logic;
|
95 |
|
|
sdclk : out std_logic;
|
96 |
|
|
rasn : out std_logic;
|
97 |
|
|
casn : out std_logic;
|
98 |
|
|
sdcke : out std_logic;
|
99 |
|
|
sdcsn : out std_logic;
|
100 |
|
|
|
101 |
|
|
tx : out std_logic;
|
102 |
|
|
rx : in std_logic;
|
103 |
|
|
|
104 |
|
|
can_txd : out std_logic;
|
105 |
|
|
can_rxd : in std_logic;
|
106 |
|
|
|
107 |
|
|
phy_txck : in std_logic;
|
108 |
|
|
phy_rxck : in std_logic;
|
109 |
|
|
phy_rxd : in std_logic_vector(3 downto 0);
|
110 |
|
|
phy_rxdv : in std_logic;
|
111 |
|
|
phy_rxer : in std_logic;
|
112 |
|
|
phy_col : in std_logic;
|
113 |
|
|
phy_crs : in std_logic;
|
114 |
|
|
phy_txd : out std_logic_vector(3 downto 0);
|
115 |
|
|
phy_txen : out std_logic;
|
116 |
|
|
phy_txer : out std_logic;
|
117 |
|
|
phy_mdc : out std_logic;
|
118 |
|
|
phy_mdio : inout std_logic; -- ethernet PHY interface
|
119 |
|
|
phy_reset_l : inout std_logic;
|
120 |
|
|
|
121 |
|
|
video_clk : in std_logic;
|
122 |
|
|
comp_sync : out std_logic;
|
123 |
|
|
blank : out std_logic;
|
124 |
|
|
video_out : out std_logic_vector(23 downto 0);
|
125 |
|
|
|
126 |
|
|
msclk : inout std_logic;
|
127 |
|
|
msdata : inout std_logic;
|
128 |
|
|
kbclk : inout std_logic;
|
129 |
|
|
kbdata : inout std_logic;
|
130 |
|
|
|
131 |
|
|
disp_seg1 : out std_logic_vector(7 downto 0);
|
132 |
|
|
disp_seg2 : out std_logic_vector(7 downto 0);
|
133 |
|
|
|
134 |
|
|
pci_clk : in std_logic;
|
135 |
|
|
pci_gnt : in std_logic;
|
136 |
|
|
pci_idsel : in std_logic;
|
137 |
|
|
pci_lock : inout std_logic;
|
138 |
|
|
pci_ad : inout std_logic_vector(31 downto 0);
|
139 |
|
|
pci_cbe : inout std_logic_vector(3 downto 0);
|
140 |
|
|
pci_frame : inout std_logic;
|
141 |
|
|
pci_irdy : inout std_logic;
|
142 |
|
|
pci_trdy : inout std_logic;
|
143 |
|
|
pci_devsel : inout std_logic;
|
144 |
|
|
pci_stop : inout std_logic;
|
145 |
|
|
pci_perr : inout std_logic;
|
146 |
|
|
pci_par : inout std_logic;
|
147 |
|
|
pci_req : inout std_logic;
|
148 |
|
|
pci_serr : inout std_logic;
|
149 |
|
|
pci_host : in std_logic;
|
150 |
|
|
pci_66 : in std_logic
|
151 |
|
|
);
|
152 |
|
|
end component;
|
153 |
|
|
|
154 |
|
|
signal clk : std_logic := '0';
|
155 |
|
|
constant ct : integer := clkperiod/2;
|
156 |
|
|
|
157 |
|
|
signal gnd : std_logic := '0';
|
158 |
|
|
signal vcc : std_logic := '1';
|
159 |
|
|
|
160 |
|
|
signal sdcke : std_logic;
|
161 |
|
|
signal sdcsn : std_logic;
|
162 |
|
|
signal sdwen : std_logic; -- write en
|
163 |
|
|
signal sdrasn : std_logic; -- row addr stb
|
164 |
|
|
signal sdcasn : std_logic; -- col addr stb
|
165 |
|
|
signal sddqm : std_logic_vector ( 7 downto 0); -- data i/o mask
|
166 |
|
|
signal sdclk : std_logic;
|
167 |
|
|
signal plllock : std_logic;
|
168 |
|
|
signal tx, rx : std_logic;
|
169 |
|
|
signal dsutx, dsurx : std_logic;
|
170 |
|
|
|
171 |
|
|
signal leds : std_logic_vector(7 downto 0);
|
172 |
|
|
signal switches : std_logic_vector(5 downto 0);
|
173 |
|
|
|
174 |
|
|
constant lresp : boolean := false;
|
175 |
|
|
|
176 |
|
|
signal sram_oe_l, sram_we_l : std_logic;
|
177 |
|
|
signal sram_cs_l : std_logic_vector(1 downto 0);
|
178 |
|
|
signal sram_ben_l : std_logic_vector(0 to 3);
|
179 |
|
|
signal sram_dq : std_logic_vector(31 downto 0);
|
180 |
|
|
signal flash_cs_l, flash_rst_l : std_logic;
|
181 |
|
|
signal iosn : std_logic;
|
182 |
|
|
|
183 |
|
|
signal phy_txck : std_logic;
|
184 |
|
|
signal phy_rxck : std_logic;
|
185 |
|
|
signal phy_rxd : std_logic_vector(3 downto 0);
|
186 |
|
|
signal phy_rxdt : std_logic_vector(7 downto 0);
|
187 |
|
|
signal phy_rxdv : std_logic;
|
188 |
|
|
signal phy_rxer : std_logic;
|
189 |
|
|
signal phy_col : std_logic;
|
190 |
|
|
signal phy_crs : std_logic;
|
191 |
|
|
signal phy_txd : std_logic_vector(3 downto 0);
|
192 |
|
|
signal phy_txdt : std_logic_vector(7 downto 0);
|
193 |
|
|
signal phy_txen : std_logic;
|
194 |
|
|
signal phy_txer : std_logic;
|
195 |
|
|
signal phy_mdc : std_logic;
|
196 |
|
|
signal phy_mdio : std_logic;
|
197 |
|
|
signal phy_reset_l : std_logic;
|
198 |
|
|
signal phy_gtx_clk : std_logic := '0';
|
199 |
|
|
|
200 |
|
|
signal video_clk : std_logic := '0';
|
201 |
|
|
signal comp_sync : std_logic;
|
202 |
|
|
signal blank : std_logic;
|
203 |
|
|
signal video_out : std_logic_vector(23 downto 0);
|
204 |
|
|
|
205 |
|
|
signal msclk : std_logic;
|
206 |
|
|
signal msdata : std_logic;
|
207 |
|
|
signal kbclk : std_logic;
|
208 |
|
|
signal kbdata : std_logic;
|
209 |
|
|
signal dsurst : std_logic;
|
210 |
|
|
|
211 |
|
|
signal disp_seg1 : std_logic_vector(7 downto 0);
|
212 |
|
|
signal disp_seg2 : std_logic_vector(7 downto 0);
|
213 |
|
|
|
214 |
|
|
signal baddr : std_logic_vector(27 downto 0) := (others => '0');
|
215 |
|
|
|
216 |
|
|
signal can_txd : std_logic;
|
217 |
|
|
signal can_rxd : std_logic;
|
218 |
|
|
|
219 |
|
|
begin
|
220 |
|
|
|
221 |
|
|
-- clock and reset
|
222 |
|
|
|
223 |
|
|
clk <= not clk after ct * 1 ns;
|
224 |
|
|
switches(0) <= '1'; -- DSUEN
|
225 |
|
|
switches(4) <= not dsurst; -- reset
|
226 |
|
|
switches(5) <= '0'; -- DSUBRE
|
227 |
|
|
dsutx <= tx; rx <= dsurx;
|
228 |
|
|
pci_rst <= phy_reset_l;
|
229 |
|
|
phy_reset_l <= 'H';
|
230 |
|
|
video_clk <= not video_clk after 20 ns;
|
231 |
|
|
|
232 |
|
|
can_rxd <= can_txd;
|
233 |
|
|
sddqm(3) <= sram_ben_l(0); sddqm(2) <= sram_ben_l(1);
|
234 |
|
|
sddqm(1) <= sram_ben_l(2); sddqm(0) <= sram_ben_l(3);
|
235 |
|
|
cpu : leon3mp
|
236 |
|
|
generic map (fabtech, memtech, padtech, clktech,
|
237 |
|
|
disas, dbguart, pclow )
|
238 |
|
|
port map (clk, sdclk, leds, switches, baddr(24 downto 0),
|
239 |
|
|
sram_ben_l, sram_cs_l, sram_oe_l, sram_we_l, sram_dq,
|
240 |
|
|
flash_cs_l, flash_rst_l, iosn, sdclk, sdrasn, sdcasn, sdcke, sdcsn,
|
241 |
|
|
tx, rx, can_txd, can_rxd, phy_txck, phy_rxck, phy_rxd, phy_rxdv,
|
242 |
|
|
phy_rxer, phy_col, phy_crs, phy_txd, phy_txen, phy_txer, phy_mdc,
|
243 |
|
|
phy_mdio, phy_reset_l,
|
244 |
|
|
video_clk, comp_sync, blank, video_out,
|
245 |
|
|
msclk, msdata, kbclk, kbdata, disp_seg1, disp_seg2,
|
246 |
|
|
pci_clk, pci_gnt, pci_idsel, pci_lock, pci_ad, pci_cbe,
|
247 |
|
|
pci_frame, pci_irdy, pci_trdy, pci_devsel, pci_stop, pci_perr, pci_par,
|
248 |
|
|
pci_req, pci_serr, pci_host, pci_66);
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
-- One 32-bit SRAM bank on main board
|
252 |
|
|
|
253 |
|
|
sram0 : for i in 0 to 1 generate
|
254 |
|
|
sr0 : sram16 generic map (index => i*2, abits => 18, fname => sramfile)
|
255 |
|
|
port map (baddr(17 downto 0), sram_dq(31-i*16 downto 16-i*16),
|
256 |
|
|
sram_ben_l(i*2), sram_ben_l(i*2+1), sram_cs_l(0), sram_we_l, sram_oe_l);
|
257 |
|
|
end generate;
|
258 |
|
|
|
259 |
|
|
phy_mdio <= 'H';
|
260 |
|
|
phy_rxd <= phy_rxdt(3 downto 0);
|
261 |
|
|
phy_txdt <= "0000" & phy_txd;
|
262 |
|
|
|
263 |
|
|
p0: phy
|
264 |
|
|
generic map(base1000_t_fd => 0, base1000_t_hd => 0)
|
265 |
|
|
port map(dsurst, phy_mdio, phy_txck, phy_rxck, phy_rxdt, phy_rxdv,
|
266 |
|
|
phy_rxer, phy_col, phy_crs, phy_txdt, phy_txen, phy_txer, phy_mdc, phy_gtx_clk);
|
267 |
|
|
|
268 |
|
|
-- optional communications adapter
|
269 |
|
|
|
270 |
|
|
comms : if (comboard = 1) generate
|
271 |
|
|
|
272 |
|
|
-- 32-bit flash prom
|
273 |
|
|
flash0 : for i in 0 to 1 generate
|
274 |
|
|
sr0 : sram16 generic map (index => i*2, abits => 18, fname => promfile)
|
275 |
|
|
port map (baddr(19 downto 2), sram_dq(31-i*16 downto 16-i*16),
|
276 |
|
|
flash_cs_l, flash_cs_l, flash_cs_l, sram_we_l, sram_oe_l);
|
277 |
|
|
end generate;
|
278 |
|
|
|
279 |
|
|
-- second SRAM bank
|
280 |
|
|
|
281 |
|
|
sram1 : for i in 0 to 1 generate
|
282 |
|
|
sr0 : sram16 generic map (index => i*2, abits => 18, fname => sramfile)
|
283 |
|
|
port map (baddr(19 downto 2), sram_dq(31-i*16 downto 16-i*16),
|
284 |
|
|
sram_ben_l(i*2), sram_ben_l(i*2+1), sram_cs_l(1), sram_we_l, sram_oe_l);
|
285 |
|
|
end generate;
|
286 |
|
|
|
287 |
|
|
sdwen <= sram_we_l;
|
288 |
|
|
|
289 |
|
|
u0: mt48lc16m16a2 generic map (index => 0, fname => sdramfile)
|
290 |
|
|
PORT MAP(
|
291 |
|
|
Dq => sram_dq(31 downto 16), Addr => baddr(14 downto 2),
|
292 |
|
|
Ba => baddr(16 downto 15), Clk => sdclk, Cke => sdcke,
|
293 |
|
|
Cs_n => sdcsn, Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
|
294 |
|
|
Dqm => sddqm(3 downto 2));
|
295 |
|
|
u1: mt48lc16m16a2 generic map (index => 16, fname => sdramfile)
|
296 |
|
|
PORT MAP(
|
297 |
|
|
Dq => sram_dq(15 downto 0), Addr => baddr(14 downto 2),
|
298 |
|
|
Ba => baddr(16 downto 15), Clk => sdclk, Cke => sdcke,
|
299 |
|
|
Cs_n => sdcsn, Ras_n => sdrasn, Cas_n => sdcasn, We_n => sdwen,
|
300 |
|
|
Dqm => sddqm(1 downto 0));
|
301 |
|
|
|
302 |
|
|
end generate;
|
303 |
|
|
|
304 |
|
|
test0 : grtestmod
|
305 |
|
|
port map ( dsurst, clk, leds(0), baddr(21 downto 2), sram_dq,
|
306 |
|
|
iosn, sram_oe_l, sram_we_l, open);
|
307 |
|
|
|
308 |
|
|
leds(0) <= 'H'; -- ERROR pull-up
|
309 |
|
|
|
310 |
|
|
iuerr : process
|
311 |
|
|
begin
|
312 |
|
|
wait for 2000 ns;
|
313 |
|
|
if to_x01(leds(0)) = '0' then wait on leds; end if;
|
314 |
|
|
assert (to_x01(leds(0)) = '0')
|
315 |
|
|
report "*** IU in error mode, simulation halted ***"
|
316 |
|
|
severity failure ;
|
317 |
|
|
end process;
|
318 |
|
|
|
319 |
|
|
sram_dq <= buskeep(sram_dq), (others => 'H') after 250 ns;
|
320 |
|
|
|
321 |
|
|
dsucom : process
|
322 |
|
|
procedure dsucfg(signal dsurx : in std_logic; signal dsutx : out std_logic) is
|
323 |
|
|
variable w32 : std_logic_vector(31 downto 0);
|
324 |
|
|
variable c8 : std_logic_vector(7 downto 0);
|
325 |
|
|
constant txp : time := 160 * 1 ns;
|
326 |
|
|
begin
|
327 |
|
|
dsutx <= '1';
|
328 |
|
|
dsurst <= '0';
|
329 |
|
|
wait for 500 ns;
|
330 |
|
|
dsurst <= '1';
|
331 |
|
|
wait;
|
332 |
|
|
wait for 5000 ns;
|
333 |
|
|
txc(dsutx, 16#55#, txp); -- sync uart
|
334 |
|
|
|
335 |
|
|
txc(dsutx, 16#c0#, txp);
|
336 |
|
|
txa(dsutx, 16#90#, 16#00#, 16#00#, 16#00#, txp);
|
337 |
|
|
txa(dsutx, 16#00#, 16#00#, 16#00#, 16#ef#, txp);
|
338 |
|
|
|
339 |
|
|
txc(dsutx, 16#c0#, txp);
|
340 |
|
|
txa(dsutx, 16#90#, 16#00#, 16#00#, 16#20#, txp);
|
341 |
|
|
txa(dsutx, 16#00#, 16#00#, 16#ff#, 16#ff#, txp);
|
342 |
|
|
|
343 |
|
|
txc(dsutx, 16#c0#, txp);
|
344 |
|
|
txa(dsutx, 16#90#, 16#40#, 16#00#, 16#48#, txp);
|
345 |
|
|
txa(dsutx, 16#00#, 16#00#, 16#00#, 16#12#, txp);
|
346 |
|
|
|
347 |
|
|
txc(dsutx, 16#c0#, txp);
|
348 |
|
|
txa(dsutx, 16#90#, 16#40#, 16#00#, 16#60#, txp);
|
349 |
|
|
txa(dsutx, 16#00#, 16#00#, 16#12#, 16#10#, txp);
|
350 |
|
|
|
351 |
|
|
txc(dsutx, 16#80#, txp);
|
352 |
|
|
txa(dsutx, 16#90#, 16#00#, 16#00#, 16#00#, txp);
|
353 |
|
|
rxi(dsurx, w32, txp, lresp);
|
354 |
|
|
|
355 |
|
|
txc(dsutx, 16#a0#, txp);
|
356 |
|
|
txa(dsutx, 16#40#, 16#00#, 16#00#, 16#00#, txp);
|
357 |
|
|
rxi(dsurx, w32, txp, lresp);
|
358 |
|
|
|
359 |
|
|
end;
|
360 |
|
|
|
361 |
|
|
begin
|
362 |
|
|
|
363 |
|
|
dsucfg(dsutx, dsurx);
|
364 |
|
|
|
365 |
|
|
wait;
|
366 |
|
|
end process;
|
367 |
|
|
end ;
|
368 |
|
|
|