1
0
forked from tanchou/Verilog

Refactor uart_tx module to implement FIFO functionality with write and read pointers

This commit is contained in:
Gamenight77
2025-05-05 15:29:45 +02:00
parent 7156abf4e7
commit 1d39c68b5c

View File

@@ -12,5 +12,26 @@
output wire empty,
);
reg [WIDTH-1:0] fifo[0:DETPH-1];
reg [3:0] wr_ptr;
reg [3:0] rd_ptr;
reg [3:0] count;
assign full = (count == DETPH);
assign empty = (count == 0);
assign rd_data = fifo[rd_ptr];
always @(posedge clk) begin
if (wr_en && !full) begin
fifo[wr_ptr] <= wr_data;
wr_ptr <= (wr_ptr + 1) % DETPH;
count <= count + 1;
end
if (rd_en && !empty) begin
rd_ptr <= (rd_ptr + 1) % DETPH;
count <= count - 1;
end
end
endmodule