Add functionality to flatten values that are sampled using a serdes.

This code add some functionality to flatten the values back from
the serial to parallel conversion that happens when sampling
using the serdes.
This commit is contained in:
kees.jongenburger 2019-06-14 16:57:33 +02:00
parent 2474ce9db2
commit 7f4dc390d9
2 changed files with 26 additions and 9 deletions

View File

@ -126,7 +126,7 @@ class LiteScopeAnalyzerDriver:
print("")
return self.data
def save(self, filename, samplerate=None):
def save(self, filename, samplerate=None, flatten=False):
if self.debug:
print("[writing to " + filename + "]...")
name, ext = os.path.splitext(filename)
@ -140,7 +140,10 @@ class LiteScopeAnalyzerDriver:
dump = SigrokDump(samplerate=samplerate)
else:
raise NotImplementedError
dump.add_from_layout(self.layouts[self.group], self.data)
if not flatten:
dump.add_from_layout(self.layouts[self.group], self.data)
else:
dump.add_from_layout_flatten(self.layouts[self.group], self.data)
dump.write(filename)
def get_instant_value(self, group, name):

View File

@ -48,8 +48,8 @@ class DumpData(list):
class DumpVariable:
def __init__(self, name, width, values=[]):
self.width = width
self.name = name
self.width = width
self.values = [int(v)%2**width for v in values]
def __len__(self):
@ -64,12 +64,26 @@ class Dump:
self.variables.append(variable)
def add_from_layout(self, layout, variable):
i = 0
for s, n in layout:
values = variable[i:i+n]
values2x = [values[j//2] for j in range(len(values)*2)]
self.add(DumpVariable(s, n, values2x))
i += n
offset = 0
for name, sample_width in layout:
values = variable[offset:offset+sample_width]
values2x = [values[i//2] for i in range(len(values)*2)]
self.add(DumpVariable(name, sample_width, values2x))
offset += sample_width
self.add(DumpVariable("scope_clk", 1, [1, 0]*(len(self)//2)))
def add_from_layout_flatten(self, layout, variable):
offset = 0
for name, sample_width in layout:
# The samples from the logic analyzer end up in an array of size sample size
# and have n (number of channel) bits. The following does a bit slice on the array
# elements (implemented above)
values = variable[offset:offset+sample_width]
values_flatten = [values[i//sample_width] >> (i % sample_width ) & 1 for i in range(len(values)*sample_width)]
self.add(DumpVariable(name, 1, values_flatten))
offset += sample_width
# the clock.. might need some more love here. the clock pattern probably should be sample_width wide
# e.g. 11110000 and not 10101010
self.add(DumpVariable("scope_clk", 1, [1, 0]*(len(self)//2)))
def __len__(self):