10
10
interfaces to hosts via isochronous pipes.
11
11
"""
12
12
13
- from amaranth import Elaboratable , Module , Signal
13
+ from amaranth import *
14
+ from amaranth .lib import stream , wiring
15
+ from amaranth .lib .wiring import In , Out
14
16
15
- from ..endpoint import EndpointInterface
16
- from ...stream import StreamInterface , USBOutStreamBoundaryDetector
17
- from ....memory import TransactionalizedFIFO
17
+ from ..endpoint import EndpointInterface
18
+ from ...stream import USBOutStreamBoundaryDetector
19
+ from ....stream .future import Packet
20
+ from ....memory import TransactionalizedFIFO
18
21
19
22
20
23
class USBIsochronousStreamOutEndpoint (Elaboratable ):
@@ -52,9 +55,15 @@ def __init__(self, *, endpoint_number, max_packet_size, buffer_size=None):
52
55
#
53
56
# I/O port
54
57
#
55
- self .stream = StreamInterface ()
58
+ self .stream = stream .Interface (
59
+ stream .Signature (
60
+ Packet (unsigned (8 ))
61
+ )
62
+ )
56
63
self .interface = EndpointInterface ()
57
64
65
+ self .busy = Signal ()
66
+ self .byteclk = Signal ()
58
67
59
68
def elaborate (self , platform ):
60
69
m = Module ()
@@ -125,17 +134,17 @@ def elaborate(self, platform):
125
134
126
135
# Our stream data always comes directly out of the FIFO; and is valid
127
136
# whenever our FIFO actually has data for us to read.
128
- stream .valid .eq (~ fifo .empty ),
129
- stream .payload .eq (fifo .read_data [0 :8 ]),
137
+ stream .valid .eq (~ fifo .empty ),
138
+ stream .p . data .eq (fifo .read_data [0 :8 ]),
130
139
131
140
# Our `last` bit comes directly from the FIFO; and we know a `first` bit immediately
132
141
# follows a `last` one.
133
- stream .last .eq (fifo .read_data [8 ]),
134
- stream .first .eq (fifo .read_data [9 ]),
142
+ stream .p . last .eq (fifo .read_data [8 ]),
143
+ stream .p . first .eq (fifo .read_data [9 ]),
135
144
136
145
# Move to the next byte in the FIFO whenever our stream is advaced.
137
- fifo .read_en .eq (stream .ready ),
138
- fifo .read_commit .eq (1 )
146
+ fifo .read_en .eq (stream .ready ),
147
+ fifo .read_commit .eq (1 )
139
148
]
140
149
141
150
# Count bytes in packet.
@@ -155,4 +164,11 @@ def elaborate(self, platform):
155
164
m .d .usb += overflow .eq (0 )
156
165
m .d .usb += rx_cnt .eq (0 )
157
166
167
+ # Debug
168
+ last_cnt = Signal .like (rx_cnt )
169
+ m .d .comb += self .busy .eq (rx_cnt != 0 )
170
+ m .d .usb += last_cnt .eq (rx_cnt )
171
+ with m .If (last_cnt != rx_cnt ):
172
+ m .d .usb += self .byteclk .eq (~ self .byteclk )
173
+
158
174
return m
0 commit comments