tools/litex_client/RemoteClient: Clear socket buffer in case of Timeout.

This commit is contained in:
Florent Kermarrec 2025-01-03 16:37:56 +01:00
parent fc529dcab5
commit b9cc5c58d7
1 changed files with 10 additions and 0 deletions

View File

@ -64,6 +64,15 @@ class RemoteClient(EtherboneIPC, CSRBuilder):
del self.socket del self.socket
self.binded = False self.binded = False
def clear_socket_buffer(self):
try:
while True:
data = self.socket.recv(4096)
if not data:
break
except (TimeoutError, socket.error):
pass
def read(self, addr, length=None, burst="incr"): def read(self, addr, length=None, burst="incr"):
length_int = 1 if length is None else length length_int = 1 if length is None else length
addr_size = self.csr_bus_address_width // 8 addr_size = self.csr_bus_address_width // 8
@ -88,6 +97,7 @@ class RemoteClient(EtherboneIPC, CSRBuilder):
# Handle error by returning default values # Handle error by returning default values
if self.debug: if self.debug:
print("Timeout occurred during read. Returning default values.") print("Timeout occurred during read. Returning default values.")
self.clear_socket_buffer()
return 0 if length is None else [0] * length_int return 0 if length is None else [0] * length_int
packet = EtherbonePacket( packet = EtherbonePacket(