合起来 dat_recv_blocks
`timescale 1ns / 1ps
module dat_recv_blocks(
clk ,
rst ,
din ,
din_clk_p ,
dout ,
real_clk_p ,
dout_clk_p ,
LENGTH_REAL ,
LENGTH_THIMBLE ,
LENGTH_DIV4 ,
thimble_valid
);
input clk ;
input rst ;
input [7:0] din ;
input din_clk_p ;
output [15:0] dout;
output real_clk_p ;
output dout_clk_p ;
output [15:0] LENGTH_REAL ;
output [23:0] LENGTH_THIMBLE ;
output [15:0] LENGTH_DIV4 ;
output thimble_valid ;
reg delay_din_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_din_clk_p<=1'b0;
end
else
begin
delay_din_clk_p<=din_clk_p;
end
end
reg select_0_1 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
select_0_1<=1'b0;
end
else if((din_clk_p==1'b1)&&(delay_din_clk_p==1'b0))
begin
select_0_1<=din[0];
end
else
begin
select_0_1<=select_0_1;
end
end
reg pack_check_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_check_pulse<=1'b0;
end
else if((din_clk_p==1'b1)&&(delay_din_clk_p==1'b0))
begin
pack_check_pulse<=1'b1;
end
else
begin
pack_check_pulse<=1'b0;
end
end
reg pack_check;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_check<=1'b0;
end
else if(pack_check_pulse==1'b1)
begin
if((din[7:4]<=din[3:0])&&(din[7:4]>=4'd1)&&(din[7:4]<=4'd7))
begin
pack_check<=1'b1;
end
else
begin
pack_check<=1'b0;
end
end
else
begin
pack_check<=pack_check;
end
end
reg pack_end;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_end<=1'b0;
end
else if(pack_check_pulse==1'b1)
begin
if((din[7:4]==din[3:0])&&(din[7:4]>=4'd1)&&(din[7:4]<=4'd7))
begin
pack_end<=1'b1;
end
else
begin
pack_end<=1'b0;
end
end
else
begin
pack_end<=pack_end;
end
end
reg length_check_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
length_check_pulse<=1'b0;
end
else
begin
length_check_pulse<=pack_check_pulse;
end
end
reg length_check;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
length_check<=1'b0;
end
else if(length_check_pulse)
begin
if((din<=8'd220)&&(din>=8'd1))
begin
length_check<=1'b1;
end
else
begin
length_check<=1'b0;
end
end
else
begin
length_check<=length_check;
end
end
reg [7:0] local_length;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
local_length<=8'd0;
end
else if(length_check_pulse)
begin
local_length<=din;
end
else
begin
local_length<=local_length;
end
end
reg wr_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wr_pulse<=1'b0;
end
else
begin
wr_pulse<=length_check_pulse;
end
end
reg [15:0] local_cnts;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
local_cnts<=16'hffff;
end
else if(local_cnts<=16'd230)
begin
local_cnts<=local_cnts + 1'b1;
end
else if((wr_pulse==1'b1)&&(length_check==1'b1)&&(pack_check==1'b1))
begin
local_cnts<=16'd0;
end
else
begin
local_cnts<=local_cnts;
end
end
reg wea_0 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wea_0<=1'b0;
end
else if((select_0_1==1'b0)&&(local_cnts<=16'd220)&&(local_cnts<=local_length)&&(local_cnts>=16'd1))
begin
wea_0<=1'b1;
end
else
begin
wea_0<=1'b0;
end
end
reg wea_1 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wea_1<=1'b0;
end
else if((select_0_1==1'b1)&&(local_cnts<=16'd220)&&(local_cnts<=local_length)&&(local_cnts>=16'd1))
begin
wea_1<=1'b1;
end
else
begin
wea_1<=1'b0;
end
end
reg [15:0] addra_0;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addra_0<=16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd228)&&(pack_end==1'b1))
begin
addra_0<=16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts<=16'd221)&&(local_cnts<=(local_length + 1'b1))&&(local_cnts>=16'd2))
begin
addra_0<=addra_0 + 1'b1;
end
else
begin
addra_0<=addra_0;
end
end
reg [15:0] addra_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addra_1<=16'd0;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd228)&&(pack_end==1'b1))
begin
addra_1<=16'd0;
end
else if((select_0_1==1'b1)&&(local_cnts<=16'd221)&&(local_cnts<=(local_length +1'b1 ))&&(local_cnts>=16'd2))
begin
addra_1<=addra_1 + 1'b1;
end
else
begin
addra_1<=addra_1;
end
end
reg [7:0] delay_dina_0 ;
reg [7:0] delay_dina_1 ;
reg [7:0] delay_dina_2 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_0<=8'd0;
end
else
begin
delay_dina_0<=din;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_1<=8'd0;
end
else
begin
delay_dina_1<=delay_dina_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_2<=8'd0;
end
else
begin
delay_dina_2<=delay_dina_1;
end
end
reg [15:0] all_dat_num_0;
reg [15:0] all_dat_num_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
all_dat_num_0<=16'd2047;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
all_dat_num_0<=addra_0;
end
else
begin
all_dat_num_0<=all_dat_num_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
all_dat_num_1<=16'd2047;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
all_dat_num_1<=addra_1;
end
else
begin
all_dat_num_1<=all_dat_num_1;
end
end
reg [15:0] LENGTH_REAL ;
reg [23:0] LENGTH_THIMBLE ;
reg [15:0] LENGTH_DIV4 ;
reg thimble_valid ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_REAL<=16'd2047;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
LENGTH_REAL<=addra_0;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
LENGTH_REAL<=addra_1;
end
else
begin
LENGTH_REAL<=LENGTH_REAL;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
thimble_valid <= 1'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_0[1:0] == 2'd0)
begin
thimble_valid <= 1'b0;
end
else
begin
thimble_valid <= 1'b1;
end
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_1[1:0] == 2'd0)
begin
thimble_valid <= 1'b0;
end
else
begin
thimble_valid <= 1'b1;
end
end
else
begin
thimble_valid <= thimble_valid;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_THIMBLE <= 24'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
case(addra_0[1:0])
2'b00:begin LENGTH_THIMBLE <= 24'd0; end
2'b01:begin LENGTH_THIMBLE <= 24'd3; end
2'b10:begin LENGTH_THIMBLE <= 24'd2; end
2'b11:begin LENGTH_THIMBLE <= 24'd1; end
default:begin LENGTH_THIMBLE<=LENGTH_THIMBLE; end
endcase
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
case(addra_1[1:0])
2'b00:begin LENGTH_THIMBLE <= 24'd0; end
2'b01:begin LENGTH_THIMBLE <= 24'd3; end
2'b10:begin LENGTH_THIMBLE <= 24'd2; end
2'b11:begin LENGTH_THIMBLE <= 24'd1; end
default:begin LENGTH_THIMBLE<=LENGTH_THIMBLE; end
endcase
end
else
begin
LENGTH_THIMBLE <= LENGTH_THIMBLE;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_DIV4 <= 16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_0[1:0] == 2'd0)
begin
LENGTH_DIV4 <= {addra_0[15],addra_0[15],addra_0[15:2]};
end
else
begin
LENGTH_DIV4 <= {addra_0[15],addra_0[15],addra_0[15:2]} + 1'b1;
end
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_1[1:0] == 2'd0)
begin
LENGTH_DIV4 <= {addra_1[15],addra_1[15],addra_1[15:2]};
end
else
begin
LENGTH_DIV4 <= {addra_1[15],addra_1[15],addra_1[15:2]} + 1'b1;
end
end
else
begin
LENGTH_DIV4 <= LENGTH_DIV4;
end
end
reg [15:0] rd_cnts;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
rd_cnts<=16'hffff;
end
else if(rd_cnts<=16'd1600)
begin
rd_cnts<=rd_cnts + 1'b1;
end
else if((local_cnts==16'd228)&&(pack_end==1'b1))
begin
rd_cnts<=16'd0;
end
else
begin
rd_cnts<=rd_cnts;
end
end
reg [15:0] addrb_0;
reg [15:0] addrb_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addrb_0<=16'd0;
end
else if(rd_cnts==16'd1599)
begin
addrb_0<=16'd0;
end
else if((select_0_1==1'b0)&&(rd_cnts<=16'd1539)&&(rd_cnts<=all_dat_num_0)&&(rd_cnts>=16'd0))
begin
addrb_0<=addrb_0 + 1'b1;
end
else
begin
addrb_0<=addrb_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addrb_1<=16'd0;
end
else if(rd_cnts==16'd1599)
begin
addrb_1<=16'd0;
end
else if((select_0_1==1'b1)&&(rd_cnts<=16'd1539)&&(rd_cnts<=all_dat_num_1)&&(rd_cnts>=16'd0))
begin
addrb_1<=addrb_1 + 1'b1;
end
else
begin
addrb_1<=addrb_1;
end
end
reg real_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
real_clk_p<=1'b0;
end
else if(((select_0_1==1'b1)&&(rd_cnts<=16'd1540)&&(rd_cnts<=(all_dat_num_1+1))&&(rd_cnts>=16'd2))||((select_0_1==1'b0)&&(rd_cnts<=16'd1540)&&(rd_cnts<=(all_dat_num_0+1))&&(rd_cnts>=16'd2)))
begin
real_clk_p<=1'b1;
end
else
begin
real_clk_p<=1'b0;
end
end
reg dout_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
dout_clk_p<=1'b0;
end
else if((rd_cnts>=16'd1)&&(rd_cnts<=16'd1541))
begin
if(( select_0_1==1'b1 )&&( rd_cnts <= ( all_dat_num_1 + 1 )))
begin
dout_clk_p<=1'b1;
end
else if((select_0_1==1'b0 )&&( rd_cnts <= ( all_dat_num_0 + 1 )))
begin
dout_clk_p<=1'b1;
end
else
begin
dout_clk_p<=1'b0;
end
end
else
begin
dout_clk_p<=dout_clk_p;
end
end
wire [7:0] doutb_0;
wire [7:0] doutb_1;
reg [15:0] dout;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
dout<=16'd0;
end
else if(rd_cnts==16'd1)
begin
if(select_0_1==1'b1)
begin
dout<=all_dat_num_1 ;
end
else
begin
dout<=all_dat_num_0 ;
end
end
else
begin
if(select_0_1==1'b1)
begin
dout<={dout[15:8],doutb_1};
end
else
begin
dout<={dout[15:8],doutb_0};
end
end
end
blk_mem_8_2048 BLKS_A_0 (
.clka(clk ),
.ena(1'b1 ),
.wea(wea_0 ),
.addra(addra_0 ),
.dina(delay_dina_2 ),
.douta( ),
.clkb(clk ),
.web(1'b0 ),
.addrb(addrb_0 ),
.dinb( ),
.doutb(doutb_0 )
);
blk_mem_8_2048 BLKS_A_1 (
.clka(clk ),
.ena(1'b1 ),
.wea(wea_1 ),
.addra(addra_1 ),
.dina(delay_dina_2 ),
.douta( ),
.clkb(clk ),
.web(1'b0 ),
.addrb(addrb_1 ),
.dinb( ),
.doutb(doutb_1 )
);
endmodule
升级版本: 丢失一小包 整包全部丢弃
`timescale 1ns / 1ps
module dat_recv_block_complete(
clk ,
rst ,
din ,
din_clk_p ,
dout ,
real_clk_p ,
dout_clk_p ,
LENGTH_REAL ,
LENGTH_THIMBLE ,
LENGTH_DIV4 ,
thimble_valid
);
input clk ;
input rst ;
input [7:0] din ;
input din_clk_p ;
output [15:0] dout;
output real_clk_p ;
output dout_clk_p ;
output [15:0] LENGTH_REAL ;
output [23:0] LENGTH_THIMBLE ;
output [15:0] LENGTH_DIV4 ;
output thimble_valid ;
reg delay_din_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_din_clk_p<=1'b0;
end
else
begin
delay_din_clk_p<=din_clk_p;
end
end
reg select_0_1 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
select_0_1<=1'b0;
end
else if((din_clk_p==1'b1)&&(delay_din_clk_p==1'b0))
begin
select_0_1<=din[0];
end
else
begin
select_0_1<=select_0_1;
end
end
reg pack_check_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_check_pulse<=1'b0;
end
else if((din_clk_p==1'b1)&&(delay_din_clk_p==1'b0))
begin
pack_check_pulse<=1'b1;
end
else
begin
pack_check_pulse<=1'b0;
end
end
reg [15:0] min_length;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
min_length<=16'd0;
end
else if(pack_check_pulse==1'b1)
begin
case(din[3:0])
4'd1: begin min_length<=16'd0; end
4'd2: begin min_length<=16'd220; end
4'd3: begin min_length<=16'd440; end
4'd4: begin min_length<=16'd660; end
4'd5: begin min_length<=16'd880; end
4'd6: begin min_length<=16'd1100; end
4'd7: begin min_length<=16'd1320; end
default: begin min_length<=16'd0; end
endcase
end
else
begin
min_length<=min_length;
end
end
reg pack_check;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_check<=1'b0;
end
else if(pack_check_pulse==1'b1)
begin
if((din[7:4]<=din[3:0])&&(din[7:4]>=4'd1)&&(din[7:4]<=4'd7))
begin
pack_check<=1'b1;
end
else
begin
pack_check<=1'b0;
end
end
else
begin
pack_check<=pack_check;
end
end
reg pack_end;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
pack_end<=1'b0;
end
else if(pack_check_pulse==1'b1)
begin
if((din[7:4]==din[3:0])&&(din[7:4]>=4'd1)&&(din[7:4]<=4'd7))
begin
pack_end<=1'b1;
end
else
begin
pack_end<=1'b0;
end
end
else
begin
pack_end<=pack_end;
end
end
reg length_check_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
length_check_pulse<=1'b0;
end
else
begin
length_check_pulse<=pack_check_pulse;
end
end
reg length_check;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
length_check<=1'b0;
end
else if(length_check_pulse)
begin
if((din<=8'd220)&&(din>=8'd1))
begin
length_check<=1'b1;
end
else
begin
length_check<=1'b0;
end
end
else
begin
length_check<=length_check;
end
end
reg [7:0] local_length;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
local_length<=8'd0;
end
else if(length_check_pulse)
begin
local_length<=din;
end
else
begin
local_length<=local_length;
end
end
reg wr_pulse;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wr_pulse<=1'b0;
end
else
begin
wr_pulse<=length_check_pulse;
end
end
reg [15:0] local_cnts;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
local_cnts<=16'hffff;
end
else if(local_cnts<=16'd230)
begin
local_cnts<=local_cnts + 1'b1;
end
else if((wr_pulse==1'b1)&&(length_check==1'b1)&&(pack_check==1'b1))
begin
local_cnts<=16'd0;
end
else
begin
local_cnts<=local_cnts;
end
end
reg wea_0 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wea_0<=1'b0;
end
else if((select_0_1==1'b0)&&(local_cnts<=16'd220)&&(local_cnts<=local_length)&&(local_cnts>=16'd1))
begin
wea_0<=1'b1;
end
else
begin
wea_0<=1'b0;
end
end
reg wea_1 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
wea_1<=1'b0;
end
else if((select_0_1==1'b1)&&(local_cnts<=16'd220)&&(local_cnts<=local_length)&&(local_cnts>=16'd1))
begin
wea_1<=1'b1;
end
else
begin
wea_1<=1'b0;
end
end
reg [15:0] addra_0;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addra_0<=16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd228)&&(pack_end==1'b1))
begin
addra_0<=16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts<=16'd221)&&(local_cnts<=(local_length + 1'b1))&&(local_cnts>=16'd2))
begin
addra_0<=addra_0 + 1'b1;
end
else
begin
addra_0<=addra_0;
end
end
reg [15:0] addra_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addra_1<=16'd0;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd228)&&(pack_end==1'b1))
begin
addra_1<=16'd0;
end
else if((select_0_1==1'b1)&&(local_cnts<=16'd221)&&(local_cnts<=(local_length +1'b1 ))&&(local_cnts>=16'd2))
begin
addra_1<=addra_1 + 1'b1;
end
else
begin
addra_1<=addra_1;
end
end
reg [7:0] delay_dina_0 ;
reg [7:0] delay_dina_1 ;
reg [7:0] delay_dina_2 ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_0<=8'd0;
end
else
begin
delay_dina_0<=din;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_1<=8'd0;
end
else
begin
delay_dina_1<=delay_dina_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
delay_dina_2<=8'd0;
end
else
begin
delay_dina_2<=delay_dina_1;
end
end
reg [15:0] all_dat_num_0;
reg [15:0] all_dat_num_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
all_dat_num_0<=16'd2047;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
all_dat_num_0<=addra_0;
end
else
begin
all_dat_num_0<=all_dat_num_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
all_dat_num_1<=16'd2047;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
all_dat_num_1<=addra_1;
end
else
begin
all_dat_num_1<=all_dat_num_1;
end
end
reg output_flag;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
output_flag<=1'b1;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_0 >= min_length)
begin
output_flag<=1'b1;
end
else
begin
output_flag<=1'b0;
end
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_1 >= min_length)
begin
output_flag<=1'b1;
end
else
begin
output_flag<=1'b0;
end
end
else
begin
output_flag<=output_flag;
end
end
reg [15:0] LENGTH_REAL ;
reg [23:0] LENGTH_THIMBLE ;
reg [15:0] LENGTH_DIV4 ;
reg thimble_valid ;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_REAL<=16'd2047;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
LENGTH_REAL<=addra_0;
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
LENGTH_REAL<=addra_1;
end
else
begin
LENGTH_REAL<=LENGTH_REAL;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
thimble_valid <= 1'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_0[1:0] == 2'd0)
begin
thimble_valid <= 1'b0;
end
else
begin
thimble_valid <= 1'b1;
end
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_1[1:0] == 2'd0)
begin
thimble_valid <= 1'b0;
end
else
begin
thimble_valid <= 1'b1;
end
end
else
begin
thimble_valid <= thimble_valid;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_THIMBLE <= 24'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
case(addra_0[1:0])
2'b00:begin LENGTH_THIMBLE <= 24'd0; end
2'b01:begin LENGTH_THIMBLE <= 24'd3; end
2'b10:begin LENGTH_THIMBLE <= 24'd2; end
2'b11:begin LENGTH_THIMBLE <= 24'd1; end
default:begin LENGTH_THIMBLE<=LENGTH_THIMBLE; end
endcase
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
case(addra_1[1:0])
2'b00:begin LENGTH_THIMBLE <= 24'd0; end
2'b01:begin LENGTH_THIMBLE <= 24'd3; end
2'b10:begin LENGTH_THIMBLE <= 24'd2; end
2'b11:begin LENGTH_THIMBLE <= 24'd1; end
default:begin LENGTH_THIMBLE<=LENGTH_THIMBLE; end
endcase
end
else
begin
LENGTH_THIMBLE <= LENGTH_THIMBLE;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
LENGTH_DIV4 <= 16'd0;
end
else if((select_0_1==1'b0)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_0[1:0] == 2'd0)
begin
LENGTH_DIV4 <= {addra_0[15],addra_0[15],addra_0[15:2]};
end
else
begin
LENGTH_DIV4 <= {addra_0[15],addra_0[15],addra_0[15:2]} + 1'b1;
end
end
else if((select_0_1==1'b1)&&(local_cnts==16'd224)&&(pack_end==1'b1))
begin
if(addra_1[1:0] == 2'd0)
begin
LENGTH_DIV4 <= {addra_1[15],addra_1[15],addra_1[15:2]};
end
else
begin
LENGTH_DIV4 <= {addra_1[15],addra_1[15],addra_1[15:2]} + 1'b1;
end
end
else
begin
LENGTH_DIV4 <= LENGTH_DIV4;
end
end
reg [15:0] rd_cnts;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
rd_cnts<=16'hffff;
end
else if(rd_cnts<=16'd1600)
begin
rd_cnts<=rd_cnts + 1'b1;
end
else if((local_cnts==16'd228)&&(pack_end==1'b1)&&(output_flag==1'b1))
begin
rd_cnts<=16'd0;
end
else
begin
rd_cnts<=rd_cnts;
end
end
reg [15:0] addrb_0;
reg [15:0] addrb_1;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addrb_0<=16'd0;
end
else if(rd_cnts==16'd1599)
begin
addrb_0<=16'd0;
end
else if((select_0_1==1'b0)&&(rd_cnts<=16'd1539)&&(rd_cnts<=all_dat_num_0)&&(rd_cnts>=16'd0))
begin
addrb_0<=addrb_0 + 1'b1;
end
else
begin
addrb_0<=addrb_0;
end
end
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
addrb_1<=16'd0;
end
else if(rd_cnts==16'd1599)
begin
addrb_1<=16'd0;
end
else if((select_0_1==1'b1)&&(rd_cnts<=16'd1539)&&(rd_cnts<=all_dat_num_1)&&(rd_cnts>=16'd0))
begin
addrb_1<=addrb_1 + 1'b1;
end
else
begin
addrb_1<=addrb_1;
end
end
reg real_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
real_clk_p<=1'b0;
end
else if(((select_0_1==1'b1)&&(rd_cnts<=16'd1540)&&(rd_cnts<=(all_dat_num_1+1))&&(rd_cnts>=16'd2))||((select_0_1==1'b0)&&(rd_cnts<=16'd1540)&&(rd_cnts<=(all_dat_num_0+1))&&(rd_cnts>=16'd2)))
begin
real_clk_p<=1'b1;
end
else
begin
real_clk_p<=1'b0;
end
end
reg dout_clk_p;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
dout_clk_p<=1'b0;
end
else if((rd_cnts>=16'd1)&&(rd_cnts<=16'd1541))
begin
if(( select_0_1==1'b1 )&&( rd_cnts <= ( all_dat_num_1 + 1 )))
begin
dout_clk_p<=1'b1;
end
else if((select_0_1==1'b0 )&&( rd_cnts <= ( all_dat_num_0 + 1 )))
begin
dout_clk_p<=1'b1;
end
else
begin
dout_clk_p<=1'b0;
end
end
else
begin
dout_clk_p<=dout_clk_p;
end
end
wire [7:0] doutb_0;
wire [7:0] doutb_1;
reg [15:0] dout;
always @ (posedge clk or posedge rst)
begin
if(rst)
begin
dout<=16'd0;
end
else if(rd_cnts==16'd1)
begin
if(select_0_1==1'b1)
begin
dout<=all_dat_num_1 ;
end
else
begin
dout<=all_dat_num_0 ;
end
end
else
begin
if(select_0_1==1'b1)
begin
dout<={dout[15:8],doutb_1};
end
else
begin
dout<={dout[15:8],doutb_0};
end
end
end
blk_mem_8_2048 BLKS_A_0 (
.clka(clk ),
.ena(1'b1 ),
.wea(wea_0 ),
.addra(addra_0 ),
.dina(delay_dina_2 ),
.douta( ),
.clkb(clk ),
.web(1'b0 ),
.addrb(addrb_0 ),
.dinb( ),
.doutb(doutb_0 )
);
blk_mem_8_2048 BLKS_A_1 (
.clka(clk ),
.ena(1'b1 ),
.wea(wea_1 ),
.addra(addra_1 ),
.dina(delay_dina_2 ),
.douta( ),
.clkb(clk ),
.web(1'b0 ),
.addrb(addrb_1 ),
.dinb( ),
.doutb(doutb_1 )
);
ila_data_recv_com ila_data_recv_com (
.clk(clk),
.probe0(din),
.probe1(din_clk_p),
.probe2(delay_din_clk_p),
.probe3(select_0_1),
.probe4(pack_check_pulse),
.probe5(pack_check),
.probe6(pack_end),
.probe7(length_check_pulse),
.probe8(length_check),
.probe9(local_length),
.probe10(wr_pulse),
.probe11(local_cnts),
.probe12(wea_0),
.probe13(wea_1),
.probe14(addra_0),
.probe15(addra_1),
.probe16(delay_dina_0),
.probe17(delay_dina_1),
.probe18(delay_dina_2),
.probe19(all_dat_num_0),
.probe20(all_dat_num_1),
.probe21(rd_cnts),
.probe22(addrb_0),
.probe23(addrb_1),
.probe24(real_clk_p),
.probe25(dout_clk_p),
.probe26(doutb_0),
.probe27(doutb_1),
.probe28(dout),
.probe29(LENGTH_REAL),
.probe30(LENGTH_THIMBLE),
.probe31(LENGTH_DIV4),
.probe32(thimble_valid),
.probe33(min_length),
.probe34(output_flag)
);
endmodule