Skip to content

Commit

Permalink
Emit event on buffer overrun.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Jul 16, 2024
1 parent ede0a78 commit a8d06d4
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions cynthion/python/src/gateware/analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,30 @@ def elaborate(self, platform):
# Capture data until the packet is complete.
with m.State("CAPTURE_PACKET"):

byte_received = self.utmi.rx_valid & self.utmi.rx_active

# Capture data whenever RxValid is asserted.
m.d.comb += [
write_packet .eq(byte_received),
]

# Advance the write pointer each time we receive a bit.
with m.If(byte_received):
m.d.usb += [
packet_size .eq(packet_size + 1),
]

# If this would be filling up our data memory,
# move to the OVERRUN state.
with m.If(fifo_word_count + fifo_words_pending == self.mem_size_words - 1):
m.next = "OVERRUN"
# Is the packet still ongoing?
with m.If(self.utmi.rx_active):

# Did we receive a byte?
with m.If(self.utmi.rx_valid):

# Would one more word fill up our buffer?
words_allocated = fifo_word_count + fifo_words_pending
with m.If(words_allocated == self.mem_size_words - 1):
# Discard the packet we were writing.
m.d.sync += [
write_byte_addr .eq(header_word_addr << 1),
fifo_words_pending .eq(0),
]
# Instead, we'll write an event to record the overrun.
m.next = "OVERRUN_EVENT"

with m.Else():
# Write packet byte and increase packet size.
m.d.comb += write_packet.eq(1)
m.d.usb += packet_size.eq(packet_size + 1)

# If we've stopped receiving, write header.
with m.If(~self.utmi.rx_active):
with m.Else():
m.d.comb += [
write_header .eq(1),
]
Expand All @@ -267,8 +271,18 @@ def elaborate(self, platform):
pass


with m.State("OVERRUN_EVENT"):
# Write an event to indicate the overrun.
m.d.comb += [
write_event .eq(1),
event_code .eq(USBAnalyzerEvent.CAPTURE_FULL),
]

# Wait in the OVERRUN state until restarted.
m.next = "OVERRUN"


with m.State("OVERRUN"):
# TODO: we should probably set an overrun flag and then emit an EOP, here?

# If capture is stopped by the host, reset back to the ready state.
with m.If(~self.capture_enable):
Expand Down

0 comments on commit a8d06d4

Please sign in to comment.