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 *
|
2013-03-10 14:32:38 -04:00
|
|
|
from migen.fhdl.module import Module
|
2012-03-14 13:26:05 -04:00
|
|
|
from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
|
2013-03-10 14:32:38 -04:00
|
|
|
from migen.bank import csrgen
|
2011-12-16 10:02:49 -05:00
|
|
|
|
2012-12-01 06:59:32 -05:00
|
|
|
from milkymist import m1crg, lm32, norflash, uart, s6ddrphy, dfii, asmicon, \
|
2013-03-13 14:56:56 -04:00
|
|
|
identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler
|
2012-05-16 04:36:46 -04:00
|
|
|
from cmacros import get_macros
|
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),
|
2012-03-18 09:57:31 -04:00
|
|
|
tRFC=ns(70),
|
2012-03-18 17:11:01 -04:00
|
|
|
|
|
|
|
CL=3,
|
|
|
|
rd_delay=4,
|
|
|
|
|
|
|
|
read_time=32,
|
|
|
|
write_time=16
|
2012-03-14 13:26:05 -04:00
|
|
|
)
|
2012-02-17 17:50:10 -05:00
|
|
|
|
2012-05-16 04:36:46 -04:00
|
|
|
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]
|
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
def csr_address_map(name, memory):
|
|
|
|
if memory is not None:
|
|
|
|
name += "_" + memory.name_override
|
|
|
|
return csr_offset(name.upper())
|
|
|
|
|
|
|
|
class SoC(Module):
|
2013-02-11 12:23:06 -05:00
|
|
|
def __init__(self):
|
|
|
|
#
|
|
|
|
# ASMI
|
|
|
|
#
|
2013-03-10 14:32:38 -04:00
|
|
|
self.submodules.asmicon = asmicon.ASMIcon(sdram_phy, sdram_geom, sdram_timing)
|
2013-02-11 12:23:06 -05:00
|
|
|
asmiport_wb = self.asmicon.hub.get_port()
|
|
|
|
asmiport_fb = self.asmicon.hub.get_port(2)
|
|
|
|
self.asmicon.finalize()
|
|
|
|
|
|
|
|
#
|
|
|
|
# DFI
|
|
|
|
#
|
2013-03-10 14:32:38 -04:00
|
|
|
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)
|
2012-02-17 17:50:10 -05:00
|
|
|
|
2013-02-11 12:23:06 -05:00
|
|
|
#
|
|
|
|
# WISHBONE
|
|
|
|
#
|
2013-03-10 14:32:38 -04:00
|
|
|
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()
|
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)
|
2013-03-10 14:32:38 -04:00
|
|
|
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),
|
|
|
|
(lambda a: a[27:29] == 2, self.wishbone2asmi.wishbone),
|
|
|
|
(lambda a: a[27:29] == 3, self.wishbone2csr.wishbone)
|
|
|
|
],
|
|
|
|
register=True)
|
|
|
|
|
|
|
|
#
|
|
|
|
# CSR
|
|
|
|
#
|
2013-03-10 14:32:38 -04:00
|
|
|
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)
|
2013-03-13 14:56:56 -04:00
|
|
|
self.submodules.dvisampler0 = dvisampler.DVISampler("02")
|
|
|
|
self.submodules.dvisampler1 = dvisampler.DVISampler("02")
|
2013-03-10 14:32:38 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
]
|
2013-02-11 12:23:06 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Clocking
|
|
|
|
#
|
2013-03-10 14:32:38 -04:00
|
|
|
self.submodules.crg = m1crg.M1CRG(50*MHz, clk_freq)
|
|
|
|
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)
|
|
|
|
]
|