Skip to content

Commit

Permalink
tools/litex_server, tools/remote/comm_udp: fix Etherbonexx constructo…
Browse files Browse the repository at this point in the history
…rs by passing addr_width/add_size
  • Loading branch information
trabucayre committed Nov 9, 2023
1 parent 4610713 commit 1ab8563
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion litex/tools/litex_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def main():
assert len(udp_ip) == 4
udp_ip[3] = "x"
udp_ip = ".".join(udp_ip)
comm = CommUDP(udp_ip, udp_port, debug=args.debug)
comm = CommUDP(udp_ip, udp_port, debug=args.debug, addr_width=int(args.addr_width))
comm.open(probe=False)
comm.scan(udp_ip)
comm.close()
Expand Down
21 changes: 11 additions & 10 deletions litex/tools/remote/comm_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
# CommUDP ------------------------------------------------------------------------------------------

class CommUDP(CSRBuilder):
def __init__(self, server="192.168.1.50", port=1234, csr_csv=None, debug=False, timeout=1.0):
def __init__(self, server="192.168.1.50", port=1234, csr_csv=None, debug=False, timeout=1.0, addr_width=32):
CSRBuilder.__init__(self, comm=self, csr_csv=csr_csv)
self.server = server
self.port = port
self.debug = debug
self.timeout= timeout
self.read_counter = 0
self.addr_width = addr_width

def open(self, probe=True):
if hasattr(self, "socket"):
Expand All @@ -41,7 +42,7 @@ def close(self):

def probe(self, ip, port, loose=False):

packet = EtherbonePacket()
packet = EtherbonePacket(self.addr_width)
packet.pf = 1
packet.encode()
packet.bytes += bytes([0x00, 0x00, 0x00, 0x00]) # Add Padding as payload.
Expand All @@ -66,7 +67,7 @@ def probe(self, ip, port, loose=False):
raise Exception(f"Unable to probe Etherbone server at {self.server}.")

if datas is not None:
packet = EtherbonePacket(datas)
packet = EtherbonePacket(self.addr_width, datas)
packet.decode()
assert packet.pr == 1
return 1
Expand All @@ -89,12 +90,12 @@ def read(self, addr, length=None, burst="incr"):
for r in range(retries):
self.read_counter += 1

record = EtherboneRecord()
record.reads = EtherboneReads(addrs=[addr+4*j for j in range(length_int)])
record = EtherboneRecord(addr_size=self.addr_width//8)
record.reads = EtherboneReads(addr_size=self.addr_width//8, addrs=[addr+4*j for j in range(length_int)])
record.rcount = len(record.reads)
record.reads.base_ret_addr = self.read_counter

packet = EtherbonePacket()
packet = EtherbonePacket(addr_width=self.addr_width)
packet.records = [record]
packet.encode()

Expand All @@ -110,7 +111,7 @@ def read(self, addr, length=None, burst="incr"):
timed_out = True
break

packet = EtherbonePacket(datas)
packet = EtherbonePacket(self.addr_width, datas)
packet.decode()
record = packet.records.pop()
datas = record.writes.get_datas()
Expand All @@ -135,11 +136,11 @@ def read(self, addr, length=None, burst="incr"):
def write(self, addr, datas):
datas = datas if isinstance(datas, list) else [datas]
length = len(datas)
record = EtherboneRecord()
record.writes = EtherboneWrites(base_addr=addr, datas=iter(datas))
record = EtherboneRecord(addr_size=self.addr_width//8)
record.writes = EtherboneWrites(addr_size=self.addr_width//8, base_addr=addr, datas=iter(datas))
record.wcount = len(record.writes)

packet = EtherbonePacket()
packet = EtherbonePacket(self.addr_width)
packet.records = [record]
packet.encode()

Expand Down

0 comments on commit 1ab8563

Please sign in to comment.