2015-02-12 15:04:52 -05:00
|
|
|
import os
|
2014-12-19 17:10:51 -05:00
|
|
|
|
2015-02-28 04:53:51 -05:00
|
|
|
from misoclib.mem.litesata.common import *
|
2014-09-22 06:33:23 -04:00
|
|
|
from migen.bank import csrgen
|
|
|
|
from migen.bus import wishbone, csr
|
|
|
|
from migen.bus import wishbone2csr
|
2015-01-16 14:25:11 -05:00
|
|
|
from migen.genlib.cdc import *
|
2014-09-22 06:33:23 -04:00
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
2014-10-24 13:24:05 -04:00
|
|
|
from migen.bank.description import *
|
2014-09-22 06:33:23 -04:00
|
|
|
|
2015-02-21 13:27:03 -05:00
|
|
|
from targets import *
|
2015-01-16 17:52:41 -05:00
|
|
|
|
2015-01-22 19:34:59 -05:00
|
|
|
from litescope.common import *
|
|
|
|
from litescope.bridge.uart2wb import LiteScopeUART2WB
|
|
|
|
from litescope.frontend.la import LiteScopeLA
|
2015-01-25 10:21:56 -05:00
|
|
|
from litescope.core.port import LiteScopeTerm
|
2014-09-22 06:33:23 -04:00
|
|
|
|
2015-02-28 04:53:51 -05:00
|
|
|
from misoclib.mem.litesata.common import *
|
|
|
|
from misoclib.mem.litesata.phy import LiteSATAPHY
|
|
|
|
from misoclib.mem.litesata import LiteSATA
|
2014-09-22 06:33:23 -04:00
|
|
|
|
|
|
|
class _CRG(Module):
|
|
|
|
def __init__(self, platform):
|
2015-01-22 10:02:41 -05:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
2015-01-16 17:52:41 -05:00
|
|
|
self.reset = Signal()
|
2014-09-22 06:33:23 -04:00
|
|
|
|
|
|
|
clk200 = platform.request("clk200")
|
|
|
|
clk200_se = Signal()
|
|
|
|
self.specials += Instance("IBUFDS", i_I=clk200.p, i_IB=clk200.n, o_O=clk200_se)
|
|
|
|
|
|
|
|
pll_locked = Signal()
|
|
|
|
pll_fb = Signal()
|
|
|
|
pll_sys = Signal()
|
|
|
|
self.specials += [
|
|
|
|
Instance("PLLE2_BASE",
|
|
|
|
p_STARTUP_WAIT="FALSE", o_LOCKED=pll_locked,
|
|
|
|
|
|
|
|
# VCO @ 1GHz
|
|
|
|
p_REF_JITTER1=0.01, p_CLKIN1_PERIOD=5.0,
|
|
|
|
p_CLKFBOUT_MULT=5, p_DIVCLK_DIVIDE=1,
|
|
|
|
i_CLKIN1=clk200_se, i_CLKFBIN=pll_fb, o_CLKFBOUT=pll_fb,
|
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
# 166MHz
|
2015-01-08 16:58:26 -05:00
|
|
|
p_CLKOUT0_DIVIDE=6, p_CLKOUT0_PHASE=0.0, o_CLKOUT0=pll_sys,
|
2014-09-22 06:33:23 -04:00
|
|
|
|
|
|
|
p_CLKOUT1_DIVIDE=2, p_CLKOUT1_PHASE=0.0, #o_CLKOUT1=,
|
|
|
|
|
|
|
|
p_CLKOUT2_DIVIDE=2, p_CLKOUT2_PHASE=0.0, #o_CLKOUT2=,
|
|
|
|
|
|
|
|
p_CLKOUT3_DIVIDE=2, p_CLKOUT3_PHASE=0.0, #o_CLKOUT3=,
|
|
|
|
|
|
|
|
p_CLKOUT4_DIVIDE=2, p_CLKOUT4_PHASE=0.0, #o_CLKOUT4=
|
|
|
|
),
|
|
|
|
Instance("BUFG", i_I=pll_sys, o_O=self.cd_sys.clk),
|
2015-01-16 17:52:41 -05:00
|
|
|
AsyncResetSynchronizer(self.cd_sys, ~pll_locked | platform.request("cpu_reset") | self.reset),
|
2014-09-22 06:33:23 -04:00
|
|
|
]
|
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
class GenSoC(Module):
|
2014-09-22 06:33:23 -04:00
|
|
|
csr_base = 0x00000000
|
2015-01-16 14:53:17 -05:00
|
|
|
csr_data_width = 32
|
2014-09-22 06:33:23 -04:00
|
|
|
csr_map = {
|
2015-01-22 19:34:59 -05:00
|
|
|
"bridge": 0,
|
|
|
|
"identifier": 1,
|
2014-09-22 06:33:23 -04:00
|
|
|
}
|
2014-09-24 08:28:52 -04:00
|
|
|
interrupt_map = {}
|
2014-09-22 06:33:23 -04:00
|
|
|
cpu_type = None
|
|
|
|
def __init__(self, platform, clk_freq):
|
2015-01-22 15:23:14 -05:00
|
|
|
self.clk_freq = clk_freq
|
2015-01-16 14:25:11 -05:00
|
|
|
# UART <--> Wishbone bridge
|
2015-01-22 19:34:59 -05:00
|
|
|
self.submodules.bridge = LiteScopeUART2WB(platform.request("serial"), clk_freq, baud=921600)
|
2014-09-22 06:33:23 -04:00
|
|
|
|
|
|
|
# CSR bridge 0x00000000 (shadow @0x00000000)
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.wishbone2csr = wishbone2csr.WB2CSR(bus_csr=csr.Interface(self.csr_data_width))
|
2015-01-22 19:34:59 -05:00
|
|
|
self._wb_masters = [self.bridge.wishbone]
|
2014-09-22 06:33:23 -04:00
|
|
|
self._wb_slaves = [(lambda a: a[23:25] == 0, self.wishbone2csr.wishbone)]
|
2014-12-17 06:03:52 -05:00
|
|
|
self.cpu_csr_regions = [] # list of (name, origin, busword, csr_list/Memory)
|
|
|
|
|
2014-09-22 06:33:23 -04:00
|
|
|
# CSR
|
2015-02-21 13:27:03 -05:00
|
|
|
self.submodules.identifier = Identifier(0, int(clk_freq))
|
2014-09-22 06:33:23 -04:00
|
|
|
|
2014-12-17 06:03:52 -05:00
|
|
|
def add_cpu_memory_region(self, name, origin, length):
|
|
|
|
self.cpu_memory_regions.append((name, origin, length))
|
|
|
|
|
|
|
|
def add_cpu_csr_region(self, name, origin, busword, obj):
|
|
|
|
self.cpu_csr_regions.append((name, origin, busword, obj))
|
|
|
|
|
2014-09-22 06:33:23 -04:00
|
|
|
def do_finalize(self):
|
|
|
|
# Wishbone
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.wishbonecon = wishbone.InterconnectShared(self._wb_masters,
|
2014-09-22 06:33:23 -04:00
|
|
|
self._wb_slaves, register=True)
|
|
|
|
|
|
|
|
# CSR
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.csrbankarray = csrgen.BankArray(self,
|
2014-09-22 06:33:23 -04:00
|
|
|
lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override],
|
|
|
|
data_width=self.csr_data_width)
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.csrcon = csr.Interconnect(self.wishbone2csr.csr, self.csrbankarray.get_buses())
|
2014-12-17 06:03:52 -05:00
|
|
|
for name, csrs, mapaddr, rmap in self.csrbankarray.banks:
|
|
|
|
self.add_cpu_csr_region(name, 0xe0000000+0x800*mapaddr, flen(rmap.bus.dat_w), csrs)
|
|
|
|
for name, memory, mapaddr, mmap in self.csrbankarray.srams:
|
|
|
|
self.add_cpu_csr_region(name, 0xe0000000+0x800*mapaddr, flen(rmap.bus.dat_w), memory)
|
2014-09-22 06:33:23 -04:00
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
class BISTLeds(Module):
|
2014-12-24 09:05:17 -05:00
|
|
|
def __init__(self, platform, sata_phy):
|
2015-01-16 14:25:11 -05:00
|
|
|
# 1Hz blinking leds (sata_rx and sata_tx clocks)
|
2014-12-24 09:05:17 -05:00
|
|
|
sata_rx_led = platform.request("user_led", 0)
|
|
|
|
sata_tx_led = platform.request("user_led", 1)
|
2014-10-24 13:24:05 -04:00
|
|
|
|
|
|
|
sata_rx_cnt = Signal(32)
|
|
|
|
sata_tx_cnt = Signal(32)
|
|
|
|
|
2015-01-19 11:52:05 -05:00
|
|
|
sata_freq = int(frequencies[sata_phy.revision]*1000*1000)
|
2015-01-16 14:25:11 -05:00
|
|
|
|
2014-10-24 13:24:05 -04:00
|
|
|
self.sync.sata_rx += \
|
|
|
|
If(sata_rx_cnt == 0,
|
2014-12-24 09:05:17 -05:00
|
|
|
sata_rx_led.eq(~sata_rx_led),
|
2015-01-16 14:25:11 -05:00
|
|
|
sata_rx_cnt.eq(sata_freq//2)
|
2014-10-24 13:24:05 -04:00
|
|
|
).Else(
|
|
|
|
sata_rx_cnt.eq(sata_rx_cnt-1)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.sync.sata_tx += \
|
|
|
|
If(sata_tx_cnt == 0,
|
2014-12-24 09:05:17 -05:00
|
|
|
sata_tx_led.eq(~sata_tx_led),
|
2015-01-16 14:25:11 -05:00
|
|
|
sata_tx_cnt.eq(sata_freq//2)
|
2014-10-24 13:24:05 -04:00
|
|
|
).Else(
|
|
|
|
sata_tx_cnt.eq(sata_tx_cnt-1)
|
|
|
|
)
|
|
|
|
|
2014-12-24 09:05:17 -05:00
|
|
|
# ready leds (crg and ctrl)
|
|
|
|
self.comb += platform.request("user_led", 2).eq(sata_phy.crg.ready)
|
|
|
|
self.comb += platform.request("user_led", 3).eq(sata_phy.ctrl.ready)
|
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
class BISTSoC(GenSoC, AutoCSR):
|
2014-10-24 13:24:05 -04:00
|
|
|
default_platform = "kc705"
|
|
|
|
csr_map = {
|
2015-01-16 17:52:41 -05:00
|
|
|
"sata": 10,
|
2014-10-24 13:24:05 -04:00
|
|
|
}
|
2015-01-16 14:25:11 -05:00
|
|
|
csr_map.update(GenSoC.csr_map)
|
2015-01-23 03:10:14 -05:00
|
|
|
def __init__(self, platform):
|
2015-01-08 16:58:26 -05:00
|
|
|
clk_freq = 166*1000000
|
2015-01-16 14:25:11 -05:00
|
|
|
GenSoC.__init__(self, platform, clk_freq)
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.crg = _CRG(platform)
|
2014-10-24 13:24:05 -04:00
|
|
|
|
2015-01-16 17:52:41 -05:00
|
|
|
# SATA PHY/Core/Frontend
|
2015-01-22 11:15:12 -05:00
|
|
|
self.submodules.sata_phy = LiteSATAPHY(platform.device, platform.request("sata"), "sata_gen2", clk_freq)
|
2015-01-16 17:52:41 -05:00
|
|
|
self.comb += self.crg.reset.eq(self.sata_phy.ctrl.need_reset) # XXX FIXME
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.sata = LiteSATA(self.sata_phy, with_bist=True, with_bist_csr=True)
|
2014-12-19 13:02:31 -05:00
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
# Status Leds
|
2015-01-22 10:02:41 -05:00
|
|
|
self.submodules.leds = BISTLeds(platform, self.sata_phy)
|
2014-10-24 13:24:05 -04:00
|
|
|
|
2015-01-16 14:25:11 -05:00
|
|
|
class BISTSoCDevel(BISTSoC, AutoCSR):
|
|
|
|
csr_map = {
|
2015-01-23 06:36:45 -05:00
|
|
|
"la": 20
|
2015-01-16 14:25:11 -05:00
|
|
|
}
|
|
|
|
csr_map.update(BISTSoC.csr_map)
|
2015-01-23 03:10:14 -05:00
|
|
|
def __init__(self, platform):
|
|
|
|
BISTSoC.__init__(self, platform)
|
2015-01-16 14:25:11 -05:00
|
|
|
|
2015-01-16 17:52:41 -05:00
|
|
|
self.sata_core_link_rx_fsm_state = Signal(4)
|
|
|
|
self.sata_core_link_tx_fsm_state = Signal(4)
|
|
|
|
self.sata_core_transport_rx_fsm_state = Signal(4)
|
|
|
|
self.sata_core_transport_tx_fsm_state = Signal(4)
|
|
|
|
self.sata_core_command_rx_fsm_state = Signal(4)
|
|
|
|
self.sata_core_command_tx_fsm_state = Signal(4)
|
2015-01-16 16:49:34 -05:00
|
|
|
|
2015-01-25 10:21:56 -05:00
|
|
|
debug = (
|
2015-01-16 14:25:11 -05:00
|
|
|
self.sata_phy.ctrl.ready,
|
|
|
|
|
|
|
|
self.sata_phy.source.stb,
|
|
|
|
self.sata_phy.source.data,
|
|
|
|
self.sata_phy.source.charisk,
|
|
|
|
|
|
|
|
self.sata_phy.sink.stb,
|
|
|
|
self.sata_phy.sink.data,
|
|
|
|
self.sata_phy.sink.charisk,
|
|
|
|
|
2015-01-16 17:52:41 -05:00
|
|
|
self.sata.core.command.sink.stb,
|
|
|
|
self.sata.core.command.sink.sop,
|
|
|
|
self.sata.core.command.sink.eop,
|
|
|
|
self.sata.core.command.sink.ack,
|
|
|
|
self.sata.core.command.sink.write,
|
|
|
|
self.sata.core.command.sink.read,
|
|
|
|
self.sata.core.command.sink.identify,
|
|
|
|
|
|
|
|
self.sata.core.command.source.stb,
|
|
|
|
self.sata.core.command.source.sop,
|
|
|
|
self.sata.core.command.source.eop,
|
|
|
|
self.sata.core.command.source.ack,
|
|
|
|
self.sata.core.command.source.write,
|
|
|
|
self.sata.core.command.source.read,
|
|
|
|
self.sata.core.command.source.identify,
|
|
|
|
self.sata.core.command.source.failed,
|
|
|
|
self.sata.core.command.source.data,
|
|
|
|
|
|
|
|
self.sata_core_link_rx_fsm_state,
|
|
|
|
self.sata_core_link_tx_fsm_state,
|
|
|
|
self.sata_core_transport_rx_fsm_state,
|
|
|
|
self.sata_core_transport_tx_fsm_state,
|
|
|
|
self.sata_core_command_rx_fsm_state,
|
|
|
|
self.sata_core_command_tx_fsm_state,
|
2015-01-16 14:25:11 -05:00
|
|
|
)
|
|
|
|
|
2015-01-25 10:21:56 -05:00
|
|
|
self.submodules.la = LiteScopeLA(debug, 2048)
|
|
|
|
self.la.trigger.add_port(LiteScopeTerm(self.la.dw))
|
2015-01-16 17:52:41 -05:00
|
|
|
|
2015-01-16 16:49:34 -05:00
|
|
|
def do_finalize(self):
|
|
|
|
BISTSoC.do_finalize(self)
|
|
|
|
self.comb += [
|
2015-01-16 17:52:41 -05:00
|
|
|
self.sata_core_link_rx_fsm_state.eq(self.sata.core.link.rx.fsm.state),
|
|
|
|
self.sata_core_link_tx_fsm_state.eq(self.sata.core.link.tx.fsm.state),
|
|
|
|
self.sata_core_transport_rx_fsm_state.eq(self.sata.core.transport.rx.fsm.state),
|
|
|
|
self.sata_core_transport_tx_fsm_state.eq(self.sata.core.transport.tx.fsm.state),
|
|
|
|
self.sata_core_command_rx_fsm_state.eq(self.sata.core.command.rx.fsm.state),
|
|
|
|
self.sata_core_command_tx_fsm_state.eq(self.sata.core.command.tx.fsm.state)
|
2015-01-16 16:49:34 -05:00
|
|
|
]
|
2015-01-16 14:25:11 -05:00
|
|
|
|
2015-02-12 15:04:52 -05:00
|
|
|
def do_exit(self, vns):
|
|
|
|
self.la.export(vns, "test/la.csv")
|
2015-01-23 03:10:14 -05:00
|
|
|
|
2015-01-17 08:17:31 -05:00
|
|
|
default_subtarget = BISTSoC
|