1
0
mirror of https://github.com/pConst/basic_verilog.git synced 2025-01-14 06:42:54 +08:00

Fixed usedw[] calculations in preview_fifo. Other minor fixes

This commit is contained in:
Konstantin Pavlov 2020-10-30 11:51:59 +03:00
parent eb69a3a374
commit 2d2041a663
4 changed files with 46 additions and 32 deletions

View File

@ -34,18 +34,20 @@ dynamic_delay #(
module dynamic_delay #( parameter module dynamic_delay #( parameter
LENGTH = 63, // maximum delay chain length LENGTH = 63, // maximum delay chain length
WIDTH = 4, // data width WIDTH = 4, // data width
SEL_W = $clog2( (LENGTH+1)*WIDTH ) // output selector width SEL_W = $clog2( (LENGTH+1)*WIDTH ) // output selector width
// plus one is for zero delay element // plus one is for zero delay element
)( )(
input clk, input clk,
input nrst, input nrst,
input ena, input ena,
input [WIDTH-1:0] in, // input data input [WIDTH-1:0] in, // input data
input [SEL_W-1:0] sel, // output selector // bit in[0] is the "oldest" one
output logic [WIDTH-1:0] out // output data // bit in[WIDTH] is considered the most recent
input [SEL_W-1:0] sel, // output selector
output logic [WIDTH-1:0] out // output data
); );

View File

