3d52befd9e5f996f3fca02d653b163513edc3612
5 from litex
.gen
import *
6 from litex
.gen
.genlib
.resetsync
import AsyncResetSynchronizer
8 from litex
.boards
.platforms
import nexys_video
10 from litex
.soc
.integration
.soc_core
import *
11 from litex
.soc
.integration
.builder
import *
13 from liteeth
.phy
.s7rgmii
import LiteEthPHYRGMII
14 from liteeth
.core
.mac
import LiteEthMAC
18 def __init__(self
, platform
):
19 self
.clock_domains
.cd_sys
= ClockDomain()
20 self
.clock_domains
.cd_clk200
= ClockDomain()
22 clk100
= platform
.request("clk100")
23 rst
= platform
.request("cpu_reset")
30 Instance("PLLE2_BASE",
31 p_STARTUP_WAIT
="FALSE", o_LOCKED
=pll_locked
,
34 p_REF_JITTER1
=0.01, p_CLKIN1_PERIOD
=10.0,
35 p_CLKFBOUT_MULT
=8, p_DIVCLK_DIVIDE
=1,
36 i_CLKIN1
=clk100
, i_CLKFBIN
=pll_fb
, o_CLKFBOUT
=pll_fb
,
39 p_CLKOUT0_DIVIDE
=8, p_CLKOUT0_PHASE
=0.0,
43 p_CLKOUT3_DIVIDE
=4, p_CLKOUT3_PHASE
=0.0,
46 Instance("BUFG", i_I
=pll_sys
, o_O
=self
.cd_sys
.clk
),
47 Instance("BUFG", i_I
=pll_clk200
, o_O
=self
.cd_clk200
.clk
),
48 AsyncResetSynchronizer(self
.cd_sys
, ~pll_locked | ~rst
),
49 AsyncResetSynchronizer(self
.cd_clk200
, ~pll_locked | rst
),
52 reset_counter
= Signal(4, reset
=15)
53 ic_reset
= Signal(reset
=1)
55 If(reset_counter
!= 0,
56 reset_counter
.eq(reset_counter
- 1)
60 self
.specials
+= Instance("IDELAYCTRL", i_REFCLK
=ClockSignal("clk200"), i_RST
=ic_reset
)
63 class BaseSoC(SoCCore
):
64 def __init__(self
, **kwargs
):
65 platform
= nexys_video
.Platform()
66 SoCCore
.__init
__(self
, platform
, clk_freq
=100*1000000,
67 integrated_rom_size
=0x8000,
68 integrated_sram_size
=0x8000,
69 integrated_main_ram_size
=0x10000,
72 self
.submodules
.crg
= _CRG(platform
)
75 class MiniSoC(BaseSoC
):
80 csr_map
.update(BaseSoC
.csr_map
)
85 interrupt_map
.update(BaseSoC
.interrupt_map
)
88 "ethmac": 0x30000000, # (shadow @0xb0000000)
90 mem_map
.update(BaseSoC
.mem_map
)
92 def __init__(self
, **kwargs
):
93 BaseSoC
.__init
__(self
, **kwargs
)
95 self
.submodules
.ethphy
= LiteEthPHYRGMII(self
.platform
.request("eth_clocks"),
96 self
.platform
.request("eth"))
97 self
.submodules
.ethmac
= LiteEthMAC(phy
=self
.ethphy
, dw
=32, interface
="wishbone")
98 self
.add_wb_slave(mem_decoder(self
.mem_map
["ethmac"]), self
.ethmac
.bus
)
99 self
.add_memory_region("ethmac", self
.mem_map
["ethmac"] | self
.shadow_base
, 0x2000)
102 parser
= argparse
.ArgumentParser(description
="LiteX SoC port to Nexys Video")
104 soc_core_args(parser
)
105 parser
.add_argument("--with-ethernet", action
="store_true",
106 help="enable Ethernet support")
107 parser
.add_argument("--build", action
="store_true",
108 help="build bitstream")
109 parser
.add_argument("--load", action
="store_true",
110 help="load bitstream")
111 args
= parser
.parse_args()
113 cls
= MiniSoC
if args
.with_ethernet
else BaseSoC
114 soc
= cls(**soc_core_argdict(args
))
115 builder
= Builder(soc
, **builder_argdict(args
))
121 prog
= soc
.platform
.create_programmer()
122 prog
.load_bitstream(os
.path
.join(builder
.output_dir
, "gateware", "top.bit"))
125 if __name__
== "__main__":