Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check subsampling value for overflow. #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions litescope/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ def __init__(self, data_width, depth=16):
]

class _SubSampler(Module, AutoCSR):
def __init__(self, data_width):
def __init__(self, data_width, counter_bits=16):
self.sink = sink = stream.Endpoint(core_layout(data_width))
self.source = source = stream.Endpoint(core_layout(data_width))

self.value = CSRStorage(16)
self.value = CSRStorage(counter_bits)

# # #

value = Signal(16)
value = Signal(counter_bits)
self.specials += MultiReg(self.value.storage, value, "scope")

counter = Signal(16)
counter = Signal(counter_bits)
done = Signal()
self.sync.scope += \
If(source.ready,
Expand Down Expand Up @@ -240,10 +240,11 @@ def __init__(self, data_width, depth):


class LiteScopeAnalyzer(Module, AutoCSR):
def __init__(self, groups, depth, samplerate=1e12, clock_domain="sys", trigger_depth=16, register=False, csr_csv="analyzer.csv"):
self.groups = groups = self.format_groups(groups)
self.depth = depth
self.samplerate = int(samplerate)
def __init__(self, groups, depth, samplerate=1e12, clock_domain="sys", trigger_depth=16, subsampler_bits=16, register=False, csr_csv="analyzer.csv"):
self.groups = groups = self.format_groups(groups)
self.depth = depth
self.samplerate = int(samplerate)
self.subsampler_bits = subsampler_bits

self.data_width = data_width = max([sum([len(s) for s in g]) for g in groups.values()])

Expand Down Expand Up @@ -271,7 +272,7 @@ def __init__(self, groups, depth, samplerate=1e12, clock_domain="sys", trigger_d

# Frontend
self.submodules.trigger = _Trigger(data_width, depth=trigger_depth)
self.submodules.subsampler = _SubSampler(data_width)
self.submodules.subsampler = _SubSampler(data_width, counter_bits=self.subsampler_bits)

# Storage
self.submodules.storage = _Storage(data_width, depth)
Expand Down Expand Up @@ -311,6 +312,7 @@ def format_line(*args):
r = format_line("config", "None", "data_width", str(self.data_width))
r += format_line("config", "None", "depth", str(self.depth))
r += format_line("config", "None", "samplerate", str(self.samplerate))
r += format_line("config", "None", "subsampler_counter_bits", str(self.subsampler_bits))
for i, signals in self.groups.items():
for s in signals:
r += format_line("signal", str(i), vns.get_name(s), str(len(s)))
Expand Down
3 changes: 3 additions & 0 deletions litescope/software/driver/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def configure_trigger(self, value=0, mask=0, cond=None):

def configure_subsampler(self, value):
self.subsampling = value
counter_max = 2**self.subsampler_counter_bits
if self.subsampling > counter_max:
raise ValueError(f"Subsampler counter must be <= {counter_max:,d}")
self.subsampler_value.write(value-1)

def run(self, offset=0, length=None):
Expand Down