From: Florent Kermarrec Date: Sat, 2 May 2015 13:25:40 +0000 (+0200) Subject: liteusb/software/wishbone: optimize writes/reads (send a single packet for a command) X-Git-Tag: 24jan2021_ls180~2269 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ff51bde7f061b690e435ecda375fb81aef968dae;p=litex.git liteusb/software/wishbone: optimize writes/reads (send a single packet for a command) --- diff --git a/misoclib/com/liteusb/software/ftdi/__init__.py b/misoclib/com/liteusb/software/ftdi/__init__.py index a9327fe1..17e60b40 100644 --- a/misoclib/com/liteusb/software/ftdi/__init__.py +++ b/misoclib/com/liteusb/software/ftdi/__init__.py @@ -195,8 +195,18 @@ class UART: return -1 return resp - def do_write(self, value): - msg = [0x5A, 0xA5, 0x5A, 0xA5, self.tag, 0x00, 0x00, 0x00, 1, value&0xFF] + def do_write(self, data): + if isinstance(data, int): + data = [data] + msg = [0x5A, 0xA5, 0x5A, 0xA5] + msg.append(self.tag) + length = len(data) + msg.append((length >> 24) & 0xff) + msg.append((length >> 16) & 0xff) + msg.append((length >> 8) & 0xff) + msg.append((length >> 0) & 0xff) + for value in data: + msg.append(value&0xff) self.service.write(bytes(msg)) @@ -339,8 +349,8 @@ class FTDIComDevice: def uartread(self, timeout=None): return self.uart.do_read(timeout) - def uartwrite(self, value): - return self.uart.do_write(value) + def uartwrite(self, data): + return self.uart.do_write(data) def dmaread(self): return self.dma.do_read() diff --git a/misoclib/com/liteusb/software/wishbone.py b/misoclib/com/liteusb/software/wishbone.py index a1a1a637..d8972740 100644 --- a/misoclib/com/liteusb/software/wishbone.py +++ b/misoclib/com/liteusb/software/wishbone.py @@ -24,17 +24,18 @@ class LiteUSBWishboneDriverFTDI: def close(self): self.com.close() - # XXX regroup cmds in a single packet def read(self, addr, burst_length=1): datas = [] + msg = [] self.com.uartflush() - self.com.uartwrite(self.cmds["read"]) - self.com.uartwrite(burst_length) + msg.append(self.cmds["read"]) + msg.append(burst_length) word_addr = addr//4 - self.com.uartwrite((word_addr >> 24) & 0xff) - self.com.uartwrite((word_addr >> 16) & 0xff) - self.com.uartwrite((word_addr >> 8) & 0xff) - self.com.uartwrite((word_addr >> 0) & 0xff) + msg.append((word_addr >> 24) & 0xff) + msg.append((word_addr >> 16) & 0xff) + msg.append((word_addr >> 8) & 0xff) + msg.append((word_addr >> 0) & 0xff) + self.com.uartwrite(msg) for i in range(burst_length): data = 0 for k in range(4): @@ -48,27 +49,28 @@ class LiteUSBWishboneDriverFTDI: else: return datas - # XXX regroup cmds in a single packet def write(self, addr, data): if isinstance(data, list): burst_length = len(data) else: burst_length = 1 data = [data] - self.com.uartwrite(self.cmds["write"]) - self.com.uartwrite(burst_length) + msg = [] + msg.append(self.cmds["write"]) + msg.append(burst_length) word_addr = addr//4 - self.com.uartwrite((word_addr >> 24) & 0xff) - self.com.uartwrite((word_addr >> 16) & 0xff) - self.com.uartwrite((word_addr >> 8) & 0xff) - self.com.uartwrite((word_addr >> 0) & 0xff) + msg.append((word_addr >> 24) & 0xff) + msg.append((word_addr >> 16) & 0xff) + msg.append((word_addr >> 8) & 0xff) + msg.append((word_addr >> 0) & 0xff) for i in range(len(data)): dat = data[i] for j in range(4): - self.com.uartwrite((dat >> 24) & 0xff) + msg.append((dat >> 24) & 0xff) dat = dat << 8 if self.debug: print("WR {:08X} @ {:08X}".format(data[i], addr + 4*i)) + self.com.uartwrite(msg) def LiteUSBWishboneDriver(chip="ft2232h", *args, **kwargs):