Refactor packet_handler RTL for synthesis quality and handshake correctness#6
Open
kiro-agent[bot] wants to merge 9 commits into
Open
Refactor packet_handler RTL for synthesis quality and handshake correctness#6kiro-agent[bot] wants to merge 9 commits into
kiro-agent[bot] wants to merge 9 commits into
Conversation
- Replaces simplistic Verilog test bench with robust Python test bench. - Adds `test_packet_handler.py` containing a comprehensive suite: basic, multiple streams, dropped packet detection, min length packets, and randomized testing. - Includes a cocotb `Makefile` to run tests with Icarus Verilog. Co-authored-by: RafailDD <123392637+RafailDD@users.noreply.github.com> Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
- Replaces simplistic Verilog test bench with robust Python test bench. - Adds `test_packet_handler.py` containing a comprehensive suite: basic, multiple streams, dropped packet detection, min length packets, and randomized testing. - Includes a cocotb `Makefile` to run tests with Icarus Verilog. Co-authored-by: RafailDD <123392637+RafailDD@users.noreply.github.com> Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
- Replaces simplistic Verilog test bench with robust Python test bench. - Adds `test_packet_handler.py` containing a comprehensive suite: basic, multiple streams, dropped packet detection, min length packets, and randomized testing. - Includes a cocotb `Makefile` to run tests with Icarus Verilog. - Fixes cocotb deprecation warnings (MODULE -> COCOTB_TEST_MODULES, units -> unit). Co-authored-by: RafailDD <123392637+RafailDD@users.noreply.github.com> Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
…67122689535779 Add extensive cocotb test bench for packet handler Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
Adds a 256-depth synchronous FIFO at the input to buffer incoming data and allow continuous ingestion, decoupled from the FSM processing speed. This prevents stalling the transmitter when the internal FSM is processing or waiting for receiver readiness. The packet tracking logic to assert o_packetLost has been adapted to evaluate stream sequences as data is pushed into the FIFO. Fixes an issue where o_data was partially initialized to 32 bits instead of 296. Co-authored-by: RafailDD <123392637+RafailDD@users.noreply.github.com> Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
…375545090 Add Input FIFO to Packet Handler Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
Creates a SystemVerilog class-based testbench that structurally mimics UVM without relying on the official IEEE 1800.2 UVM libraries, ensuring compatibility with open-source tools like Verilator. Includes: - Pseudo-randomization constraints via `packet_item` class methods. - Generators, drivers, and scoreboards using SV classes. - A functional coverage proxy inside the monitor that samples packet drops, minimum-length packets, and maximum-length packets. - A dedicated `Makefile.sv` for standalone Verilator compilation and execution. Co-authored-by: RafailDD <123392637+RafailDD@users.noreply.github.com> Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
…780058197 Add UVM-style pure SystemVerilog testbench for FOSS compatibility Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
…ctness Synthesizability: * Move FIFO and packetTracker memory writes into reset-free always blocks so synthesis can map them to distributed/block RAM instead of resettable flip-flops. * Replace the for-loop reset of packetTracker[31:0] (1024 FFs) with a per-stream tracker_valid bit array (32 FFs) that suppresses spurious o_packetLost on the first packet of each stream. * Bound the packetTracker index to STREAM_IDX_W=5 bits; previously the 16-bit (in_streamId-1) was used, allowing out-of-range access. * Compute fifo_full from fifo_count[FIFO_AW] (single bit) instead of an equality compare to 9'd256. * Tag the FSM with (* fsm_encoding = "one_hot" *) to preserve one-hot encoding through synthesis (Vivado-style hint, ignored elsewhere). * Add next_state = state default at the top of the combinational block; default branch in the case still recovers to IDLE. * Replace o_data <= o_data self-assignment with implicit hold. Functional fixes (verified bit-identical o_packetLost timing on the existing testbench): * o_data is now loaded on the DATA -> DONE transition so it is valid in the same cycle that o_valid rises. Previously the receiver would sample stale data on the first handshake cycle (o_data was only assigned on i_ready==1 inside DONE). * Sequence-number tracker now stores the actual received seqNumber, so after a discontinuity the next valid packet recovers cleanly. The previous behaviour incremented the tracker by 1 unconditionally and reported every subsequent packet as lost once a discontinuity occurred. Verification: simulated original and refactored designs against packet_handler_tb.v with iverilog. o_packetLost pulses identically at t=235ns. o_valid timing is identical. o_data is correct (was 0 in the original) during the first transaction's DONE wait. Co-authored-by: Rafail Dalakouras <123392637+RafailDD@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was created by @kiro-agent on behalf of @RafailDD 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent
Summary
Refactor
packet_handler.vfor synthesis quality and handshake correctness, based on thejules-experimentingbranch tip.Synthesizability improvements
fifo_memandpacketTrackerwrites into their own reset-freealwaysblocksfor (i=0; i<32; i=i+1) packetTracker[i] <= 0;reset loop with a 32-bittracker_validregistertracker_valid) are reset; the data array is RAM-inference friendly.packetTrackerindex to 5 bits (in_streamId[4:0] - 1)fifo_full = fifo_count[FIFO_AW]instead offifo_count == 9'd256(* fsm_encoding = "one_hot" *)attribute onstatenext_state = state;default at top of comb blockdefaultbranch still recovers toIDLE.o_data <= o_data;self-assignmentFIFO_DEPTH/NUM_STREAMS/STREAM_IDX_WFunctional fixes
Both fixes were verified by simulating the original and refactored RTL against
packet_handler_tb.vwith Icarus Verilog 12.0. Theo_packetLostpulse is bit-identical att = 235 ns, ando_validtiming matches; onlyo_datadiffers (correctly).AXI-stream handshake compliance.
o_datais now loaded on theDATA -> DONEtransition, so it is valid in the same cycle thato_validrises. Previouslyo_datawas only assigned inDONEwheni_ready == 1, meaning a receiver sampling on(o_valid && i_ready)would capture the previous transaction's payload (or zeros after reset) on the first cycle of the handshake.validOut=1, dataOut=000…0:x:validOut=1, dataOut=…5a22b2d45a22b49e42e3c71e43995b7e:white_check_mark:o_packetLostrecovers after a gap. The tracker now stores the actual receivedseqNumberinstead of unconditionally incrementing by 1. Combined with the new per-streamtracker_validbit, the first packet of any stream is unconditionally accepted, and after a discontinuity the next sequential packet stops the pulse. Previously, once a packet was lost, every subsequent packet for that stream was incorrectly flagged as lost forever.Verification
iverilog -g2005-sv -Wall packet_handler.v packet_handler_tb.v— clean (no warnings).vvpof original vs. refactored design against the existing testbench —$monitoroutputs match except for theo_dataandmsgLength/streamIddifferences described above (the second is internal-only and taggedlint_off UNUSEDSIGNAL).o_packetLostpulses fire at the same time on the wrong-seqNumberpacket.Known follow-ups (not in this PR)
fifo_data = fifo_mem[fifo_rd_ptr]), which favours distributed RAM inference. To target block RAM (BRAM) for the 256x33-bit FIFO, the FSM would need to be reworked for one-cycle read latency. Out of scope for this synthesis-quality pass.o_datais 296 bits, but{shiftReg[263:0], i_data}only carries 9 full 32-bit words = 288 bits of payload through the shift register. Packets with the maximummsgLength = 45(37 bytes payload) would lose the last byte. Existing limitation, not regressed here.Target
This PR targets
jules-experimenting(used as the basis), as requested.