RTL Problems / Level 8 · Advanced RTL & Protocol Design
What You Will Learn
By solving Programmable FIFO Watermark & Threshold Controller, 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
Design a programmable watermark controller generating almost-full and almost-empty interrupt thresholds for DMA flow control.
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.
Prerequisites: Watermark indicators, DMA burst thresholds, FIFO occupancy counters.
Port List & Interface Timing
The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:
| Port | Dir | Width | Description |
|---|---|---|---|
clk, rst_n | input | 1 | Clock and active-low synchronous reset |
push, pop | input | 1, 1 | Enqueue and dequeue strobes |
almost_full_thresh[3:0] | input | 4 | Upper watermark threshold |
almost_empty_thresh[3:0] | input | 4 | Lower watermark threshold |
almost_full, almost_empty | output | 1, 1 | Programmable watermark status indicators |
full, empty | output | 1, 1 | Absolute capacity boundaries |
occupancy[4:0] | output | 5 | Exact item count (0 to 16) |
Timing Constraints & Synthesizable RTL Rules
Timing Contract: Clocked on posedge clk with active-low rst_n. Count increments on push, decrements on pop, holds on both.
Synthesis Constraints: Synthesizable Verilog-2001. No latch inference.
Architectural Deep Dive & Implementation Walkthrough
DMA Flow Control Using Watermarks
Direct Memory Access (DMA) controllers cannot wait until a buffer is completely full or completely empty before issuing bus requests. Doing so leads to buffer under-run or bus under-utilization.
Watermark Thresholds
- Almost Full Watermark: Warns the DMA scatter-gather engine that the buffer is reaching capacity (e.g. 12/16 slots), allowing it to throttle upstream producers before overflow occurs.
- Almost Empty Watermark: Signals that the buffer is nearly drained (e.g. 2/16 slots), prompting a burst read request to refill it before underflow occurs.
Common RTL Designer Pitfalls
Using a 4-bit counter for a depth-16 buffer, which wraps around from 15 to 0 instead of reaching 16.
Silicon & Hardware Engineering Notes
High-performance PCIe Root Complexes use programmable watermark thresholds to tune DMA burst lengths according to payload MTU.
Starter RTL Code
module top_module (
input wire clk,
input wire rst_n,
input wire push,
input wire pop,
input wire [3:0] almost_full_thresh,
input wire [3:0] almost_empty_thresh,
output wire almost_full,
output wire almost_empty,
output wire full,
output wire empty,
output reg [4:0] occupancy
);
// Implement watermark evaluator:
// 1. Capacity = 16 words.
// 2. Track occupancy (0 to 16).
// 3. full = (occupancy == 16); empty = (occupancy == 0).
Verified Reference Solution
🔒 Reveal Verified Reference RTL Solution
module top_module (
input wire clk,
input wire rst_n,
input wire push,
input wire pop,
input wire [3:0] almost_full_thresh,
input wire [3:0] almost_empty_thresh,
output wire almost_full,
output wire almost_empty,
output wire full,
output wire empty,
output reg [4:0] occupancy
);
assign full = (occupancy == 5'd16);
assign empty = (occupancy == 5'd0);
assign almost_full = (occupancy >= {1'b0, almost_full_thresh});
assign almost_empty = (occupancy <= {1'b0, almost_empty_thresh});
wire valid_push = push && (!full || pop);
wire valid_pop = pop && !empty;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
occupancy <= 5'd0;
end else begin
case ({valid_push, valid_pop})
2'b10: occupancy <= occupancy + 5'd1;
2'b01: occupancy <= occupancy - 5'd1;
default: ; // 2'b00 or 2'b11 -> maintain count
endcase
end
end
endmodule
Related RTL Problems in Level 8
- Watchdog Timer — A timeout that fires unless it keeps getting "kicked" — the safety-net circuit that resets a hung system when its heartbeat stops arriving.
- Fixed-Priority Arbiter — Grant exactly one of four requesters at a time, always favoring the highest-index request when several arrive together.
- CRC-4 Generator — Compute the 4-bit CRC remainder of an 8-bit message using the CRC-4 (poly x⁴+x+1) bit-serial algorithm, entirely in combinational logic.
Connected EcrioniX Learning Resources
Accelerate your VLSI engineering knowledge with these curated learning materials:
Progress through step-by-step verified modules from fundamentals to advanced silicon design.
Benchmark your hardware knowledge across 10 semiconductor domains and receive study roadmaps.
Explore foundational circuit theory, waveform timing, and physical hardware implementation.
Frequently Asked Questions
What does Programmable FIFO Watermark & Threshold Controller require?
Design a programmable watermark controller generating almost-full and almost-empty interrupt thresholds for DMA flow control. Implement it as Verilog module top_module matching the listed ports.
Is this design combinational or sequential?
Tags: advanced-rtl, fifo-and-buffer-architecture, systemverilog, asic, fpga. 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 Programmable FIFO Watermark & Threshold Controller to assess real-world synthesizability and race-condition awareness.