Hardware interview practice
Model credit-based flow control
Implement a small reference model for a transmitter that may send only when at least one credit is available. Sending consumes one credit and asynchronous returns replenish credits.
Reviewed example
Work through one case
Input
capacity=2, initial=2; send(), send(), send(), return_credits(1)Expected output
credits: 1,0; third send raises underflow and stays 0; return restores credits to 1The rejected send never makes the count negative, and every successful transition preserves 0 <= credits <= 2.
What to cover
Requirements
- Reject a send at zero credits without allowing the count to become negative.
- Reject negative credit returns and define whether returns may exceed the configured capacity.
- Expose the current count for scoreboard diagnostics.
- Maintain the invariant 0 <= credits <= capacity after every successful operation.
