pkg: Implement to_string functions for MAC and IP addresses
This commit is contained in:
parent
5f389b0c7b
commit
5f7704cf63
@ -19,6 +19,7 @@ package trashernet_pkg is
|
|||||||
|
|
||||||
-- MAC specific types
|
-- MAC specific types
|
||||||
subtype mac_addr_t is byte_vector(0 to 5);
|
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);
|
subtype ethertype_t is byte_vector(0 to 1);
|
||||||
|
|
||||||
type mac_header_fields is record
|
type mac_header_fields is record
|
||||||
@ -29,6 +30,7 @@ package trashernet_pkg is
|
|||||||
|
|
||||||
-- IP specific types
|
-- IP specific types
|
||||||
subtype ip_addr_t is byte_vector(0 to 3);
|
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
|
-- Configuration interface
|
||||||
type configuration_t is record
|
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_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;
|
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');
|
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;
|
end package trashernet_pkg;
|
||||||
|
|
||||||
package body trashernet_pkg is
|
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;
|
end package body trashernet_pkg;
|
||||||
|
Loading…
Reference in New Issue
Block a user