以太网:ARP
ARP过程只需要一次发送和一次接受就可以完成了;
在实际实现协议栈的时候我个人认为要以主动ARP开始;
主动ARP:发送一次ARP请求,接受一个ARP报文;
使用这种方式的原因是上位机可能不知道你的IP地址(当然如果使用的是开发好的上位机的话,被动ARP也是可以的,例如原子上位机);
这是我的实现方法,提供给大家参考:
主要过程是:一次主动ARP之后,进入NORMAL状态,当NORMAL状态下接收到ARP请求的时候,再发送ARP ACK;
可以看到很好的完成了我的需求;

always @(posedge sys_clk) begin if(sys_rst_n == 1'b0) begin state <= state_idle; end else begin case (state) state_idle:begin state <= state_arp_req; end state_arp_req:begin if(r1_arp_rx_ack_vaild == 1'b0 && arp_rx_ack_vaild == 1'b1) begin state <= state_normal; end else begin state <= state_arp_req; end end state_normal:begin if(arp_wait == 1'b1) begin state <= state_arp_ack; end else if(hb_wait == 1'b1 && data_wait == 1'b0) begin state <= state_hb; end else if(hb_wait == 1'b1 && data_wait == 1'b1) begin state <= state_hb; end else if(hb_wait == 1'b0 && data_wait == 1'b1)begin state <= state_tx_data; end else begin state <= state_normal; end end state_arp_ack:begin if(r1_slave_arp_tx_end == 1'b1 && slave_arp_tx_end == 1'b0) begin state <= state_normal; end else begin state <= state_arp_ack; end end state_hb:begin if(r1_slave_hb_tx_end == 1'b0 && slave_hb_tx_end == 1'b1) begin state <= state_normal; end else begin state <= state_hb; end end state_tx_data:begin if(r1_slave_data_tx_end == 1'b0 && slave_data_tx_end == 1'b1) begin state <= state_normal; end else begin state <= state_tx_data; end end default: begin state <= state; end endcase end end

浙公网安备 33010602011771号