Part of Curriculum: Advanced SoC and Chiplet RTL (Module 4: Credit-Based Flow Control Counter)
View Full Roadmap →
Level 4 Hard ★ Flagship #39 50 pts ✓ Solved

Credit-Based Flow Control — Credit Management

On-Chip Protocols · cdc, industry-rtl, arbiters, clock-domain-crossing, hard, credit-flow-control

Implement a transmitter credit manager with initial credits MAX_CREDITS (default 4). Transmitter can send when credits > 0, decrementing credits; credits return via credit_return strobe.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
tx_reqcredit_rettx_sendcredit_count[3:0]>clkrst_nCREDIT-BASED FLOW COSEQUENTIAL COUNTER
⚡ Timing & Synthesizability Constraints

Timing Contract: Transmitter transmits (`tx_send=1`) only when `credit_count > 0`. Each returned credit (`credit_ret=1`) increments `credit_count`.

RTL Constraints: Total credits must never exceed `MAX_CREDITS`. Credit counter must not underflow or overflow.

Objective: Understand credit-based flow control used in PCIe, NoC (Network-on-Chip), and NVLink for high-latency inter-chip links.

Prerequisites: Flow control, counters, latency-insensitive protocols.
NameDirWidthDescription
clkinput1Clock signal
areset_ninput1Active-low reset
tx_reqinput1Transmit request from internal core
credit_retinput1Credit return strobe from remote receiver
tx_sendoutput1Packet transmitted onto physical link
credit_countoutput4Current available credit balance
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Initialize `credit_count <= MAX_CREDITS;` on reset.
Hint 2: Implementation Architecture & Approach
`tx_send` is true when `tx_req && (credit_count > 0)`.
Hint 3: Edge Cases, Timing & Verilog Syntax
Decrement `credit_count` when `tx_send` is 1; increment when `credit_ret` is 1; hold unchanged if both happen concurrently.
🔒 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 #(
  parameter MAX_CREDITS = 4
)(
  input        clk,
  input        areset_n,
  input        tx_req,
  input        credit_ret,
  output       tx_send,
  output reg [3:0] credit_count
);
  // Can send if core requests and we have available credits
  assign tx_send = tx_req && (credit_count > 4'd0);

  always @(posedge clk or negedge areset_n) begin
    if (!areset_n) begin
      credit_count <= MAX_CREDITS[3:0];
    end else begin
      case ({tx_send, credit_ret})
        2'b10: credit_count <= credit_count - 1'b1; // spent 1 credit
        2'b01: credit_count <= (credit_count < MAX_CREDITS[3:0]) ? (credit_count + 1'b1) : credit_count; // returned 1
        default: credit_count <= credit_count; // both 00 or 11 (send and return in same cycle)
      endcase
    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 4 · On-Chip Protocols

What You Will Learn

By solving Credit-Based Flow Control — Credit Management, 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

Implement a transmitter credit manager with initial credits MAX_CREDITS (default 4). Transmitter can send when credits > 0, decrementing credits; credits return via credit_return strobe.

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: Understand credit-based flow control used in PCIe, NoC (Network-on-Chip), and NVLink for high-latency inter-chip links.

Prerequisites: Flow control, counters, latency-insensitive protocols.

Port List & Interface Timing

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

NameDirWidthDescription
clkinput1Clock signal
areset_ninput1Active-low reset
tx_reqinput1Transmit request from internal core
credit_retinput1Credit return strobe from remote receiver
tx_sendoutput1Packet transmitted onto physical link
credit_countoutput4Current available credit balance

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Transmitter transmits (`tx_send=1`) only when `credit_count > 0`. Each returned credit (`credit_ret=1`) increments `credit_count`.

Synthesis Constraints: Total credits must never exceed `MAX_CREDITS`. Credit counter must not underflow or overflow.

Architectural Deep Dive & Implementation Walkthrough

Valid-Ready handshakes break down over long physical cables or printed circuit board traces because round-trip propagation latency causes pipeline stalls whenever `ready` toggles. Credit-based flow control decouples transmitter and receiver: the receiver pre-allocates buffer credits to the sender. The sender transmits freely at line rate until credits reach 0, completely hiding cable latency.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Allowing `credit_count` to decrement below 0 (underflow) when `tx_req` is asserted with 0 credits.', 'Not accounting for simultaneous transmission and credit return in the same clock cycle.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

PCI Express (PCIe) Transaction Layer Protocol (TLP) and high-speed Network-on-Chip (NoC) interconnects (ARM CoreLink NIC-400 / CMN-700) exclusively use credit-based flow control.

Starter RTL Code

module top_module #(
  parameter MAX_CREDITS = 4
)(
  input        clk,
  input        areset_n,
  input        tx_req,
  input        credit_ret,
  output       tx_send,
  output reg [3:0] credit_count
);

  // Credit-based flow control manager

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module #(
  parameter MAX_CREDITS = 4
)(
  input        clk,
  input        areset_n,
  input        tx_req,
  input        credit_ret,
  output       tx_send,
  output reg [3:0] credit_count
);
  // Can send if core requests and we have available credits
  assign tx_send = tx_req && (credit_count > 4'd0);

  always @(posedge clk or negedge areset_n) begin
    if (!areset_n) begin
      credit_count <= MAX_CREDITS[3:0];
    end else begin
      case ({tx_send, credit_ret})
        2'b10: credit_count <= credit_count - 1'b1; // spent 1 credit
        2'b01: credit_count <= (credit_count < MAX_CREDITS[3:0]) ? (credit_count + 1'b1) : credit_count; // returned 1
        default: credit_count <= credit_count; // both 00 or 11 (send and return in same cycle)
      endcase
    end
  end
endmodule
Advertisement

Related RTL Problems in Level 4

Frequently Asked Questions

What does Credit-Based Flow Control — Credit Management require?

Implement a transmitter credit manager with initial credits MAX_CREDITS (default 4). Transmitter can send when credits > 0, decrementing credits; credits return via credit_return strobe. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: cdc, industry-rtl, arbiters, clock-domain-crossing, hard, credit-flow-control. 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 Credit-Based Flow Control — Credit Management to assess real-world synthesizability and race-condition awareness.

Advertisement