forked from tanchou/Verilog
Refactor uart_tx module to implement FIFO functionality with write and read pointers
This commit is contained in:
@@ -12,5 +12,26 @@
|
|||||||
output wire empty,
|
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
|
endmodule
|
||||||
|
Reference in New Issue
Block a user