Localparam Derivation with Clog2
A FIFO's pointer width follows from its depth. Deriving it with $clog2(DEPTH) stops anyone from passing a depth and a width that disagree.
This module is a synchronous FIFO that derives its internal pointer sizes automatically. It accepts DATA_WIDTH and DEPTH as parameters. Internally, it must use the SystemVerilog $clog2 function to calculate a localparam for the address width. The FIFO supports standard write and read operations, maintaining full and empty flags.
Positive-edge triggered clock clk. Asynchronous active-low reset rst_n. On reset, all internal pointers, counters, and the read_data output must be driven to 0. The empty flag must be 1, and the full flag must be 0.
Priority and edge cases:
- If
write_enis asserted and the FIFO is not full,write_datais written and the internal write pointer increments. - If
read_enis asserted and the FIFO is not empty, data is read intoread_dataand the internal read pointer increments. - If both
write_enandread_enare asserted:- If the FIFO is neither full nor empty, both operations execute simultaneously.
- If the FIFO is full, the read executes and the write is ignored.
- If the FIFO is empty, the write executes and the read is ignored.
- Writes to a full FIFO (without a simultaneous read) are ignored.
- Reads from an empty FIFO (without a simultaneous write) are ignored, and
read_dataholds its previous value.
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset |
write_en |
input | 1 | Write enable |
write_data |
input | DATA_WIDTH |
Data to be written |
read_en |
input | 1 | Read enable |
read_data |
output | DATA_WIDTH |
Registered read data |
full |
output | 1 | Asserted when the FIFO cannot accept more writes |
empty |
output | 1 | Asserted when the FIFO has no data to read |
Constraints
- You must declare a
localparamfor the address width using$clog2(DEPTH). DEPTHwill always be a power of 2 (e.g., 4, 8, 16, 32).read_data,full, andemptymust update on the positive edge ofclk(or immediately onrst_nassertion).- You must not use any external modules or macros.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of SystemVerilog RTL
Problem 9 of 15 in the SystemVerilog RTL track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks