Skip to content

Commit 2413e51

Browse files
committed
trace.tpiu: Count packetizer timeout from start of packet.
1 parent 279b78e commit 2413e51

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

orbtrace/trace/tpiu.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ def elaborate(self, platform):
148148
with m.If(timeout_cnt):
149149
m.d.sync += timeout_cnt.eq(timeout_cnt - 1)
150150

151-
with m.If(self.input.valid):
152-
m.d.sync += timeout_cnt.eq(self.timeout)
153-
154151
with m.FSM() as fsm:
155152
with m.State('HEADER'):
156153
m.d.comb += [
@@ -166,6 +163,7 @@ def elaborate(self, platform):
166163
channel.eq(self.input.payload.channel),
167164
byte_cnt.eq(0),
168165
data.eq(self.input.payload.data),
166+
timeout_cnt.eq(self.timeout),
169167
]
170168

171169
with m.State('DATA'):

tests/test_tpiu.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from sim_helpers import *
22

3+
import itertools
4+
35
from amaranth.sim import Simulator, SimulatorContext
46

57
from orbtrace.trace import tpiu
@@ -29,6 +31,32 @@ async def timeout(ctx: SimulatorContext):
2931

3032
sim.run()
3133

34+
def test_packetizer_slow_timeout():
35+
dut = tpiu.Packetizer(timeout = 1000)
36+
37+
sim = Simulator(dut)
38+
sim.add_clock(1e-6)
39+
40+
@sim.add_process
41+
async def input_testbench(ctx: SimulatorContext):
42+
await ctx.tick()
43+
44+
for i in itertools.count():
45+
await stream_put(ctx, dut.input, {'channel': 1, 'data': i & 0xff})
46+
await ctx.tick().repeat(100)
47+
48+
@sim.add_testbench
49+
async def output_testbench(ctx: SimulatorContext):
50+
assert await recv_packet(ctx, dut.output) == [1, *((i & 0xff) for i in range(10))]
51+
assert await recv_packet(ctx, dut.output) == [1, *((i & 0xff) for i in range(10, 20))]
52+
53+
@sim.add_process
54+
async def timeout(ctx: SimulatorContext):
55+
await ctx.tick().repeat(10_000)
56+
raise TimeoutError('Simulation timed out')
57+
58+
sim.run()
59+
3260
def test_demux():
3361
dut = tpiu.TPIUDemux(timeout = 1000)
3462

0 commit comments

Comments
 (0)