litex/top.py

193 lines
6.1 KiB
Python
Raw Normal View History

2012-02-16 12:02:37 -05:00
from fractions import Fraction
2012-03-14 13:26:05 -04:00
from math import ceil
from operator import itemgetter
2012-02-16 12:02:37 -05:00
2013-05-22 11:10:13 -04:00
from migen.fhdl.std import *
2013-06-11 08:18:16 -04:00
from migen.bus import wishbone, csr, lasmibus, dfi
from migen.bus import wishbone2lasmi, wishbone2csr
from migen.bank import csrgen
2013-07-04 13:19:39 -04:00
from mibuild.generic_platform import ConstraintError
2011-12-16 10:02:49 -05:00
2013-07-04 13:19:39 -04:00
from milkymist import mxcrg, lm32, norflash, uart, s6ddrphy, dfii, lasmicon, \
identifier, timer, minimac3, framebuffer, dvisampler, gpio, memtest
2013-05-30 15:38:21 -04:00
from milkymist.cif import get_macros
2011-12-13 11:33:12 -05:00
2013-03-26 12:57:17 -04:00
version = get_macros("common/version.h")["VERSION"][1:-1]
clk_freq = (83 + Fraction(1, 3))*1000000
2012-02-13 17:12:57 -05:00
sram_size = 4096 # in bytes
l2_size = 8192 # in bytes
2012-03-14 13:26:05 -04:00
clk_period_ns = 1000000000/clk_freq
2012-03-17 19:12:03 -04:00
def ns(t, margin=True):
2012-03-14 13:26:05 -04:00
if margin:
t += clk_period_ns/2
return ceil(t/clk_period_ns)
2013-06-11 08:18:16 -04:00
sdram_geom = lasmicon.GeomSettings(
2012-03-15 15:29:26 -04:00
bank_a=2,
2012-03-14 13:26:05 -04:00
row_a=13,
col_a=10
)
2013-06-11 08:18:16 -04:00
sdram_timing = lasmicon.TimingSettings(
2012-03-15 15:29:26 -04:00
tRP=ns(15),
2012-03-17 19:12:03 -04:00
tRCD=ns(15),
2012-03-18 17:11:01 -04:00
tWR=ns(15),
2013-06-11 08:18:16 -04:00
tWTR=2,
2012-03-17 19:12:03 -04:00
tREFI=ns(7800, False),
tRFC=ns(70),
2012-03-18 17:11:01 -04:00
req_queue_size=8,
2012-03-18 17:11:01 -04:00
read_time=32,
write_time=16
2012-03-14 13:26:05 -04:00
)
2012-02-17 17:50:10 -05:00
2013-07-04 13:19:39 -04:00
class MXClockPads:
2013-03-26 12:57:17 -04:00
def __init__(self, platform):
self.clk50 = platform.request("clk50")
2013-07-04 13:19:39 -04:00
self.trigger_reset = 0
try:
self.trigger_reset = platform.request("user_btn", 1)
except ConstraintError:
pass
2013-03-26 12:57:17 -04:00
self.norflash_rst_n = platform.request("norflash_rst_n")
ddram_clock = platform.request("ddram_clock")
self.ddr_clk_p = ddram_clock.p
self.ddr_clk_n = ddram_clock.n
eth_clocks = platform.request("eth_clocks")
self.eth_phy_clk = eth_clocks.phy
self.eth_rx_clk = eth_clocks.rx
self.eth_tx_clk = eth_clocks.tx
2012-05-16 19:41:41 -04:00
class SoC(Module):
csr_base = 0xe0000000
csr_map = {
"crg": 0,
"uart": 1,
"dfii": 2,
"identifier": 3,
"timer0": 4,
"minimac": 5,
"fb": 6,
2013-06-15 06:51:11 -04:00
"lasmicon": 7,
"dvisampler0": 8,
"dvisampler0_edid_mem": 9,
"dvisampler1": 10,
"dvisampler1_edid_mem": 11,
"pots": 12,
"buttons": 13,
2013-07-11 12:31:51 -04:00
"leds": 14,
"memtest_w": 15,
"memtest_r": 16
}
interrupt_map = {
"uart": 0,
"timer0": 1,
"minimac": 2,
2013-05-28 09:56:14 -04:00
"dvisampler0": 3,
"dvisampler1": 4,
}
2013-07-11 12:31:51 -04:00
def __init__(self, platform, platform_name, with_memtest):
2013-07-17 07:58:58 -04:00
#
# DFI
#
self.submodules.ddrphy = s6ddrphy.S6DDRPHY(platform.request("ddram"), memtype="DDR", nphases=2, cl=3, bitslip=0)
self.submodules.dfii = dfii.DFIInjector(sdram_geom.mux_a, sdram_geom.bank_a,
self.ddrphy.phy_settings.dfi_d, self.ddrphy.phy_settings.nphases)
self.submodules.dficon0 = dfi.Interconnect(self.dfii.master, self.ddrphy.dfi)
2013-02-11 12:23:06 -05:00
#
2013-06-11 08:18:16 -04:00
# LASMI
2013-02-11 12:23:06 -05:00
#
2013-07-17 07:58:58 -04:00
self.submodules.lasmicon = lasmicon.LASMIcon(self.ddrphy.phy_settings, sdram_geom, sdram_timing)
self.submodules.dficon1 = dfi.Interconnect(self.lasmicon.dfi, self.dfii.slave)
n_lasmims = 1 # wishbone bridging
if platform_name == "mixxeo":
n_lasmims += 4 # framebuffer (2-channel mixing) + 2 DVI samplers
if platform_name == "m1":
n_lasmims += 1 # framebuffer (single channel)
if with_memtest:
n_lasmims += 2 # writer + reader
2013-07-11 12:31:51 -04:00
self.submodules.lasmixbar = lasmibus.Crossbar([self.lasmicon.lasmic], n_lasmims, self.lasmicon.nrowbits)
2013-07-11 12:31:51 -04:00
lasmims = list(self.lasmixbar.masters)
lasmim_wb = lasmims.pop()
if platform_name == "mixxeo":
lasmim_fb0, lasmim_fb1, lasmim_dvi0, lasmim_dvi1 = (lasmims.pop() for i in range(4))
if platform_name == "m1":
lasmim_fb = lasmims.pop()
2013-07-11 12:31:51 -04:00
if with_memtest:
lasmim_mtw, lasmim_mtr = lasmims.pop(), lasmims.pop()
assert(not lasmims)
2012-02-17 17:50:10 -05:00
2013-02-11 12:23:06 -05:00
#
# WISHBONE
#
self.submodules.cpu = lm32.LM32()
2013-03-26 12:57:17 -04:00
self.submodules.norflash = norflash.NorFlash(platform.request("norflash"), 12)
self.submodules.sram = wishbone.SRAM(sram_size)
2013-03-26 12:57:17 -04:00
self.submodules.minimac = minimac3.MiniMAC(platform.request("eth"))
2013-06-11 08:18:16 -04:00
self.submodules.wishbone2lasmi = wishbone2lasmi.WB2LASMI(l2_size//4, lasmim_wb)
self.submodules.wishbone2csr = wishbone2csr.WB2CSR()
2013-02-11 12:23:06 -05:00
# 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(
2013-02-11 12:23:06 -05:00
[
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),
2013-06-11 08:18:16 -04:00
(lambda a: a[27:29] == 2, self.wishbone2lasmi.wishbone),
2013-02-11 12:23:06 -05:00
(lambda a: a[27:29] == 3, self.wishbone2csr.wishbone)
],
register=True)
#
# CSR
#
2013-07-04 13:19:39 -04:00
self.submodules.crg = mxcrg.MXCRG(MXClockPads(platform), clk_freq)
2013-03-26 12:57:17 -04:00
self.submodules.uart = uart.UART(platform.request("serial"), clk_freq, baud=115200)
self.submodules.identifier = identifier.Identifier(0x4D31, version, int(clk_freq))
self.submodules.timer0 = timer.Timer()
if platform_name == "mixxeo":
self.submodules.leds = gpio.GPIOOut(platform.request("user_led"))
2013-09-17 12:15:22 -04:00
self.submodules.fb = framebuffer.MixFramebuffer(platform.request("vga_out"), None, lasmim_fb0, lasmim_fb1)
self.submodules.dvisampler0 = dvisampler.DVISampler(platform.request("dvi_in", 0), lasmim_dvi0)
self.submodules.dvisampler1 = dvisampler.DVISampler(platform.request("dvi_in", 1), lasmim_dvi1)
2013-07-04 13:19:39 -04:00
if platform_name == "m1":
self.submodules.buttons = gpio.GPIOIn(Cat(platform.request("user_btn", 0), platform.request("user_btn", 2)))
self.submodules.leds = gpio.GPIOOut(Cat(*[platform.request("user_led", i) for i in range(2)]))
self.submodules.fb = framebuffer.Framebuffer(platform.request("vga"), lasmim_fb)
2013-07-11 12:31:51 -04:00
if with_memtest:
self.submodules.memtest_w = memtest.MemtestWriter(lasmim_mtw)
self.submodules.memtest_r = memtest.MemtestReader(lasmim_mtr)
self.submodules.csrbankarray = csrgen.BankArray(self,
lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override])
self.submodules.csrcon = csr.Interconnect(self.wishbone2csr.csr, self.csrbankarray.get_buses())
#
# Interrupts
#
for k, v in sorted(self.interrupt_map.items(), key=itemgetter(1)):
2013-05-08 16:31:42 -04:00
if hasattr(self, k):
self.comb += self.cpu.interrupt[v].eq(getattr(self, k).ev.irq)
2013-02-11 12:23:06 -05:00
#
# Clocking
#
self.comb += [
2013-02-11 12:23:06 -05:00
self.ddrphy.clk4x_wr_strb.eq(self.crg.clk4x_wr_strb),
self.ddrphy.clk4x_rd_strb.eq(self.crg.clk4x_rd_strb)
]