soc/tools/remote: allow direct use of comm_udp and some fixes
This commit is contained in:
parent
d59757eb4a
commit
99f2e31b2e
|
@ -2,11 +2,13 @@ import socket
|
||||||
|
|
||||||
from litex.soc.tools.remote.etherbone import EtherbonePacket, EtherboneRecord
|
from litex.soc.tools.remote.etherbone import EtherbonePacket, EtherboneRecord
|
||||||
from litex.soc.tools.remote.etherbone import EtherboneReads, EtherboneWrites
|
from litex.soc.tools.remote.etherbone import EtherboneReads, EtherboneWrites
|
||||||
|
from litex.soc.tools.remote.csr_builder import CSRBuilder
|
||||||
|
|
||||||
|
class CommUDP(CSRBuilder):
|
||||||
class CommUDP:
|
def __init__(self, server="192.168.1.50", port=1234, csr_csv="csr.csv", csr_data_width=32, debug=False):
|
||||||
def __init__(self, host="localhost", port=1234, debug=False):
|
if csr_csv is not None:
|
||||||
self.host = host
|
CSRBuilder.__init__(self, self, csr_csv, csr_data_width)
|
||||||
|
self.server = server
|
||||||
self.port = port
|
self.port = port
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
|
@ -36,21 +38,21 @@ class CommUDP:
|
||||||
packet.encode()
|
packet.encode()
|
||||||
self.tx_socket.sendto(bytes(packet), (self.server, self.port))
|
self.tx_socket.sendto(bytes(packet), (self.server, self.port))
|
||||||
|
|
||||||
data, dummy = self.rx_socket.recvfrom(8192)
|
datas, dummy = self.rx_socket.recvfrom(8192)
|
||||||
packet = EtherbonePacket(datas)
|
packet = EtherbonePacket(datas)
|
||||||
packet.decode()
|
packet.decode()
|
||||||
data = packet.records.pop().writes.get_datas()
|
datas = packet.records.pop().writes.get_datas()
|
||||||
if self.debug:
|
if self.debug:
|
||||||
for i, value in enumerate(data):
|
for i, value in enumerate(datas):
|
||||||
print("RD {:08X} @ {:08X}".format(data, addr + 4*i))
|
print("read {:08x} @ {:08x}".format(value, addr + 4*i))
|
||||||
return data[0] if length is None else data
|
return datas[0] if length is None else datas
|
||||||
|
|
||||||
def write(self, addr, data):
|
def write(self, addr, datas):
|
||||||
data = data if isinstance(data, list) else [data]
|
datas = datas if isinstance(datas, list) else [datas]
|
||||||
length = len(data)
|
length = len(datas)
|
||||||
record = EtherboneRecord()
|
record = EtherboneRecord()
|
||||||
record.writes = EtherboneWrites(base_addr=addr, datas=iter(data))
|
record.writes = EtherboneWrites(base_addr=addr, datas=iter(datas))
|
||||||
record.wcount = len(record.write)
|
record.wcount = len(record.writes)
|
||||||
|
|
||||||
packet = EtherbonePacket()
|
packet = EtherbonePacket()
|
||||||
packet.records = [record]
|
packet.records = [record]
|
||||||
|
@ -58,5 +60,5 @@ class CommUDP:
|
||||||
self.tx_socket.sendto(bytes(packet), (self.server, self.port))
|
self.tx_socket.sendto(bytes(packet), (self.server, self.port))
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
for i, value in enumerate(data):
|
for i, value in enumerate(datas):
|
||||||
print("WR {:08X} @ {:08X}".format(data, addr + 4*i))
|
print("write {:08x} @ {:08x}".format(value, addr + 4*i))
|
||||||
|
|
Loading…
Reference in New Issue