From: Sebastien Bourdeauducq Date: Mon, 1 Apr 2013 20:15:23 +0000 (+0200) Subject: flow: adapt to new Record API X-Git-Tag: 24jan2021_ls180~2099^2~617 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=20bdd424c81178a859351c211b3f4960fa135902;p=litex.git flow: adapt to new Record API --- diff --git a/migen/actorlib/spi.py b/migen/actorlib/spi.py index b831c3ba..7b94fe45 100644 --- a/migen/actorlib/spi.py +++ b/migen/actorlib/spi.py @@ -108,7 +108,7 @@ class Collector(Actor, AutoCSR): self._r_wc.dat_w.eq(self._r_wc.storage - 1), 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), self._r_rd.status.eq(rp.dat_r) diff --git a/migen/actorlib/structuring.py b/migen/actorlib/structuring.py index dbe2204a..0041806d 100644 --- a/migen/actorlib/structuring.py +++ b/migen/actorlib/structuring.py @@ -29,7 +29,7 @@ class Cast(CombinatorialActor): ]) 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): def __init__(self, n, layout_to): @@ -57,7 +57,7 @@ class Unpack(Actor): ] cases = {} 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()) return Fragment(comb, sync) @@ -75,7 +75,7 @@ class Pack(Actor): strobe_all = Signal() cases = {} 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 = [ self.busy.eq(strobe_all), self.endpoints["sink"].ack.eq(~strobe_all | self.endpoints["source"].ack), diff --git a/migen/flow/actor.py b/migen/flow/actor.py index 0b286342..867a5009 100644 --- a/migen/flow/actor.py +++ b/migen/flow/actor.py @@ -163,7 +163,6 @@ class PipelinedActor(BinaryActor): def get_conn_fragment(source, sink): assert isinstance(source, Source) assert isinstance(sink, Sink) - assert sink.token.compatible(source.token) sigs_source = source.token.flatten() sigs_sink = sink.token.flatten() comb = [ diff --git a/migen/flow/network.py b/migen/flow/network.py index ee696294..4f222143 100644 --- a/migen/flow/network.py +++ b/migen/flow/network.py @@ -170,7 +170,7 @@ class DataFlowGraph(MultiDiGraph): other_ep = other.single_sink() else: raise AssertionError - layout = other.token(other_ep).layout() + layout = other.token(other_ep).layout a.parameters["layout"] = layout self.instantiate(a) diff --git a/migen/flow/plumbing.py b/migen/flow/plumbing.py index 04fc5d12..d19abc07 100644 --- a/migen/flow/plumbing.py +++ b/migen/flow/plumbing.py @@ -1,4 +1,5 @@ from migen.fhdl.structure import * +from migen.fhdl.module import Module from migen.flow.actor import * from migen.genlib.record import * 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)))] return Fragment(sync=sync) -class Combinator(Actor): +class Combinator(Module, Actor): def __init__(self, layout, subrecords): - source = Record(layout) - subrecords = [source.subrecord(*subr) for subr in subrecords] - eps = [("sink{0}".format(n), Sink, r) + eps = [("source", Source, layout)] + eps += [("sink"+str(n), Sink, layout_partial(layout, r)) for n, r in enumerate(subrecords)] - ep_source = ("source", Source, source) - eps.append(ep_source) Actor.__init__(self, *eps) - def get_fragment(self): + ### + 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)] - comb = [source.stb.eq(optree("&", [sink.stb for sink in sinks]))] - comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks] - return Fragment(comb) + self.comb += [source.stb.eq(optree("&", [sink.stb for sink in sinks]))] + self.comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks] + self.comb += [source.token.eq(sink.token) for sink in sinks] -class Splitter(Actor): +class Splitter(Module, Actor): def __init__(self, layout, subrecords): - sink = Record(layout) - subr = [] - for s in 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) + eps = [("sink", Sink, layout)] + eps += [("source"+str(n), Source, layout_partial(layout, *r)) + for n, r in enumerate(subrecords)] Actor.__init__(self, *eps) - def get_fragment(self): + ### + sources = [self.endpoints[e] for e in self.sources()] sink = self.endpoints[self.sinks()[0]] + + self.comb += [source.token.eq(sink.token) for source in sources] already_acked = Signal(len(sources)) - sync = [ - If(sink.stb, + self.sync += If(sink.stb, already_acked.eq(already_acked | Cat(*[s.ack for s in sources])), If(sink.ack, already_acked.eq(0)) ) - ] - comb = [ - sink.ack.eq(optree("&", + self.comb += sink.ack.eq(optree("&", [s.ack | already_acked[n] for n, s in enumerate(sources)])) - ] for n, s in enumerate(sources): - comb.append(s.stb.eq(sink.stb & ~already_acked[n])) - return Fragment(comb, sync) + self.comb += s.stb.eq(sink.stb & ~already_acked[n]) # Actors whose layout should be inferred from what their single sink is connected to. layout_sink = {Buffer, Splitter}