Skip to content

Commit 36587ed

Browse files
committed
wip: Add TPIU decoder and bypass for SWO.
1 parent f5c81b2 commit 36587ed

File tree

2 files changed

+76
-20
lines changed

2 files changed

+76
-20
lines changed

orbtrace/trace/__init__.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def __init__(self, platform):
254254
swo_manchester = Signal()
255255
swo_nrz = Signal()
256256
swo_tpiu = Signal()
257+
swo_itm = Signal()
257258

258259
self.comb += Case(self.input_format, {
259260
0x01: [
@@ -271,6 +272,7 @@ def __init__(self, platform):
271272
0x10: [
272273
swo_active.eq(1),
273274
swo_manchester.eq(1),
275+
swo_itm.eq(1),
274276
],
275277
0x11: [
276278
swo_active.eq(1),
@@ -280,6 +282,7 @@ def __init__(self, platform):
280282
0x12: [
281283
swo_active.eq(1),
282284
swo_nrz.eq(1),
285+
swo_itm.eq(1),
283286
],
284287
0x13: [
285288
swo_active.eq(1),
@@ -307,20 +310,11 @@ def __init__(self, platform):
307310
trace_pipeline = [
308311
phy := ClockDomainsRenamer('trace')(TracePHY(trace_pads)),
309312
ClockDomainsRenamer({'write': 'trace', 'read': 'sys'})(AsyncFIFO([('data', 128)], 4)),
310-
ByteSwap(16),
311-
#injector := Injector(),
312-
#pv := PipeValid([('data', 128)]),
313-
#Converter(128, 8),
314-
tpiu.TPIUDemux(),
315-
cobs.ChecksumAppender(),
316-
cobs.COBSEncoder(),
317-
cobs.DelimiterAppender(),
318-
cobs.SuperFramer(7500000, 65536),
319313
]
320314

321315
#pv.comb += pv.source.last.eq(1)
322316

323-
trace_stream = Endpoint([('data', 8)])
317+
trace_stream = Endpoint([('data', 128)])
324318

325319
self.submodules += [*trace_pipeline, Pipeline(*trace_pipeline, trace_stream)]
326320

@@ -370,7 +364,7 @@ def __init__(self, platform):
370364
swo_stream_backend_source = Endpoint([('data', 8)])
371365
swo_pipeline_backend = [
372366
ClockDomainsRenamer({'write': 'swo', 'read': 'sys'})(AsyncFIFO([('data', 8)], 4)),
373-
StreamFlush(7500000),
367+
#StreamFlush(7500000),
374368
]
375369
self.submodules += [*swo_pipeline_backend, Pipeline(swo_stream_backend_sink, *swo_pipeline_backend, swo_stream_backend_source)]
376370

@@ -393,18 +387,30 @@ def __init__(self, platform):
393387
self.submodules.swo_overrun_indicator = Indicator(swo_monitor.lost, 7500000)
394388
self.submodules.swo_data_indicator = Indicator(swo_monitor.total, 7500000)
395389

396-
# Output mux and FIFO
397-
fifo = SyncFIFO([('data', 8)], 8192, buffered = True)
390+
# Orbtag pipeline
391+
orbtag_pipeline_sink = Endpoint([('data', 128)])
392+
orbtag_pipeline = [
393+
ByteSwap(16),
394+
tpiu_demux := tpiu.TPIUDemux(),
395+
cobs.ChecksumAppender(),
396+
cobs.COBSEncoder(),
397+
cobs.DelimiterAppender(),
398+
cobs.SuperFramer(7500000, 65536),
399+
SyncFIFO([('data', 8)], 8192, buffered = True),
400+
]
401+
self.submodules += [*orbtag_pipeline, Pipeline(orbtag_pipeline_sink, *orbtag_pipeline, source)]
402+
403+
self.submodules.swo_tpiu_sync = swo_tpiu_sync = tpiu.TPIUSync()
398404

405+
# Output mux
399406
self.comb += [
400407
If(trace_active,
401-
trace_stream.connect(fifo.sink),
408+
trace_stream.connect(orbtag_pipeline_sink),
402409
self.led_overrun.eq(self.overrun_indicator.out),
403410
self.led_data.eq(self.data_indicator.out),
404411
self.led_clk.eq(self.clk_indicator.out),
405412
),
406413
If(swo_active,
407-
swo_stream_backend_source.connect(fifo.sink),
408414
self.led_overrun.eq(self.swo_overrun_indicator.out),
409415
self.led_data.eq(self.swo_data_indicator.out),
410416
),
@@ -416,10 +422,15 @@ def __init__(self, platform):
416422
swo_stream_frontend_source.connect(swo_stream_nrz_sink),
417423
swo_stream_nrz_source.connect(swo_stream_backend_sink),
418424
),
419-
fifo.source.connect(source),
425+
If(swo_tpiu,
426+
swo_stream_backend_source.connect(swo_tpiu_sync.sink),
427+
swo_tpiu_sync.source.connect(orbtag_pipeline_sink),
428+
),
429+
If(swo_itm,
430+
swo_stream_backend_source.connect(tpiu_demux.bypass_sink),
431+
tpiu_demux.bypass.eq(1),
432+
),
420433
]
421434

422-
self.submodules += fifo
423-
424435
# Add verilog sources.
425436
platform.add_source('verilog/traceIF.v') # TODO: make sure the path is correct

orbtrace/trace/tpiu.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ def __init__(self):
158158
class TPIUDemux(Module):
159159
def __init__(self):
160160
self.sink = sink = Endpoint([('data', 128)])
161+
self.bypass_sink = bypass_sink = Endpoint([('data', 8)])
161162
self.source = source = Endpoint([('data', 8)])
162163

164+
self.bypass = Signal()
165+
163166
self.submodules.rearrange = Rearrange()
164167
self.submodules.converter = Converter(135, 9)
165168
self.submodules.track_stream = TrackStream()
@@ -168,17 +171,59 @@ def __init__(self):
168171
self.submodules.packetizer = Packetizer()
169172
self.submodules.last_from_first = LastFromFirst()
170173

171-
self.submodules.pipeline = Pipeline(
174+
self.submodules += Pipeline(
172175
sink,
173176
self.rearrange,
174177
self.converter,
175178
self.track_stream,
176179
#self.demux,
177180
self.strip_channel_zero,
181+
)
182+
183+
self.submodules += Pipeline(
178184
self.packetizer,
179185
self.last_from_first,
180186
source,
181187
)
182188

189+
self.comb += If(self.bypass,
190+
bypass_sink.ready.eq(self.packetizer.sink.ready),
191+
self.packetizer.sink.valid.eq(bypass_sink.valid),
192+
self.packetizer.sink.data.eq(bypass_sink.data),
193+
self.packetizer.sink.channel.eq(1),
194+
).Else(
195+
self.strip_channel_zero.source.connect(self.packetizer.sink),
196+
)
197+
183198
#self.comb += self.demux.source_etm.connect(source)
184-
#self.comb += self.demux.source_itm.ready.eq(1)
199+
#self.comb += self.demux.source_itm.ready.eq(1)
200+
201+
class TPIUSync(Module):
202+
def __init__(self):
203+
self.sink = sink = Endpoint([('data', 8)])
204+
self.source = source = Endpoint([('data', 128)])
205+
206+
buf = Signal(129, reset = 1)
207+
208+
self.comb += [
209+
source.valid.eq(buf[128]),
210+
source.data.eq(buf),
211+
sink.ready.eq(~source.valid),
212+
]
213+
214+
self.sync += If(source.valid & source.ready,
215+
buf.eq(1),
216+
)
217+
218+
self.sync += If(sink.valid & sink.ready,
219+
If(Cat(sink.data, buf)[:32] == 0xffffff7f,
220+
# Full sync, reset buffer.
221+
buf.eq(1),
222+
).Elif(Cat(sink.data, buf)[:16] == 0xff7f,
223+
# Half sync, drop previous byte from buffer.
224+
buf.eq(buf[8:]),
225+
).Else(
226+
# Regular byte, add to buffer.
227+
buf.eq(Cat(sink.data, buf)),
228+
)
229+
)

0 commit comments

Comments
 (0)