flow: adapt to new Record API

This commit is contained in:
Sebastien Bourdeauducq 2013-04-01 22:15:23 +02:00
parent 29b468529f
commit 20bdd424c8
5 changed files with 26 additions and 38 deletions

View file

@ -108,7 +108,7 @@ class Collector(Actor, AutoCSR):
self._r_wc.dat_w.eq(self._r_wc.storage - 1), self._r_wc.dat_w.eq(self._r_wc.storage - 1),
wp.adr.eq(self._r_wa.storage), wp.adr.eq(self._r_wa.storage),
wp.dat_w.eq(Cat(*self.token("sink").flatten())), wp.dat_w.eq(self.token("sink").raw_bits()),
rp.adr.eq(self._r_ra.storage), rp.adr.eq(self._r_ra.storage),
self._r_rd.status.eq(rp.dat_r) self._r_rd.status.eq(rp.dat_r)

View file

@ -29,7 +29,7 @@ class Cast(CombinatorialActor):
]) ])
def pack_layout(l, n): def pack_layout(l, n):
return [("chunk{0}".format(i), l) for i in range(n)] return [("chunk"+str(i), l) for i in range(n)]
class Unpack(Actor): class Unpack(Actor):
def __init__(self, n, layout_to): def __init__(self, n, layout_to):
@ -57,7 +57,7 @@ class Unpack(Actor):
] ]
cases = {} cases = {}
for i in range(self.n): for i in range(self.n):
cases[i] = [Cat(*self.token("source").flatten()).eq(Cat(*self.token("sink").subrecord("chunk{0}".format(i)).flatten()))] cases[i] = [self.token("source").raw_bits().eq(getattr(self.token("sink"), "chunk"+str(i)).raw_bits())]
comb.append(Case(mux, cases).makedefault()) comb.append(Case(mux, cases).makedefault())
return Fragment(comb, sync) return Fragment(comb, sync)
@ -75,7 +75,7 @@ class Pack(Actor):
strobe_all = Signal() strobe_all = Signal()
cases = {} cases = {}
for i in range(self.n): for i in range(self.n):
cases[i] = [Cat(*self.token("source").subrecord("chunk{0}".format(i)).flatten()).eq(*self.token("sink").flatten())] cases[i] = [getattr(self.token("source"), "chunk"+str(i)).raw_bits().eq(self.token("sink").raw_bits())]
comb = [ comb = [
self.busy.eq(strobe_all), self.busy.eq(strobe_all),
self.endpoints["sink"].ack.eq(~strobe_all | self.endpoints["source"].ack), self.endpoints["sink"].ack.eq(~strobe_all | self.endpoints["source"].ack),

View file

@ -163,7 +163,6 @@ class PipelinedActor(BinaryActor):
def get_conn_fragment(source, sink): def get_conn_fragment(source, sink):
assert isinstance(source, Source) assert isinstance(source, Source)
assert isinstance(sink, Sink) assert isinstance(sink, Sink)
assert sink.token.compatible(source.token)
sigs_source = source.token.flatten() sigs_source = source.token.flatten()
sigs_sink = sink.token.flatten() sigs_sink = sink.token.flatten()
comb = [ comb = [

View file

@ -170,7 +170,7 @@ class DataFlowGraph(MultiDiGraph):
other_ep = other.single_sink() other_ep = other.single_sink()
else: else:
raise AssertionError raise AssertionError
layout = other.token(other_ep).layout() layout = other.token(other_ep).layout
a.parameters["layout"] = layout a.parameters["layout"] = layout
self.instantiate(a) self.instantiate(a)

View file

@ -1,4 +1,5 @@
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.fhdl.module import Module
from migen.flow.actor import * from migen.flow.actor import *
from migen.genlib.record import * from migen.genlib.record import *
from migen.genlib.misc import optree from migen.genlib.misc import optree
@ -14,57 +15,45 @@ class Buffer(PipelinedActor):
sync = [If(self.pipe_ce, Cat(*sigs_q).eq(Cat(*sigs_d)))] sync = [If(self.pipe_ce, Cat(*sigs_q).eq(Cat(*sigs_d)))]
return Fragment(sync=sync) return Fragment(sync=sync)
class Combinator(Actor): class Combinator(Module, Actor):
def __init__(self, layout, subrecords): def __init__(self, layout, subrecords):
source = Record(layout) eps = [("source", Source, layout)]
subrecords = [source.subrecord(*subr) for subr in subrecords] eps += [("sink"+str(n), Sink, layout_partial(layout, r))
eps = [("sink{0}".format(n), Sink, r)
for n, r in enumerate(subrecords)] for n, r in enumerate(subrecords)]
ep_source = ("source", Source, source)
eps.append(ep_source)
Actor.__init__(self, *eps) Actor.__init__(self, *eps)
def get_fragment(self): ###
source = self.endpoints["source"] source = self.endpoints["source"]
sinks = [self.endpoints["sink{0}".format(n)] sinks = [self.endpoints["sink"+str(n)]
for n in range(len(self.endpoints)-1)] for n in range(len(self.endpoints)-1)]
comb = [source.stb.eq(optree("&", [sink.stb for sink in sinks]))] self.comb += [source.stb.eq(optree("&", [sink.stb for sink in sinks]))]
comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks] self.comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks]
return Fragment(comb) self.comb += [source.token.eq(sink.token) for sink in sinks]
class Splitter(Actor): class Splitter(Module, Actor):
def __init__(self, layout, subrecords): def __init__(self, layout, subrecords):
sink = Record(layout) eps = [("sink", Sink, layout)]
subr = [] eps += [("source"+str(n), Source, layout_partial(layout, *r))
for s in subrecords: for n, r in enumerate(subrecords)]
if s is None:
subr.append(sink)
else:
subr.append(sink.subrecord(*s))
eps = [("source{0}".format(n), Source, r)
for n, r in enumerate(subr)]
ep_sink = ("sink", Sink, sink)
eps.append(ep_sink)
Actor.__init__(self, *eps) Actor.__init__(self, *eps)
def get_fragment(self): ###
sources = [self.endpoints[e] for e in self.sources()] sources = [self.endpoints[e] for e in self.sources()]
sink = self.endpoints[self.sinks()[0]] sink = self.endpoints[self.sinks()[0]]
self.comb += [source.token.eq(sink.token) for source in sources]
already_acked = Signal(len(sources)) already_acked = Signal(len(sources))
sync = [ self.sync += If(sink.stb,
If(sink.stb,
already_acked.eq(already_acked | Cat(*[s.ack for s in sources])), already_acked.eq(already_acked | Cat(*[s.ack for s in sources])),
If(sink.ack, already_acked.eq(0)) If(sink.ack, already_acked.eq(0))
) )
] self.comb += sink.ack.eq(optree("&",
comb = [
sink.ack.eq(optree("&",
[s.ack | already_acked[n] for n, s in enumerate(sources)])) [s.ack | already_acked[n] for n, s in enumerate(sources)]))
]
for n, s in enumerate(sources): for n, s in enumerate(sources):
comb.append(s.stb.eq(sink.stb & ~already_acked[n])) self.comb += s.stb.eq(sink.stb & ~already_acked[n])
return Fragment(comb, sync)
# Actors whose layout should be inferred from what their single sink is connected to. # Actors whose layout should be inferred from what their single sink is connected to.
layout_sink = {Buffer, Splitter} layout_sink = {Buffer, Splitter}