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()
30 self
.cd_sys
.clk
.attr
.add("keep")
31 self
.cd_sys4x
.clk
.attr
.add("keep")
33 self
.submodules
.pll
= pll
= S7MMCM(speedgrade
=-2)
34 self
.comb
+= pll
.reset
.eq(~platform
.request("cpu_reset_n"))
35 pll
.register_clkin(platform
.request("clk200"), 200e6
)
36 pll
.create_clkout(self
.cd_sys
, sys_clk_freq
)
37 pll
.create_clkout(self
.cd_sys4x
, 4*sys_clk_freq
)
38 pll
.create_clkout(self
.cd_clk200
, 200e6
)
40 self
.submodules
.idelayctrl
= S7IDELAYCTRL(self
.cd_clk200
)
42 # BaseSoC ------------------------------------------------------------------------------------------
44 class BaseSoC(SoCSDRAM
):
48 csr_map
.update(SoCSDRAM
.csr_map
)
49 def __init__(self
, sys_clk_freq
=int(125e6
), **kwargs
):
50 platform
= genesys2
.Platform()
51 SoCSDRAM
.__init
__(self
, platform
, clk_freq
=sys_clk_freq
,
52 integrated_rom_size
=0x8000,
53 integrated_sram_size
=0x8000,
56 self
.submodules
.crg
= _CRG(platform
, sys_clk_freq
)
59 self
.submodules
.ddrphy
= s7ddrphy
.K7DDRPHY(platform
.request("ddram"), sys_clk_freq
=sys_clk_freq
)
60 sdram_module
= MT41J256M16(self
.clk_freq
, "1:4")
61 self
.register_sdram(self
.ddrphy
,
62 sdram_module
.geom_settings
,
63 sdram_module
.timing_settings
)
65 # EthernetSoC ------------------------------------------------------------------------------------------
67 class EthernetSoC(BaseSoC
):
72 csr_map
.update(BaseSoC
.csr_map
)
77 interrupt_map
.update(BaseSoC
.interrupt_map
)
80 "ethmac": 0x30000000, # (shadow @0xb0000000)
82 mem_map
.update(BaseSoC
.mem_map
)
84 def __init__(self
, **kwargs
):
85 BaseSoC
.__init
__(self
, **kwargs
)
87 self
.submodules
.ethphy
= LiteEthPHYRGMII(self
.platform
.request("eth_clocks"),
88 self
.platform
.request("eth"))
89 self
.submodules
.ethmac
= LiteEthMAC(phy
=self
.ethphy
, dw
=32,
90 interface
="wishbone", endianness
=self
.cpu
.endianness
)
91 self
.add_wb_slave(mem_decoder(self
.mem_map
["ethmac"]), self
.ethmac
.bus
)
92 self
.add_memory_region("ethmac", self
.mem_map
["ethmac"] | self
.shadow_base
, 0x2000)
94 self
.ethphy
.crg
.cd_eth_rx
.clk
.attr
.add("keep")
95 self
.ethphy
.crg
.cd_eth_tx
.clk
.attr
.add("keep")
96 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_rx
.clk
, 1e9
/125e6
)
97 self
.platform
.add_period_constraint(self
.ethphy
.crg
.cd_eth_tx
.clk
, 1e9
/125e6
)
98 self
.platform
.add_false_path_constraints(
100 self
.ethphy
.crg
.cd_eth_rx
.clk
,
101 self
.ethphy
.crg
.cd_eth_tx
.clk
)
103 # Build --------------------------------------------------------------------------------------------
106 parser
= argparse
.ArgumentParser(description
="LiteX SoC on Genesys2")
108 soc_sdram_args(parser
)
109 parser
.add_argument("--with-ethernet", action
="store_true",
110 help="enable Ethernet support")
111 args
= parser
.parse_args()
113 cls
= EthernetSoC
if args
.with_ethernet
else BaseSoC
114 soc
= cls(**soc_sdram_argdict(args
))
115 builder
= Builder(soc
, **builder_argdict(args
))
119 if __name__
== "__main__":