soc/tools/remote: small cleanup and remove csr_data_width from server side
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 17 Nov 2015 10:11:50 +0000 (11:11 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 17 Nov 2015 10:35:22 +0000 (11:35 +0100)
litex/soc/tools/remote/client.py
litex/soc/tools/remote/comm_uart.py
litex/soc/tools/remote/server.py

index 2c1e64d1643ac8c2dd21d8e5c6d13c4cb5acca98..92510c1ce51014ea87e04f3c4c10eb6c1c603164 100644 (file)
@@ -25,10 +25,11 @@ class RemoteClient(EtherboneIPC, CSRBuilder):
         self.socket.close()
         del self.socket
 
-    def read(self, addr, length=1):
+    def read(self, addr, length=None):
+        length_int = 1 if length is None else length
         # prepare packet
         record = EtherboneRecord()
-        record.reads = EtherboneReads(addrs=[addr + 4*j for j in range(length)])
+        record.reads = EtherboneReads(addrs=[addr + 4*j for j in range(length_int)])
         record.rcount = len(record.reads)
 
         # send packet
@@ -44,14 +45,10 @@ class RemoteClient(EtherboneIPC, CSRBuilder):
         if self.debug:
             for i, data in enumerate(datas):
                 print("read {:08x} @ {:08x}".format(data, addr + 4*i))
-        if length == 1:
-            return datas[0]
-        else:
-            return datas
+        return datas[0] if length is None else datas
 
     def write(self, addr, datas):
-        if not isinstance(datas, list):
-            datas = [datas]
+        datas = datas if isinstance(datas, list) else [datas]
         record = EtherboneRecord()
         record.writes = EtherboneWrites(base_addr=addr, datas=[d for d in datas])
         record.wcount = len(record.writes)
index 5845d102aae294cd9a9d673792e352d947f0e11e..06dea93dd1128a6848f1372bce1056b591090961 100644 (file)
@@ -10,12 +10,10 @@ class CommUART:
     def __init__(self, port, baudrate=115200, debug=False):
         self.port = port
         self.baudrate = str(baudrate)
-        self.csr_data_width = None
         self.debug = debug
         self.port = serial.serial_for_url(port, baudrate)
 
-    def open(self, csr_data_width):
-        self.csr_data_width = csr_data_width
+    def open(self):
         if hasattr(self, "port"):
             return
         self.port.open()
@@ -40,25 +38,25 @@ class CommUART:
             pos += written
 
     def read(self, addr, length=None):
-        r = []
+        data = []
         length_int = 1 if length is None else length
         self._write([self.msg_type["read"], length_int])
         self._write(list((addr//4).to_bytes(4, byteorder="big")))
         for i in range(length_int):
-            data = int.from_bytes(self._read(4), "big")
+            value = int.from_bytes(self._read(4), "big")
             if self.debug:
                 print("read {:08x} @ {:08x}".format(data, addr + 4*i))
             if length is None:
-                return data
-            r.append(data)
-        return r
+                return value
+            data.append(value)
+        return data
 
     def write(self, addr, data):
         data = data if isinstance(data, list) else [data]
         length = len(data)
         self._write([self.msg_type["write"], length])
         self._write(list((addr//4).to_bytes(4, byteorder="big")))
-        for i in range(len(data)):
-            self._write(list(data[i].to_bytes(4, byteorder="big")))
+        for i, value in enumerate(range(data)):
+            self._write(list(value.to_bytes(4, byteorder="big")))
             if self.debug:
-                print("write {:08x} @ {:08x}".format(data[i], addr + 4*i))
+                print("write {:08x} @ {:08x}".format(value, addr + 4*i))
index 5f6bb99f6fb223108562541fff0b2dd2392e2909..bccae1d53cc1f7893257eb132b2d16f413589209 100644 (file)
@@ -7,10 +7,9 @@ from litex.soc.tools.remote.etherbone import EtherboneIPC
 
 
 class RemoteServer(EtherboneIPC):
-    def __init__(self, comm, port=1234, csr_data_width=32):
+    def __init__(self, comm, port=1234):
         self.comm = comm
         self.port = port
-        self.csr_data_width = 32
 
     def open(self):
         if hasattr(self, "socket"):
@@ -18,7 +17,7 @@ class RemoteServer(EtherboneIPC):
         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.socket.bind(("localhost", self.port))
         self.socket.listen(1)
-        self.comm.open(self.csr_data_width)
+        self.comm.open()
 
     def close(self):
         self.comm.close()
@@ -78,7 +77,6 @@ def _get_args():
     parser.add_argument("--comm", default="uart", help="comm interface")
     parser.add_argument("--port", default="2", help="UART port")
     parser.add_argument("--baudrate", default=115200, help="UART baudrate")
-    parser.add_argument("--csr_data_width", default=32, help="CSR data_width")
     return parser.parse_args()
 
 def main():
@@ -92,7 +90,7 @@ def main():
     else:
         raise NotImplementedError
 
-    server = RemoteServer(comm, csr_data_width=args.csr_data_width)
+    server = RemoteServer(comm)
     server.open()
     server.start()
     try: