3 # This file is Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
10 from litex
.boards
.platforms
import nexys_video
12 from litex
.soc
.cores
.clock
import *
13 from litex
.soc
.integration
.soc_core
import mem_decoder
14 from litex
.soc
.integration
.soc_sdram
import *
15 from litex
.soc
.integration
.builder
import *
17 from litedram
.modules
import MT41K256M16
18 from litedram
.phy
import s7ddrphy
20 from liteeth
.phy
.s7rgmii
import LiteEthPHYRGMII
21 from liteeth
.core
.mac
import LiteEthMAC
23 # CRG ----------------------------------------------------------------------------------------------
26 def __init__(self
, platform
, sys_clk_freq
):
27 self
.clock_domains
.cd_sys
= ClockDomain()
28 self
.clock_domains
.cd_sys4x
= ClockDomain(reset_less
=True)
29 self
.clock_domains
.cd_sys4x_dqs
= ClockDomain(reset_less
=True)
30 self
.clock_domains
.cd_clk200
= ClockDomain()
31 self
.clock_domains
.cd_clk100
= ClockDomain()
35 self
.cd_sys
.clk
.attr
.add("keep")
36 self
.cd_sys4x
.clk
.attr
.add("keep")
37 self
.cd_sys4x_dqs
.clk
.attr
.add("keep")
39 self
.submodules
.pll
= pll
= S7MMCM(speedgrade
=-1)
40 self
.comb
+= pll
.reset
.eq(~platform
.request("cpu_reset"))
41 pll
.register_clkin(platform
.request("clk100"), 100e6
)
42 pll
.create_clkout(self
.cd_sys
, sys_clk_freq
)
43 pll
.create_clkout(self
.cd_sys4x
, 4*sys_clk_freq
)
44 pll
.create_clkout(self
.cd_sys4x_dqs
, 4*sys_clk_freq
, phase
=90)
45 pll
.create_clkout(self
.cd_clk200
, 200e6
)
47 self
.submodules
.idelayctrl
= S7IDELAYCTRL(self
.cd_clk200
)
49 # BaseSoC ------------------------------------------------------------------------------------------
51 class BaseSoC(SoCSDRAM
):
52 def __init__(self
, sys_clk_freq
=int(100e6
), **kwargs
):
53 platform
= nexys_video
.Platform()
54 SoCSDRAM
.__init
__(self
, platform
, clk_freq
=sys_clk_freq
,
55 integrated_rom_size
=0x8000,
56 integrated_sram_size
=0x8000,
59 self
.submodules
.crg
= _CRG(platform
, sys_clk_freq
)
62 self
.submodules
.ddrphy
= s7ddrphy
.A7DDRPHY(platform
.request("ddram"), sys_clk_freq
=sys_clk_freq
)
63 self
.add_csr("ddrphy")
64 sdram_module
= MT41K256M16(sys_clk_freq
, "1:4")
65 self
.register_sdram(self
.ddrphy
,
66 sdram_module
.geom_settings
,
67 sdram_module
.timing_settings
)
69 # EthernetSoC --------------------------------------------------------------------------------------
71 class EthernetSoC(BaseSoC
):
73 "ethmac": 0x30000000, # (shadow @0xb0000000)
75 mem_map
.update(BaseSoC
.mem_map
)
77 def __init__(self
, **kwargs
):
78 BaseSoC
.__init
__(self
, **kwargs
)
80 self
.submodules
.ethphy
= LiteEthPHYRGMII(self
.platform
.request("eth_clocks"),
81 self
.platform
.request("eth"))
82 self
.add_csr("ethphy")
83 self
.submodules
.ethmac
= LiteEthMAC(phy
=self
.ethphy
, dw
=32,
84 interface
="wishbone", endianness
=self
.cpu
.endianness
)
85 self
.add_wb_slave(mem_decoder(self
.mem_map
["ethmac"]), self
.ethmac
.bus
)
86 self
.add_memory_region("ethmac", self
.mem_map
["ethmac"] | self
.shadow_base
, 0x2000)
87 self
.add_csr("ethmac")
88 self
.add_interrupt("ethmac")
90 self
.ethphy
.crg
.cd_eth_rx
.clk
.attr
.add("keep")
91 self
.ethphy
.crg
.cd_eth_tx
.clk
.attr
.add("keep")
92 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_rx
.clk
, 1e9
/125e6
)
93 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_tx
.clk
, 1e9
/125e6
)
94 self
.platform
.add_false_path_constraints(
96 self
.ethphy
.crg
.cd_eth_rx
.clk
,
97 self
.ethphy
.crg
.cd_eth_tx
.clk
)
99 # Build --------------------------------------------------------------------------------------------
102 parser
= argparse
.ArgumentParser(description
="LiteX SoC on Nexys Video")
104 soc_sdram_args(parser
)
105 parser
.add_argument("--with-ethernet", action
="store_true",
106 help="enable Ethernet support")
107 args
= parser
.parse_args()
109 cls
= EthernetSoC
if args
.with_ethernet
else BaseSoC
110 soc
= cls(**soc_sdram_argdict(args
))
111 builder
= Builder(soc
, **builder_argdict(args
))
115 if __name__
== "__main__":