mila: simplify usage

This commit is contained in:
Florent Kermarrec 2014-10-10 15:32:36 +02:00
parent d0c9838dca
commit bf95ea6c1c
1 changed files with 34 additions and 15 deletions

View File

@ -9,40 +9,59 @@ from miscope.storage import Recorder, RunLengthEncoder
from mibuild.tools import write_to_file from mibuild.tools import write_to_file
def _getattr_all(l, attr):
it = iter(l)
r = getattr(next(it), attr)
for e in it:
if getattr(e, attr) != r:
raise ValueError
return r
class MiLa(Module, AutoCSR): class MiLa(Module, AutoCSR):
def __init__(self, width, depth, ports, with_rle=False, clk_domain="sys"): def __init__(self, depth, dat, with_rle=False, clk_domain="sys"):
self.width = width
self.depth = depth self.depth = depth
self.with_rle = with_rle self.with_rle = with_rle
self.ports = ports self.clk_domain = clk_domain
self.ports = []
self.width = flen(dat)
self.sink = Record(dat_layout(width)) self.stb = Signal(reset=1)
self.dat = dat
if clk_domain is not "sys": def add_port(self, port_class):
fifo = AsyncFIFO([("dat", width)], 32) port = port_class(self.width)
self.submodules += RenameClockDomains(fifo, {"write": clk_domain, "read": "sys"}) self.ports.append(port)
def do_finalize(self):
if self.clk_domain is not "sys":
fifo = AsyncFIFO([("dat", self.width)], 32)
self.submodules += RenameClockDomains(fifo, {"write": self.clk_domain, "read": "sys"})
self.comb += [ self.comb += [
fifo.sink.stb.eq(self.sink.stb), fifo.sink.stb.eq(self.stb),
fifo.sink.dat.eq(self.sink.dat) fifo.sink.dat.eq(self.dat)
] ]
sink = Record(dat_layout(width)) sink = Record(dat_layout(self.width))
self.comb += [ self.comb += [
sink.stb.eq(fifo.source.stb), sink.stb.eq(fifo.source.stb),
sink.dat.eq(fifo.source.dat), sink.dat.eq(fifo.source.dat),
fifo.source.ack.eq(1) fifo.source.ack.eq(1)
] ]
else: else:
sink = self.sink sink = Record(dat_layout(self.width))
self.comb += [
sink.stb.eq(self.stb),
sink.dat.eq(self.dat)
]
self.submodules.trigger = trigger = Trigger(width, ports) self.submodules.trigger = trigger = Trigger(self.width, self.ports)
self.submodules.recorder = recorder = Recorder(width, depth) self.submodules.recorder = recorder = Recorder(self.width, self.depth)
self.comb += [ self.comb += [
sink.connect(trigger.sink), sink.connect(trigger.sink),
trigger.source.connect(recorder.trig_sink) trigger.source.connect(recorder.trig_sink)
] ]
if with_rle: if self.with_rle:
self.submodules.rle = rle = RunLengthEncoder(width) self.submodules.rle = rle = RunLengthEncoder(self.width)
self.comb += [ self.comb += [
sink.connect(rle.sink), sink.connect(rle.sink),
rle.source.connect(recorder.dat_sink) rle.source.connect(recorder.dat_sink)