software/dump: cleanup imports
This commit is contained in:
parent
34e8263572
commit
d316948c87
|
@ -125,16 +125,12 @@ class LiteScopeLADriver():
|
|||
print("saving to " + filename)
|
||||
name, ext = os.path.splitext(filename)
|
||||
if ext == ".vcd":
|
||||
from litescope.software.dump.vcd import VCDDump
|
||||
dump = VCDDump()
|
||||
elif ext == ".csv":
|
||||
from litescope.software.dump.csv import CSVDump
|
||||
dump = CSVDump()
|
||||
elif ext == ".py":
|
||||
from litescope.software.dump.python import PythonDump
|
||||
dump = PythonDump()
|
||||
elif ext == ".sr":
|
||||
from litescope.software.dump.sigrok import SigrokDump
|
||||
if self.samplerate is None:
|
||||
raise ValueError("Unable to automatically retrieve clk_freq, clk_freq parameter required")
|
||||
dump = SigrokDump(samplerate=self.samplerate)
|
||||
|
|
|
@ -1,90 +1,5 @@
|
|||
def dec2bin(d, width=0):
|
||||
if d == "x":
|
||||
return "x"*width
|
||||
elif d == 0:
|
||||
b = "0"
|
||||
else:
|
||||
b = ""
|
||||
while d != 0:
|
||||
b = "01"[d&1] + b
|
||||
d = d >> 1
|
||||
return b.zfill(width)
|
||||
|
||||
|
||||
def get_bits(values, low, high=None):
|
||||
r = []
|
||||
if high is None:
|
||||
high = low + 1
|
||||
for val in values:
|
||||
t = (val >> low) & (2**(high - low) - 1)
|
||||
r.append(t)
|
||||
return r
|
||||
|
||||
|
||||
class DumpData(list):
|
||||
def __init__(self, width):
|
||||
self.width = width
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, int):
|
||||
return get_bits(self, key)
|
||||
elif isinstance(key, slice):
|
||||
if key.start != None:
|
||||
start = key.start
|
||||
else:
|
||||
start = 0
|
||||
if key.stop != None:
|
||||
stop = key.stop
|
||||
else:
|
||||
stop = self.width
|
||||
if stop > self.width:
|
||||
stop = self.width
|
||||
if key.step != None:
|
||||
raise KeyError
|
||||
return get_bits(self, start, stop)
|
||||
else:
|
||||
raise KeyError
|
||||
|
||||
def decode_rle(self):
|
||||
datas = DumpData(self.width - 1)
|
||||
last_data = 0
|
||||
for data in self:
|
||||
rle = data >> (self.width - 1)
|
||||
data = data & (2**(self.width - 1) - 1)
|
||||
if rle:
|
||||
for i in range(data):
|
||||
datas.append(last_data)
|
||||
else:
|
||||
datas.append(data)
|
||||
last_data = data
|
||||
return datas
|
||||
|
||||
|
||||
class DumpVariable:
|
||||
def __init__(self, name, width, values=[]):
|
||||
self.width = width
|
||||
self.name = name
|
||||
self.values = [int(v)%2**width for v in values]
|
||||
|
||||
def __len__(self):
|
||||
return len(self.values)
|
||||
|
||||
|
||||
class Dump:
|
||||
def __init__(self):
|
||||
self.variables = []
|
||||
|
||||
def add(self, variable):
|
||||
self.variables.append(variable)
|
||||
|
||||
def add_from_layout(self, layout, variable):
|
||||
i = 0
|
||||
for s, n in layout:
|
||||
self.add(DumpVariable(s, n, variable[i:i+n]))
|
||||
i += n
|
||||
|
||||
def __len__(self):
|
||||
l = 0
|
||||
for variable in self.variables:
|
||||
l = max(len(variable), l)
|
||||
return l
|
||||
from litescope.software.dump.common import DumpData, DumpVariable, Dump
|
||||
from litescope.software.dump.csv import CSVDump
|
||||
from litescope.software.dump.python import PythonDump
|
||||
from litescope.software.dump.sigrok import SigrokDump
|
||||
from litescope.software.dump.vcd import VCDDump
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
def dec2bin(d, width=0):
|
||||
if d == "x":
|
||||
return "x"*width
|
||||
elif d == 0:
|
||||
b = "0"
|
||||
else:
|
||||
b = ""
|
||||
while d != 0:
|
||||
b = "01"[d&1] + b
|
||||
d = d >> 1
|
||||
return b.zfill(width)
|
||||
|
||||
|
||||
def get_bits(values, low, high=None):
|
||||
r = []
|
||||
if high is None:
|
||||
high = low + 1
|
||||
for val in values:
|
||||
t = (val >> low) & (2**(high - low) - 1)
|
||||
r.append(t)
|
||||
return r
|
||||
|
||||
|
||||
class DumpData(list):
|
||||
def __init__(self, width):
|
||||
self.width = width
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, int):
|
||||
return get_bits(self, key)
|
||||
elif isinstance(key, slice):
|
||||
if key.start != None:
|
||||
start = key.start
|
||||
else:
|
||||
start = 0
|
||||
if key.stop != None:
|
||||
stop = key.stop
|
||||
else:
|
||||
stop = self.width
|
||||
if stop > self.width:
|
||||
stop = self.width
|
||||
if key.step != None:
|
||||
raise KeyError
|
||||
return get_bits(self, start, stop)
|
||||
else:
|
||||
raise KeyError
|
||||
|
||||
def decode_rle(self):
|
||||
datas = DumpData(self.width - 1)
|
||||
last_data = 0
|
||||
for data in self:
|
||||
rle = data >> (self.width - 1)
|
||||
data = data & (2**(self.width - 1) - 1)
|
||||
if rle:
|
||||
for i in range(data):
|
||||
datas.append(last_data)
|
||||
else:
|
||||
datas.append(data)
|
||||
last_data = data
|
||||
return datas
|
||||
|
||||
|
||||
class DumpVariable:
|
||||
def __init__(self, name, width, values=[]):
|
||||
self.width = width
|
||||
self.name = name
|
||||
self.values = [int(v)%2**width for v in values]
|
||||
|
||||
def __len__(self):
|
||||
return len(self.values)
|
||||
|
||||
|
||||
class Dump:
|
||||
def __init__(self):
|
||||
self.variables = []
|
||||
|
||||
def add(self, variable):
|
||||
self.variables.append(variable)
|
||||
|
||||
def add_from_layout(self, layout, variable):
|
||||
i = 0
|
||||
for s, n in layout:
|
||||
self.add(DumpVariable(s, n, variable[i:i+n]))
|
||||
i += n
|
||||
|
||||
def __len__(self):
|
||||
l = 0
|
||||
for variable in self.variables:
|
||||
l = max(len(variable), l)
|
||||
return l
|
|
@ -1,4 +1,4 @@
|
|||
from litescope.software.dump import *
|
||||
from litescope.software.dump.common import Dump, dec2bin
|
||||
|
||||
|
||||
class CSVDump(Dump):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from litescope.software.dump import *
|
||||
from litescope.software.dump.common import Dump
|
||||
|
||||
|
||||
class PythonDump(Dump):
|
||||
|
|
|
@ -5,7 +5,7 @@ import zipfile
|
|||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
from litescope.software.dump import *
|
||||
from litescope.software.dump.common import Dump, DumpVariable
|
||||
|
||||
|
||||
class SigrokDump(Dump):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import datetime
|
||||
from litescope.software.dump import *
|
||||
from litescope.software.dump.common import Dump, dec2bin
|
||||
|
||||
|
||||
class VCDDump(Dump):
|
||||
|
|
|
@ -10,19 +10,15 @@ dump.add(DumpVariable("sinus", 8, [128+128*sin(j/(2*pi*16)) for j in range(1024)
|
|||
dump.add(DumpVariable("cosinus", 8, [128+128*cos(j/(2*pi*16)) for j in range(1024)]))
|
||||
|
||||
print("csv export test")
|
||||
from litescope.software.dump.csv import CSVDump
|
||||
CSVDump(dump).write("dump.csv")
|
||||
|
||||
print("python export test...")
|
||||
from litescope.software.dump.python import PythonDump
|
||||
PythonDump(dump).write("dump.py")
|
||||
|
||||
print("vcd export test...")
|
||||
from litescope.software.dump.vcd import VCDDump
|
||||
VCDDump(dump).write("dump.vcd")
|
||||
|
||||
print("sigrok export/import test...")
|
||||
from litescope.software.dump.sigrok import SigrokDump
|
||||
SigrokDump(dump).write("dump.sr")
|
||||
SigrokDump(dump).read("dump.sr")
|
||||
SigrokDump(dump).write("dump.sr")
|
||||
|
||||
print("vcd export test...")
|
||||
VCDDump(dump).write("dump.vcd")
|
Loading…
Reference in New Issue