From 5f7704cf63569a1d5223e29755e0bcdcde79ad3a Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 15 May 2022 14:45:06 +0200 Subject: [PATCH] pkg: Implement to_string functions for MAC and IP addresses --- trashernet/trashernet_pkg.vhd | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/trashernet/trashernet_pkg.vhd b/trashernet/trashernet_pkg.vhd index b04b885..2b29ee7 100644 --- a/trashernet/trashernet_pkg.vhd +++ b/trashernet/trashernet_pkg.vhd @@ -19,6 +19,7 @@ package trashernet_pkg is -- MAC specific types subtype mac_addr_t is byte_vector(0 to 5); + function mac_to_string(constant mac_address : in mac_addr_t) return string; subtype ethertype_t is byte_vector(0 to 1); type mac_header_fields is record @@ -29,6 +30,7 @@ package trashernet_pkg is -- IP specific types subtype ip_addr_t is byte_vector(0 to 3); + function ip_to_string(constant ip_address : in ip_addr_t) return string; -- Configuration interface type configuration_t is record @@ -119,8 +121,38 @@ package trashernet_pkg is type ethernet_ii_out_vector is array (natural range <>) of ethernet_ii_out_t; type ethernet_ii_in_vector is array (natural range <>) of ethernet_ii_in_t; constant ETHERNET_II_IN_UNUSED : ethernet_ii_in_t := (tx_mac_address => (others => x"00"), tx_data => x"00", others => '0'); + + type arp_out_t is record + arp_mac : mac_addr_t; -- Resulting MAC address for query + arp_ok_stb : std_logic; -- ARP request successful, `arp_mac` valid + arp_fail_stb : std_logic; -- ARP request failed, `arp_mac` invalid + end record arp_out_t; + type arp_in_t is record + arp_ip : ip_addr_t; -- IP address to query + arp_query_stb : std_logic; -- Request MAC for IP + end record arp_in_t; end package trashernet_pkg; package body trashernet_pkg is + function mac_to_string(constant mac_address : in mac_addr_t) return string is + begin + return -- + to_hstring(mac_address(0)) & ":" & -- + to_hstring(mac_address(1)) & ":" & -- + to_hstring(mac_address(2)) & ":" & -- + to_hstring(mac_address(3)) & ":" & -- + to_hstring(mac_address(4)) & ":" & -- + to_hstring(mac_address(5)) -- + ; + end function mac_to_string; + function ip_to_string(constant ip_address : in ip_addr_t) return string is + begin + return -- + to_string(to_integer(unsigned(ip_address(0)))) & "." & -- + to_string(to_integer(unsigned(ip_address(1)))) & "." & -- + to_string(to_integer(unsigned(ip_address(2)))) & "." & -- + to_string(to_integer(unsigned(ip_address(3)))) -- + ; + end function ip_to_string; end package body trashernet_pkg;