Skip to content

Commit

Permalink
trace: Add a timeout to end a frame if no new data arrives.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyp committed Aug 28, 2024
1 parent 14e974c commit 80a7ac5
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions orbtrace/trace/tpiu.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,67 +93,70 @@ def __init__(self):
self.source = source = Endpoint([('data', 8)])

max_size = 1024
timeout = 7500000

channel = Signal(7)
data = Signal(8)
byte_cnt = Signal(max = max_size)
timeout_cnt = Signal(max = timeout + 1)

start_new_packet = Signal()

self.comb += start_new_packet.eq((sink.channel != channel) | (byte_cnt >= max_size - 1))

self.submodules.fsm = fsm = FSM()

fsm.act('DATA',
source.data.eq(sink.data),
source.valid.eq(sink.valid & ~start_new_packet),
sink.ready.eq(source.ready & ~start_new_packet),
self.comb += start_new_packet.eq(
(sink.valid & (sink.channel != channel)) |
(byte_cnt >= max_size - 1) |
(timeout_cnt == 0))

If(sink.valid & start_new_packet,
NextState('HEADER'),
NextValue(channel, sink.channel),
self.sync += [
If(timeout_cnt,
timeout_cnt.eq(timeout_cnt - 1),
),
If(sink.valid,
timeout_cnt.eq(timeout),
)
]

If(sink.valid & sink.ready,
NextValue(byte_cnt, byte_cnt + 1),
),
)
self.submodules.fsm = fsm = FSM()

fsm.act('HEADER',
source.data.eq(channel),
source.data.eq(sink.channel),
source.first.eq(1),
source.valid.eq(1),
source.valid.eq(sink.valid),
sink.ready.eq(source.ready),

If(source.ready,
If(sink.valid & sink.ready,
NextState('DATA'),
NextValue(byte_cnt, 0),
NextValue(data, sink.data),
),
)

class LastFromFirst(Module):
def __init__(self):
self.sink = sink = Endpoint([('data', 8)])
self.source = source = Endpoint([('data', 8)])
fsm.act('DATA',
source.data.eq(data),
source.valid.eq(sink.valid),
sink.ready.eq(source.ready),

data = Signal(8)
first = Signal()
valid = Signal()
If(start_new_packet,
source.valid.eq(0),
sink.ready.eq(0),
NextState('END'),
),

self.comb += [
sink.ready.eq(~valid | (source.ready & source.valid)),
If(sink.valid & sink.ready,
NextValue(data, sink.data),
NextValue(byte_cnt, byte_cnt + 1),
),
)

fsm.act('END',
source.data.eq(data),
source.first.eq(first),
source.last.eq(sink.first),
source.valid.eq(valid & sink.valid),
]

self.sync += [
If(sink.ready & sink.valid,
data.eq(sink.data),
first.eq(sink.first),
valid.eq(1),
source.last.eq(1),
source.valid.eq(1),

If(source.ready,
NextState('HEADER'),
),
]
)

class TPIUDemux(Module):
def __init__(self):
Expand All @@ -169,7 +172,6 @@ def __init__(self):
self.submodules.demux = Demux()
self.submodules.strip_channel_zero = StripChannelZero()
self.submodules.packetizer = Packetizer()
self.submodules.last_from_first = LastFromFirst()

self.submodules += Pipeline(
sink,
Expand All @@ -182,7 +184,6 @@ def __init__(self):

self.submodules += Pipeline(
self.packetizer,
self.last_from_first,
source,
)

Expand Down

0 comments on commit 80a7ac5

Please sign in to comment.