Skip to content
Snippets Groups Projects
Commit ec5487e9 authored by dam1n19's avatar dam1n19
Browse files

Fix FIFO Read Bug

parent 16b662c6
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,11 @@ module fifo_vr #( ...@@ -51,6 +51,11 @@ module fifo_vr #(
assign status_ptr_dif = ptr_dif; assign status_ptr_dif = ptr_dif;
logic [PTR_W-1:0] still_read_ptr;
assign still_read_ptr = ((ptr_dif - 1) + {{(PTR_W-1){1'b0}},data_in_shake}) - 1;
logic dinshake_min1;
assign dinshake_min1 = (data_in_shake - 1'b1);
// EXAMPLE: Conditions to write and read from FIFO's // EXAMPLE: Conditions to write and read from FIFO's
// Write Ptr | Read Ptr | Ptr_Dif | Valid Write | Valid Read // Write Ptr | Read Ptr | Ptr_Dif | Valid Write | Valid Read
// 000 - 000 = 000 | Y | N // 000 - 000 = 000 | Y | N
...@@ -75,6 +80,10 @@ module fifo_vr #( ...@@ -75,6 +80,10 @@ module fifo_vr #(
read_ptr <= 0; read_ptr <= 0;
data_in_ready <= 1'b0; data_in_ready <= 1'b0;
data_out_valid <= 1'b0; data_out_valid <= 1'b0;
// Ensure FIFO Values are Known
for (int i = 0; i < DEPTH; i++) begin
fifo[i] <= 'b0;
end
end else if (en == 1'b1) begin end else if (en == 1'b1) begin
// Enable signal is High // Enable signal is High
// Write Logic // Write Logic
...@@ -117,8 +126,8 @@ module fifo_vr #( ...@@ -117,8 +126,8 @@ module fifo_vr #(
// -> the "-1" causes dif of 0 to wrap where (dif - 1) becomes > DEPTH // -> the "-1" causes dif of 0 to wrap where (dif - 1) becomes > DEPTH
if (data_out_shake) begin if (data_out_shake) begin
// Successful Handshake Increment Read Pointer // Successful Handshake Increment Read Pointer
read_ptr <= read_ptr + 1; read_ptr <= read_ptr + 1;
if (((ptr_dif - 1) + {{(PTR_W-1){1'b0}},(data_in_shake - 1'b1)}) < DEPTH) begin if (((ptr_dif - 1) + {{(PTR_W-1){1'b0}},data_in_shake}) - 1 < DEPTH) begin
// Still Data in FIFO after latest Read // Still Data in FIFO after latest Read
// If there is a successful write this clock cycle, // If there is a successful write this clock cycle,
// there will be one more piece of data in the FIFO // there will be one more piece of data in the FIFO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment