// sync_fifo.sv // Synchronous FIFO (one clock) with a registered read port, so the storage // maps to block RAM or distributed RAM. // // Write: data is stored when wr_en = 1 and full = 0. // Read: when rd_en = 1 and empty = 0, the oldest word appears on rd_data // on the NEXT clock edge (read latency 1). // Pointers carry one extra bit. Equal pointers mean empty. Pointers that // differ only in the extra (top) bit mean full. `timescale 1ns/1ps module sync_fifo #( parameter int DW = 8, // data width parameter int AW = 4 // address width, depth = 2**AW ) ( input logic clk, input logic rst, // synchronous, active high input logic wr_en, input logic [DW-1:0] wr_data, output logic full, input logic rd_en, output logic [DW-1:0] rd_data, output logic empty, output logic [AW:0] count // words stored, 0 to 2**AW ); logic [DW-1:0] mem [0:(1<