ARP過程只需要一次發送和一次接受就可以完成了;
在實際實現協議棧的時候我個人認為要以主動ARP開始;
主動ARP:發送一次ARP請求,接受一個ARP報文;
使用這種方式的原因是上位機可能不知道你的IP地址(當然如果使用的是開發好的上位機的話,被動ARP也是可以的,例如原子上位機);
這是我的實現方法,提供給大家參考:
主要過程是:一次主動ARP之后,進入NORMAL狀態,當NORMAL狀態下接收到ARP請求的時候,再發送ARP ACK;
always @(posedge sys_clk) beginif(sys_rst_n == 1'b0) beginstate <= state_idle;end else begincase (state)state_idle:beginstate <= state_arp_req;endstate_arp_req:beginif(r1_arp_rx_ack_vaild == 1'b0 && arp_rx_ack_vaild == 1'b1) beginstate <= state_normal;end else beginstate <= state_arp_req;endendstate_normal:beginif(arp_wait == 1'b1) beginstate <= state_arp_ack;end else if(hb_wait == 1'b1 && data_wait == 1'b0) beginstate <= state_hb;end else if(hb_wait == 1'b1 && data_wait == 1'b1) beginstate <= state_hb;end else if(hb_wait == 1'b0 && data_wait == 1'b1)beginstate <= state_tx_data;end else beginstate <= state_normal;endendstate_arp_ack:beginif(r1_slave_arp_tx_end == 1'b1 && slave_arp_tx_end == 1'b0) beginstate <= state_normal;end else beginstate <= state_arp_ack;endendstate_hb:beginif(r1_slave_hb_tx_end == 1'b0 && slave_hb_tx_end == 1'b1) beginstate <= state_normal;end else beginstate <= state_hb;endendstate_tx_data:beginif(r1_slave_data_tx_end == 1'b0 && slave_data_tx_end == 1'b1) beginstate <= state_normal;end else beginstate <= state_tx_data;endenddefault: beginstate <= state;endendcaseendend