From a5d5ca280d6606c81271ae42f11e1bef4826d383 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 29 Oct 2022 19:18:51 +0200 Subject: [PATCH] arp: Add timeout --- design/top_hwitl.vhd | 4 ++++ trashernet/trashernet_arp.vhd | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/design/top_hwitl.vhd b/design/top_hwitl.vhd index 9e03cd9..54dc98d 100644 --- a/design/top_hwitl.vhd +++ b/design/top_hwitl.vhd @@ -215,9 +215,13 @@ architecture eth of top_hwitl is signal arp_in : arp_in_t; begin trashernet_arp_inst : entity trashernet.trashernet_arp + generic map( + TIMEOUT_TICK_FREQ => F_CLK + ) port map( clk => clk, rst => rst, + timeout_tick => '1', mac_config => ETH_CONFIG, ip_config => IP_CONFIG, arp_out => arp_out, diff --git a/trashernet/trashernet_arp.vhd b/trashernet/trashernet_arp.vhd index 4ea1663..ec1cbb6 100644 --- a/trashernet/trashernet_arp.vhd +++ b/trashernet/trashernet_arp.vhd @@ -16,10 +16,14 @@ use ieee.numeric_std.all; use work.trashernet_pkg.all; entity trashernet_arp is + generic( + TIMEOUT_TICK_FREQ : integer + ); port( -- Global clk : in std_logic; -- Global clock rst : in std_logic; -- Asynchronous reset + timeout_tick : in std_logic; -- Global timeout tick strobe -- Configuration mac_config : in configuration_t; -- Trashernet MAC configuration @@ -43,6 +47,8 @@ architecture rtl of trashernet_arp is constant OPER_REQUEST : byte_vector := (x"00", x"01"); constant OPER_REPLY : byte_vector := (x"00", x"02"); + constant ARP_TIMEOUT : time := 1 sec; + signal arp_tx_reply_rq : std_logic; -- Request to transmit an ARP reply signal arp_tx_reply_tha : mac_addr_t; -- Target MAC to use in reply (SHA in received packet) signal arp_tx_reply_tpa : ip_addr_t; -- Target IP to use in reply (SPA in received packet) @@ -113,6 +119,22 @@ begin query_mac_found <= '1' when (arp_tx_request_tpa = replied_ip) else '0'; arp_out.arp_mac <= replied_mac; arp_tx_request_tpa <= arp_in.arp_ip; + + timeout_timer_inst : entity work.timer + generic map( + F_TICK => TIMEOUT_TICK_FREQ, + DURATION => ARP_TIMEOUT, + AUTOSTART => false + ) + port map( + clk => clk, + rst => rst, + tick => timeout_tick, + start => arp_tx_request_rq, + expired => query_timeout, + expired_stb => open + ); + end block resolver; rx : block