udp/crossbar: add possibility to get port with dw != 8 (16, 32, 64, ...)
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 10 Feb 2015 10:22:23 +0000 (11:22 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 10 Feb 2015 10:22:23 +0000 (11:22 +0100)
liteeth/core/ip/crossbar.py
liteeth/core/udp/crossbar.py
liteeth/test/udp_tb.py

index b008130d87d2e9c9f8920f7cdf6a88058fb94cf7..edff815b1e38a19dcb18e717aa4e8ecd16ad0a7d 100644 (file)
@@ -11,9 +11,9 @@ class LiteEthIPV4Crossbar(Module):
                self.master = LiteEthIPV4MasterPort(8)
 
        def get_port(self, protocol):
-               port = LiteEthIPV4UserPort(8)
                if protocol in self.users.keys():
                        raise ValueError("Protocol {0:#x} already assigned".format(protocol))
+               port = LiteEthIPV4UserPort(8)
                self.users[protocol] = port
                return port
 
index f533a67754f0e2de126e0b87657682b0a7291438..ccc7594d6060b91f94cc053ae764c5137663a35d 100644 (file)
@@ -10,12 +10,28 @@ class LiteEthUDPCrossbar(Module):
                self.users = OrderedDict()
                self.master = LiteEthUDPMasterPort(8)
 
-       def get_port(self, udp_port):
-               port = LiteEthUDPUserPort(8)
+       def get_port(self, udp_port, dw=8):
                if udp_port in self.users.keys():
                        raise ValueError("Port {0:#x} already assigned".format(udp_port))
-               self.users[udp_port] = port
-               return port
+               user_port = LiteEthUDPUserPort(dw)
+               internal_port = LiteEthUDPUserPort(8)
+               if dw != 8:
+                       converter = Converter(eth_udp_user_description(user_port.dw), eth_udp_user_description(8))
+                       self.submodules += converter
+                       self.comb += [
+                               Record.connect(user_port.sink, converter.sink),
+                               Record.connect(converter.source, internal_port.sink)
+                       ]
+                       converter = Converter(eth_udp_user_description(8), eth_udp_user_description(user_port.dw))
+                       self.submodules += converter
+                       self.comb += [
+                               Record.connect(internal_port.source, converter.sink),
+                               Record.connect(converter.source, user_port.source)
+                       ]
+                       self.users[udp_port] = internal_port
+               else:
+                       self.users[udp_port] = user_port
+               return user_port
 
        def do_finalize(self):
                # TX arbitrate
index b0274773cd0fb6fa8e8a38c0c719a267a870f525..74811dc7b9a16d00d95b8573a1ad09b1f2997c40 100644 (file)
@@ -13,7 +13,8 @@ ip_address = 0x12345678
 mac_address = 0x12345678abcd
 
 class TB(Module):
-       def __init__(self):
+       def __init__(self, dw=8):
+               self.dw = dw
                self.submodules.phy_model = phy.PHY(8, debug=False)
                self.submodules.mac_model = mac.MAC(self.phy_model, debug=False, loopback=False)
                self.submodules.arp_model = arp.ARP(self.mac_model, mac_address, ip_address, debug=False)
@@ -21,15 +22,15 @@ class TB(Module):
                self.submodules.udp_model = udp.UDP(self.ip_model, ip_address, debug=False, loopback=True)
 
                self.submodules.core = LiteEthUDPIPCore(self.phy_model, mac_address, ip_address, 100000)
-               udp_port = self.core.udp.crossbar.get_port(0x5678)
-               self.submodules.streamer = PacketStreamer(eth_udp_user_description(8))
-               self.submodules.logger = PacketLogger(eth_udp_user_description(8))
+               udp_port = self.core.udp.crossbar.get_port(0x5678, dw)
+               self.submodules.streamer = PacketStreamer(eth_udp_user_description(dw))
+               self.submodules.logger = PacketLogger(eth_udp_user_description(dw))
                self.comb += [
                        Record.connect(self.streamer.source, udp_port.sink),
                        udp_port.sink.ip_address.eq(0x12345678),
                        udp_port.sink.src_port.eq(0x1234),
                        udp_port.sink.dst_port.eq(0x5678),
-                       udp_port.sink.length.eq(64),
+                       udp_port.sink.length.eq(64//(dw//8)),
                        Record.connect(udp_port.source, self.logger.sink)
                ]
 
@@ -54,7 +55,7 @@ class TB(Module):
                        yield
 
                while True:
-                       packet = Packet([i for i in range(64)])
+                       packet = Packet([i for i in range(64//(self.dw//8))])
                        yield from self.streamer.send(packet)
                        yield from self.logger.receive()
 
@@ -64,4 +65,6 @@ class TB(Module):
 
 
 if __name__ == "__main__":
-       run_simulation(TB(), ncycles=2048, vcd_name="my.vcd", keep_files=True)
+       run_simulation(TB(8), ncycles=2048, vcd_name="my.vcd", keep_files=True)
+       run_simulation(TB(16), ncycles=2048, vcd_name="my.vcd", keep_files=True)
+       run_simulation(TB(32), ncycles=2048, vcd_name="my.vcd", keep_files=True)
\ No newline at end of file