2015-11-13 08:48:42 -05:00
|
|
|
from litex.gen.genlib.io import CRG
|
|
|
|
from litex.gen.fhdl.specials import Keep
|
2015-09-07 07:28:02 -04:00
|
|
|
|
2015-11-11 19:45:37 -05:00
|
|
|
from litex.build.xilinx.vivado import XilinxVivadoToolchain
|
|
|
|
from litex.soc.interconnect import wishbone
|
|
|
|
|
|
|
|
from litex.soc.integration.soc_core import SoCCore
|
|
|
|
from litex.soc.cores.uart.bridge import UARTWishboneBridge
|
2015-09-07 07:28:02 -04:00
|
|
|
|
2015-09-08 03:50:45 -04:00
|
|
|
from liteeth.common import *
|
|
|
|
from liteeth.phy import LiteEthPHY
|
|
|
|
from liteeth.core import LiteEthUDPIPCore
|
2015-09-07 07:28:02 -04:00
|
|
|
|
|
|
|
|
2015-11-11 19:45:37 -05:00
|
|
|
class BaseSoC(SoCCore):
|
2015-09-07 07:28:02 -04:00
|
|
|
csr_map = {
|
|
|
|
"phy": 11,
|
|
|
|
"core": 12
|
|
|
|
}
|
2015-11-11 19:45:37 -05:00
|
|
|
csr_map.update(SoCCore.csr_map)
|
2015-09-07 07:28:02 -04:00
|
|
|
def __init__(self, platform, clk_freq=166*1000000,
|
|
|
|
mac_address=0x10e2d5000000,
|
2016-03-15 10:40:06 -04:00
|
|
|
ip_address="192.168.1.50"):
|
2015-09-07 07:28:02 -04:00
|
|
|
clk_freq = int((1/(platform.default_clk_period))*1000000000)
|
2015-11-11 19:45:37 -05:00
|
|
|
SoCCore.__init__(self, platform, clk_freq,
|
|
|
|
cpu_type=None,
|
|
|
|
csr_data_width=32,
|
2015-09-07 07:28:02 -04:00
|
|
|
with_uart=False,
|
2015-11-11 19:45:37 -05:00
|
|
|
ident="LiteEth Base Design",
|
2015-09-07 07:28:02 -04:00
|
|
|
with_timer=False
|
|
|
|
)
|
|
|
|
self.add_cpu_or_bridge(UARTWishboneBridge(platform.request("serial"), clk_freq, baudrate=115200))
|
|
|
|
self.add_wb_master(self.cpu_or_bridge.wishbone)
|
|
|
|
self.submodules.crg = CRG(platform.request(platform.default_clk_name))
|
|
|
|
|
|
|
|
# wishbone SRAM (to test Wishbone over UART and Etherbone)
|
|
|
|
self.submodules.sram = wishbone.SRAM(1024)
|
|
|
|
self.add_wb_slave(lambda a: a[23:25] == 1, self.sram.bus)
|
|
|
|
|
|
|
|
# ethernet PHY and UDP/IP stack
|
|
|
|
self.submodules.phy = LiteEthPHY(platform.request("eth_clocks"), platform.request("eth"), clk_freq=clk_freq)
|
|
|
|
self.submodules.core = LiteEthUDPIPCore(self.phy, mac_address, convert_ip(ip_address), clk_freq)
|
|
|
|
|
|
|
|
if isinstance(platform.toolchain, XilinxVivadoToolchain):
|
|
|
|
self.specials += [
|
|
|
|
Keep(self.crg.cd_sys.clk),
|
|
|
|
Keep(self.phy.crg.cd_eth_rx.clk),
|
|
|
|
Keep(self.phy.crg.cd_eth_tx.clk)
|
|
|
|
]
|
|
|
|
platform.add_platform_command("""
|
|
|
|
create_clock -name sys_clk -period 6.0 [get_nets sys_clk]
|
|
|
|
create_clock -name eth_rx_clk -period 8.0 [get_nets eth_rx_clk]
|
|
|
|
create_clock -name eth_tx_clk -period 8.0 [get_nets eth_tx_clk]
|
|
|
|
set_false_path -from [get_clocks sys_clk] -to [get_clocks eth_rx_clk]
|
|
|
|
set_false_path -from [get_clocks eth_rx_clk] -to [get_clocks sys_clk]
|
|
|
|
set_false_path -from [get_clocks sys_clk] -to [get_clocks eth_tx_clk]
|
|
|
|
set_false_path -from [get_clocks eth_tx_clk] -to [get_clocks sys_clk]
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
class BaseSoCDevel(BaseSoC):
|
|
|
|
csr_map = {
|
2016-03-31 15:27:08 -04:00
|
|
|
"analyzer": 20
|
2015-09-07 07:28:02 -04:00
|
|
|
}
|
|
|
|
csr_map.update(BaseSoC.csr_map)
|
|
|
|
def __init__(self, platform):
|
2016-03-31 15:27:08 -04:00
|
|
|
from litescope import LiteScopeAnalyzer
|
2015-09-07 07:28:02 -04:00
|
|
|
BaseSoC.__init__(self, platform)
|
|
|
|
|
|
|
|
self.core_icmp_rx_fsm_state = Signal(4)
|
|
|
|
self.core_icmp_tx_fsm_state = Signal(4)
|
|
|
|
self.core_udp_rx_fsm_state = Signal(4)
|
|
|
|
self.core_udp_tx_fsm_state = Signal(4)
|
|
|
|
self.core_ip_rx_fsm_state = Signal(4)
|
|
|
|
self.core_ip_tx_fsm_state = Signal(4)
|
|
|
|
self.core_arp_rx_fsm_state = Signal(4)
|
|
|
|
self.core_arp_tx_fsm_state = Signal(4)
|
|
|
|
self.core_arp_table_fsm_state = Signal(4)
|
|
|
|
|
2016-03-31 15:27:08 -04:00
|
|
|
debug = [
|
2015-09-07 07:28:02 -04:00
|
|
|
# MAC interface
|
2016-03-16 16:30:01 -04:00
|
|
|
self.core.mac.core.sink.valid,
|
|
|
|
self.core.mac.core.sink.last,
|
|
|
|
self.core.mac.core.sink.ready,
|
2015-09-07 07:28:02 -04:00
|
|
|
self.core.mac.core.sink.data,
|
|
|
|
|
2016-03-16 16:30:01 -04:00
|
|
|
self.core.mac.core.source.valid,
|
|
|
|
self.core.mac.core.source.last,
|
|
|
|
self.core.mac.core.source.ready,
|
2015-09-07 07:28:02 -04:00
|
|
|
self.core.mac.core.source.data,
|
|
|
|
|
|
|
|
# ICMP interface
|
2016-03-16 16:30:01 -04:00
|
|
|
self.core.icmp.echo.sink.valid,
|
|
|
|
self.core.icmp.echo.sink.last,
|
|
|
|
self.core.icmp.echo.sink.ready,
|
2015-09-07 07:28:02 -04:00
|
|
|
self.core.icmp.echo.sink.data,
|
|
|
|
|
2016-03-16 16:30:01 -04:00
|
|
|
self.core.icmp.echo.source.valid,
|
|
|
|
self.core.icmp.echo.source.last,
|
|
|
|
self.core.icmp.echo.source.ready,
|
2015-09-07 07:28:02 -04:00
|
|
|
self.core.icmp.echo.source.data,
|
|
|
|
|
|
|
|
# IP interface
|
2016-03-16 16:30:01 -04:00
|
|
|
self.core.ip.crossbar.master.sink.valid,
|
|
|
|
self.core.ip.crossbar.master.sink.last,
|
|
|
|
self.core.ip.crossbar.master.sink.ready,
|
2015-09-07 07:28:02 -04:00
|
|
|
self.core.ip.crossbar.master.sink.data,
|
|
|
|
self.core.ip.crossbar.master.sink.ip_address,
|
|
|
|
self.core.ip.crossbar.master.sink.protocol,
|
|
|
|
|
|
|
|
# State machines
|
|
|
|
self.core_icmp_rx_fsm_state,
|
|
|
|
self.core_icmp_tx_fsm_state,
|
|
|
|
|
|
|
|
self.core_arp_rx_fsm_state,
|
|
|
|
self.core_arp_tx_fsm_state,
|
|
|
|
self.core_arp_table_fsm_state,
|
|
|
|
|
|
|
|
self.core_ip_rx_fsm_state,
|
|
|
|
self.core_ip_tx_fsm_state,
|
|
|
|
|
|
|
|
self.core_udp_rx_fsm_state,
|
|
|
|
self.core_udp_tx_fsm_state
|
2016-03-31 15:27:08 -04:00
|
|
|
]
|
|
|
|
self.submodules.analyzer = LiteScopeAnalyzer(debug, 4096)
|
2015-09-07 07:28:02 -04:00
|
|
|
|
|
|
|
def do_finalize(self):
|
|
|
|
BaseSoC.do_finalize(self)
|
|
|
|
self.comb += [
|
|
|
|
self.core_icmp_rx_fsm_state.eq(self.core.icmp.rx.fsm.state),
|
|
|
|
self.core_icmp_tx_fsm_state.eq(self.core.icmp.tx.fsm.state),
|
|
|
|
|
|
|
|
self.core_arp_rx_fsm_state.eq(self.core.arp.rx.fsm.state),
|
|
|
|
self.core_arp_tx_fsm_state.eq(self.core.arp.tx.fsm.state),
|
|
|
|
self.core_arp_table_fsm_state.eq(self.core.arp.table.fsm.state),
|
|
|
|
|
|
|
|
self.core_ip_rx_fsm_state.eq(self.core.ip.rx.fsm.state),
|
|
|
|
self.core_ip_tx_fsm_state.eq(self.core.ip.tx.fsm.state),
|
|
|
|
|
|
|
|
self.core_udp_rx_fsm_state.eq(self.core.udp.rx.fsm.state),
|
|
|
|
self.core_udp_tx_fsm_state.eq(self.core.udp.tx.fsm.state)
|
|
|
|
]
|
|
|
|
|
|
|
|
def do_exit(self, vns):
|
2016-03-31 15:27:08 -04:00
|
|
|
self.analyzer.export_csv(vns, "test/analyzer.csv")
|
2015-09-07 07:28:02 -04:00
|
|
|
|
|
|
|
default_subtarget = BaseSoC
|