litex/top.py

157 lines
3.8 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
2012-02-16 12:02:37 -05:00
2011-12-16 16:25:26 -05:00
from migen.fhdl.structure import *
2012-02-13 17:12:57 -05:00
from migen.fhdl import verilog, autofragment
2012-03-14 13:26:05 -04:00
from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
2011-12-16 10:02:49 -05:00
2012-05-21 13:46:04 -04:00
from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon, identifier, timer, minimac3
from cmacros import get_macros
from constraints import Constraints
2011-12-13 11:33:12 -05:00
2012-02-13 17:12:57 -05:00
MHz = 1000000
2012-02-16 12:02:37 -05:00
clk_freq = (83 + Fraction(1, 3))*MHz
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)
sdram_phy = asmicon.PhySettings(
dfi_d=64,
nphases=2,
rdphase=0,
wrphase=1
)
sdram_geom = asmicon.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
)
sdram_timing = asmicon.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),
2012-03-17 19:12:03 -04:00
tREFI=ns(7800, False),
tRFC=ns(70),
2012-03-18 17:11:01 -04:00
CL=3,
rd_delay=4,
slot_time=16,
read_time=32,
write_time=16
2012-03-14 13:26:05 -04:00
)
2012-02-17 17:50:10 -05:00
def ddrphy_clocking(crg, phy):
names = [
2012-02-20 17:55:20 -05:00
"clk2x_270",
2012-02-19 12:43:42 -05:00
"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)
assert((base >= 0xe0000000) and (base <= 0xe0010000))
return (base - 0xe0000000)//0x800
2012-05-21 13:52:41 -04:00
interrupt_macros = get_macros("common/interrupt.h")
def interrupt_n(name):
return int(interrupt_macros[name + "_INTERRUPT"], 0)
2012-05-16 19:41:41 -04:00
version = get_macros("common/version.h")["VERSION"][1:-1]
2011-12-16 10:02:49 -05:00
def get():
2012-02-13 17:12:57 -05:00
#
# ASMI
#
asmicon0 = asmicon.ASMIcon(sdram_phy, sdram_geom, sdram_timing)
2012-03-14 13:26:05 -04:00
asmiport_wb = asmicon0.hub.get_port()
asmicon0.finalize()
2011-12-16 16:25:26 -05:00
2012-02-17 17:50:10 -05:00
#
# DFI
#
2012-03-17 19:12:03 -04:00
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)
2012-02-17 17:50:10 -05:00
dficon0 = dfi.Interconnect(dfii0.master, ddrphy0.dfi)
2012-03-14 13:26:05 -04:00
dficon1 = dfi.Interconnect(asmicon0.dfi, dfii0.slave)
2012-02-17 17:50:10 -05:00
2012-02-13 17:12:57 -05:00
#
# WISHBONE
#
2012-01-21 06:25:22 -05:00
cpu0 = lm32.LM32()
norflash0 = norflash.NorFlash(25, 12)
2012-01-27 16:09:03 -05:00
sram0 = sram.SRAM(sram_size//4)
2012-05-19 18:30:03 -04:00
minimac0 = minimac3.MiniMAC(csr_offset("MINIMAC"))
2012-02-13 17:12:57 -05:00
wishbone2asmi0 = wishbone2asmi.WB2ASMI(l2_size//4, asmiport_wb)
2012-01-21 06:25:22 -05:00
wishbone2csr0 = wishbone2csr.WB2CSR()
2012-02-05 13:54:08 -05:00
# norflash 0x00000000 (shadow @0x80000000)
# SRAM/debug 0x10000000 (shadow @0x90000000)
# USB 0x20000000 (shadow @0xa0000000)
# Ethernet 0x30000000 (shadow @0xb0000000)
# SDRAM 0x40000000 (shadow @0xc0000000)
2012-02-13 17:12:57 -05:00
# CSR bridge 0x60000000 (shadow @0xe0000000)
2011-12-13 11:33:12 -05:00
wishbonecon0 = wishbone.InterconnectShared(
2012-02-05 13:54:08 -05:00
[
cpu0.ibus,
cpu0.dbus
], [
(binc("000"), norflash0.bus),
(binc("001"), sram0.bus),
2012-05-19 18:30:03 -04:00
(binc("011"), minimac0.membus),
2012-02-13 17:12:57 -05:00
(binc("10"), wishbone2asmi0.wishbone),
2012-02-05 13:54:08 -05:00
(binc("11"), wishbone2csr0.wishbone)
],
2011-12-13 11:33:12 -05:00
register=True,
offset=1)
2012-02-05 13:54:08 -05:00
2012-02-13 17:12:57 -05:00
#
# CSR
#
uart0 = uart.UART(csr_offset("UART"), clk_freq, baud=115200)
2012-05-22 07:23:44 -04:00
identifier0 = identifier.Identifier(csr_offset("ID"), 0x4D31, version, int(clk_freq))
2012-05-21 13:46:04 -04:00
timer0 = timer.Timer(csr_offset("TIMER0"))
2012-02-17 11:34:59 -05:00
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
uart0.bank.interface,
2012-05-16 19:41:41 -04:00
dfii0.bank.interface,
2012-05-19 18:30:03 -04:00
identifier0.bank.interface,
2012-05-21 13:46:04 -04:00
timer0.bank.interface,
2012-05-19 18:30:03 -04:00
minimac0.bank.interface
2012-02-17 11:34:59 -05:00
])
2011-12-13 11:33:12 -05:00
2012-02-13 17:12:57 -05:00
#
# Interrupts
#
2012-02-06 11:45:40 -05:00
interrupts = Fragment([
2012-05-21 13:52:41 -04:00
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)
2012-02-06 11:45:40 -05:00
])
2012-02-13 17:12:57 -05:00
#
# Housekeeping
#
2012-02-16 12:02:37 -05:00
crg0 = m1crg.M1CRG(50*MHz, clk_freq)
2012-02-13 17:12:57 -05:00
frag = autofragment.from_local() + interrupts + ddrphy_clocking(crg0, ddrphy0)
2012-05-19 18:30:03 -04:00
cst = Constraints(crg0, norflash0, uart0, ddrphy0, minimac0)
2012-01-20 17:00:11 -05:00
src_verilog, vns = verilog.convert(frag,
cst.get_ios(),
2011-12-17 09:00:18 -05:00
name="soc",
2012-02-16 12:02:37 -05:00
clk_signal=crg0.sys_clk,
rst_signal=crg0.sys_rst,
2012-01-20 17:00:11 -05:00
return_ns=True)
src_ucf = cst.get_ucf(vns)
2011-12-13 11:33:12 -05:00
return (src_verilog, src_ucf)