prepare reads grouping to speed up upload

This commit is contained in:
Florent Kermarrec 2015-02-23 17:04:23 +01:00
parent e309ba55ea
commit 71f3a5bf13
3 changed files with 45 additions and 39 deletions

View File

@ -111,8 +111,11 @@ class LiteScopeLADriver():
def upload(self): def upload(self):
if self.debug: if self.debug:
print("uploading") print("uploading")
while self.recorder_source_level.read(): level = self.recorder_source_level.read()
self.data.append(self.recorder_source_data.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.with_rle:
if self.rle_enable.read(): if self.rle_enable.read():
self.data = self.data.decode_rle() self.data = self.data.decode_rle()

View File

@ -9,19 +9,24 @@ class MappedReg:
self.busword = busword self.busword = busword
self.mode = mode self.mode = mode
def read(self): def read(self, repeats=None):
if self.mode not in ["rw", "ro"]: if self.mode not in ["rw", "ro"]:
raise KeyError(name + "register not readable") raise KeyError(name + "register not readable")
datas = self.readfn(self.addr, burst_length=self.length)
if isinstance(datas, int): def to_int(v):
return datas return 1 if v is None else v
else: read_datas = self.readfn(self.addr, burst_length=self.length, repeats=repeats)
datas = []
for i in range(to_int(repeats)):
data = 0 data = 0
for i in range(self.length): for j in range(self.length):
data |= datas[i] data = data << self.busword
if i != (self.length-1): data |= read_datas[i*self.length+j]
data <<= self.busword datas.append(data)
return data if repeats is None:
return datas[0]
else:
return datas
def write(self, value): def write(self, value):
if self.mode not in ["rw", "wo"]: if self.mode not in ["rw", "wo"]:

View File

@ -35,28 +35,27 @@ class LiteScopeUARTDriver:
self.uart.flushOutput() self.uart.flushOutput()
self.uart.close() self.uart.close()
def read(self, addr, burst_length=1): def read(self, addr, burst_length=None, repeats=None):
self.uart.flushInput() datas = []
write_b(self.uart, self.cmds["read"]) def to_int(v):
write_b(self.uart, burst_length) return 1 if v is None else v
addr = addr//4 for i in range(to_int(repeats)):
write_b(self.uart, (addr & 0xff000000) >> 24) self.uart.flushInput()
write_b(self.uart, (addr & 0x00ff0000) >> 16) write_b(self.uart, self.cmds["read"])
write_b(self.uart, (addr & 0x0000ff00) >> 8) write_b(self.uart, burst_length)
write_b(self.uart, (addr & 0x000000ff)) write_b(self.uart, (addr//4 & 0xff000000) >> 24)
values = [] write_b(self.uart, (addr//4 & 0x00ff0000) >> 16)
for i in range(burst_length): write_b(self.uart, (addr//4 & 0x0000ff00) >> 8)
val = 0 write_b(self.uart, (addr//4 & 0x000000ff))
for j in range(4): for j in range(to_int(burst_length)):
val = val << 8 data = 0
val |= ord(self.uart.read()) for k in range(4):
if self.debug: data = data << 8
print("RD %08X @ %08X" %(val, (addr+i)*4)) data |= ord(self.uart.read())
values.append(val) if self.debug:
if burst_length == 1: print("RD %08X @ %08X" %(data, (addr+j)*4))
return values[0] datas.append(data)
else: return datas
return values
def write(self, addr, data): def write(self, addr, data):
if isinstance(data, list): if isinstance(data, list):
@ -65,11 +64,10 @@ class LiteScopeUARTDriver:
burst_length = 1 burst_length = 1
write_b(self.uart, self.cmds["write"]) write_b(self.uart, self.cmds["write"])
write_b(self.uart, burst_length) write_b(self.uart, burst_length)
addr = addr//4 write_b(self.uart, (addr//4 & 0xff000000) >> 24)
write_b(self.uart, (addr & 0xff000000) >> 24) write_b(self.uart, (addr//4 & 0x00ff0000) >> 16)
write_b(self.uart, (addr & 0x00ff0000) >> 16) write_b(self.uart, (addr//4 & 0x0000ff00) >> 8)
write_b(self.uart, (addr & 0x0000ff00) >> 8) write_b(self.uart, (addr//4 & 0x000000ff))
write_b(self.uart, (addr & 0x000000ff))
if isinstance(data, list): if isinstance(data, list):
for i in range(len(data)): for i in range(len(data)):
dat = data[i] dat = data[i]