2015-02-21 17:13:43 -05:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.genlib.fsm import *
|
|
|
|
from migen.actorlib.fifo import *
|
|
|
|
from migen.flow.actor import EndpointDescription
|
2015-04-28 12:58:38 -04:00
|
|
|
from migen.actorlib.packet import *
|
2015-05-01 10:11:15 -04:00
|
|
|
from migen.actorlib.structuring import Pipeline
|
2015-02-21 17:13:43 -05:00
|
|
|
|
|
|
|
|
2015-04-28 12:58:38 -04:00
|
|
|
packet_header_length = 9
|
|
|
|
packet_header_fields = {
|
|
|
|
"preamble": HeaderField(0, 0, 32),
|
|
|
|
"dst": HeaderField(4, 0, 8),
|
|
|
|
"length": HeaderField(5, 0, 32)
|
|
|
|
}
|
|
|
|
packet_header = Header(packet_header_fields,
|
|
|
|
packet_header_length,
|
|
|
|
swap_field_bytes=True)
|
2015-02-21 17:13:43 -05:00
|
|
|
|
2015-04-13 08:27:31 -04:00
|
|
|
|
2015-04-28 12:58:38 -04:00
|
|
|
def phy_description(dw):
|
|
|
|
payload_layout = [("data", dw)]
|
|
|
|
return EndpointDescription(payload_layout, packetized=False)
|
2015-02-21 17:13:43 -05:00
|
|
|
|
2015-04-28 12:58:38 -04:00
|
|
|
|
|
|
|
def packet_description(dw):
|
|
|
|
param_layout = packet_header.get_layout()
|
|
|
|
payload_layout = [
|
|
|
|
("data", dw),
|
|
|
|
("error", dw//8)
|
|
|
|
]
|
|
|
|
return EndpointDescription(payload_layout, param_layout, packetized=True)
|
|
|
|
|
|
|
|
|
|
|
|
def user_description(dw):
|
|
|
|
param_layout = [
|
|
|
|
("dst", 8),
|
|
|
|
("length", 32)
|
|
|
|
]
|
|
|
|
payload_layout = [
|
|
|
|
("data", dw),
|
|
|
|
("error", dw//8)
|
|
|
|
]
|
|
|
|
return EndpointDescription(payload_layout, param_layout, packetized=True)
|
|
|
|
|
|
|
|
|
|
|
|
class LiteUSBMasterPort:
|
|
|
|
def __init__(self, dw):
|
|
|
|
self.source = Source(user_description(dw))
|
|
|
|
self.sink = Sink(user_description(dw))
|
|
|
|
|
|
|
|
|
|
|
|
class LiteUSBSlavePort:
|
2015-05-01 10:11:15 -04:00
|
|
|
def __init__(self, dw, tag):
|
2015-04-28 12:58:38 -04:00
|
|
|
self.sink = Sink(user_description(dw))
|
|
|
|
self.source = Source(user_description(dw))
|
2015-05-01 10:11:15 -04:00
|
|
|
self.tag = tag
|
2015-04-28 12:58:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
class LiteUSBUserPort(LiteUSBSlavePort):
|
2015-05-01 10:11:15 -04:00
|
|
|
def __init__(self, dw, tag):
|
|
|
|
LiteUSBSlavePort.__init__(self, dw, tag)
|