Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
    • SRAM and ROM
    • Register Files
    • Valid/Ready Handshake
      • Rules That Keep Flow Control Safe
      • Skid Buffer and Pipeline Stages
      • AXI-Style Channels and Backpressure
      • Three Pipeline Stage Styles, Measured
    • AXI-Lite
    • AXI-Stream
    • Bus Integration
    • Synchronous FIFO
    • Register-Map and CSR RTL
    • Memory Reliability
    • Peripheral RTL Integration
    • Full AXI4: RTL Roadmap
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Valid/Ready Handshake
  1. Topics
  2. RTL Design
  3. Memory & Buses
  4. Valid/Ready Handshake
  5. Rules That Keep Flow Control Safe

Part 7 · Memory & Buses · Intermediate

Rules That Keep Flow Control Safe

The transfer rule, who drives what, and the stability rules that keep flow control safe.

On this page

    Why this matters

    A source that waits for ready before raising valid, facing a sink that waits for valid before raising ready, stalls forever. A monitor that counts valid cycles instead of valid-and-ready edges overcounts every stall.

    After this lesson you can: state the transfer rule and the stability rules behind it, and count beats correctly in a monitor.

    The transfer rule

    A transfer is valid && ready sampled at a clock edge. The relationship is asymmetric: the source offers valid (with a stable payload) without waiting for ready, while the sink may wait for valid before raising ready. The beat moves on the first edge where both are high.

    Ownership is fixed. The source drives valid and the payload, and the sink drives ready.

    Rule

    What it says

    Transfer

    One beat moves per clock edge with valid && ready high.

    Valid ownership

    The source drives valid and the payload.

    Ready ownership

    The sink drives ready.

    Asymmetry

    The source never waits for ready to offer; the sink may wait for valid before raising ready.

    Each slot is one clock cycle. The xfer lane is high exactly when valid and ready are both high, so it marks the edges where a beat moves.

    • Slots 0 to 2 hold beat 0xA1 with ready low. Valid and data stay stable and xfer stays low, so nothing moves.

    • Slot 3 raises ready. Both signals are high, so the one transfer of 0xA1 happens at the edge ending the slot.

    • Slot 4 holds ready high with valid low. Xfer stays low: ready alone moves nothing.

    • Slot 5 offers beat 0xB2 with ready already high, so it transfers at the edge ending the slot.

    Staying stable under backpressure

    • Independence. valid must not depend combinationally on ready. A source that waits for ready before raising valid, facing a sink that waits for valid before raising ready, deadlocks. Register the source state and let ready only complete transfers.

    • Stability. While valid is high and ready is low, both valid and the payload stay stable. The sink may sample the payload on any cycle of the stall.

    • Counting. Throughput is transfer events, not levels. A valid held for ten cycles with one ready pulse is one beat, so monitors and scoreboards count valid && ready edges.

    Common mistakes

    Common pitfall

    Deriving valid combinationally from ready, as in assign valid = has_data && ready. The source then cannot offer until the sink is ready, and through chained stages the ready path becomes one long combinational chain. Register valid from source state and let ready only complete transfers.

    Interview

    Likely question: “Why must valid not depend on ready?”

    • Deadlock. Mutual waiting between source and sink stalls the link forever.

    • Timing. A combinational ready to valid path chains through every stage.

    • Rule. The source offers independently; the sink disposes independently.

    Check yourself Ready is high for three cycles while valid stays low, then valid rises for one cycle. How many beats move, and did the sink break a rule by raising ready first?

    One beat, in the cycle where both are high. The sink broke no rule: it may raise ready before valid, and ready without valid moves nothing.

    Check yourself A monitor counts cycles with valid high as beats. When does it overcount?

    Whenever a beat stalls. One transfer can hold valid high for many cycles, so the monitor must count valid && ready edges instead.

    Check yourself Valid is high, ready is low, and the source computes a newer word. What may change on the interface this cycle?

    Nothing. valid and the payload stay stable until the edge where ready joins them; the newer word waits its turn.

    Testbench

    The testbench sends 64 words under deterministic pseudo-random backpressure. It samples at each rising edge before nonblocking updates, then waits until after those updates before ending the iteration. Counts therefore describe actual transfer edges, including the final beat. The bounded run checks order and stalled-offer stability.

    vr_source.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    module vr_source #(
      parameter int DW = 8,
      parameter int N = 64                        // words to send; N <= 2**DW
    ) (
      input  logic          clk,
      input  logic          rst_n,
      output logic          valid,
      output logic [DW-1:0] data,
      input  logic          ready
    );
      logic [DW:0] count;                         // next word index (one extra bit so N = 2**DW is safe)
      logic [15:0] lfsr;                          // fixed-seed offer pattern
    
      always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
          valid <= 1'b0;
          data  <= '0;
          count <= '0;
          lfsr  <= 16'hACE1;
        end else begin
          lfsr <= {lfsr[14:0], lfsr[15] ^ lfsr[13] ^ lfsr[12] ^ lfsr[10]};
          if (!valid) begin
            valid <= (count < N) && lfsr[0];       // random offer; valid never reads ready
            data  <= count[DW-1:0];
          end else if (ready) begin
            count <= count + 1'b1;                // transfer done: move to the next word
            valid <= (count + 1'b1 < N) && lfsr[0];
            data  <= count[DW-1:0] + 1'b1;
          end
          // valid && !ready: hold both stable
        end
      end
    endmodule
    
    // Sink: answers with a pseudo-random ready pattern. The testbench keeps the scoreboard.
    module vr_sink (
      input  logic clk,
      output logic ready
    );
      logic [15:0] lfsr = 16'h1D0F;               // fixed seed: the run is deterministic
    
      always_ff @(posedge clk) begin
        lfsr  <= {lfsr[14:0], lfsr[15] ^ lfsr[13] ^ lfsr[12] ^ lfsr[10]};
        ready <= lfsr[0] ^ lfsr[7];
      end
    endmodule
    

    Remember

    • A beat moves on the clock edge where valid and ready are both high. The source drives valid and the payload, and the sink drives ready.

    • Valid must not depend combinationally on ready. While valid is high and ready is low, valid and the payload stay stable.

    • Throughput is transfer events, not levels: count valid && ready edges.

    Rule of thumb: the source offers without waiting for ready, and holds the offer until the edge where ready joins it.

    How this was checked

    Source checker, run with Icarus Verilog 13.0 (2026-10-16): prints PASS. It sends 64 words under deterministic pseudo-random backpressure, samples at each rising edge before nonblocking updates, and checks order and stalled-offer stability in a bounded run. It is not a proof for every traffic pattern.

    Keep going

    • Practice: Two-stage valid/ready pipeline: throughput, backpressure and skid buffers

    • Code lab: AXI stream handshake

    • Interview: run a mock interview on this topic

    Related topics

    • Skid Buffer and Pipeline Stages

    Previous

    198 / 350

    Next: Skid Buffer and Pipeline Stages

    Up next

    Up nextSkid Buffer and Pipeline Stages

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • AXI-Style Channels and Backpressure
    • Three Pipeline Stage Styles, Measured
    clkvalidreadydataa1b2xfer
    A beat held stable while ready stays low, then one transfer when ready rises, then a ready with no valid, then a beat that moves at once