MultiReg: remove idomain
[litex.git] / top.py
diff --git a/top.py b/top.py
index 53b4c04d85cd1c2587abc6348c23e66e8c4beb3c..453db3bb742b22d1e2541bcceeb185fc39033c61 100644 (file)
--- a/top.py
+++ b/top.py
@@ -2,12 +2,13 @@ from fractions import Fraction
 from math import ceil
 
 from migen.fhdl.structure import *
-from migen.fhdl import verilog, autofragment
+from migen.fhdl.module import Module
 from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
+from migen.bank import csrgen
 
-from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon, identifier, timer, minimac3
+from milkymist import m1crg, lm32, norflash, uart, s6ddrphy, dfii, asmicon, \
+       identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler
 from cmacros import get_macros
-from constraints import Constraints
 
 MHz = 1000000
 clk_freq = (83 + Fraction(1, 3))*MHz
@@ -41,22 +42,10 @@ sdram_timing = asmicon.TimingSettings(
        CL=3,
        rd_delay=4,
 
-       slot_time=16,
        read_time=32,
        write_time=16
 )
 
-def ddrphy_clocking(crg, phy):
-       names = [
-               "clk2x_270",
-               "clk4x_wr",
-               "clk4x_wr_strb",
-               "clk4x_rd",
-               "clk4x_rd_strb"
-       ]
-       comb = [getattr(phy, name).eq(getattr(crg, name)) for name in names]
-       return Fragment(comb)
-
 csr_macros = get_macros("common/csrbase.h")
 def csr_offset(name):
        base = int(csr_macros[name + "_BASE"], 0)
@@ -69,88 +58,87 @@ def interrupt_n(name):
 
 version = get_macros("common/version.h")["VERSION"][1:-1]
 
-def get():
-       #
-       # ASMI
-       #
-       asmicon0 = asmicon.ASMIcon(sdram_phy, sdram_geom, sdram_timing)
-       asmiport_wb = asmicon0.hub.get_port()
-       asmicon0.finalize()
-       
-       #
-       # DFI
-       #
-       ddrphy0 = s6ddrphy.S6DDRPHY(sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d)
-       dfii0 = dfii.DFIInjector(csr_offset("DFII"),
-               sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d, sdram_phy.nphases)
-       dficon0 = dfi.Interconnect(dfii0.master, ddrphy0.dfi)
-       dficon1 = dfi.Interconnect(asmicon0.dfi, dfii0.slave)
+def csr_address_map(name, memory):
+       if memory is not None:
+               name += "_" + memory.name_override
+       return csr_offset(name.upper())
 
