move some functions in drivers and export layout in csv
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 20 May 2014 09:36:10 +0000 (11:36 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 20 May 2014 09:36:10 +0000 (11:36 +0200)
miscope/host/drivers.py
miscope/mila.py

index b3a19ceaf30a277c9dcfcdfc8e70524273593e0c..efa2e0a06e2b0968329690633c271325f2a0821b 100644 (file)
@@ -1,3 +1,5 @@
+import csv
+from miscope.host.vcd import *
 
 class MiIoDriver():
        def __init__(self, regs, name):
@@ -18,16 +20,27 @@ class MiIoDriver():
                return self.miio_i.read()
 
 class MiLaDriver():
-       def __init__(self, regs, name):
+       def __init__(self, width, regs, name, config_csv=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
 
        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)       
+                               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)))
 
        def prog_term(self, port, trigger, mask):
                t = getattr(self, "mila_trigger_port{d}_trig".format(d=int(port)))
@@ -65,15 +78,24 @@ class MiLaDriver():
                return self.mila_recorder_done.read()
 
        def trigger(self, offset, length):
+               print("T")
+               if self.use_rle:
+                       self.enable_rle()
                self.mila_recorder_offset.write(offset)
                self.mila_recorder_length.write(length)
                self.mila_recorder_trigger.write(1)
 
-       def read(self):
-               r = []
+       def read(self, vcd=None):
+               print("R")
                empty = self.mila_recorder_read_empty.read()
                while(not empty):
-                       r.append(self.mila_recorder_read_dat.read())
+                       self.dat.append(self.mila_recorder_read_dat.read())
                        empty = self.mila_recorder_read_empty.read()
                        self.mila_recorder_read_en.write(1)
-               return r
\ No newline at end of file
+               if self.use_rle:
+                       self.dat = self.dat.decode_rle()
+               if vcd:
+                       print("V")
+                       _vcd = Vcd()
+                       _vcd.add_from_layout(self.layout, self.dat)
+                       _vcd.write(vcd)
index e9bb875b3c72cbf0d387269662e4fe51936f6b71..805ee10aab91fa05d2497156ebb6004c582972d1 100644 (file)
@@ -29,3 +29,9 @@ class MiLa(Module, AutoCSR):
                        self.comb += self.sink.connect(self.rle.sink)
                        recorder_dat_source = self.rle.source
                self.comb += recorder_dat_source.connect(recorder.dat_sink)
+
+       def get_csv(self, dat):
+               r = ""
+               for e in dat:
+                       r += e.backtrace[-1][0] + "," + str(flen(e)) + "\n"
+               return r