class LiteEthIPStack(Module, AutoCSR):
def __init__(self, phy, mac_address, ip_address):
self.phy = phy
- self.submodules.mac = mac = LiteEthMAC(phy, 8, interface="mac", with_hw_preamble_crc=True)
+ self.submodules.mac = mac = LiteEthMAC(phy, 8, interface="crossbar", with_hw_preamble_crc=True)
self.submodules.arp = arp = LiteEthARP(mac, mac_address, ip_address)
self.submodules.ip = ip = LiteEthIP(mac, ip_address, arp.table)
self.sink, self.source = self.ip.sink, self.ip.source
###
request_timeout = Timeout(512) # XXX fix me 100ms?
request_pending = FlipFlop()
- self.submodules += request_timeout, request_pending
+ request_ip_address = FlipFlop(32, reset=0xffffffff) # XXX add cached_valid?
+ self.submodules += request_timeout, request_pending, request_ip_address
self.comb += [
request_timeout.ce.eq(request_pending.q),
- request_pending.d.eq(1)
+ request_pending.d.eq(1),
+ request_ip_address.d.eq(request.ip_address)
]
# Note: Store only one ip/mac couple, replace this with
If(sink.stb & sink.request,
NextState("SEND_REPLY")
).Elif(sink.stb & sink.reply & request_pending.q,
- NextState("UPDATE_TABLE")
+ NextState("UPDATE_TABLE"),
).Elif(request.stb | (request_pending.q & request_timeout.reached),
NextState("CHECK_TABLE")
)
found = Signal()
fsm.act("CHECK_TABLE",
# XXX: add a live time for cached_mac_address
- If(request.ip_address == cached_ip_address,
+ If(request_ip_address.q == cached_ip_address,
+ request_ip_address.reset.eq(1),
+ NextState("PRESENT_RESPONSE"),
+ ).Elif(request.ip_address == cached_ip_address,
request.ack.eq(request.stb),
- NextState("PRESENT_RESPONSE")
+ NextState("PRESENT_RESPONSE"),
).Else(
+ request_ip_address.ce.eq(1),
NextState("SEND_REQUEST")
)
)
@DecorateModule(InsertReset)
@DecorateModule(InsertCE)
class FlipFlop(Module):
- def __init__(self, **kwargs):
- self.d = Signal(**kwargs)
- self.q = Signal(**kwargs)
+ def __init__(self, *args, **kwargs):
+ self.d = Signal(*args, **kwargs)
+ self.q = Signal(*args, **kwargs)
self.sync += self.q.eq(self.d)
@DecorateModule(InsertReset)
self.grant = Signal()
self.comb += Record.connect(sources[0], sink)
else:
- self.rr = RoundRobin(len(sources))
+ self.submodules.rr = RoundRobin(len(sources))
self.grant = self.rr.grant
cases = {}
for i, source in enumerate(sources):
class LiteEthIPTX(Module):
def __init__(self, ip_address, arp_table):
- self.sink = sink = Sink(eth_ipv4_description(8))
+ self.sink = Sink(eth_ipv4_description(8))
self.source = Source(eth_mac_description(8))
###
packetizer = LiteEthIPV4Packetizer()
self.submodules += packetizer
- source = packetizer.sink
+ self.comb += Record.connect(self.sink, packetizer.sink)
+ sink = packetizer.source
fsm = FSM(reset_state="IDLE")
self.submodules += fsm
)
fsm.act("SEND_MAC_ADDRESS_REQUEST",
arp_table.request.stb.eq(1),
- arp_table.request.ip_address.eq(sink.destination_ip_address),
+ arp_table.request.ip_address.eq(self.sink.destination_ip_address),
If(arp_table.request.stb & arp_table.request.ack,
NextState("WAIT_MAC_ADDRESS_RESPONSE")
)
fsm.act("WAIT_MAC_ADDRESS_RESPONSE",
# XXX add timeout
If(arp_table.response.stb,
+ arp_table.response.ack.eq(1),
# XXX manage failed
NextState("SEND")
)
elif interface == "dma":
raise NotImplementedError
else:
- raise ValueError(inteface + " not supported by LiteEthMac!")
+ raise ValueError(interface + " not supported by LiteEthMac!")
def get_csrs(self):
return self.csrs
yield
selfp.ip.sink.stb = 1
+ selfp.ip.sink.sop = 1
+ selfp.ip.sink.eop = 1
selfp.ip.sink.destination_ip_address = 0x12345678
selfp.ip.sink.source_ip_address = ip_address