-       #
-       # WISHBONE
-       #
-       cpu0 = lm32.LM32()
-       norflash0 = norflash.NorFlash(25, 12)
-       sram0 = sram.SRAM(sram_size//4)
-       minimac0 = minimac3.MiniMAC(csr_offset("MINIMAC"))
-       wishbone2asmi0 = wishbone2asmi.WB2ASMI(l2_size//4, asmiport_wb)
-       wishbone2csr0 = wishbone2csr.WB2CSR()
-       
-       # norflash     0x00000000 (shadow @0x80000000)
-       # SRAM/debug   0x10000000 (shadow @0x90000000)
-       # USB          0x20000000 (shadow @0xa0000000)
-       # Ethernet     0x30000000 (shadow @0xb0000000)
-       # SDRAM        0x40000000 (shadow @0xc0000000)
-       # CSR bridge   0x60000000 (shadow @0xe0000000)
-       wishbonecon0 = wishbone.InterconnectShared(
-               [
-                       cpu0.ibus,
-                       cpu0.dbus
-               ], [
-                       (binc("000"), norflash0.bus),
-                       (binc("001"), sram0.bus),
-                       (binc("011"), minimac0.membus),
-                       (binc("10"), wishbone2asmi0.wishbone),
-                       (binc("11"), wishbone2csr0.wishbone)
-               ],
-               register=True,
-               offset=1)
-       
-       #
-       # CSR
-       #
-       uart0 = uart.UART(csr_offset("UART"), clk_freq, baud=115200)
-       identifier0 = identifier.Identifier(csr_offset("ID"), 0x4D31, version)
-       timer0 = timer.Timer(csr_offset("TIMER0"))
-       csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
-               uart0.bank.interface,
-               dfii0.bank.interface,
-               identifier0.bank.interface,
-               timer0.bank.interface,
-               minimac0.bank.interface
-       ])
-       
-       #
-       # Interrupts
-       #
-       interrupts = Fragment([
-               cpu0.interrupt[interrupt_n("UART")].eq(uart0.events.irq),
-               cpu0.interrupt[interrupt_n("TIMER0")].eq(timer0.events.irq),
-               cpu0.interrupt[interrupt_n("MINIMAC")].eq(minimac0.events.irq)
-       ])
-       
-       #
-       # Housekeeping
-       #
-       crg0 = m1crg.M1CRG(50*MHz, clk_freq)
-       
-       frag = autofragment.from_local() + interrupts + ddrphy_clocking(crg0, ddrphy0)
-       cst = Constraints(crg0, norflash0, uart0, ddrphy0, minimac0)
-       src_verilog, vns = verilog.convert(frag,
-               cst.get_ios(),
-               name="soc",
-               clk_signal=crg0.sys_clk,
-               rst_signal=crg0.sys_rst,
-               return_ns=True)
-       src_ucf = cst.get_ucf(vns)
-       return (src_verilog, src_ucf)
+class SoC(Module):
+       def __init__(self):
+               #
+               # ASMI
+               #
+               self.submodules.asmicon = asmicon.ASMIcon(sdram_phy, sdram_geom, sdram_timing)
+               asmiport_wb = self.asmicon.hub.get_port()
+               asmiport_fb = self.asmicon.hub.get_port(2)
+               self.asmicon.finalize()
+               
+               #
+               # DFI
+               #
+               self.submodules.ddrphy = s6ddrphy.S6DDRPHY(sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d)
+               self.submodules.dfii = dfii.DFIInjector(sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d,
+                       sdram_phy.nphases)
+               self.submodules.dficon0 = dfi.Interconnect(self.dfii.master, self.ddrphy.dfi)
+               self.submodules.dficon1 = dfi.Interconnect(self.asmicon.dfi, self.dfii.slave)
+
+               #
+               # WISHBONE
+               #
+               self.submodules.cpu = lm32.LM32()
+               self.submodules.norflash = norflash.NorFlash(25, 12)
+               self.submodules.sram = wishbone.SRAM(sram_size)
+               self.submodules.minimac = minimac3.MiniMAC()
+               self.submodules.wishbone2asmi = wishbone2asmi.WB2ASMI(l2_size//4, asmiport_wb)
+               self.submodules.wishbone2csr = wishbone2csr.WB2CSR()
+               
+               # norflash     0x00000000 (shadow @0x80000000)
+               # SRAM/debug   0x10000000 (shadow @0x90000000)
+               # USB          0x20000000 (shadow @0xa0000000)
+               # Ethernet     0x30000000 (shadow @0xb0000000)
+               # SDRAM        0x40000000 (shadow @0xc0000000)
+               # CSR bridge   0x60000000 (shadow @0xe0000000)
+               self.submodules.wishbonecon = wishbone.InterconnectShared(
+                       [
+                               self.cpu.ibus,
+                               self.cpu.dbus
+                       ], [
+                               (lambda a: a[26:29] == 0, self.norflash.bus),
+                               (lambda a: a[26:29] == 1, self.sram.bus),
+                               (lambda a: a[26:29] == 3, self.minimac.membus),
+                               (lambda a: a[27:29] == 2, self.wishbone2asmi.wishbone),
+                               (lambda a: a[27:29] == 3, self.wishbone2csr.wishbone)
+                       ],
+                       register=True)
+               
+               #
+               # CSR
+               #
+               self.submodules.uart = uart.UART(clk_freq, baud=115200)
+               self.submodules.identifier = identifier.Identifier(0x4D31, version, int(clk_freq))
+               self.submodules.timer0 = timer.Timer()
+               self.submodules.fb = framebuffer.Framebuffer(asmiport_fb)
+               self.submodules.asmiprobe = asmiprobe.ASMIprobe(self.asmicon.hub)
+               self.submodules.dvisampler0 = dvisampler.DVISampler("02")
+               self.submodules.dvisampler1 = dvisampler.DVISampler("02")
+
+               self.submodules.csrbankarray = csrgen.BankArray(self, csr_address_map)
+               self.submodules.csrcon = csr.Interconnect(self.wishbone2csr.csr, self.csrbankarray.get_buses())
+
+               #
+               # Interrupts
+               #
+               self.comb += [
+                       self.cpu.interrupt[interrupt_n("UART")].eq(self.uart.ev.irq),
+                       self.cpu.interrupt[interrupt_n("TIMER0")].eq(self.timer0.ev.irq),
+                       self.cpu.interrupt[interrupt_n("MINIMAC")].eq(self.minimac.ev.irq)
+               ]
+               
+               #
+               # Clocking
+               #
+               self.submodules.crg = m1crg.M1CRG(50*MHz, clk_freq)
+               self.comb += [
+                       self.ddrphy.clk4x_wr_strb.eq(self.crg.clk4x_wr_strb),
+                       self.ddrphy.clk4x_rd_strb.eq(self.crg.clk4x_rd_strb)
+               ]