Skip to content

Commit

Permalink
Do not lose synchronization on truncated packets
Browse files Browse the repository at this point in the history
In current bitstream introduced in commit d0192dc ("Update to
latest FPGA bitstream") only 1027 bytes are captured when HF0_TRUNC flag
is set. HF0_TRUNC can happen either when there is babble packet on the
bus or when the gateware incoming ULPI buffer gets full. When HF0_TRUNC
is set, the packet size stored in header is guaranteed to be larger than
1027 but only 1027 bytes are actually captured. The next packet data are
then incorrectly treated as remainder of the packet and therefore the
stream gets out of sync.

Fix the issue by respecting gateware maximum captured packet size.
  • Loading branch information
desowin committed Feb 9, 2024
1 parent 16d541e commit 570d7a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int packet_decoder_proc(struct packet_decoder* pd, uint8_t* buf, size_t size) {
}
} break;
case NEED_PACKET_DATA: {
const size_t required_length = pd->packet->size - pd->buf_actual_length;
const size_t required_length = ov_packet_captured_size(pd->packet) - pd->buf_actual_length;
const size_t copy = MIN(required_length, end - buf);

memcpy(pd->packet->data + pd->buf_actual_length, buf, copy);
Expand Down
2 changes: 1 addition & 1 deletion tools/sample/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

static void packet_handler(struct ov_packet* packet, void* data) {
printf("[%02x] Received %d bytes at %" PRId64 ":", packet->flags, packet->size, packet->timestamp);
for (int i = 0; i < packet->size; ++i)
for (int i = 0; i < ov_packet_captured_size(packet); ++i)
printf(" %02x", packet->data[i]);
printf("\n");
}
Expand Down

0 comments on commit 570d7a0

Please sign in to comment.