2012-02-16 12:02:37 -05:00
|
|
|
from fractions import Fraction
|
|
|
|
|
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
|
|
|
|
from migen.bus import wishbone, asmibus, wishbone2asmi, csr, wishbone2csr
|
2011-12-16 10:02:49 -05:00
|
|
|
|
2012-02-17 05:04:44 -05:00
|
|
|
from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy
|
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-02-17 05:04:44 -05:00
|
|
|
def ddrphy_clocking(crg, phy):
|
|
|
|
names = [
|
|
|
|
"clk2x_90",
|
|
|
|
"clk4x_wr_left",
|
|
|
|
"clk4x_wr_strb_left",
|
|
|
|
"clk4x_wr_right",
|
|
|
|
"clk4x_wr_strb_right",
|
|
|
|
"clk4x_rd_left",
|
|
|
|
"clk4x_rd_strb_left",
|
|
|
|
"clk4x_rd_right",
|
|
|
|
"clk4x_rd_strb_right",
|
|
|
|
]
|
|
|
|
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-02-17 05:04:44 -05:00
|
|
|
ddrphy0 = s6ddrphy.S6DDRPHY(13, 2, 128)
|
2012-02-16 12:02:37 -05:00
|
|
|
asmihub0 = asmibus.Hub(23, 128, 12) # TODO: get hub from memory controller
|
2012-02-13 17:12:57 -05:00
|
|
|
asmiport_wb = asmihub0.get_port()
|
|
|
|
asmihub0.finalize()
|
2011-12-16 16:25:26 -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)
|
2011-12-17 18:29:37 -05:00
|
|
|
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [uart0.bank.interface])
|
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)
|