欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

基于 FPGA 的 UDP 协议栈设计 第 3 章_ARP 层设计 - II.ARP 传输

最编程 2024-03-24 09:20:30
...

首先系统上电会进行一次主动ARP,当ARP_TX模块收到主动ARP信号请求时,会产生一个ARP请求报文;其次当收到ARP_RX模块的o_trig_reply信号时,会产生一个回复ARP报文。就如何进行组帧的部分前俩章都进行了介绍,不做赘述。

always @(posedge i_clk or posedge i_rst)begin
    if(i_rst)
        ro_mac_data <= 'd0;
    else case (r_arp_cnt)
        0       : ro_mac_data <= 8'h00;             //硬件类型,对以太网,值为1
        1       : ro_mac_data <= 8'h01;             
        2       : ro_mac_data <= 8'h08;             //协议类型,IP 0x0800
        3       : ro_mac_data <= 8'h00;     
        4       : ro_mac_data <= 'd6;               //硬件地址长度
        5       : ro_mac_data <= 'd4;               //协议长度
        6       : ro_mac_data <= r_arp_op[15:8];    //操作类型
        7       : ro_mac_data <= r_arp_op[7 :0];
        8       : ro_mac_data <= r_src_mac[47:40];
        9       : ro_mac_data <= r_src_mac[39:32];
        10      : ro_mac_data <= r_src_mac[31:24];
        11      : ro_mac_data <= r_src_mac[23:16];
        12      : ro_mac_data <= r_src_mac[15: 8];
        13      : ro_mac_data <= r_src_mac[7 : 0];
        14      : ro_mac_data <= r_src_ip[31:24];
        15      : ro_mac_data <= r_src_ip[23:16];
        16      : ro_mac_data <= r_src_ip[15: 8];
        17      : ro_mac_data <= r_src_ip[7 : 0];
        18      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[47:40] : 8'h00;
        19      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[39:32] : 8'h00; 
        20      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[31:24] : 8'h00;
        21      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[23:16] : 8'h00;
        22      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[15: 8] : 8'h00;
        23      : ro_mac_data <= r_arp_op == P_ARP_OP_REPLY ? ri_reply_mac[7 : 0] : 8'h00;
        24      : ro_mac_data <= r_dst_ip[31:24];
        25      : ro_mac_data <= r_dst_ip[23:16];
        26      : ro_mac_data <= r_dst_ip[15: 8];
        27      : ro_mac_data <= r_dst_ip[7 : 0];
        default : ro_mac_data <= 'd0; 
    endcase
end