2020-08-23 10:06:55 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteEth.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-06-24 05:43:10 -04:00
|
|
|
|
2015-09-07 07:28:02 -04:00
|
|
|
import math
|
|
|
|
|
2015-11-13 18:42:33 -05:00
|
|
|
from litex.soc.interconnect.stream_sim import *
|
2019-11-22 18:14:19 -05:00
|
|
|
from litex.tools.remote.etherbone import *
|
2015-11-13 18:42:33 -05:00
|
|
|
|
2015-09-08 03:50:45 -04:00
|
|
|
from liteeth.common import *
|
2015-09-07 07:28:02 -04:00
|
|
|
|
2017-01-19 08:33:24 -05:00
|
|
|
from test.model import udp
|
2015-09-07 07:28:02 -04:00
|
|
|
|
2019-11-23 09:16:29 -05:00
|
|
|
# Helpers ------------------------------------------------------------------------------------------
|
2015-09-07 07:28:02 -04:00
|
|
|
|
|
|
|
def print_etherbone(s):
|
|
|
|
print_with_prefix(s, "[ETHERBONE]")
|
|
|
|
|
|
|
|
|
2019-11-23 09:16:29 -05:00
|
|
|
# Etherbone ----------------------------------------------------------------------------------------
|
|
|
|
|
2015-09-07 07:28:02 -04:00
|
|
|
class Etherbone(Module):
|
|
|
|
def __init__(self, udp, debug=False):
|
2019-11-23 09:16:29 -05:00
|
|
|
self.udp = udp
|
2015-09-07 07:28:02 -04:00
|
|
|
self.debug = debug
|
|
|
|
self.tx_packets = []
|
2019-11-23 09:16:29 -05:00
|
|
|
self.tx_packet = EtherbonePacket()
|
|
|
|
self.rx_packet = EtherbonePacket()
|
2015-09-07 07:28:02 -04:00
|
|
|
|
|
|
|
udp.set_etherbone_callback(self.callback)
|
|
|
|
|
|
|
|
def send(self, packet):
|
|
|
|
packet.encode()
|
|
|
|
if self.debug:
|
|
|
|
print_etherbone(">>>>>>>>")
|
|
|
|
print_etherbone(packet)
|
|
|
|
udp_packet = udp.UDPPacket(packet)
|
2019-11-25 05:43:16 -05:00
|
|
|
udp_packet.src_port = 0x1234 # FIXME
|
|
|
|
udp_packet.dst_port = 0x1234 # FIXME
|
2019-11-23 09:16:29 -05:00
|
|
|
udp_packet.length = len(packet)
|
2015-09-07 07:28:02 -04:00
|
|
|
udp_packet.checksum = 0
|
|
|
|
self.udp.send(udp_packet)
|
|
|
|
|
|
|
|
def receive(self):
|
|
|
|
self.rx_packet = EtherbonePacket()
|
|
|
|
while not self.rx_packet.done:
|
|
|
|
yield
|
|
|
|
|
|
|
|
def callback(self, packet):
|
|
|
|
packet = EtherbonePacket(packet)
|
|
|
|
packet.decode()
|
|
|
|
if self.debug:
|
|
|
|
print_etherbone("<<<<<<<<")
|
|
|
|
print_etherbone(packet)
|
|
|
|
self.rx_packet = packet
|
|
|
|
self.rx_packet.done = True
|
|
|
|
self.process(packet)
|
|
|
|
|
|
|
|
def process(self, packet):
|
|
|
|
pass
|