1 from liteeth
.common
import *
2 from liteeth
.generic
.depacketizer
import LiteEthDepacketizer
3 from liteeth
.generic
.packetizer
import LiteEthPacketizer
5 class LiteEthUDPDepacketizer(LiteEthDepacketizer
):
7 LiteEthDepacketizer
.__init
__(self
,
8 eth_ipv4_user_description(8),
9 eth_udp_description(8),
13 class LiteEthUDPPacketizer(LiteEthPacketizer
):
15 LiteEthPacketizer
.__init
__(self
,
16 eth_udp_description(8),
17 eth_ipv4_user_description(8),
21 class LiteEthUDPTX(Module
):
22 def __init__(self
, ip_address
):
23 self
.sink
= Sink(eth_udp_user_description(8))
24 self
.source
= Source(eth_ipv4_user_description(8))
26 packetizer
= LiteEthUDPPacketizer()
27 self
.submodules
+= packetizer
29 packetizer
.sink
.stb
.eq(self
.sink
.stb
),
30 packetizer
.sink
.sop
.eq(self
.sink
.sop
),
31 packetizer
.sink
.eop
.eq(self
.sink
.eop
),
32 self
.sink
.ack
.eq(packetizer
.sink
.ack
),
33 packetizer
.sink
.source_port
.eq(self
.sink
.source_port
),
34 packetizer
.sink
.destination_port
.eq(self
.sink
.destination_port
),
35 packetizer
.sink
.length
.eq(self
.sink
.length
+ udp_header_len
),
36 packetizer
.sink
.checksum
.eq(0),
37 packetizer
.sink
.data
.eq(self
.sink
.data
)
39 sink
= packetizer
.source
41 fsm
= FSM(reset_state
="IDLE")
42 self
.submodules
+= fsm
45 If(sink
.stb
& sink
.sop
,
51 Record
.connect(packetizer
.source
, self
.source
),
52 self
.source
.length
.eq(packetizer
.sink
.length
+ ipv4_header_len
),
53 self
.source
.protocol
.eq(udp_protocol
),
54 self
.source
.ip_address
.eq(self
.sink
.ip_address
),
55 If(self
.source
.stb
& self
.source
.eop
& self
.source
.ack
,
60 class LiteEthUDPRX(Module
):
61 def __init__(self
, ip_address
):
62 self
.sink
= Sink(eth_ipv4_user_description(8))
63 self
.source
= source
= Source(eth_udp_user_description(8))
65 depacketizer
= LiteEthUDPDepacketizer()
66 self
.submodules
+= depacketizer
67 self
.comb
+= Record
.connect(self
.sink
, depacketizer
.sink
)
68 sink
= depacketizer
.source
70 fsm
= FSM(reset_state
="IDLE")
71 self
.submodules
+= fsm
74 If(sink
.stb
& sink
.sop
,
80 self
.comb
+= valid
.eq(
82 (self
.sink
.protocol
== udp_protocol
) &
83 (self
.sink
.ip_address
== ip_address
)
94 source
.stb
.eq(sink
.stb
),
95 source
.sop
.eq(sink
.sop
),
96 source
.eop
.eq(sink
.eop
),
97 sink
.ack
.eq(source
.ack
),
98 source
.source_port
.eq(sink
.source_port
),
99 source
.destination_port
.eq(sink
.destination_port
),
100 source
.ip_address
.eq(0),
101 source
.length
.eq(sink
.length
- udp_header_len
),
102 source
.data
.eq(sink
.data
),
103 source
.error
.eq(sink
.error
),
104 If(source
.stb
& source
.eop
& source
.ack
,
110 If(source
.stb
& source
.eop
& source
.ack
,
115 class LiteEthUDP(Module
):
116 def __init__(self
, ip
, ip_address
):
117 self
.submodules
.tx
= LiteEthUDPTX(ip_address
)
118 self
.submodules
.rx
= LiteEthUDPRX(ip_address
)
120 Record
.connect(self
.tx
.source
, ip
.sink
),
121 Record
.connect(ip
.source
, self
.rx
.sink
)
123 self
.sink
, self
.source
= self
.tx
.sink
, self
.rx
.source