module ICMP_RX(
input i_clk ,
input i_rst ,
input [7 :0] i_icmp_data ,
input [15:0] i_icmp_len ,
input i_icmp_last ,
input i_icmp_valid ,
output o_trig_reply ,
output [15:0] o_trig_seq
);
localparam P_ICMP_REPLY_TYPE = 8'd0;
localparam P_ICMP_REQ_TYPE = 8'd8;
reg [7 :0] ri_icmp_data ;
reg [15:0] ri_icmp_len ;
reg ri_icmp_last ;
reg ri_icmp_valid ;
reg ro_trig_reply ;
reg [15:0] ro_trig_seq ;
reg [15:0] r_recv_icmp_cnt ;
reg [7 :0] r_icmp_type ;
assign o_trig_reply = ro_trig_reply ;
assign o_trig_seq = ro_trig_seq ;
always @(posedge i_clk or posedge i_rst) begin
if(i_rst) begin
ri_icmp_data <= 'd0;
ri_icmp_len <= 'd0;
ri_icmp_last <= 'd0;
ri_icmp_valid <= 'd0;
end
else begin
ri_icmp_data <= i_icmp_data ;
ri_icmp_len <= i_icmp_len ;
ri_icmp_last <= i_icmp_last ;
ri_icmp_valid <= i_icmp_valid;
end
end
always @(posedge i_clk or posedge i_rst) begin
if(i_rst)
r_recv_icmp_cnt <= 'd0;
else if(ri_icmp_valid)
r_recv_icmp_cnt <= r_recv_icmp_cnt + 'd1;
else
r_recv_icmp_cnt <= 'd0;
end
always @(posedge i_clk or posedge i_rst) begin
if(i_rst)
r_icmp_type <= 'd0;
else if(ri_icmp_valid && r_recv_icmp_cnt == 0)
r_icmp_type <= ri_icmp_data;
else
r_icmp_type <= r_icmp_type;
end
always @(posedge i_clk or posedge i_rst) begin
if(i_rst)
ro_trig_reply <= 'd0;
else if(r_recv_icmp_cnt == 7 && r_icmp_type == P_ICMP_REQ_TYPE)
ro_trig_reply <= 'd1;
else
ro_trig_reply <= 'd0;
end
always @(posedge i_clk or posedge i_rst) begin
if(i_rst)
ro_trig_seq <= 'd0;
else if(r_recv_icmp_cnt >= 6 && r_recv_icmp_cnt <= 7)
ro_trig_seq <= {ro_trig_seq[7:0],ri_icmp_data};
else
ro_trig_seq <= 'd0;
end
endmodule