litex/litescope/frontend/la.py

67 lines
2.3 KiB
Python
Raw Normal View History

from litescope.common import *
from litescope.core.trigger import LiteScopeTrigger
from litescope.core.storage import LiteScopeRecorder, LiteScopeRunLengthEncoder
2013-09-22 07:28:12 -04:00
2014-10-01 04:06:59 -04:00
from mibuild.tools import write_to_file
class LiteScopeLA(Module, AutoCSR):
def __init__(self, layout, depth, clk_domain="sys", input_buffer=False, with_rle=False):
self.layout = layout
self.data = Cat(*layout)
self.dw = flen(self.data)
self.depth = depth
self.with_rle = with_rle
2014-10-10 09:32:36 -04:00
self.clk_domain = clk_domain
self.input_buffer = input_buffer
2014-10-10 09:32:36 -04:00
self.sink = Sink(data_layout(self.dw))
self.comb += [
self.sink.stb.eq(1),
self.sink.data.eq(self.data)
]
2013-09-22 07:28:12 -04:00
self.submodules.trigger = trigger = LiteScopeTrigger(self.dw)
self.submodules.recorder = recorder = LiteScopeRecorder(self.dw, self.depth)
2013-09-22 12:41:44 -04:00
2014-10-10 09:32:36 -04:00
def do_finalize(self):
# insert Buffer on sink (optional, can be used to improve timings)
if self.input_buffer:
self.submodules.buffer = Buffer(self.sink.description)
self.comb += Record.connect(self.sink, self.buffer.sink)
self.sink = self.buffer.source
2014-10-28 15:53:26 -04:00
# clock domain crossing (optional, required when capture_clk is not sys_clk)
# XXX : sys_clk must be faster than capture_clk, add Converter on data to remove this limitation
2014-10-10 09:32:36 -04:00
if self.clk_domain is not "sys":
self.submodules.fifo = AsyncFIFO(self.sink.description, 32)
self.submodules += RenameClockDomains(self.fifo, {"write": self.clk_domain, "read": "sys"})
self.comb += Record.connect(self.sink, self.fifo.sink)
self.sink = self.fifo.source
# connect everything
2013-09-22 12:41:44 -04:00
self.comb += [
self.trigger.sink.stb.eq(self.sink.stb),
self.trigger.sink.data.eq(self.sink.data),
Record.connect(self.trigger.source, self.recorder.trigger_sink)
2013-02-22 08:28:05 -05:00
]
2014-10-10 09:32:36 -04:00
if self.with_rle:
rle = LiteScopeRunLengthEncoder(self.dw)
self.submodules += rle
2014-09-24 16:09:11 -04:00
self.comb += [
Record.connect(self.sink, rle.sink),
Record.connect(rle.source, self.recorder.data_sink)
2014-09-24 16:09:11 -04:00
]
else:
self.comb += Record.connect(self.sink, self.recorder.data_sink)
def export(self, vns, filename):
def format_line(*args):
return ",".join(args) + "\n"
r = ""
r += format_line("config", "dw", str(self.dw))
r += format_line("config", "depth", str(self.depth))
r += format_line("config", "with_rle", str(int(self.with_rle)))
for e in self.layout:
r += format_line("layout", vns.get_name(e), str(flen(e)))
2014-10-01 04:06:59 -04:00
write_to_file(filename, r)