@ -18,20 +18,25 @@
preview_fifo #( preview_fifo #(
.WIDTH( 16 ), .WIDTH( 16 ),
.DEPTH( 16 ) .DEPTH( 16 ) // must be at least 8
) pf ( ) pf (
.clk( clk ), .clk( clk ),
.nrst( nrst ), .nrst( nrst ),
// input port // input port
.wrreq( ), // 3 bit one-hot .wrreq( ), // 3 bit one-hot
.id0( ), // first word .id0( ), // first word
.id1( ), // secong word .id1( ), // secong word
// output port // output port
.rdreq( ), // 3 bit one-hot .rdreq( ), // 3 bit one-hot
.od0( ), // first word .od0( ), // first word
.od1( ) // second word .od1( ), // second word
.empty( [1:0] ), // 2'b00, 2'b10 or 2'b11
.full( [1:0] ), // 2'b11, 2'b01 or 2'b00
.usedw( [USED_W:0] ) // attention to the width!
); );
--- INSTANTIATION TEMPLATE END ---*/ --- INSTANTIATION TEMPLATE END ---*/
@ -66,7 +71,8 @@ module preview_fifo #( parameter
// when FIFO has no words - // when FIFO has no words -
// both of these flags will be active // both of these flags will be active
output [1:0] full, // "full" flags, logic is similar to "empty" output [1:0] full, // "full" flags, logic is similar to "empty"
output [USED_W-1:0] usedw // word count output logic[USED_W:0] usedw // word count, attention to the additional
// MSB for holding word count when full
); );
@ -81,10 +87,6 @@ logic [1:0][WIDTH-1:0] f_wrdata;
logic [1:0] f_rdreq; logic [1:0] f_rdreq;
logic [1:0][WIDTH-1:0] f_rddata; logic [1:0][WIDTH-1:0] f_rddata;
// usedw0[] == usedw1[] OR usedw0[] == (usedw1[]-1) combinations are possible
logic [1:0][USED_W-2:0] f_usedw;
// underflow and owerflow protection flags // underflow and owerflow protection flags
logic w0_valid, w1_valid, w2_valid; logic w0_valid, w1_valid, w2_valid;
logic r0_valid, r1_valid, r2_valid; logic r0_valid, r1_valid, r2_valid;
@ -148,11 +150,11 @@ always_ff @(posedge clk) begin
end else begin end else begin
if( wr_ptr ) begin if( wr_ptr ) begin
if( wrreq[2:0] == 3'b010 && w1_valid ) begin if( wrreq[2:0] == 3'b010 && w1_valid ) begin
wr_ptr = ~wr_ptr; // no protection against full wr_ptr = ~wr_ptr;
end end
end else begin end else begin
if( wrreq[2:0] == 3'b010 && w0_valid ) begin if( wrreq[2:0] == 3'b010 && w0_valid ) begin
wr_ptr = ~wr_ptr; // no protection against full wr_ptr = ~wr_ptr;
end end
end end
end // nrst end // nrst
@ -221,6 +223,9 @@ end
// internal FIFOs itself ======================================================= // internal FIFOs itself =======================================================
logic [1:0][USED_W-2:0] f_usedw_i;
logic [1:0][USED_W-1:0] f_usedw;
scfifo #( scfifo #(
.LPM_WIDTH( WIDTH ), .LPM_WIDTH( WIDTH ),
.LPM_NUMWORDS( DEPTH/2 ), // must be at least 4 .LPM_NUMWORDS( DEPTH/2 ), // must be at least 4
@ -231,7 +236,7 @@ end
.ENABLE_ECC( "FALSE" ), .ENABLE_ECC( "FALSE" ),
.ALLOW_RWCYCLE_WHEN_FULL( "ON" ), .ALLOW_RWCYCLE_WHEN_FULL( "ON" ),
.USE_EAB( "ON" ) .USE_EAB( "ON" )
) fifo0 ( ) internal_fifo0 (
.clock( clk ), .clock( clk ),
.aclr( 1'b0 ), .aclr( 1'b0 ),
.sclr( ~nrst ), .sclr( ~nrst ),
@ -243,7 +248,7 @@ end
.q( f_rddata[0][WIDTH-1:0] ), .q( f_rddata[0][WIDTH-1:0] ),
.empty( empty[0] ), .empty( empty[0] ),
.full( full[0] ), .full( full[0] ),
.usedw( f_usedw[0][USED_W-2:0] ) .usedw( f_usedw_i[0][USED_W-2:0] )
); );
scfifo #( scfifo #(
@ -256,7 +261,7 @@ end
.ENABLE_ECC( "FALSE" ), .ENABLE_ECC( "FALSE" ),
.ALLOW_RWCYCLE_WHEN_FULL( "ON" ), .ALLOW_RWCYCLE_WHEN_FULL( "ON" ),
.USE_EAB( "ON" ) .USE_EAB( "ON" )
) fifo1 ( ) internal_fifo1 (
.clock( clk ), .clock( clk ),
.aclr( 1'b0 ), .aclr( 1'b0 ),
.sclr( ~nrst ), .sclr( ~nrst ),
@ -268,11 +273,18 @@ end
.q( f_rddata[1][WIDTH-1:0] ), .q( f_rddata[1][WIDTH-1:0] ),
.empty( empty[1] ), .empty( empty[1] ),
.full( full[1] ), .full( full[1] ),
.usedw( f_usedw[1][USED_W-2:0] ) .usedw( f_usedw_i[1][USED_W-2:0] )
); );
assign usedw[USED_W-1:0] = f_usedw[0][USED_W-2:0] + f_usedw[1][USED_W-2:0]; always_comb begin
f_usedw[0][USED_W-1:0] = ( full[0] )?
( 1<<(USED_W-1) ):
( {1'b0,f_usedw_i[0][USED_W-2:0]} );
f_usedw[1][USED_W-1:0] = ( full[1] )?
( 1<<(USED_W-1) ):
( {1'b0,f_usedw_i[1][USED_W-2:0]} );
usedw[USED_W:0] = f_usedw[0][USED_W-1:0] + f_usedw[1][USED_W-1:0];
end
endmodule endmodule

View File

@ -126,7 +126,7 @@ end
logic [1:0] empty; logic [1:0] empty;
logic [1:0] full; logic [1:0] full;
logic [4:0] usedw; logic [5:0] usedw;
logic [7:0] od0; logic [7:0] od0;
logic [7:0] od1; logic [7:0] od1;
@ -134,7 +134,7 @@ logic [7:0] od1;
logic [2:0] rdreq; logic [2:0] rdreq;
always_ff @(posedge clk200) begin always_ff @(posedge clk200) begin
`ifdef R_ENA `ifdef R_ENA
if( (usedw[4:0] >= 4) ) begin //&& dis_writes ) begin if( (usedw[5:0] >= 4) ) begin //&& dis_writes ) begin
if( RandomNumber1[14:13] == 2'b11 ) begin if( RandomNumber1[14:13] == 2'b11 ) begin
rdreq[2:0] <= 3'b010; rdreq[2:0] <= 3'b010;
//$display("RD 1 %h",od0[7:0]); //$display("RD 1 %h",od0[7:0]);
@ -197,7 +197,7 @@ preview_fifo #(
.empty( empty[1:0] ), .empty( empty[1:0] ),
.full( full[1:0] ), .full( full[1:0] ),
.usedw( usedw[4:0] ) .usedw( usedw[5:0] )
); );

View File

@ -13,8 +13,8 @@
/* --- INSTANTIATION TEMPLATE BEGIN --- /* --- INSTANTIATION TEMPLATE BEGIN ---
pulse_stretch #( pulse_stretch #(
.WIDTH( 8 ) .WIDTH( 8 ),
.USE_COUNTER(0) .USE_CNTR( 0 )
) ps1 ( ) ps1 (
.clk( clk ), .clk( clk ),
.nrst( nrst ), .nrst( nrst ),