prepare reads grouping to speed up upload
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 23 Feb 2015 16:04:23 +0000 (17:04 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 23 Feb 2015 17:11:08 +0000 (18:11 +0100)
litescope/host/driver/la.py
litescope/host/driver/reg.py
litescope/host/driver/uart.py

index 5fe0f8b4f0b8def74641c2122e0d3b2d6b86f0c4..4a9677349a43a24aaa1d8ab73afc9db2feb90893 100644 (file)
@@ -111,8 +111,11 @@ class LiteScopeLADriver():
        def upload(self):
                if self.debug:
                        print("uploading")
-               while self.recorder_source_level.read():
-                       self.data.append(self.recorder_source_data.read())
+               level = self.recorder_source_level.read()
+               while level:
+                       length = self.recorder_source_data.length
+                       self.data += self.recorder_source_data.read(repeats=min(128//length, level))
+                       level = self.recorder_source_level.read()
                if self.with_rle:
                        if self.rle_enable.read():
                                self.data = self.data.decode_rle()
index 696a94e2a7e3d44f3808875af261089686cdd83b..61390bcc83f8a6f7caeb001d4f5a2fbab5ff0bb2 100644 (file)
@@ -9,19 +9,24 @@ class MappedReg:
                self.busword = busword
                self.mode = mode
 
-       def read(self):
+       def read(self, repeats=None):
                if self.mode not in ["rw", "ro"]:
                        raise KeyError(name + "register not readable")
-               datas = self.readfn(self.addr, burst_length=self.length)
-               if isinstance(datas, int):
-                       return datas
-               else:
+
+               def to_int(v):
+                       return 1 if v is None else v
+               read_datas = self.readfn(self.addr, burst_length=self.length, repeats=repeats)
+               datas = []
+               for i in range(to_int(repeats)):
                        data = 0
-                       for i in range(self.length):
-                               data |= datas[i]
-                               if i != (self.length-1):
-                                       data <<= self.busword
-                       return data
+                       for j in range(self.length):
+                               data = data << self.busword
+                               data |= read_datas[i*self.length+j]
+                       datas.append(data)
+               if repeats is None:
+                       return datas[0]
+               else:
+                       return datas
 
        def write(self, value):
                if self.mode not in ["rw", "wo"]:
index 4bd8f713d68f947c8e430d972c2826eee3711d61..53ab2cac544362fc50ede3b78c83e1f34dac4194 100644 (file)
@@ -35,28 +35,27 @@ class LiteScopeUARTDriver:
                self.uart.flushOutput()
                self.uart.close()
 
-       def read(self, addr, burst_length=1):
-               self.uart.flushInput()
-               write_b(self.uart, self.cmds["read"])
-               write_b(self.uart, burst_length)
-               addr = addr//4
-               write_b(self.uart, (addr & 0xff000000) >> 24)
-               write_b(self.uart, (addr & 0x00ff0000) >> 16)
-               write_b(self.uart, (addr & 0x0000ff00) >> 8)
-               write_b(self.uart, (addr & 0x000000ff))
-               values = []
-               for i in range(burst_length):
-                       val = 0
-                       for j in range(4):
-                               val = val << 8
-                               val |= ord(self.uart.read())
-                       if self.debug:
-                               print("RD %08X @ %08X" %(val, (addr+i)*4))
-                       values.append(val)
-               if burst_length == 1:
-                       return values[0]
-               else:
-                       return values
+       def read(self, addr, burst_length=None, repeats=None):
+               datas = []
+               def to_int(v):
+                       return 1 if v is None else v
+               for i in range(to_int(repeats)):
+                       self.uart.flushInput()
+                       write_b(self.uart, self.cmds["read"])
+                       write_b(self.uart, burst_length)
+                       write_b(self.uart, (addr//4 & 0xff000000) >> 24)
+                       write_b(self.uart, (addr//4 & 0x00ff0000) >> 16)
+                       write_b(self.uart, (addr//4 & 0x0000ff00) >> 8)
+                       write_b(self.uart, (addr//4 & 0x000000ff))
+                       for j in range(to_int(burst_length)):
+                               data = 0
+                               for k in range(4):
+                                       data = data << 8
+                                       data |= ord(self.uart.read())
+                               if self.debug:
+                                       print("RD %08X @ %08X" %(data, (addr+j)*4))
+                               datas.append(data)
+               return datas
 
        def write(self, addr, data):
                if isinstance(data, list):
@@ -65,11 +64,10 @@ class LiteScopeUARTDriver:
                        burst_length = 1
                write_b(self.uart, self.cmds["write"])
                write_b(self.uart, burst_length)
-               addr = addr//4
-               write_b(self.uart, (addr & 0xff000000) >> 24)
-               write_b(self.uart, (addr & 0x00ff0000) >> 16)
-               write_b(self.uart, (addr & 0x0000ff00) >> 8)
-               write_b(self.uart, (addr & 0x000000ff))
+               write_b(self.uart, (addr//4 & 0xff000000) >> 24)
+               write_b(self.uart, (addr//4 & 0x00ff0000) >> 16)
+               write_b(self.uart, (addr//4 & 0x0000ff00) >> 8)
+               write_b(self.uart, (addr//4 & 0x000000ff))
                if isinstance(data, list):
                        for i in range(len(data)):
                                dat = data[i]