Part of Curriculum: Protocol RTL Design (Module 9: AXI-Stream Arbitration & Packet Framing)
View Full Roadmap →
Level 6 Industry Challenge ★ Advanced #48 50 pts ✓ Solved

4-Channel Round-Robin AXI-Stream Arbiter with Packet Locking

Advanced RTL & Protocol Design · advanced-rtl, axi-protocol, systemverilog, asic, fpga

Design a 4-channel AXI-Stream arbiter featuring packet-boundary locking, starvation-free fair round-robin scheduling, and full backpressure propagation.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
s_tvalid[3:0]s_tdata[127:0]s_tlast[3:0]m_tvalids_tready[3:0]m_tdata[31:0]>clkrst_n4-CHANNEL ROUND-ROBIPROTOCOL INTERFACE
⚡ Timing & Synthesizability Constraints

Timing Contract: Clocked on aclk with active-low aresetn. Arbitration decision occurs when unlocked and requesters are active. Priority advances only when packet completes.

RTL Constraints: No packet interleaving. Synthesizable Verilog-2001.

Objective: Implement a 4-input, 1-output AXI4-Stream arbiter. Once a channel is granted, lock the connection until the entire packet completes (indicated by TLAST && TVALID && TREADY). Support downstream backpressure (m_tready = 0) without dropping packets or switching channels mid-packet. Rotate priority fairly to the next requester upon packet termination.

