2021-09-04 19:33:32 +02:00
|
|
|
-- -------------------------------------------------------------------------- --
|
|
|
|
-- TRASHERNET - A Trashy Ethernet Stack for FPGAs --
|
|
|
|
-- -------------------------------------------------------------------------- --
|
|
|
|
-- trashernet_types.vhd : VHDL types used throughout Trashernet
|
|
|
|
-- -------------------------------------------------------------------------- --
|
|
|
|
-- Author : Markus Koch <markus@notsyncing.net>
|
|
|
|
-- Contributors : None
|
|
|
|
-- License : Mozilla Public License (MPL) Version 2
|
|
|
|
-- -------------------------------------------------------------------------- --
|
|
|
|
|
2021-08-31 20:35:15 +02:00
|
|
|
library ieee;
|
|
|
|
use ieee.std_logic_1164.all;
|
2022-05-13 20:37:28 +02:00
|
|
|
use ieee.numeric_std.all;
|
2021-08-31 20:35:15 +02:00
|
|
|
|
2021-09-25 11:07:12 +02:00
|
|
|
package trashernet_pkg is
|
2021-09-25 16:18:02 +02:00
|
|
|
-- General types
|
2021-08-31 20:35:15 +02:00
|
|
|
subtype byte is std_logic_vector(7 downto 0);
|
|
|
|
type byte_vector is array (natural range <>) of byte;
|
2021-09-25 16:18:02 +02:00
|
|
|
|
|
|
|
-- MAC specific types
|
2021-08-31 20:35:15 +02:00
|
|
|
subtype mac_addr_t is byte_vector(0 to 5);
|
|
|
|
subtype ethertype_t is byte_vector(0 to 1);
|
2021-09-25 11:20:26 +02:00
|
|
|
|
|
|
|
type mac_header_fields is record
|
2021-09-25 12:28:04 +02:00
|
|
|
mac_destination : mac_addr_t; -- Destination MAC address
|
|
|
|
mac_source : mac_addr_t; -- Source MAC address
|
|
|
|
mac_ethertype : ethertype_t; -- Ethertype or length
|
2021-09-25 11:20:26 +02:00
|
|
|
end record mac_header_fields;
|
2021-09-25 12:28:04 +02:00
|
|
|
|
2021-09-25 16:18:02 +02:00
|
|
|
-- IP specific types
|
|
|
|
subtype ip_addr_t is byte_vector(0 to 3);
|
|
|
|
|
2022-05-13 20:36:52 +02:00
|
|
|
-- Configuration interface
|
|
|
|
type configuration_t is record
|
|
|
|
mac_address : mac_addr_t; -- MAC address of this node
|
|
|
|
end record configuration_t;
|
2022-05-15 14:44:37 +02:00
|
|
|
type ip_configuration_t is record
|
|
|
|
ip_address : ip_addr_t; -- IP address of this node
|
|
|
|
end record ip_configuration_t;
|
2022-05-13 20:36:52 +02:00
|
|
|
|
2021-09-25 12:28:04 +02:00
|
|
|
-- PHY interface
|
|
|
|
type phy_in_t is record
|
|
|
|
tx_data : byte; -- TX Data
|
|
|
|
tx_data_en : std_logic; -- Transmitter enable
|
|
|
|
end record phy_in_t;
|
|
|
|
type phy_out_t is record
|
|
|
|
rx_data : byte; -- RX Data
|
|
|
|
rx_data_valid : std_logic; -- RX Data valid
|
|
|
|
rx_active : std_logic; -- RX of packet in progress
|
|
|
|
|
|
|
|
tx_data_ack : std_logic; -- Latched data_tx
|
|
|
|
tx_active : std_logic; -- Transmission in progress
|
|
|
|
|
|
|
|
carrier_detect : std_logic; -- Carrier detected
|
|
|
|
rx_error : std_logic; -- Receive error
|
|
|
|
end record phy_out_t;
|
2021-09-25 16:18:02 +02:00
|
|
|
|
|
|
|
-- MAC interface
|
|
|
|
type mac_in_t is record
|
|
|
|
tx_header : mac_header_fields; -- TX MAC Header Data
|
|
|
|
tx_mac_data : byte; -- Payload
|
|
|
|
tx_mac_data_en : std_logic; -- Start (and keep) transmitting a frame
|
|
|
|
end record mac_in_t;
|
|
|
|
type mac_out_t is record
|
|
|
|
rx_header : mac_header_fields; -- RX MAC Header Data
|
|
|
|
rx_mac_header_rcv : std_logic; -- `rx_mac` header have been received and are valid
|
|
|
|
|
|
|
|
rx_mac_data : byte; -- Ethernet data (after Ethertype)
|
|
|
|
rx_mac_valid : std_logic; -- `rx_mac` values (headers + data) are valid
|
|
|
|
tx_mac_data_ack : std_logic; -- The byte on `tx_mac_data` has been latched. Update to next word.
|
2022-01-16 13:44:33 +01:00
|
|
|
tx_active : std_logic; -- Transmission in progress
|
2021-09-25 16:18:02 +02:00
|
|
|
|
|
|
|
rx_mac_crc_ok : std_logic; -- End of packet, CRC OK (strobe independent from other rx_mac fields)
|
|
|
|
rx_mac_crc_error : std_logic; -- End of packet, CRC invalid
|
|
|
|
end record mac_out_t;
|
|
|
|
|
2022-05-13 20:37:28 +02:00
|
|
|
-- MAC ETH interface
|
|
|
|
type ethernet_ii_protocol_t is record
|
|
|
|
ethertype : ethertype_t;
|
|
|
|
end record;
|
|
|
|
type ethernet_ii_protocol_vector is array (natural range <>) of ethernet_ii_protocol_t;
|
|
|
|
constant ETHERNET_II_PROTOCOLS_NONE : ethernet_ii_protocol_vector(0 to -1) := (others => (ethertype => (x"00", x"00"))); -- NULL range
|
|
|
|
constant ETHERNET_II_PROTOCOL_IP : ethernet_ii_protocol_t := (ethertype => (x"08", x"00"));
|
|
|
|
constant ETHERNET_II_PROTOCOL_ARP : ethernet_ii_protocol_t := (ethertype => (x"08", x"06"));
|
|
|
|
|
|
|
|
type ethernet_i_out_t is record
|
|
|
|
rx_mac_address : mac_addr_t; -- Source MAC address
|
|
|
|
rx_crc_ok : std_logic; -- End of packet, CRC OK
|
|
|
|
rx_crc_error : std_logic; -- End of packet, CRC invalid
|
|
|
|
|
|
|
|
rx_data : byte; -- RX data
|
|
|
|
rx_data_valid : std_logic; -- RX data valid strobe
|
|
|
|
rx_length : unsigned(15 downto 0); -- RX payload length in bytes
|
|
|
|
rx_header_rcv : std_logic; -- Start of reception, `rx_length` is valid
|
|
|
|
tx_data_ack : std_logic; -- Give next data byte or disable `tx_en`
|
|
|
|
end record;
|
|
|
|
type ethernet_i_in_t is record
|
|
|
|
tx_mac_address : mac_addr_t; -- Destination MAC address
|
|
|
|
tx_data : byte; -- TX data
|
|
|
|
tx_en : std_logic; -- Start and continue transmitting
|
|
|
|
tx_length : unsigned(15 downto 0); -- TX payload length in bytes
|
|
|
|
end record;
|
|
|
|
constant ETHERNET_I_IN_UNUSED : ethernet_i_in_t := (tx_mac_address => (others => x"00"), tx_data => x"00", tx_length => x"0000", others => '0'); -- TODO
|
|
|
|
|
|
|
|
type ethernet_ii_out_t is record
|
|
|
|
rx_mac_address : mac_addr_t; -- Source MAC address
|
|
|
|
rx_data : byte; -- RX data
|
|
|
|
rx_data_valid : std_logic; -- RX data valid strobe
|
|
|
|
rx_crc_ok : std_logic; -- End of packet, CRC OK
|
|
|
|
rx_crc_error : std_logic; -- End of packet, CRC invalid
|
|
|
|
rx_header_rcv : std_logic; -- Start of reception
|
|
|
|
tx_data_ack : std_logic; -- Give next data byte or disable `tx_en`
|
|
|
|
end record;
|
|
|
|
type ethernet_ii_in_t is record
|
|
|
|
tx_mac_address : mac_addr_t; -- Destination MAC address
|
|
|
|
tx_data : byte; -- TX data
|
|
|
|
tx_en : std_logic; -- Start and continue transmitting
|
|
|
|
end record;
|
|
|
|
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');
|
2021-09-25 11:07:12 +02:00
|
|
|
end package trashernet_pkg;
|
2021-08-31 20:35:15 +02:00
|
|
|
|
2021-09-25 11:07:12 +02:00
|
|
|
package body trashernet_pkg is
|
2021-08-31 20:35:15 +02:00
|
|
|
|
2021-09-25 11:07:12 +02:00
|
|
|
end package body trashernet_pkg;
|