From 1a07116ab1ba78a5d1628ffe665bea9476d4744b Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 20 May 2014 13:16:24 +0200 Subject: [PATCH] change export format and simplify usage --- miscope/host/drivers.py | 66 ++++++++++++++++++++++++++--------- miscope/host/uart2wishbone.py | 8 +++++ miscope/host/vcd.py | 1 - miscope/mila.py | 16 +++++++-- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/miscope/host/drivers.py b/miscope/host/drivers.py index efa2e0a06..f6258219d 100644 --- a/miscope/host/drivers.py +++ b/miscope/host/drivers.py @@ -1,5 +1,8 @@ import csv +import time +import sys from miscope.host.vcd import * +from miscope.host.truthtable import * class MiIoDriver(): def __init__(self, regs, name): @@ -20,27 +23,52 @@ class MiIoDriver(): return self.miio_i.read() class MiLaDriver(): - def __init__(self, width, regs, name, config_csv=None, use_rle=True): + def __init__(self, regs, name, csv_name=None, use_rle=True): self.regs = regs self.name = name - self.build_mila() - if csv: - self.build_layout(config_csv) - self.dat = VcdDat(width) self.use_rle = use_rle + if csv_name is None: + self.csv = name + ".csv" + self.get_config() + self.get_layout() + self.build_mila() + self.dat = VcdDat(self.width) + + def get_config(self): + csv_reader = csv.reader(open(self.csv), delimiter=',', quotechar='#') + for item in csv_reader: + t, n, v = item + if t == "config": + setattr(self, n, int(v)) + + def get_layout(self): + self.layout = [] + csv_reader = csv.reader(open(self.csv), delimiter=',', quotechar='#') + for item in csv_reader: + t, n, v = item + if t == "layout": + self.layout.append((n, int(v))) + def build_mila(self): for key, value in self.regs.d.items(): if self.name in key: key.replace(self.name, "mila") setattr(self, key, value) - - def build_layout(self, config_csv): - self.layout = [] - csv_reader = csv.reader(open(config_csv), delimiter=',', quotechar='#') - for item in csv_reader: - name, length = item - self.layout.append((name, int(length))) + value = 1 + for name, length in self.layout: + setattr(self, name+"_o", value) + value = value*(2**length) + value = 0 + for name, length in self.layout: + setattr(self, name+"_m", (2**length-1) << value) + value += length + + def show_state(self, s, last=False): + print(s, end="") + if not last: + print("-->", end="") + sys.stdout.flush() def prog_term(self, port, trigger, mask): t = getattr(self, "mila_trigger_port{d}_trig".format(d=int(port))) @@ -62,7 +90,8 @@ class MiLaDriver(): fm.write(falling_mask) bm.write(both_mask) - def prog_sum(self, datas): + def prog_sum(self, equation): + datas = gen_truth_table(equation) for adr, dat in enumerate(datas): self.mila_trigger_sum_prog_adr.write(adr) self.mila_trigger_sum_prog_dat.write(dat) @@ -77,8 +106,13 @@ class MiLaDriver(): def is_done(self): return self.mila_recorder_done.read() + def wait_done(self): + self.show_state("WAIT") + while(not self.is_done()): + time.sleep(0.1) + def trigger(self, offset, length): - print("T") + self.show_state("TRIG") if self.use_rle: self.enable_rle() self.mila_recorder_offset.write(offset) @@ -86,7 +120,7 @@ class MiLaDriver(): self.mila_recorder_trigger.write(1) def read(self, vcd=None): - print("R") + self.show_state("READ", last=not vcd) empty = self.mila_recorder_read_empty.read() while(not empty): self.dat.append(self.mila_recorder_read_dat.read()) @@ -95,7 +129,7 @@ class MiLaDriver(): if self.use_rle: self.dat = self.dat.decode_rle() if vcd: - print("V") + self.show_state("VCD", last=True) _vcd = Vcd() _vcd.add_from_layout(self.layout, self.dat) _vcd.write(vcd) diff --git a/miscope/host/uart2wishbone.py b/miscope/host/uart2wishbone.py index 8cf29ce0c..ca4e5874f 100644 --- a/miscope/host/uart2wishbone.py +++ b/miscope/host/uart2wishbone.py @@ -22,8 +22,16 @@ class Uart2Wishbone: self.uart.close() self.uart.open() self.uart.flushInput() + try: + wb.regs.uart2wb_sel.write(1) + except: + pass def close(self): + try: + wb.regs.uart2wb_sel.write(0) + except: + pass self.uart.close() def read(self, addr, burst_length=1): diff --git a/miscope/host/vcd.py b/miscope/host/vcd.py index 9b6434970..4b2bad8a4 100644 --- a/miscope/host/vcd.py +++ b/miscope/host/vcd.py @@ -161,7 +161,6 @@ class Vcd: def p_vars(self): r = "" for var in self.vars: - print(var.name) r += "$var " r += var.type r += " " diff --git a/miscope/mila.py b/miscope/mila.py index 805ee10aa..b19837cb3 100644 --- a/miscope/mila.py +++ b/miscope/mila.py @@ -8,6 +8,9 @@ from miscope.storage import Recorder, RunLengthEncoder class MiLa(Module, AutoCSR): def __init__(self, width, depth, ports, with_rle=False): self.width = width + self.depth = depth + self.with_rle = with_rle + self.ports = ports self.sink = rec_dat(width) @@ -30,8 +33,15 @@ class MiLa(Module, AutoCSR): recorder_dat_source = self.rle.source self.comb += recorder_dat_source.connect(recorder.dat_sink) - def get_csv(self, dat): + def get_csv(self, layout): r = "" - for e in dat: - r += e.backtrace[-1][0] + "," + str(flen(e)) + "\n" + def format_line(*args): + return ",".join(args) + "\n" + + r += format_line("config", "width", str(self.width)) + r += format_line("config", "depth", str(self.depth)) + r += format_line("config", "with_rle", str(int(self.with_rle))) + + for e in layout: + r += format_line("layout", e.backtrace[-1][0], str(flen(e))) return r