host/driver/reg: use burst mode to speed up upload of data (useful with Etherbone)
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 22 Feb 2015 23:09:31 +0000 (00:09 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Sun, 22 Feb 2015 23:49:59 +0000 (00:49 +0100)
litescope/host/driver/reg.py

index 16a98d91a9eef0031e1b6df7df1acad4d81ec809..696a94e2a7e3d44f3808875af261089686cdd83b 100644 (file)
@@ -12,19 +12,24 @@ class MappedReg:
        def read(self):
                if self.mode not in ["rw", "ro"]:
                        raise KeyError(name + "register not readable")
-               r = 0
-               for i in range(self.length):
-                       r |= self.readfn(self.addr + 4*i)
-                       if i != (self.length-1):
-                               r <<= self.busword
-               return r
+               datas = self.readfn(self.addr, burst_length=self.length)
+               if isinstance(datas, int):
+                       return datas
+               else:
+                       data = 0
+                       for i in range(self.length):
+                               data |= datas[i]
+                               if i != (self.length-1):
+                                       data <<= self.busword
+                       return data
 
        def write(self, value):
                if self.mode not in ["rw", "wo"]:
                        raise KeyError(name + "register not writable")
+               datas = []
                for i in range(self.length):
-                       dat = (value >> ((self.length-1-i)*self.busword)) & (2**self.busword-1)
-                       self.writefn(self.addr + 4*i, dat)
+                       datas.append((value >> ((self.length-1-i)*self.busword)) & (2**self.busword-1))
+               self.writefn(self.addr, datas)
 
 class MappedRegs:
        def __init__(self, d):