use new implicit submodules collection and Pipeline

This commit is contained in:
Florent Kermarrec 2014-12-19 01:35:18 +01:00
parent a8e1526407
commit 9e14b1b051
16 changed files with 71 additions and 69 deletions

View File

@ -5,8 +5,8 @@ from lib.sata.command import SATACommand
class SATACON(Module): class SATACON(Module):
def __init__(self, phy, sector_size=512, max_count=8): def __init__(self, phy, sector_size=512, max_count=8):
self.submodules.link = SATALink(phy) self.link = SATALink(phy)
self.submodules.transport = SATATransport(self.link) self.transport = SATATransport(self.link)
self.submodules.command = SATACommand(self.transport, sector_size=sector_size, max_count=max_count) self.command = SATACommand(self.transport, sector_size=sector_size, max_count=max_count)
self.sink, self.source = self.command.sink, self.command.source self.sink, self.source = self.command.sink, self.command.source

View File

@ -119,7 +119,7 @@ class SATACommandRX(Module):
### ###
cmd_fifo = SyncFIFO(command_rx_cmd_description(32), 2) # Note: ideally depth=1 cmd_fifo = SyncFIFO(command_rx_cmd_description(32), 2) # Note: ideally depth=1
data_fifo = InsertReset(FIFO(command_rx_data_description(32), sector_size*max_count//4, buffered=True)) data_fifo = InsertReset(SyncFIFO(command_rx_data_description(32), sector_size*max_count//4, buffered=True))
self.submodules += cmd_fifo, data_fifo self.submodules += cmd_fifo, data_fifo
def test_type(name): def test_type(name):
@ -271,8 +271,8 @@ class SATACommand(Module):
def __init__(self, transport, sector_size=512, max_count=4): def __init__(self, transport, sector_size=512, max_count=4):
if max_count*sector_size > 8192: if max_count*sector_size > 8192:
raise ValueError("sector_size * max_count must be <= 8192") raise ValueError("sector_size * max_count must be <= 8192")
self.submodules.tx = SATACommandTX(transport, sector_size) self.tx = SATACommandTX(transport, sector_size)
self.submodules.rx = SATACommandRX(transport, sector_size, max_count) self.rx = SATACommandRX(transport, sector_size, max_count)
self.comb += [ self.comb += [
self.rx.to_tx.connect(self.tx.from_rx), self.rx.to_tx.connect(self.tx.from_rx),
self.tx.to_rx.connect(self.rx.from_tx) self.tx.to_rx.connect(self.rx.from_tx)

View File

@ -4,6 +4,7 @@ from migen.genlib.fsm import *
from migen.genlib.record import * from migen.genlib.record import *
from migen.flow.actor import * from migen.flow.actor import *
from migen.actorlib.fifo import * from migen.actorlib.fifo import *
from migen.actorlib.structuring import Pipeline
# PHY / Link Layers # PHY / Link Layers
primitives = { primitives = {

View File

@ -147,7 +147,7 @@ class SATALinkRX(Module):
) )
# small fifo to manage HOLD # small fifo to manage HOLD
self.submodules.fifo = SyncFIFO(link_description(32), 32) self.fifo = SyncFIFO(link_description(32), 32)
# graph # graph
self.sync += \ self.sync += \
@ -210,7 +210,7 @@ class SATALinkRX(Module):
class SATALink(Module): class SATALink(Module):
def __init__(self, phy): def __init__(self, phy):
self.submodules.tx = SATALinkTX(phy) self.tx = SATALinkTX(phy)
self.submodules.rx = SATALinkRX(phy) self.rx = SATALinkRX(phy)
self.comb += Record.connect(self.rx.to_tx, self.tx.from_rx) self.comb += Record.connect(self.rx.to_tx, self.tx.from_rx)
self.sink, self.source = self.tx.sink, self.rx.source self.sink, self.source = self.tx.sink, self.rx.source

View File

@ -95,7 +95,7 @@ class SATACRC(Module):
### ###
self.submodules.engine = CRCEngine(self.width, self.polynom) self.engine = CRCEngine(self.width, self.polynom)
reg_i = Signal(self.width, reset=self.init) reg_i = Signal(self.width, reset=self.init)
self.sync += reg_i.eq(self.engine.next) self.sync += reg_i.eq(self.engine.next)
self.comb += [ self.comb += [

View File

@ -75,7 +75,7 @@ class SATAScrambler(Module):
### ###
self.submodules.scrambler = Scrambler() self.scrambler = Scrambler()
self.comb += [ self.comb += [
self.scrambler.ce.eq(sink.stb & sink.ack), self.scrambler.ce.eq(sink.stb & sink.ack),
Record.connect(sink, source), Record.connect(sink, source),

View File

@ -8,17 +8,17 @@ class SATAPHY(Module):
if device_family == "k7": if device_family == "k7":
from lib.sata.phy.k7.trx import K7SATAPHYTRX from lib.sata.phy.k7.trx import K7SATAPHYTRX
from lib.sata.phy.k7.crg import K7SATAPHYCRG from lib.sata.phy.k7.crg import K7SATAPHYCRG
self.submodules.trx = K7SATAPHYTRX(pads, speed) self.trx = K7SATAPHYTRX(pads, speed)
self.submodules.crg = K7SATAPHYCRG(pads, self.trx, clk_freq, speed) self.crg = K7SATAPHYCRG(pads, self.trx, clk_freq, speed)
else: else:
raise NotImplementedError(device_family + "device family not implemented") raise NotImplementedError(device_family + "device family not implemented")
# Control # Control
if host: if host:
self.submodules.ctrl = SATAPHYHostCtrl(self.trx, self.crg, clk_freq) self.ctrl = SATAPHYHostCtrl(self.trx, self.crg, clk_freq)
else: else:
self.submodules.ctrl = SATAPHYDeviceCtrl(self.trx, self.crg, clk_freq) self.ctrl = SATAPHYDeviceCtrl(self.trx, self.crg, clk_freq)
# Datapath # Datapath
self.submodules.datapath = SATAPHYDatapath(self.trx, self.ctrl) self.datapath = SATAPHYDatapath(self.trx, self.ctrl)
self.sink, self.source = self.datapath.sink, self.datapath.source self.sink, self.source = self.datapath.sink, self.datapath.source

View File

@ -58,7 +58,7 @@ class SATAPHYDatapathRX(Module):
# due to the convertion ratio of 2, sys_clk need to be > sata_rx/2 # due to the convertion ratio of 2, sys_clk need to be > sata_rx/2
# source destination is always able to accept data (ack always 1) # source destination is always able to accept data (ack always 1)
fifo = AsyncFIFO(phy_description(32), 4) fifo = AsyncFIFO(phy_description(32), 4)
self.submodules.fifo = RenameClockDomains(fifo, {"write": "sata_rx", "read": "sys"}) self.fifo = RenameClockDomains(fifo, {"write": "sata_rx", "read": "sys"})
self.comb += [ self.comb += [
fifo.sink.stb.eq(valid), fifo.sink.stb.eq(valid),
fifo.sink.data.eq(data), fifo.sink.data.eq(data),
@ -80,7 +80,7 @@ class SATAPHYDatapathTX(Module):
# requirements: # requirements:
# source destination is always able to accept data (ack always 1) # source destination is always able to accept data (ack always 1)
fifo = AsyncFIFO(phy_description(32), 4) fifo = AsyncFIFO(phy_description(32), 4)
self.submodules.fifo = RenameClockDomains(fifo, {"write": "sys", "read": "sata_tx"}) self.fifo = RenameClockDomains(fifo, {"write": "sys", "read": "sata_tx"})
self.comb += Record.connect(self.sink, fifo.sink) self.comb += Record.connect(self.sink, fifo.sink)
# 32 to 16 # 32 to 16

View File

@ -7,16 +7,18 @@ from lib.sata.test.common import *
class TB(Module): class TB(Module):
def __init__(self): def __init__(self):
self.submodules.hdd = HDD( self.hdd = HDD(
link_debug=False, link_random_level=0, link_debug=False, link_random_level=0,
transport_debug=False, transport_loopback=False, transport_debug=False, transport_loopback=False,
hdd_debug=True) hdd_debug=True)
self.submodules.controller = SATACON(self.hdd.phy) self.controller = SATACON(self.hdd.phy)
self.submodules.bist = SATABIST() self.bist = SATABIST()
self.comb += [
self.bist.source.connect(self.controller.sink), self.pipeline = Pipeline(
self.controller.source.connect(self.bist.sink) self.bist,
] self.controller,
self.bist
)
def gen_simulation(self, selfp): def gen_simulation(self, selfp):
hdd = self.hdd hdd = self.hdd

View File

@ -61,26 +61,27 @@ class CommandLogger(PacketLogger):
class TB(Module): class TB(Module):
def __init__(self): def __init__(self):
self.submodules.hdd = HDD( self.hdd = HDD(
link_debug=False, link_random_level=50, link_debug=False, link_random_level=50,
transport_debug=False, transport_loopback=False, transport_debug=False, transport_loopback=False,
hdd_debug=True) hdd_debug=True)
self.submodules.link = SATALink(self.hdd.phy) self.link = SATALink(self.hdd.phy)
self.submodules.transport = SATATransport(self.link) self.transport = SATATransport(self.link)
self.submodules.command = SATACommand(self.transport) self.command = SATACommand(self.transport)
self.submodules.streamer = CommandStreamer() self.streamer = CommandStreamer()
streamer_ack_randomizer = AckRandomizer(command_tx_description(32), level=50) self.streamer_randomizer = Randomizer(command_tx_description(32), level=50)
self.submodules += streamer_ack_randomizer
self.submodules.logger = CommandLogger() self.logger = CommandLogger()
logger_ack_randomizer = AckRandomizer(command_rx_description(32), level=50) self.logger_randomizer = Randomizer(command_rx_description(32), level=50)
self.submodules += logger_ack_randomizer
self.comb += [ self.pipeline = Pipeline(
Record.connect(self.streamer.source, streamer_ack_randomizer.sink), self.streamer,
Record.connect(streamer_ack_randomizer.source, self.command.sink), self.streamer_randomizer,
Record.connect(self.command.source, logger_ack_randomizer.sink), self.command,
Record.connect(logger_ack_randomizer.source, self.logger.sink) self.logger_randomizer,
] self.logger
)
def gen_simulation(self, selfp): def gen_simulation(self, selfp):
hdd = self.hdd hdd = self.hdd

View File

@ -7,7 +7,7 @@ from lib.sata.test.common import *
class TB(Module): class TB(Module):
def __init__(self, length, random): def __init__(self, length, random):
self.submodules.crc = SATACRC() self.crc = SATACRC()
self.length = length self.length = length
self.random = random self.random = random

View File

@ -56,8 +56,8 @@ class PHYSink(Module):
class PHYLayer(Module): class PHYLayer(Module):
def __init__(self): def __init__(self):
self.submodules.rx = PHYSink() self.rx = PHYSink()
self.submodules.tx = PHYSource() self.tx = PHYSource()
self.source = self.tx.source self.source = self.tx.source
self.sink = self.rx.sink self.sink = self.rx.sink
@ -440,10 +440,10 @@ class HDD(Module):
hdd_debug=False, hdd_sector_size=512, hdd_debug=False, hdd_sector_size=512,
): ):
### ###
self.submodules.phy = PHYLayer() self.phy = PHYLayer()
self.submodules.link = LinkLayer(self.phy, link_debug, link_random_level) self.link = LinkLayer(self.phy, link_debug, link_random_level)
self.submodules.transport = TransportLayer(self.link, transport_debug, transport_loopback) self.transport = TransportLayer(self.link, transport_debug, transport_loopback)
self.submodules.command = CommandLayer(self.transport) self.command = CommandLayer(self.transport)
self.command.set_hdd(self) self.command.set_hdd(self)

View File

@ -4,8 +4,6 @@ from lib.sata.link import SATALink
from lib.sata.test.common import * from lib.sata.test.common import *
from lib.sata.test.hdd import * from lib.sata.test.hdd import *
from migen.actorlib.structuring import *
class LinkStreamer(PacketStreamer): class LinkStreamer(PacketStreamer):
def __init__(self): def __init__(self):
PacketStreamer.__init__(self, link_description(32), LinkTXPacket) PacketStreamer.__init__(self, link_description(32), LinkTXPacket)

View File

@ -7,7 +7,7 @@ from lib.sata.test.common import *
class TB(Module): class TB(Module):
def __init__(self, length): def __init__(self, length):
self.submodules.scrambler = InsertReset(Scrambler()) self.scrambler = InsertReset(Scrambler())
self.length = length self.length = length
def get_c_values(self, length): def get_c_values(self, length):

View File

@ -231,6 +231,6 @@ class SATATransportRX(Module):
class SATATransport(Module): class SATATransport(Module):
def __init__(self, link): def __init__(self, link):
self.submodules.tx = SATATransportTX(link) self.tx = SATATransportTX(link)
self.submodules.rx = SATATransportRX(link) self.rx = SATATransportRX(link)
self.sink, self.source = self.tx.sink, self.rx.source self.sink, self.source = self.tx.sink, self.rx.source

View File

@ -60,17 +60,17 @@ class UART2WB(Module):
interrupt_map = {} interrupt_map = {}
cpu_type = None cpu_type = None
def __init__(self, platform, clk_freq): def __init__(self, platform, clk_freq):
self.submodules.uart2wb = UART2Wishbone(platform.request("serial"), clk_freq) self.uart2wb = UART2Wishbone(platform.request("serial"), clk_freq)
# CSR bridge 0x00000000 (shadow @0x00000000) # CSR bridge 0x00000000 (shadow @0x00000000)
self.submodules.wishbone2csr = wishbone2csr.WB2CSR(bus_csr=csr.Interface(self.csr_data_width)) self.wishbone2csr = wishbone2csr.WB2CSR(bus_csr=csr.Interface(self.csr_data_width))
self._wb_masters = [self.uart2wb.wishbone] self._wb_masters = [self.uart2wb.wishbone]
self._wb_slaves = [(lambda a: a[23:25] == 0, self.wishbone2csr.wishbone)] self._wb_slaves = [(lambda a: a[23:25] == 0, self.wishbone2csr.wishbone)]
self.cpu_csr_regions = [] # list of (name, origin, busword, csr_list/Memory) self.cpu_csr_regions = [] # list of (name, origin, busword, csr_list/Memory)
# CSR # CSR
self.submodules.identifier = identifier.Identifier(0, int(clk_freq), 0) self.identifier = identifier.Identifier(0, int(clk_freq), 0)
def add_wb_master(self, wbm): def add_wb_master(self, wbm):
if self.finalized: if self.finalized:
@ -90,14 +90,14 @@ class UART2WB(Module):
def do_finalize(self): def do_finalize(self):
# Wishbone # Wishbone
self.submodules.wishbonecon = wishbone.InterconnectShared(self._wb_masters, self.wishbonecon = wishbone.InterconnectShared(self._wb_masters,
self._wb_slaves, register=True) self._wb_slaves, register=True)
# CSR # CSR
self.submodules.csrbankarray = csrgen.BankArray(self, self.csrbankarray = csrgen.BankArray(self,
lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override], lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override],
data_width=self.csr_data_width) data_width=self.csr_data_width)
self.submodules.csrcon = csr.Interconnect(self.wishbone2csr.csr, self.csrbankarray.get_buses()) self.csrcon = csr.Interconnect(self.wishbone2csr.csr, self.csrbankarray.get_buses())
for name, csrs, mapaddr, rmap in self.csrbankarray.banks: for name, csrs, mapaddr, rmap in self.csrbankarray.banks:
self.add_cpu_csr_region(name, 0xe0000000+0x800*mapaddr, flen(rmap.bus.dat_w), csrs) self.add_cpu_csr_region(name, 0xe0000000+0x800*mapaddr, flen(rmap.bus.dat_w), csrs)
for name, memory, mapaddr, mmap in self.csrbankarray.srams: for name, memory, mapaddr, mmap in self.csrbankarray.srams:
@ -109,15 +109,15 @@ class SimDesign(UART2WB):
def __init__(self, platform, export_mila=False): def __init__(self, platform, export_mila=False):
clk_freq = 200*1000000 clk_freq = 200*1000000
UART2WB.__init__(self, platform, clk_freq) UART2WB.__init__(self, platform, clk_freq)
self.submodules.crg = _CRG(platform) self.crg = _CRG(platform)
self.submodules.sata_phy_host = SATAPHY(platform.request("sata_host"), clk_freq, host=True) self.sata_phy_host = SATAPHY(platform.request("sata_host"), clk_freq, host=True)
self.comb += [ self.comb += [
self.sata_phy_host.sink.stb.eq(1), self.sata_phy_host.sink.stb.eq(1),
self.sata_phy_host.sink.data.eq(primitives["SYNC"]), self.sata_phy_host.sink.data.eq(primitives["SYNC"]),
self.sata_phy_host.sink.charisk.eq(0b0001) self.sata_phy_host.sink.charisk.eq(0b0001)
] ]
self.submodules.sata_phy_device = SATAPHY(platform.request("sata_device"), clk_freq, host=False) self.sata_phy_device = SATAPHY(platform.request("sata_device"), clk_freq, host=False)
self.comb += [ self.comb += [
self.sata_phy_device.sink.stb.eq(1), self.sata_phy_device.sink.stb.eq(1),
self.sata_phy_device.sink.data.eq(primitives["SYNC"]), self.sata_phy_device.sink.data.eq(primitives["SYNC"]),
@ -155,8 +155,8 @@ class VeryBasicPHYStim(Module, AutoCSR):
self._tx_primitive = CSRStorage(32) self._tx_primitive = CSRStorage(32)
self._rx_primitive = CSRStatus(32) self._rx_primitive = CSRStatus(32)
self.submodules.cont_inserter = SATACONTInserter(phy_description(32)) self.cont_inserter = SATACONTInserter(phy_description(32))
self.submodules.cont_remover = SATACONTRemover(phy_description(32)) self.cont_remover = SATACONTRemover(phy_description(32))
self.comb += [ self.comb += [
self.cont_inserter.source.connect(phy.sink), self.cont_inserter.source.connect(phy.sink),
phy.source.connect(self.cont_remover.sink) phy.source.connect(self.cont_remover.sink)
@ -185,12 +185,12 @@ class TestDesign(UART2WB, AutoCSR):
def __init__(self, platform, mila=True, export_mila=False): def __init__(self, platform, mila=True, export_mila=False):
clk_freq = 200*1000000 clk_freq = 200*1000000
UART2WB.__init__(self, platform, clk_freq) UART2WB.__init__(self, platform, clk_freq)
self.submodules.crg = _CRG(platform) self.crg = _CRG(platform)
self.submodules.sata_phy = SATAPHY(platform.request("sata_host"), clk_freq, host=True, speed="SATA1") self.sata_phy = SATAPHY(platform.request("sata_host"), clk_freq, host=True, speed="SATA1")
self.submodules.stim = VeryBasicPHYStim(self.sata_phy) self.stim = VeryBasicPHYStim(self.sata_phy)
self.submodules.clock_leds = ClockLeds(platform) self.clock_leds = ClockLeds(platform)
if mila: if mila:
import os import os
@ -231,7 +231,7 @@ class TestDesign(UART2WB, AutoCSR):
self.comb += platform.request("user_led", 2).eq(crg.ready) self.comb += platform.request("user_led", 2).eq(crg.ready)
self.comb += platform.request("user_led", 3).eq(ctrl.ready) self.comb += platform.request("user_led", 3).eq(ctrl.ready)
self.submodules.mila = MiLa(depth=512, dat=Cat(*debug)) self.mila = MiLa(depth=512, dat=Cat(*debug))
self.mila.add_port(Term) self.mila.add_port(Term)
if export_mila: if export_mila: