7 from litex
.boards
.platforms
import genesys2
9 from litex
.soc
.cores
.clock
import *
10 from litex
.soc
.integration
.soc_core
import mem_decoder
11 from litex
.soc
.integration
.soc_sdram
import *
12 from litex
.soc
.integration
.builder
import *
14 from litedram
.modules
import MT41J256M16
15 from litedram
.phy
import s7ddrphy
17 from liteeth
.phy
.s7rgmii
import LiteEthPHYRGMII
18 from liteeth
.core
.mac
import LiteEthMAC
20 # CRG ----------------------------------------------------------------------------------------------
23 def __init__(self
, platform
, sys_clk_freq
):
24 self
.clock_domains
.cd_sys
= ClockDomain()
25 self
.clock_domains
.cd_sys4x
= ClockDomain(reset_less
=True)
26 self
.clock_domains
.cd_clk200
= ClockDomain()
28 self
.submodules
.pll
= pll
= S7MMCM(speedgrade
=-2)
29 self
.comb
+= pll
.reset
.eq(~platform
.request("cpu_reset_n"))
30 pll
.register_clkin(platform
.request("clk200"), 200e6
)
31 pll
.create_clkout(self
.cd_sys
, sys_clk_freq
)
32 pll
.create_clkout(self
.cd_sys4x
, 4*sys_clk_freq
)
33 pll
.create_clkout(self
.cd_clk200
, 200e6
)
35 self
.submodules
.idelayctrl
= S7IDELAYCTRL(self
.cd_clk200
)
37 # BaseSoC ------------------------------------------------------------------------------------------
39 class BaseSoC(SoCSDRAM
):
43 csr_map
.update(SoCSDRAM
.csr_map
)
44 def __init__(self
, **kwargs
):
45 platform
= genesys2
.Platform()
46 sys_clk_freq
= int(125e6
)
47 SoCSDRAM
.__init
__(self
, platform
, clk_freq
=sys_clk_freq
,
48 integrated_rom_size
=0x8000,
49 integrated_sram_size
=0x8000,
52 self
.submodules
.crg
= _CRG(platform
, sys_clk_freq
)
55 self
.submodules
.ddrphy
= s7ddrphy
.K7DDRPHY(platform
.request("ddram"), sys_clk_freq
=sys_clk_freq
)
56 sdram_module
= MT41J256M16(self
.clk_freq
, "1:4")
57 self
.register_sdram(self
.ddrphy
,
58 sdram_module
.geom_settings
,
59 sdram_module
.timing_settings
)
61 # EthernetSoC ------------------------------------------------------------------------------------------
63 class EthernetSoC(BaseSoC
):
68 csr_map
.update(BaseSoC
.csr_map
)
73 interrupt_map
.update(BaseSoC
.interrupt_map
)
76 "ethmac": 0x30000000, # (shadow @0xb0000000)
78 mem_map
.update(BaseSoC
.mem_map
)
80 def __init__(self
, **kwargs
):
81 BaseSoC
.__init
__(self
, **kwargs
)
83 self
.submodules
.ethphy
= LiteEthPHYRGMII(self
.platform
.request("eth_clocks"),
84 self
.platform
.request("eth"))
85 self
.submodules
.ethmac
= LiteEthMAC(phy
=self
.ethphy
, dw
=32,
86 interface
="wishbone", endianness
=self
.cpu
.endianness
)
87 self
.add_wb_slave(mem_decoder(self
.mem_map
["ethmac"]), self
.ethmac
.bus
)
88 self
.add_memory_region("ethmac", self
.mem_map
["ethmac"] | self
.shadow_base
, 0x2000)
90 self
.crg
.cd_sys
.clk
.attr
.add("keep")
91 self
.ethphy
.crg
.cd_eth_rx
.clk
.attr
.add("keep")
92 self
.ethphy
.crg
.cd_eth_tx
.clk
.attr
.add("keep")
93 self
.platform
.add_period_constraint(self
.crg
.cd_sys
.clk
, 8.0)
94 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_rx
.clk
, 8.0)
95 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_tx
.clk
, 8.0)
96 self
.platform
.add_false_path_constraints(
98 self
.ethphy
.crg
.cd_eth_rx
.clk
,
99 self
.ethphy
.crg
.cd_eth_tx
.clk
)
101 # Build --------------------------------------------------------------------------------------------
104 parser
= argparse
.ArgumentParser(description
="LiteX SoC on Genesys2")
106 soc_sdram_args(parser
)
107 parser
.add_argument("--with-ethernet", action
="store_true",
108 help="enable Ethernet support")
109 args
= parser
.parse_args()
111 cls
= EthernetSoC
if args
.with_ethernet
else BaseSoC
112 soc
= cls(**soc_sdram_argdict(args
))
113 builder
= Builder(soc
, **builder_argdict(args
))
117 if __name__
== "__main__":