5 from litex
.gen
import *
6 from litex
.gen
.genlib
.resetsync
import AsyncResetSynchronizer
8 from litex
.boards
.platforms
import arty
10 from litex
.soc
.integration
.soc_core
import *
11 from litex
.soc
.integration
.builder
import *
13 from liteeth
.phy
.mii
import LiteEthPHYMII
14 from liteeth
.core
.mac
import LiteEthMAC
17 def __init__(self
, platform
):
18 self
.clock_domains
.cd_sys
= ClockDomain()
19 self
.clock_domains
.cd_eth
= ClockDomain(reset_less
=True)
21 clk100
= platform
.request("clk100")
22 rst
= platform
.request("cpu_reset")
29 Instance("PLLE2_BASE",
30 p_STARTUP_WAIT
="FALSE", o_LOCKED
=pll_locked
,
33 p_REF_JITTER1
=0.01, p_CLKIN1_PERIOD
=10.0,
34 p_CLKFBOUT_MULT
=8, p_DIVCLK_DIVIDE
=1,
35 i_CLKIN1
=clk100
, i_CLKFBIN
=pll_fb
, o_CLKFBOUT
=pll_fb
,
38 p_CLKOUT0_DIVIDE
=8, p_CLKOUT0_PHASE
=0.0,
42 p_CLKOUT1_DIVIDE
=32, p_CLKOUT1_PHASE
=0.0,
46 p_CLKOUT2_DIVIDE
=4, p_CLKOUT2_PHASE
=0.0,
50 p_CLKOUT3_DIVIDE
=4, p_CLKOUT3_PHASE
=0.0,
54 p_CLKOUT4_DIVIDE
=4, p_CLKOUT4_PHASE
=0.0,
57 Instance("BUFG", i_I
=pll_sys
, o_O
=self
.cd_sys
.clk
),
58 Instance("BUFG", i_I
=pll_eth
, o_O
=self
.cd_eth
.clk
),
59 AsyncResetSynchronizer(self
.cd_sys
, ~pll_locked | ~rst
),
64 Instance("ODDR2", p_DDR_ALIGNMENT
="NONE",
65 p_INIT
=0, p_SRTYPE
="SYNC",
66 i_D0
=0, i_D1
=1, i_S
=0, i_R
=0, i_CE
=1,
67 i_C0
=self
.cd_eth
.clk
, i_C1
=~self
.cd_eth
.clk
,
68 o_Q
=platform
.request("eth_ref_clk"))
72 class BaseSoC(SoCCore
):
73 def __init__(self
, **kwargs
):
74 platform
= arty
.Platform()
75 SoCCore
.__init
__(self
, platform
, clk_freq
=100*1000000,
76 integrated_rom_size
=0x8000,
77 integrated_sram_size
=0x8000,
78 integrated_main_ram_size
=0x10000,
81 self
.submodules
.crg
= _CRG(platform
)
84 class MiniSoC(BaseSoC
):
89 csr_map
.update(BaseSoC
.csr_map
)
94 interrupt_map
.update(BaseSoC
.interrupt_map
)
97 "ethmac": 0x30000000, # (shadow @0xb0000000)
99 mem_map
.update(BaseSoC
.mem_map
)
101 def __init__(self
, **kwargs
):
102 BaseSoC
.__init
__(self
, **kwargs
)
104 self
.submodules
.ethphy
= LiteEthPHYMII(self
.platform
.request("eth_clocks"),
105 self
.platform
.request("eth"))
106 self
.submodules
.ethmac
= LiteEthMAC(phy
=self
.ethphy
, dw
=32, interface
="wishbone")
107 self
.add_wb_slave(mem_decoder(self
.mem_map
["ethmac"]), self
.ethmac
.bus
)
108 self
.add_memory_region("ethmac", self
.mem_map
["ethmac"] | self
.shadow_base
, 0x2000)
112 parser
= argparse
.ArgumentParser(description
="LiteX SoC port to Arty")
114 soc_core_args(parser
)
115 parser
.add_argument("--with-ethernet", action
="store_true",
116 help="enable Ethernet support")
117 args
= parser
.parse_args()
119 cls
= MiniSoC
if args
.with_ethernet
else BaseSoC
120 soc
= cls(**soc_core_argdict(args
))
121 builder
= Builder(soc
, **builder_argdict(args
))
125 if __name__
== "__main__":