DescriptionQ121
Q121DVDesignASIC interview problem
Monitor a credit-based link
TechniquesDVDesignArchCredit flow controlProtocol monitor
DifficultyMedium
TopicVerification Utilities
LanguageSystemVerilog
Requirements5 checkpoints
01
Problem
Monitor a producer-consumer link in which each transmission consumes one credit and each return restores one credit. Detect a transmission with no available credit and a return that would exceed the legal maximum.
Class declarationSystemVerilog
class CreditMonitor;
function new(int initial_credits = 16, int max_credits = 16);
function void on_tx();
function void on_credit_return();
function int get_current_credits();
function int error_count();
endclassExample input and output
Use this case to check your interpretationInput
initial_credits=2, max_credits=4; transmit three times; return five timesOutput
credits 1,0, then underflow rejected at 0; four legal returns restore 4; fifth return rejected; error_count=2Explanation
Rejected underflow and overflow events leave state unchanged while legal sequential events preserve the configured maximum.
02
Requirements (5)
- Validate that zero is less than or equal to initial_credits and initial_credits is less than or equal to max_credits.
- Leave state unchanged when underflow or overflow is detected.
- Track any legal sequential interleaving of transmit and return events.
- Expose current credits and the cumulative error count.
- Treat max_credits as the legal capacity even when initial_credits begins below it.
