diff --git a/litescope/host/driver/la.py b/litescope/host/driver/la.py index 5fe0f8b4f..4a9677349 100644 --- a/litescope/host/driver/la.py +++ b/litescope/host/driver/la.py @@ -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() diff --git a/litescope/host/driver/reg.py b/litescope/host/driver/reg.py index 696a94e2a..61390bcc8 100644 --- a/litescope/host/driver/reg.py +++ b/litescope/host/driver/reg.py @@ -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"]: diff --git a/litescope/host/driver/uart.py b/litescope/host/driver/uart.py index 4bd8f713d..53ab2cac5 100644 --- a/litescope/host/driver/uart.py +++ b/litescope/host/driver/uart.py @@ -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]