2012-01-06 11:24:05 -05:00
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.flow.actor import *
|
|
|
|
from migen.corelogic.record import *
|
|
|
|
from migen.corelogic.misc import optree
|
|
|
|
|
|
|
|
class Buffer(Actor):
|
2012-01-09 09:14:42 -05:00
|
|
|
def __init__(self, layout):
|
2012-01-06 11:24:05 -05:00
|
|
|
Actor.__init__(self,
|
|
|
|
SchedulingModel(SchedulingModel.PIPELINE, 1),
|
2012-01-15 09:09:44 -05:00
|
|
|
("d", Sink, layout), ("q", Source, layout))
|
2012-01-06 11:24:05 -05:00
|
|
|
|
|
|
|
def get_process_fragment(self):
|
2012-01-15 09:09:44 -05:00
|
|
|
sigs_d = self.token("d").flatten()
|
|
|
|
sigs_q = self.token("q").flatten()
|
2012-01-06 18:33:28 -05:00
|
|
|
sync = [If(self.pipe_ce, Cat(*sigs_q).eq(Cat(*sigs_d)))]
|
2012-01-06 11:24:05 -05:00
|
|
|
return Fragment(sync=sync)
|
|
|
|
|
|
|
|
class Combinator(Actor):
|
2012-01-09 09:14:42 -05:00
|
|
|
def __init__(self, layout, *subrecords):
|
2012-01-15 09:09:44 -05:00
|
|
|
source = Record(layout)
|
|
|
|
subrecords = [source.subrecord(*subr) for subr in subrecords]
|
|
|
|
eps = [("sink{0}".format(x[0]), Sink, x[1])
|
|
|
|
for x in zip(range(len(subrecords)), subrecords)]
|
|
|
|
ep_source = ("source", Source, source)
|
|
|
|
eps.append(ep_source)
|
2012-01-06 11:24:05 -05:00
|
|
|
Actor.__init__(self,
|
|
|
|
SchedulingModel(SchedulingModel.COMBINATORIAL),
|
2012-01-15 09:09:44 -05:00
|
|
|
*eps)
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2012-01-10 09:54:51 -05:00
|
|
|
def get_fragment(self):
|
2012-01-15 09:09:44 -05:00
|
|
|
source = self.endpoints["source"]
|
|
|
|
sinks = [self.endpoints["sink{0}".format(n)]
|
|
|
|
for n in range(len(self.endpoints)-1)]
|
2012-01-06 18:33:28 -05:00
|
|
|
comb = [source.stb.eq(optree('&', [sink.stb for sink in sinks]))]
|
|
|
|
comb += [sink.ack.eq(source.ack & source.stb) for sink in sinks]
|
2012-01-06 11:24:05 -05:00
|
|
|
return Fragment(comb)
|
|
|
|
|
|
|
|
class Splitter(Actor):
|
2012-01-09 09:14:42 -05:00
|
|
|
def __init__(self, layout, *subrecords):
|
2012-01-15 09:09:44 -05:00
|
|
|
sink = Record(layout)
|
|
|
|
subrecords = [sink.subrecord(*subr) for subr in subrecords]
|
|
|
|
eps = [("source{0}".format(x[0]), Source, x[1])
|
|
|
|
for x in zip(range(len(subrecords)), subrecords)]
|
|
|
|
ep_sink = ("sink", Sink, sink)
|
|
|
|
eps.append(ep_sink)
|
2012-01-06 11:24:05 -05:00
|
|
|
Actor.__init__(self,
|
|
|
|
SchedulingModel(SchedulingModel.COMBINATORIAL),
|
2012-01-15 09:09:44 -05:00
|
|
|
*eps)
|
2012-01-06 11:24:05 -05:00
|
|
|
|
2012-01-10 09:54:51 -05:00
|
|
|
# TODO def get_fragment(self):
|