Prerequisites: AXI-Stream packet framing, round-robin arbitration algorithms, fair resource sharing, packet locking.
PortDirWidthDescription
aclk, aresetninput1Clock and active-low synchronous reset
s_tvalid[3:0]input4Ingress valid signals for channels 0..3
s_tready[3:0]output4Backpressure ready signals for channels 0..3
s_tdata[127:0]input128Packed data: ch0=[31:0], ch1=[63:32], ch2=[95:64], ch3=[127:96]
s_tlast[3:0]input4End-of-packet indicators for channels 0..3
m_tvalid, m_treadyout/in1Downstream AXI-Stream valid and ready
m_tdata[31:0], m_tlastoutput32, 1Arbitrated egress data stream and end-of-packet flag
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Packet locking is essential: once an input channel begins sending, you cannot switch to another channel mid-packet even if other channels assert valid.
Hint 2: Implementation Architecture & Approach
A packet ends when m_tvalid && m_tready && m_tlast is true on the clock edge.
Hint 3: Edge Cases, Timing & Verilog Syntax
When the packet completes, update the base pointer to (winner + 1) % 4 to guarantee starvation-free round-robin fairness.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module (
  input  wire         aclk,
  input  wire         aresetn,
  input  wire [3:0]   s_tvalid,
  output reg  [3:0]   s_tready,
  input  wire [127:0] s_tdata,
  input  wire [3:0]   s_tlast,
  output reg          m_tvalid,
  input  wire         m_tready,
  output reg  [31:0]  m_tdata,
  output reg          m_tlast
);

  reg [1:0] winner;
  reg [1:0] base_ptr;
  reg       locked;

  wire [31:0] ch_data [0:3];
  assign ch_data[0] = s_tdata[31:0];
  assign ch_data[1] = s_tdata[63:32];
  assign ch_data[2] = s_tdata[95:64];
  assign ch_data[3] = s_tdata[127:96];

  // Combinational round-robin priority picker
  reg [1:0] next_grant;
  reg       any_req;

  always @(*) begin
    any_req    = |s_tvalid;
    next_grant = base_ptr;
    if (s_tvalid[base_ptr]) begin
      next_grant = base_ptr;
    end else if (s_tvalid[(base_ptr + 2'd1) & 2'd3]) begin
      next_grant = (base_ptr + 2'd1) & 2'd3;
    end else if (s_tvalid[(base_ptr + 2'd2) & 2'd3]) begin
      next_grant = (base_ptr + 2'd2) & 2'd3;
    end else if (s_tvalid[(base_ptr + 2'd3) & 2'd3]) begin
      next_grant = (base_ptr + 2'd3) & 2'd3;
    end
  end

  // Mux selection
  always @(*) begin
    if (locked || any_req) begin
      m_tvalid = s_tvalid[winner];
      m_tdata  = ch_data[winner];
      m_tlast  = s_tlast[winner];
    end else begin
      m_tvalid = 1'b0;
      m_tdata  = 32'h0;
      m_tlast  = 1'b0;
    end

    s_tready = 4'b0000;
    if (locked || any_req) begin
      s_tready[winner] = m_tready;
    end
  end

  always @(posedge aclk or negedge aresetn) begin
    if (!aresetn) begin
      winner   <= 2'd0;
      base_ptr <= 2'd0;
      locked   <= 1'b0;
    end else begin
      if (!locked) begin
        if (any_req) begin
          winner <= next_grant;
          locked <= 1'b1;
          // Single-beat packet check
          if (s_tvalid[next_grant] && m_tready && s_tlast[next_grant]) begin
            locked   <= 1'b0;
            base_ptr <= (next_grant + 2'd1) & 2'd3;
          end
        end
      end else begin
        // Locked in transfer
        if (m_tvalid && m_tready && m_tlast) begin
          locked   <= 1'b0;
          base_ptr <= (winner + 2'd1) & 2'd3;
        end
      end
    end
  end

endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 6 · Advanced RTL & Protocol Design

What You Will Learn

By solving 4-Channel Round-Robin AXI-Stream Arbiter with Packet Locking, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Design a 4-channel AXI-Stream arbiter featuring packet-boundary locking, starvation-free fair round-robin scheduling, and full backpressure propagation.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Implement a 4-input, 1-output AXI4-Stream arbiter. Once a channel is granted, lock the connection until the entire packet completes (indicated by TLAST && TVALID && TREADY). Support downstream backpressure (m_tready = 0) without dropping packets or switching channels mid-packet. Rotate priority fairly to the next requester upon packet termination.

Prerequisites: AXI-Stream packet framing, round-robin arbitration algorithms, fair resource sharing, packet locking.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

PortDirWidthDescription
aclk, aresetninput1Clock and active-low synchronous reset
s_tvalid[3:0]input4Ingress valid signals for channels 0..3
s_tready[3:0]output4Backpressure ready signals for channels 0..3
s_tdata[127:0]input128Packed data: ch0=[31:0], ch1=[63:32], ch2=[95:64], ch3=[127:96]
s_tlast[3:0]input4End-of-packet indicators for channels 0..3
m_tvalid, m_treadyout/in1Downstream AXI-Stream valid and ready
m_tdata[31:0], m_tlastoutput32, 1Arbitrated egress data stream and end-of-packet flag

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Clocked on aclk with active-low aresetn. Arbitration decision occurs when unlocked and requesters are active. Priority advances only when packet completes.

Synthesis Constraints: No packet interleaving. Synthesizable Verilog-2001.

Architectural Deep Dive & Implementation Walkthrough

Packet Interleaving vs. Packet Locking

In streaming networking protocols (Ethernet, PCIe TLP, AXI-Stream), data beats belong to distinct packets bounded by TLAST. Arbitrating on a pure per-beat basis would cause packet fragmentation and interleaving, corrupting packet payloads at the receiver.

Arbiter Design Rules

  • Arbitration Phase: When the arbiter is idle (unlocked), it inspects all requesting channels and grants access according to the current round-robin priority pointer.
  • Locked Phase: The winner gains exclusive access to the egress bus. Even if downstream backpressure occurs (m_tready = 0), the arbiter holds its grant.
  • Release & Rotation: When the final beat is transferred (m_tvalid && m_tready && m_tlast), the lock releases and the priority pointer advances to prevent starvation.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

Switching channels on backpressure (m_tready=0) or breaking packet boundaries when higher-priority requesters arrive.

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

In network-on-chip (NoC) routers, packet arbiters include aging counters to prevent low-bandwidth channels from starving under high-rate streaming flows.

Starter RTL Code

module top_module (
  input  wire         aclk,
  input  wire         aresetn,
  input  wire [3:0]   s_tvalid,
  output reg  [3:0]   s_tready,
  input  wire [127:0] s_tdata,
  input  wire [3:0]   s_tlast,
  output reg          m_tvalid,
  input  wire         m_tready,
  output reg  [31:0]  m_tdata,
  output reg          m_tlast
);

  // Implement 4-to-1 Round-Robin Arbiter:
  // 1. Lock arbitration onto winning channel until (m_tvalid && m_tready && m_tlast).
  // 2. Rotate priority to (winner + 1) % 4 only upon packet completion.
  // 3. Forward s_tdata and s_tlast of selected channel to egress.

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module (
  input  wire         aclk,
  input  wire         aresetn,
  input  wire [3:0]   s_tvalid,
  output reg  [3:0]   s_tready,
  input  wire [127:0] s_tdata,
  input  wire [3:0]   s_tlast,
  output reg          m_tvalid,
  input  wire         m_tready,
  output reg  [31:0]  m_tdata,
  output reg          m_tlast
);

  reg [1:0] winner;
  reg [1:0] base_ptr;
  reg       locked;

  wire [31:0] ch_data [0:3];
  assign ch_data[0] = s_tdata[31:0];
  assign ch_data[1] = s_tdata[63:32];
  assign ch_data[2] = s_tdata[95:64];
  assign ch_data[3] = s_tdata[127:96];

  // Combinational round-robin priority picker
  reg [1:0] next_grant;
  reg       any_req;

  always @(*) begin
    any_req    = |s_tvalid;
    next_grant = base_ptr;
    if (s_tvalid[base_ptr]) begin
      next_grant = base_ptr;
    end else if (s_tvalid[(base_ptr + 2'd1) & 2'd3]) begin
      next_grant = (base_ptr + 2'd1) & 2'd3;
    end else if (s_tvalid[(base_ptr + 2'd2) & 2'd3]) begin
      next_grant = (base_ptr + 2'd2) & 2'd3;
    end else if (s_tvalid[(base_ptr + 2'd3) & 2'd3]) begin
      next_grant = (base_ptr + 2'd3) & 2'd3;
    end
  end

  // Mux selection
  always @(*) begin
    if (locked || any_req) begin
      m_tvalid = s_tvalid[winner];
      m_tdata  = ch_data[winner];
      m_tlast  = s_tlast[winner];
    end else begin
      m_tvalid = 1'b0;
      m_tdata  = 32'h0;
      m_tlast  = 1'b0;
    end

    s_tready = 4'b0000;
    if (locked || any_req) begin
      s_tready[winner] = m_tready;
    end
  end

  always @(posedge aclk or negedge aresetn) begin
    if (!aresetn) begin
      winner   <= 2'd0;
      base_ptr <= 2'd0;
      locked   <= 1'b0;
    end else begin
      if (!locked) begin
        if (any_req) begin
          winner <= next_grant;
          locked <= 1'b1;
          // Single-beat packet check
          if (s_tvalid[next_grant] && m_tready && s_tlast[next_grant]) begin
            locked   <= 1'b0;
            base_ptr <= (next_grant + 2'd1) & 2'd3;
          end
        end
      end else begin
        // Locked in transfer
        if (m_tvalid && m_tready && m_tlast) begin
          locked   <= 1'b0;
          base_ptr <= (winner + 2'd1) & 2'd3;
        end
      end
    end
  end

endmodule

Related RTL Problems in Level 6

  • Manchester Encoder — Combine a data bit with the clock to produce a Manchester-encoded line signal — the self-clocking encoding used in classic Ethernet and RFID.
  • Manchester Decoder — Recover the original data bit from a Manchester-encoded line signal — the exact inverse of the Manchester Encoder problem.
  • Quadrature Rotary Encoder Decoder — Decode the two-phase A/B signal from a real rotary knob or mouse wheel into a direction and position count — sample B on every rising edge of A.

Frequently Asked Questions

What does 4-Channel Round-Robin AXI-Stream Arbiter with Packet Locking require?

Design a 4-channel AXI-Stream arbiter featuring packet-boundary locking, starvation-free fair round-robin scheduling, and full backpressure propagation. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: advanced-rtl, axi-protocol, systemverilog, asic, fpga. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of 4-Channel Round-Robin AXI-Stream Arbiter with Packet Locking to assess real-world synthesizability and race-condition awareness.