host/driver: simplify

This commit is contained in:
Florent Kermarrec 2015-01-25 16:13:06 +01:00
parent 4472dac603
commit a3dae5fc5c
2 changed files with 33 additions and 37 deletions

View File

@ -112,10 +112,11 @@ class LiteScopeIODriver():
return self.i.read() return self.i.read()
class LiteScopeLADriver(): class LiteScopeLADriver():
def __init__(self, regs, name, config_csv=None, use_rle=False): def __init__(self, regs, name, config_csv=None, use_rle=False, debug=False):
self.regs = regs self.regs = regs
self.name = name self.name = name
self.use_rle = use_rle self.use_rle = use_rle
self.debug = debug
if config_csv is None: if config_csv is None:
self.config_csv = name + ".csv" self.config_csv = name + ".csv"
self.get_config() self.get_config()
@ -152,11 +153,7 @@ class LiteScopeLADriver():
setattr(self, name + "_m", (2**length-1) << value) setattr(self, name + "_m", (2**length-1) << value)
value += length value += length
def show_state(self, s): def configure_term(self, port, trigger=0, mask=0, cond=None):
print(s, end="|")
sys.stdout.flush()
def prog_term(self, port, trigger=0, mask=0, cond=None):
if cond is not None: if cond is not None:
for k, v in cond.items(): for k, v in cond.items():
trigger |= getattr(self, k + "_o")*v trigger |= getattr(self, k + "_o")*v
@ -166,13 +163,13 @@ class LiteScopeLADriver():
t.write(trigger) t.write(trigger)
m.write(mask) m.write(mask)
def prog_range_detector(self, port, low, high): def configure_range_detector(self, port, low, high):
l = getattr(self, "trigger_port{d}_low".format(d=int(port))) l = getattr(self, "trigger_port{d}_low".format(d=int(port)))
h = getattr(self, "trigger_port{d}_high".format(d=int(port))) h = getattr(self, "trigger_port{d}_high".format(d=int(port)))
l.write(low) l.write(low)
h.write(high) h.write(high)
def prog_edge_detector(self, port, rising_mask, falling_mask, both_mask): def configure_edge_detector(self, port, rising_mask, falling_mask, both_mask):
rm = getattr(self, "trigger_port{d}_rising_mask".format(d=int(port))) rm = getattr(self, "trigger_port{d}_rising_mask".format(d=int(port)))
fm = getattr(self, "trigger_port{d}_falling_mask".format(d=int(port))) fm = getattr(self, "trigger_port{d}_falling_mask".format(d=int(port)))
bm = getattr(self, "trigger_port{d}_both_mask".format(d=int(port))) bm = getattr(self, "trigger_port{d}_both_mask".format(d=int(port)))
@ -180,34 +177,31 @@ class LiteScopeLADriver():
fm.write(falling_mask) fm.write(falling_mask)
bm.write(both_mask) bm.write(both_mask)
def prog_sum(self, equation): def configure_sum(self, equation):
datas = gen_truth_table(equation) datas = gen_truth_table(equation)
for adr, dat in enumerate(datas): for adr, dat in enumerate(datas):
self.trigger_sum_prog_adr.write(adr) self.trigger_sum_prog_adr.write(adr)
self.trigger_sum_prog_dat.write(dat) self.trigger_sum_prog_dat.write(dat)
self.trigger_sum_prog_we.write(1) self.trigger_sum_prog_we.write(1)
def config_rle(self, v): def set_rle(self, v):
self.rle_enable.write(v) self.rle_enable.write(v)
def is_done(self): def done(self):
return self.recorder_done.read() return self.recorder_done.read()
def wait_done(self): def run(self, offset, length):
self.show_state("WAIT HIT") if self.debug:
while(not self.is_done()): print("run")
time.sleep(0.1)
def trigger(self, offset, length):
self.show_state("TRIG")
if self.with_rle: if self.with_rle:
self.config_rle(self.use_rle) self.config_rle(self.use_rle)
self.recorder_offset.write(offset) self.recorder_offset.write(offset)
self.recorder_length.write(length) self.recorder_length.write(length)
self.recorder_trigger.write(1) self.recorder_trigger.write(1)
def read(self): def upload(self):
self.show_state("READ") if self.debug:
print("upload")
while self.recorder_source_stb.read(): while self.recorder_source_stb.read():
self.dat.append(self.recorder_source_data.read()) self.dat.append(self.recorder_source_data.read())
self.recorder_source_ack.write(1) self.recorder_source_ack.write(1)
@ -216,15 +210,16 @@ class LiteScopeLADriver():
self.dat = self.dat.decode_rle() self.dat = self.dat.decode_rle()
return self.dat return self.dat
def export(self, export_fn=None): def save(self, filename):
self.show_state("EXPORT") if self.debug:
print("save to " + filename)
dump = Dump() dump = Dump()
dump.add_from_layout(self.layout, self.dat) dump.add_from_layout(self.layout, self.dat)
if ".vcd" in export_fn: if ".vcd" in filename:
VCDExport(dump).write(export_fn) VCDExport(dump).write(filename)
elif ".csv" in export_fn: elif ".csv" in filename:
CSVExport(dump).write(export_fn) CSVExport(dump).write(filename)
elif ".py" in export_fn: elif ".py" in filename:
PYExport(dump).write(export_fn) PYExport(dump).write(filename)
else: else:
raise NotImplementedError raise NotImplementedError

View File

@ -3,18 +3,19 @@ from litescope.host.driver import LiteScopeLADriver
wb.open() wb.open()
### ###
la = LiteScopeLADriver(wb.regs, "la") la = LiteScopeLADriver(wb.regs, "la", debug=True)
cond = {"cnt0" : 128} # trigger on cnt0 = 128 cond = {"cnt0" : 128} # trigger on cnt0 = 128
la.prog_term(port=0, cond=cond) la.configure_term(port=0, cond=cond)
la.prog_sum("term") la.configure_sum("term")
la.trigger(offset=128, length=256) la.run(offset=128, length=256)
la.wait_done() while not la.done():
la.read() pass
la.upload()
la.export("dump.vcd") la.save("dump.vcd")
la.export("dump.csv") la.save("dump.csv")
la.export("dump.py") la.save("dump.py")
### ###
wb.close() wb.close()