2015-02-26 03:41:47 -05:00
|
|
|
from misoclib.liteeth.common import *
|
|
|
|
from misoclib.liteeth.test.common import *
|
2015-01-28 04:25:33 -05:00
|
|
|
|
2015-01-28 14:44:41 -05:00
|
|
|
def print_phy(s):
|
|
|
|
print_with_prefix(s, "[PHY]")
|
|
|
|
|
2015-01-28 04:25:33 -05:00
|
|
|
# PHY model
|
|
|
|
class PHYSource(PacketStreamer):
|
|
|
|
def __init__(self, dw):
|
|
|
|
PacketStreamer.__init__(self, eth_phy_description(dw))
|
|
|
|
|
|
|
|
class PHYSink(PacketLogger):
|
|
|
|
def __init__(self, dw):
|
|
|
|
PacketLogger.__init__(self, eth_phy_description(dw))
|
|
|
|
|
|
|
|
class PHY(Module):
|
2015-01-28 14:44:41 -05:00
|
|
|
def __init__(self, dw, debug=False):
|
2015-01-28 04:25:33 -05:00
|
|
|
self.dw = dw
|
|
|
|
self.debug = debug
|
|
|
|
|
2015-01-28 13:07:59 -05:00
|
|
|
self.submodules.phy_source = PHYSource(dw)
|
|
|
|
self.submodules.phy_sink = PHYSink(dw)
|
2015-01-28 04:25:33 -05:00
|
|
|
|
|
|
|
self.source = self.phy_source.source
|
|
|
|
self.sink = self.phy_sink.sink
|
|
|
|
|
2015-01-28 13:07:59 -05:00
|
|
|
self.mac_callback = None
|
|
|
|
|
|
|
|
def set_mac_callback(self, callback):
|
|
|
|
self.mac_callback = callback
|
|
|
|
|
|
|
|
def send(self, datas):
|
2015-01-28 04:25:33 -05:00
|
|
|
packet = Packet(datas)
|
2015-01-28 14:44:41 -05:00
|
|
|
if self.debug:
|
|
|
|
r = ">>>>>>>>\n"
|
|
|
|
r += "length " + str(len(datas)) + "\n"
|
|
|
|
for d in datas:
|
2015-02-11 05:28:15 -05:00
|
|
|
r += "{:02x}".format(d)
|
2015-01-28 14:44:41 -05:00
|
|
|
print_phy(r)
|
2015-02-06 06:22:24 -05:00
|
|
|
self.phy_source.send(packet)
|
2015-01-28 04:25:33 -05:00
|
|
|
|
|
|
|
def receive(self):
|
|
|
|
yield from self.phy_sink.receive()
|
2015-01-28 14:44:41 -05:00
|
|
|
if self.debug:
|
|
|
|
r = "<<<<<<<<\n"
|
|
|
|
r += "length " + str(len(self.phy_sink.packet)) + "\n"
|
|
|
|
for d in self.phy_sink.packet:
|
2015-02-11 05:28:15 -05:00
|
|
|
r += "{:02x}".format(d)
|
2015-01-28 14:44:41 -05:00
|
|
|
print_phy(r)
|
2015-01-28 04:25:33 -05:00
|
|
|
self.packet = self.phy_sink.packet
|
2015-02-06 06:22:24 -05:00
|
|
|
|
|
|
|
def gen_simulation(self, selfp):
|
|
|
|
while True:
|
|
|
|
yield from self.receive()
|
|
|
|
if self.mac_callback is not None:
|
|
|
|
self.mac_callback(self.packet)
|