easy 10 pts Solved

Credit-Based Flow Control Counter

Track available send credits so a sender never transmits more than the receiver has buffer space for — the flow-control mechanism behind NoC and high-speed serial links.

Verilog problems / Sequential Design

What you must build

Track available send credits so a sender never transmits more than the receiver has buffer space for — the flow-control mechanism behind NoC and high-speed serial links.

Engineers use “Credit-Based Flow Control Counter” as a building block in sequential design. Interviewers ask for the same ports and the same corner cases this judge covers. Completing it in the browser is the same skill as writing synthesizable RTL at work, minus the EDA license.

Concept: A sender may only spend a credit when it actually has one: if(send && can_send) credits<=credits-1, alongside independently gaining one back on credit_return. Dropping the can_send guard on the decrement lets send fire with zero credits available, underflowing the counter to its maximum value — which is doubly dangerous here, because can_send is derived from credits!=0, so the underflow doesn't just corrupt the count, it flips the flow-control gate back to "go ahead and send more" at exactly the moment the sender should be blocked.

Port contract

The judge instantiates exactly these ports. Extra ports or a different module name fail to elaborate.

NameDirWidthDescription
clkinput1Clock
rstinput1Sync active-high reset (credits=4, full)
sendinput11 to spend a credit this cycle
credit_returninput11 to gain a credit back this cycle
creditsoutput3Available credits, 0-4
can_sendoutput11 if credits!=0

How to approach this kata

This is a medium kata: you will need sequential logic or a small FSM. Decide what is registered versus combinational before you type. Reset polarity and clock edge must match the spec; the judge will fail you on the first mismatched cycle.

Hidden tests instantiate top_module, drive the ports, and compare every sample against a golden model. They do not grade coding style. They do grade X/Z, off-by-one counters, and ignoring enables. Sign in only when you want the run saved on the leaderboard — the specification below is public.

Starter shape

Copy this skeleton into the editor (or press Reset starter). Fill the body; do not rename the module.

module top_module(
  input  clk,
  input  rst,
  input  send,
  input  credit_return,
  output reg [2:0] credits,
  output can_send
);

  // Your code here — MAX=4. can_send=credits!=0. send only decrements when can_send; credit_return
  // increments (capped at MAX). Handle both happening the same cycle without under/overflow.

Why this shows up in interviews

Credit-Based Flow Control Counter sits under Sequential Design (sequential, counter, protocol). Concept: A sender may only spend a credit when it actually has one: if(send && can_send) credits<=credits-1 , alongside independently gaining one back on credit_return . Dropping the can_send guard on the decrement lets send fire with zero credits available, underflowing the counter to its maximum value — which is doubly dangerous here, because can_send is derived from credits!=0 , so the underflow doesn't just corrupt the count, it flips the flow-control gate back to "go ahead and send more" at exactly the moment the sender should be blocked.

A passing solution is synthesizable intent: no delays in the DUT, no initial blocks inside top_module, and no reference to testbench tasks. Use blocking assignments only in combinational always blocks; use non-blocking for registers clocked by clk.

Related problems

  • D Flip-Flop with Asynchronous Reset — Standard D flip-flop with an active-low asynchronous reset. Reset clears q immediately, without waiting for a clock edge.
  • 4-Bit Shift Register (SIPO) — Serial-in, parallel-out shift register. Each clock, shift left and load sin into the LSB. Sync active-high reset clears q.
  • JK Flip-Flop — The flip-flop with no forbidden state: j=k=1 toggles instead of racing. Classic building block for counters.
  • 4-Bit Up/Down Counter — A synchronous counter that increments or decrements each clock edge depending on a direction input, with a synchronous reset.

FAQ

What does this problem require?

What does the Credit-Based Flow Control Counter problem ask for? Track available send credits so a sender never transmits more than the receiver has buffer space for — the flow-control mechanism behind NoC and high-speed serial links. Implement it as Verilog module top_module with the listed ports.

Combinational or sequential?

Is Credit-Based Flow Control Counter combinational or sequential? Tags: sequential, counter, protocol. Follow the clock/reset ports if they appear in the table; if there is no clock, use continuous assignment or combinational always @(*).

How does the auto-grader work?

How is Credit-Based Flow Control Counter graded? A hidden SystemVerilog/Verilog testbench in the EcrioniX judge simulates your module in the browser. You pass when every directed vector matches, including the waveform contract shown on this page.

Write a module named top_module matching the ports below exactly.
Expected waveform
Your solution
Judge output
// Output appears after you run tests.