From c3660379db9640e39456d8ed815c5c6be874ce87 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 26 Nov 2020 09:06:46 +0100 Subject: [PATCH] tools/remote/comm_udp: probe Etherbone server on open(). --- litex/tools/remote/comm_udp.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/litex/tools/remote/comm_udp.py b/litex/tools/remote/comm_udp.py index b64e3e9de..48d4976be 100644 --- a/litex/tools/remote/comm_udp.py +++ b/litex/tools/remote/comm_udp.py @@ -26,6 +26,8 @@ class CommUDP(CSRBuilder): return self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind(("", self.port)) + self.socket.settimeout(1) + self.probe() def close(self): if not hasattr(self, "socket"): @@ -33,6 +35,23 @@ class CommUDP(CSRBuilder): self.socket.close() del self.socket + def probe(self): + # Send probe request to server... + packet = EtherbonePacket() + packet.pf = 1 + packet.encode() + self.socket.sendto(packet.bytes, (self.server, self.port)) + + # ...and get/check server's response. + try: + datas, dummy = self.socket.recvfrom(8192) + packet = EtherbonePacket(datas) + packet.decode() + assert packet.pr == 1 + except: + self.close() + raise Exception(f"Unable to probe Etherbone server at {self.server}.") + def read(self, addr, length=None, burst="incr"): assert burst == "incr" length_int = 1 if length is None else length