diff --git a/liteeth/gen.py b/liteeth/gen.py old mode 100644 new mode 100755 index ab9d296..60b71d8 --- a/liteeth/gen.py +++ b/liteeth/gen.py @@ -26,6 +26,7 @@ from migen import * from litex.build.generic_platform import * from litex.build.xilinx.platform import XilinxPlatform +from litex.build.lattice.platform import LatticePlatform from litex.soc.interconnect import wishbone from litex.soc.integration.soc_core import * @@ -36,7 +37,9 @@ from liteeth.common import * from liteeth.phy.mii import LiteEthPHYMII from liteeth.phy.rmii import LiteEthPHYRMII from liteeth.phy.gmii import LiteEthPHYGMII -from liteeth.phy.s7rgmii import LiteEthPHYRGMII + +from liteeth.phy.s7rgmii import LiteEthPHYRGMII as s7phyrgmii +from liteeth.phy.ecp5rgmii import LiteEthPHYRGMII as ecp5phyrgmii from liteeth.mac import LiteEthMAC from liteeth.core import LiteEthUDPIPCore @@ -165,16 +168,20 @@ _io = [ # Platform ----------------------------------------------------------------------------------------- -class CorePlatform(XilinxPlatform): +class LatticeCorePlatform(LatticePlatform): name = "core" - def __init__(self): - XilinxPlatform.__init__(self, "xc7", _io) + def __init__(self, chip): + LatticePlatform.__init__(self, chip, _io) + +class XilinxCorePlatform(XilinxPlatform): + name = "core" + def __init__(self, chip): + XilinxPlatform.__init__(self, chip, _io) # PHY Core ----------------------------------------------------------------------------------------- class PHYCore(SoCMini): - def __init__(self, phy, clk_freq): - platform = CorePlatform() + def __init__(self, phy, clk_freq, platform): SoCMini.__init__(self, platform, clk_freq=clk_freq) self.submodules.crg = CRG(platform.request("sys_clock"), platform.request("sys_reset")) @@ -189,8 +196,12 @@ class PHYCore(SoCMini): ethphy = LiteEthPHYGMII(platform.request("gmii_eth_clocks"), platform.request("gmii_eth")) elif phy == "rgmii": - ethphy = LiteEthPHYRGMII(platform.request("rgmii_eth_clocks"), - platform.request("rgmii_eth")) + if type(platform) == LatticeCorePlatform: + ethphy = ecp5phyrgmii(platform.request("rgmii_eth_clocks"), + platform.request("rgmii_eth")) + elif type(platform) == XilinxCorePlatform: + ethphy = s7phyrgmii(platform.request("rgmii_eth_clocks"), + platform.request("rgmii_eth")) else: raise ValueError("Unsupported " + phy + " PHY"); self.submodules.ethphy = ethphy @@ -209,8 +220,8 @@ class MACCore(PHYCore): "ethmac": 0x50000000 }) - def __init__(self, phy, clk_freq, endianness): - PHYCore.__init__(self, phy, clk_freq) + def __init__(self, phy, clk_freq, platform, endianness): + PHYCore.__init__(self, phy, clk_freq, platform) self.submodules.ethmac = LiteEthMAC(phy=self.ethphy, dw=32, interface="wishbone", endianness=endianness) self.add_wb_slave(self.mem_map["ethmac"], self.ethmac.bus) @@ -231,8 +242,8 @@ class MACCore(PHYCore): # UDP Core ----------------------------------------------------------------------------------------- class UDPCore(PHYCore): - def __init__(self, phy, clk_freq, mac_address, ip_address, port): - PHYCore.__init__(self, phy, clk_freq) + def __init__(self, phy, clk_freq, mac_address, ip_address, port, platform): + PHYCore.__init__(self, phy, clk_freq, platform) self.submodules.core = LiteEthUDPIPCore(self.ethphy, mac_address, convert_ip(ip_address), clk_freq) udp_port = self.core.udp.crossbar.get_port(port, 8) @@ -284,17 +295,27 @@ def main(): parser.add_argument("--endianness", default="big", choices=("big", "little"), help="Wishbone endianness") parser.add_argument("--mac_address", default=0x10e2d5000000, help="MAC address") parser.add_argument("--ip_address", default="192.168.1.50", help="IP address") + parser.add_argument("--platform", default="xilinx", help="Development board(lattice/xilinx)") + parser.add_argument("--chip", default="xc7", help="FPGA chip model e.g. xc7 or LFE5UM5G-45F-8BG381C") args = parser.parse_args() + if args.platform == "lattice": + platform = LatticeCorePlatform(args.chip) + elif args.platform == "xilinx": + platform = XilinxCorePlatform(args.chip) + else: + raise ValueError("Unknown platform: {}".format(args.platform)) + if args.core == "wishbone": - soc = MACCore(phy=args.phy, clk_freq=int(100e6), endianness=args.endianness) + soc = MACCore(phy=args.phy, clk_freq=int(100e6), platform=platform, endianness=args.endianness) elif args.core == "udp": soc = UDPCore(phy=args.phy, clk_freq=int(100e6), mac_address = args.mac_address, ip_address = args.ip_address, - port = 6000) + port = 6000, + platform = platform) else: - raise ValueError + raise ValueError("Unknown core: {}".format(args.core)) builder = Builder(soc, output_dir=args.output_dir, compile_gateware=False, csr_csv=os.path.join(args.output_dir, "csr.csv")) builder.build(build_name="liteeth_core")