1 |
2 |
dimamali |
-----------------------------------------------------------------------------
|
2 |
|
|
-- Ethernet/PCI bridge Demonstration design
|
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 |
|
|
-- You should have received a copy of the GNU General Public License
|
16 |
|
|
-- along with this program; if not, write to the Free Software
|
17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
------------------------------------------------------------------------------
|
19 |
|
|
|
20 |
|
|
library ieee;
|
21 |
|
|
use ieee.std_logic_1164.all;
|
22 |
|
|
library grlib;
|
23 |
|
|
use grlib.amba.all;
|
24 |
|
|
library techmap;
|
25 |
|
|
use techmap.gencomp.all;
|
26 |
|
|
use grlib.stdlib.all;
|
27 |
|
|
library gaisler;
|
28 |
|
|
use gaisler.uart.all;
|
29 |
|
|
use gaisler.misc.all;
|
30 |
|
|
use gaisler.pci.all;
|
31 |
|
|
use gaisler.net.all;
|
32 |
|
|
use gaisler.jtag.all;
|
33 |
|
|
use work.config.all;
|
34 |
|
|
|
35 |
|
|
entity netcard is
|
36 |
|
|
generic (
|
37 |
|
|
fabtech : integer := CFG_FABTECH;
|
38 |
|
|
memtech : integer := CFG_MEMTECH;
|
39 |
|
|
padtech : integer := CFG_PADTECH;
|
40 |
|
|
clktech : integer := CFG_CLKTECH
|
41 |
|
|
);
|
42 |
|
|
port (
|
43 |
|
|
resetn : in std_ulogic;
|
44 |
|
|
clk : in std_ulogic;
|
45 |
|
|
dsutx : out std_ulogic; -- DSU tx data
|
46 |
|
|
dsurx : in std_ulogic; -- DSU rx data
|
47 |
|
|
|
48 |
|
|
emdio : inout std_logic;
|
49 |
|
|
etx_clk : in std_logic;
|
50 |
|
|
erx_clk : in std_logic;
|
51 |
|
|
erxd : in std_logic_vector(3 downto 0);
|
52 |
|
|
erx_dv : in std_logic;
|
53 |
|
|
erx_er : in std_logic;
|
54 |
|
|
erx_col : in std_logic;
|
55 |
|
|
erx_crs : in std_logic;
|
56 |
|
|
etxd : out std_logic_vector(3 downto 0);
|
57 |
|
|
etx_en : out std_logic;
|
58 |
|
|
etx_er : out std_logic;
|
59 |
|
|
emdc : out std_logic;
|
60 |
|
|
|
61 |
|
|
pci_rst : in std_ulogic; -- PCI bus
|
62 |
|
|
pci_clk : in std_ulogic;
|
63 |
|
|
pci_gnt : in std_ulogic;
|
64 |
|
|
pci_idsel : in std_ulogic;
|
65 |
|
|
pci_lock : inout std_ulogic;
|
66 |
|
|
pci_ad : inout std_logic_vector(31 downto 0);
|
67 |
|
|
pci_cbe : inout std_logic_vector(3 downto 0);
|
68 |
|
|
pci_frame : inout std_ulogic;
|
69 |
|
|
pci_irdy : inout std_ulogic;
|
70 |
|
|
pci_trdy : inout std_ulogic;
|
71 |
|
|
pci_devsel : inout std_ulogic;
|
72 |
|
|
pci_stop : inout std_ulogic;
|
73 |
|
|
pci_perr : inout std_ulogic;
|
74 |
|
|
pci_par : inout std_ulogic;
|
75 |
|
|
pci_req : inout std_ulogic;
|
76 |
|
|
pci_serr : inout std_ulogic;
|
77 |
|
|
pci_irq : out std_ulogic;
|
78 |
|
|
pci_host : in std_ulogic;
|
79 |
|
|
pci_66 : in std_ulogic
|
80 |
|
|
);
|
81 |
|
|
end;
|
82 |
|
|
|
83 |
|
|
architecture rtl of netcard is
|
84 |
|
|
|
85 |
|
|
signal apbi : apb_slv_in_type;
|
86 |
|
|
signal apbo : apb_slv_out_vector := (others => apb_none);
|
87 |
|
|
signal ahbsi : ahb_slv_in_type;
|
88 |
|
|
signal ahbso : ahb_slv_out_vector := (others => ahbs_none);
|
89 |
|
|
signal ahbmi : ahb_mst_in_type;
|
90 |
|
|
signal ahbmo : ahb_mst_out_vector := (others => ahbm_none);
|
91 |
|
|
signal clkm, rstn, pciclk : std_ulogic;
|
92 |
|
|
signal cgi : clkgen_in_type;
|
93 |
|
|
signal cgo : clkgen_out_type;
|
94 |
|
|
|
95 |
|
|
signal dui : uart_in_type;
|
96 |
|
|
signal duo : uart_out_type;
|
97 |
|
|
|
98 |
|
|
signal pcii : pci_in_type;
|
99 |
|
|
signal pcio : pci_out_type;
|
100 |
|
|
|
101 |
|
|
signal ethi : eth_in_type;
|
102 |
|
|
signal etho : eth_out_type;
|
103 |
|
|
signal tck, tms, tdi, tdo : std_ulogic;
|
104 |
|
|
|
105 |
|
|
signal irqn, lclk, gnd : std_logic;
|
106 |
|
|
|
107 |
|
|
constant blength : integer := 12;
|
108 |
|
|
constant fifodepth : integer := 8;
|
109 |
|
|
|
110 |
|
|
constant maxahb : integer := CFG_AHB_UART+
|
111 |
|
|
CFG_GRETH+CFG_AHB_JTAG+log2x(CFG_PCI);
|
112 |
|
|
|
113 |
|
|
begin
|
114 |
|
|
|
115 |
|
|
----------------------------------------------------------------------
|
116 |
|
|
--- Reset and Clock generation -------------------------------------
|
117 |
|
|
----------------------------------------------------------------------
|
118 |
|
|
|
119 |
|
|
gnd <= '0';
|
120 |
|
|
cgi.pllctrl <= "00"; cgi.pllrst <= resetn; cgi.pllref <= '0';
|
121 |
|
|
|
122 |
|
|
clkgen0 : clkgen -- clock generator
|
123 |
|
|
generic map (clktech, CFG_CLKMUL, CFG_CLKDIV, 0,
|
124 |
|
|
0, CFG_PCI, CFG_PCIDLL, CFG_PCISYSCLK)
|
125 |
|
|
port map (lclk, pci_clk, clkm, open, open, open, pciclk, cgi, cgo);
|
126 |
|
|
clk_pad : clkpad generic map (tech => padtech) port map (clk, lclk);
|
127 |
|
|
|
128 |
|
|
rst0 : rstgen -- reset generator
|
129 |
|
|
port map (resetn, clkm, cgo.clklock, rstn);
|
130 |
|
|
|
131 |
|
|
----------------------------------------------------------------------
|
132 |
|
|
--- AHB CONTROLLER --------------------------------------------------
|
133 |
|
|
----------------------------------------------------------------------
|
134 |
|
|
|
135 |
|
|
ahb0 : ahbctrl -- AHB arbiter/multiplexer
|
136 |
|
|
generic map (nahbm => maxahb, nahbs => 4, ioen => 0)
|
137 |
|
|
port map (rstn, clkm, ahbmi, ahbmo, ahbsi, ahbso);
|
138 |
|
|
|
139 |
|
|
-----------------------------------------------------------------------
|
140 |
|
|
--- ETHERNET ---------------------------------------------------------
|
141 |
|
|
-----------------------------------------------------------------------
|
142 |
|
|
|
143 |
|
|
eth0 : if CFG_GRETH = 1 generate -- Gaisler ethernet MAC
|
144 |
|
|
e0 : greth generic map(hindex => log2x(CFG_PCI),
|
145 |
|
|
pindex => 0, paddr => 11, pirq => 11, memtech => memtech)
|
146 |
|
|
port map( rst => rstn, clk => clk, ahbmi => ahbmi, ahbmo => ahbmo(log2x(CFG_PCI)),
|
147 |
|
|
apbi => apbi, apbo => apbo(0), ethi => ethi, etho => etho);
|
148 |
|
|
|
149 |
|
|
emdio_pad : iopad generic map (tech => padtech)
|
150 |
|
|
port map (emdio, etho.mdio_o, etho.mdio_oe, ethi.mdio_i);
|
151 |
|
|
etxc_pad : clkpad generic map (tech => padtech, arch => 1)
|
152 |
|
|
port map (etx_clk, ethi.tx_clk);
|
153 |
|
|
erxc_pad : clkpad generic map (tech => padtech, arch => 1)
|
154 |
|
|
port map (erx_clk, ethi.rx_clk);
|
155 |
|
|
erxd_pad : inpadv generic map (tech => padtech, width => 4)
|
156 |
|
|
port map (erxd, ethi.rxd(3 downto 0));
|
157 |
|
|
erxdv_pad : inpad generic map (tech => padtech)
|
158 |
|
|
port map (erx_dv, ethi.rx_dv);
|
159 |
|
|
erxer_pad : inpad generic map (tech => padtech)
|
160 |
|
|
port map (erx_er, ethi.rx_er);
|
161 |
|
|
erxco_pad : inpad generic map (tech => padtech)
|
162 |
|
|
port map (erx_col, ethi.rx_col);
|
163 |
|
|
erxcr_pad : inpad generic map (tech => padtech)
|
164 |
|
|
port map (erx_crs, ethi.rx_crs);
|
165 |
|
|
|
166 |
|
|
etxd_pad : outpadv generic map (tech => padtech, width => 4)
|
167 |
|
|
port map (etxd, etho.txd(3 downto 0));
|
168 |
|
|
etxen_pad : outpad generic map (tech => padtech)
|
169 |
|
|
port map ( etx_en, etho.tx_en);
|
170 |
|
|
etxer_pad : outpad generic map (tech => padtech)
|
171 |
|
|
port map (etx_er, etho.tx_er);
|
172 |
|
|
emdc_pad : outpad generic map (tech => padtech)
|
173 |
|
|
port map (emdc, etho.mdc);
|
174 |
|
|
|
175 |
|
|
end generate;
|
176 |
|
|
|
177 |
|
|
irqn <= ahbso(3).hirq(11);
|
178 |
|
|
|
179 |
|
|
irq_pad : odpad generic map (tech => padtech, level => pci33)
|
180 |
|
|
port map (pci_irq, irqn);
|
181 |
|
|
|
182 |
|
|
----------------------------------------------------------------------
|
183 |
|
|
--- AHB/APB Bridge -------------------------------------------------
|
184 |
|
|
----------------------------------------------------------------------
|
185 |
|
|
|
186 |
|
|
apb0 : apbctrl -- AHB/APB bridge
|
187 |
|
|
generic map (hindex => 0, haddr => 16#800#)
|
188 |
|
|
port map (rstn, clkm, ahbsi, ahbso(0), apbi, apbo );
|
189 |
|
|
|
190 |
|
|
----------------------------------------------------------------------
|
191 |
|
|
--- AHB RAM --------------------------------------------------------
|
192 |
|
|
----------------------------------------------------------------------
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
ram0 : if CFG_AHBRAMEN = 1 generate
|
196 |
|
|
ahbram0 : ahbram generic map (hindex => 2, haddr => CFG_AHBRADDR,
|
197 |
|
|
tech => CFG_MEMTECH, kbytes => CFG_AHBRSZ)
|
198 |
|
|
port map ( rstn, clkm, ahbsi, ahbso(2));
|
199 |
|
|
end generate;
|
200 |
|
|
|
201 |
|
|
-----------------------------------------------------------------------
|
202 |
|
|
--- PCI ------------------------------------------------------------
|
203 |
|
|
-----------------------------------------------------------------------
|
204 |
|
|
|
205 |
|
|
pp : if CFG_PCI /= 0 generate
|
206 |
|
|
|
207 |
|
|
pci_gr0 : if CFG_PCI = 1 generate -- simple target-only
|
208 |
|
|
pci0 : pci_target generic map (hindex => 0,
|
209 |
|
|
device_id => 16#0210#, vendor_id => 16#16E3#)
|
210 |
|
|
port map (rstn, clkm, pciclk, pcii, pcio, ahbmi, ahbmo(0));
|
211 |
|
|
end generate;
|
212 |
|
|
|
213 |
|
|
pci_mtf0 : if CFG_PCI = 2 generate -- master/target with fifo
|
214 |
|
|
pci0 : pci_mtf generic map (memtech => memtech, hmstndx => 0,
|
215 |
|
|
fifodepth => 6, device_id => 16#0210#, vendor_id => 16#16E3#,
|
216 |
|
|
hslvndx => 1, pindex => 6, paddr => 2, haddr => 16#E00#,
|
217 |
|
|
ioaddr => 16#400#, nsync => 2)
|
218 |
|
|
port map (rstn, clkm, pciclk, pcii, pcio, apbi, apbo(6),
|
219 |
|
|
ahbmi, ahbmo(0), ahbsi, ahbso(1));
|
220 |
|
|
end generate;
|
221 |
|
|
|
222 |
|
|
pci_dma : if CFG_PCI = 3 generate -- master/target with fifo and DMA
|
223 |
|
|
dma : pcidma generic map (memtech => memtech, dmstndx => 1,
|
224 |
|
|
dapbndx => 5, dapbaddr => 5, blength => blength, mstndx => 0,
|
225 |
|
|
fifodepth => log2(fifodepth), device_id => CFG_PCIDID, vendor_id => CFG_PCIVID,
|
226 |
|
|
slvndx => 4, apbndx => 4, apbaddr => 4, haddr => 16#E00#, ioaddr => 16#800#,
|
227 |
|
|
nsync => 1)
|
228 |
|
|
port map (rstn, clkm, pciclk, pcii, pcio, apbo(5), ahbmo(1),
|
229 |
|
|
apbi, apbo(4), ahbmi, ahbmo(0), ahbsi, ahbso(4));
|
230 |
|
|
end generate;
|
231 |
|
|
|
232 |
|
|
pci_trc0 : if CFG_PCITBUFEN /= 0 generate -- PCI trace buffer
|
233 |
|
|
pt0 : pcitrace generic map (memtech => memtech, pindex => 3,
|
234 |
|
|
paddr => 16#100#, pmask => 16#f00#)
|
235 |
|
|
port map ( rstn, clkm, pciclk, pcii, apbi, apbo(3));
|
236 |
|
|
end generate;
|
237 |
|
|
pcipads0 : pcipads generic map (padtech)
|
238 |
|
|
port map ( pci_rst, pci_gnt, pci_idsel, pci_lock, pci_ad, pci_cbe,
|
239 |
|
|
pci_frame, pci_irdy, pci_trdy, pci_devsel, pci_stop, pci_perr,
|
240 |
|
|
pci_par, pci_req, pci_serr, pci_host, pci_66, pcii, pcio );
|
241 |
|
|
end generate;
|
242 |
|
|
|
243 |
|
|
----------------------------------------------------------------------
|
244 |
|
|
--- Optional DSU UARTs ----------------------------------------------
|
245 |
|
|
----------------------------------------------------------------------
|
246 |
|
|
|
247 |
|
|
dcomgen : if CFG_AHB_UART = 1 generate
|
248 |
|
|
dcom0: ahbuart -- Debug UART
|
249 |
|
|
generic map (hindex => log2x(CFG_PCI)+CFG_GRETH, pindex => 1, paddr => 1)
|
250 |
|
|
port map (rstn, clkm, dui, duo, apbi, apbo(1), ahbmi, ahbmo(log2x(CFG_PCI)+CFG_GRETH));
|
251 |
|
|
dsurx_pad : inpad generic map (tech => padtech) port map (dsurx, dui.rxd);
|
252 |
|
|
dsutx_pad : outpad generic map (tech => padtech) port map (dsutx, duo.txd);
|
253 |
|
|
end generate;
|
254 |
|
|
|
255 |
|
|
ahbjtaggen0 :if CFG_AHB_JTAG = 1 generate
|
256 |
|
|
ahbjtag0 : ahbjtag generic map(tech => fabtech,
|
257 |
|
|
hindex => log2x(CFG_PCI)+CFG_GRETH+CFG_AHB_UART)
|
258 |
|
|
port map(rstn, clkm, tck, tms, tdi, tdo, ahbmi,
|
259 |
|
|
ahbmo(log2x(CFG_PCI)+CFG_GRETH+CFG_AHB_UART), open, open, open,
|
260 |
|
|
open, open, open, open, gnd);
|
261 |
|
|
end generate;
|
262 |
|
|
|
263 |
|
|
-----------------------------------------------------------------------
|
264 |
|
|
--- Boot message ----------------------------------------------------
|
265 |
|
|
-----------------------------------------------------------------------
|
266 |
|
|
|
267 |
|
|
-- pragma translate_off
|
268 |
|
|
x : report_version
|
269 |
|
|
generic map (
|
270 |
|
|
msg1 => "Ethernet/PCI Network Card Demonstration design",
|
271 |
|
|
msg2 => "GRLIB Version " & tost(LIBVHDL_VERSION/1000) & "." & tost((LIBVHDL_VERSION mod 1000)/100)
|
272 |
|
|
& "." & tost(LIBVHDL_VERSION mod 100) & ", build " & tost(LIBVHDL_BUILD),
|
273 |
|
|
msg3 => "Target technology: " & tech_table(fabtech) & ", memory library: " & tech_table(memtech),
|
274 |
|
|
mdel => 1
|
275 |
|
|
);
|
276 |
|
|
|
277 |
|
|
-- pragma translate_on
|
278 |
|
|
end;
|