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:
parent
2474ce9db2
commit
7f4dc390d9
|
@ -126,7 +126,7 @@ class LiteScopeAnalyzerDriver:
|
||||||
print("")
|
print("")
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def save(self, filename, samplerate=None):
|
def save(self, filename, samplerate=None, flatten=False):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print("[writing to " + filename + "]...")
|
print("[writing to " + filename + "]...")
|
||||||
name, ext = os.path.splitext(filename)
|
name, ext = os.path.splitext(filename)
|
||||||
|
@ -140,7 +140,10 @@ class LiteScopeAnalyzerDriver:
|
||||||
dump = SigrokDump(samplerate=samplerate)
|
dump = SigrokDump(samplerate=samplerate)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
if not flatten:
|
||||||
dump.add_from_layout(self.layouts[self.group], self.data)
|
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)
|
dump.write(filename)
|
||||||
|
|
||||||
def get_instant_value(self, group, name):
|
def get_instant_value(self, group, name):
|
||||||
|
|
|
@ -48,8 +48,8 @@ class DumpData(list):
|
||||||
|
|
||||||
class DumpVariable:
|
class DumpVariable:
|
||||||
def __init__(self, name, width, values=[]):
|
def __init__(self, name, width, values=[]):
|
||||||
self.width = width
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.width = width
|
||||||
self.values = [int(v)%2**width for v in values]
|
self.values = [int(v)%2**width for v in values]
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
@ -64,12 +64,26 @@ class Dump:
|
||||||
self.variables.append(variable)
|
self.variables.append(variable)
|
||||||
|
|
||||||
def add_from_layout(self, layout, variable):
|
def add_from_layout(self, layout, variable):
|
||||||
i = 0
|
offset = 0
|
||||||
for s, n in layout:
|
for name, sample_width in layout:
|
||||||
values = variable[i:i+n]
|
values = variable[offset:offset+sample_width]
|
||||||
values2x = [values[j//2] for j in range(len(values)*2)]
|
values2x = [values[i//2] for i in range(len(values)*2)]
|
||||||
self.add(DumpVariable(s, n, values2x))
|
self.add(DumpVariable(name, sample_width, values2x))
|
||||||
i += n
|
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)))
|
self.add(DumpVariable("scope_clk", 1, [1, 0]*(len(self)//2)))
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
|
Loading…
Reference in New Issue