Skip to content

Commit

Permalink
litex: sim: Get sim working in litex-buildenv
Browse files Browse the repository at this point in the history
Changes needed to get PLATFORM=sim to work again.

The platforms/sim was basically copied from
litex.boards.platforms.sim but then updated to properly handle
sending the SimConfig details to the toolchain needed during building
and running of the verilog backend.
  • Loading branch information
stffrdhrn committed Oct 4, 2018
1 parent 1a111fa commit 55f97fd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
66 changes: 63 additions & 3 deletions platforms/sim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
from litex.boards.platforms import sim
from litex.boards.platforms.sim import *
__all__ = ['SimPins', 'Platform']
from litex.build.generic_platform import *
from litex.build.sim import SimPlatform

from litex.build.sim.config import SimConfig

from targets.sim.net import NetSoC

class SimPins(Pins):
def __init__(self, n):
Pins.__init__(self, "s "*n)

_io = [
("sys_clk", 0, SimPins(1)),
("sys_rst", 0, SimPins(1)),
("serial", 0,
Subsignal("source_valid", SimPins(1)),
Subsignal("source_ready", SimPins(1)),
Subsignal("source_data", SimPins(8)),

Subsignal("sink_valid", SimPins(1)),
Subsignal("sink_ready", SimPins(1)),
Subsignal("sink_data", SimPins(8)),
),
("eth_clocks", 0,
Subsignal("none", SimPins(1)),
),
("eth", 0,
Subsignal("source_valid", SimPins(1)),
Subsignal("source_ready", SimPins(1)),
Subsignal("source_data", SimPins(8)),

Subsignal("sink_valid", SimPins(1)),
Subsignal("sink_ready", SimPins(1)),
Subsignal("sink_data", SimPins(8)),
),
("vga", 0,
Subsignal("de", SimPins(1)),
Subsignal("hsync", SimPins(1)),
Subsignal("vsync", SimPins(1)),
Subsignal("r", SimPins(8)),
Subsignal("g", SimPins(8)),
Subsignal("b", SimPins(8)),
),
]


class Platform(SimPlatform):
default_clk_name = "sys_clk"
default_clk_period = 1000 # on modern computers simulate at ~ 1MHz

def __init__(self):
SimPlatform.__init__(self, "SIM", _io)

def do_finalize(self, fragment):
pass

def build(self, fragment, **kwargs):
scfg = SimConfig(default_clk="sys_clk")
scfg.add_module("serial2console", "serial")
if isinstance(fragment, NetSoC):
scfg.add_module('ethernet', "eth", args={"interface": "tap1", "ip": "192.168.1.100"})
kwargs['sim_config'] = scfg
return SimPlatform.build(self, fragment, **kwargs)
12 changes: 6 additions & 6 deletions targets/sim/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from litex.soc.integration.builder import *
from litex.soc.cores import uart

from litex.build.sim.config import SimConfig

from litedram.common import PhySettings
from litedram.modules import IS42S16160
from litedram.phy.model import SDRAMPHYModel
Expand All @@ -18,7 +20,7 @@

class BaseSoC(SoCSDRAM):
csr_peripherals = (
,
"firmware_ram",
)
csr_map_update(SoCSDRAM.csr_map, csr_peripherals)

Expand All @@ -32,10 +34,9 @@ def __init__(self, platform, **kwargs):
kwargs['integrated_rom_size']=0x8000
if 'integrated_sram_size' not in kwargs:
kwargs['integrated_sram_size']=0x8000
if 'firmware_ram_size' not in kwargs:
kwargs['firmware_ram_size']=0x10000
if 'firmware_filename' not in kwargs:
kwargs['firmware_filename'] = "build/sim_{}_{}/software/firmware/firmware.fbi".format(

firmware_ram_size=0x20000
firmware_filename="build/sim_{}_{}/software/firmware/firmware.fbi".format(
self.__class__.__name__.lower()[:-3], kwargs.get('cpu_type', 'lm32'))

clk_freq = int((1/(platform.default_clk_period))*1000000000)
Expand Down Expand Up @@ -76,5 +77,4 @@ def __init__(self, platform, **kwargs):
self.add_constant("MEMTEST_ADDR_SIZE", 1024)
self.add_constant("SIMULATION", 1)


SoC = BaseSoC
2 changes: 1 addition & 1 deletion targets/sim/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NetSoC(BaseSoC):
csr_map.update(BaseSoC.csr_map)

interrupt_map = {
"ethmac": 2,
"ethmac": 3,
}
interrupt_map.update(BaseSoC.interrupt_map)

Expand Down

0 comments on commit 55f97fd

Please sign in to comment.