diff options
| author | uvok | 2025-12-29 12:51:39 +0100 |
|---|---|---|
| committer | uvok | 2025-12-29 12:51:39 +0100 |
| commit | fd0c169c1a7a080389c593fd50a816303f795d38 (patch) | |
| tree | 6b9a20d83138a1bd24de20172cc6e423ebfdb9fa | |
| parent | bd75f7d502048732cb434c9e8739ea04a7fb07ee (diff) | |
fifo: Count bytes
| -rw-r--r-- | fifo.v | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -5,8 +5,8 @@ module fifo #( input rst_i, input clk_i, - input data_write_i, - input data_read_i, + input write_i, + input read_i, output empty_o, output full_o, @@ -18,10 +18,26 @@ module fifo #( ); +reg [$clog2(DATA_DEPTH):0] r_count; + +initial begin + r_count = 0; +end + always @(posedge clk_i or negedge rst_i) begin if (!rst_i) begin - + r_count <= 0; + end else if (write_i && read_i) begin + // nothing to do + end else if (write_i && !full_o) begin + r_count <= r_count + 1; + end else if (read_i && !empty_o) begin + r_count <= r_count - 1; end end +assign empty_o = r_count == 0; +assign full_o = r_count >= DATA_DEPTH - 1; + + endmodule |
