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-03-14 13:26:05 -04:00
|
|
|
from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon
|
2011-12-13 11:33:12 -05:00
|
|
|
import constraints
|
|
|
|
|
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),
|
2012-03-18 09:57:31 -04:00
|
|
|
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
|
|
|
|
2012-02-17 05:04:44 -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"
|
2012-02-17 05:04:44 -05:00
|
|
|
]
|
|
|
|
comb = [getattr(phy, name).eq(getattr(crg, name)) for name in names]
|
|
|
|
return Fragment(comb)
|
|
|
|
|
2011-12-16 10:02:49 -05:00
|
|
|
def get():
|
2012-02-13 17:12:57 -05:00
|
|
|
#
|
|
|
|
# ASMI
|
|
|
|
#
|
2012-03-18 09:57:31 -04:00
|
|
|
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(1, 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-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-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
|
|
|
|
#
|
2012-01-21 06:25:22 -05:00
|
|
|
uart0 = uart.UART(0, clk_freq, baud=115200)
|
2012-02-17 11:34:59 -05:00
|
|
|
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
|
|
|
|
uart0.bank.interface,
|
2012-02-17 17:50:10 -05:00
|
|
|
dfii0.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([
|
|
|
|
cpu0.interrupt[0].eq(uart0.events.irq)
|
|
|
|
])
|
|
|
|
|
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
|
|
|
|
2012-02-17 05:04:44 -05:00
|
|
|
frag = autofragment.from_local() + interrupts + ddrphy_clocking(crg0, ddrphy0)
|
2012-01-20 17:00:11 -05:00
|
|
|
src_verilog, vns = verilog.convert(frag,
|
2012-02-16 12:02:37 -05:00
|
|
|
{crg0.trigger_reset},
|
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)
|
2012-02-17 05:04:44 -05:00
|
|
|
src_ucf = constraints.get(vns, crg0, norflash0, uart0, ddrphy0)
|
2011-12-13 11:33:12 -05:00
|
|
|
return (src_verilog, src_ucf)
|