Académique Documents
Professionnel Documents
Culture Documents
-- src_port
-- end record;
-- type ipv4_rx_header_type is record
-- is_valid
: std_logic;
-- protocol
-- last_error_code
-- is_broadcast
: std_logic;
-- end record;
--type udp_rx_type is record
--hdr
: udp_rx_header_type;
--data
: axi_in_type;
-- header received
-- rx axi bus
--end record;
--type udp_tx_type is record
--hdr
: udp_tx_header_type;
-- header received
--data
: axi_out_type;
-- tx axi bus
--end record;
entity UDP_TX is
Port (
-- UDP Layer signals
udp_tx_start
: in std_logic;
udp_txi
: in udp_tx_type;
-- UDP tx cxns
udp_tx_result
-- system signals
clk
: in STD_LOGIC;
reset
: in STD_LOGIC;
-- IP layer TX signals
ip_tx_start
: out std_logic;
ip_tx
: out ipv4_tx_type;
-- IP tx cxns
ip_tx_result
ip_tx_data_out_ready : in std_logic
end UDP_TX;
architecture Behavioral of UDP_TX is
type tx_state_type is (IDLE,
: tx_state_type;
signal tx_count
signal tx_result_reg
signal ip_tx_start_reg
: std_logic;
signal data_out_ready_reg
: std_logic;
-- tx control signals
signal next_tx_state
: tx_state_type;
signal set_tx_state
signal next_tx_result
: std_logic;
: std_logic_vector (1 downto 0);
signal set_tx_result
: std_logic;
signal tx_count_val
signal tx_count_mode
: settable_cnt_type;
signal tx_data
signal set_last
signal set_ip_tx_start
: std_logic;
: set_clr_type;
signal tx_data_valid
: std_logic;
-- tx temp signals
signal total_length
begin
------------------------------------------------------------------------ combinatorial process to implement FSM and determine control signals
----------------------------------------------------------------------tx_combinatorial : process(
-- input signals
udp_tx_start, udp_txi, clk, ip_tx_result, ip_tx_data_out_ready,
-- state variables
udp_tx_state, tx_count, tx_result_reg, ip_tx_start_reg, data_out_ready_reg,
-- control signals
next_tx_state, set_tx_state, next_tx_result, set_tx_result, tx_count_mode, tx_count_val,
tx_data, set_last, total_length, set_ip_tx_start, tx_data_valid
begin
-- set output followers
ip_tx_start <= ip_tx_start_reg;
ip_tx.hdr.protocol <= x"11";
-- UDP protocol
layer
else
udp_tx_result <= tx_result_reg;
end if;
case udp_tx_state is
when SEND_USER_DATA =>
ip_tx.data.data_out <= udp_txi.data.data_out;
tx_data_valid <= udp_txi.data.data_out_valid;
ip_tx.data.data_out_last <= udp_txi.data.data_out_last;
when SEND_UDP_HDR =>
ip_tx.data.data_out <= tx_data;
tx_data_valid <= ip_tx_data_out_ready;
ip_tx.data.data_out_last <= set_last;
when others =>
ip_tx.data.data_out <= (others => '0');
tx_data_valid <= '0';
ip_tx.data.data_out_last <= set_last;
end case;
ip_tx.data.data_out_valid <= tx_data_valid and ip_tx_data_out_ready;
-- set signal defaults
next_tx_state <= IDLE;
set_tx_state <= '0';
tx_count_mode <= HOLD;
tx_data <= x"00";
end if;
end if;
when PAUSE =>
-- delay one clock for IP layer to respond to ip_tx_start and remove any tx error
result
next_tx_state <= SEND_UDP_HDR;
set_tx_state <= '1';
-- src port
-- dst port
-- length
-- checksum (set by
upstream)
when x"0007" => tx_data <= udp_txi.hdr.checksum (7 downto 0);
when others =>
-- shouldnt get here - handle as error
next_tx_result <= UDPTX_RESULT_ERR;
set_tx_result <= '1';
end case;
end if;
when SEND_USER_DATA =>
udp_tx_data_out_ready <= ip_tx_data_out_ready;-- in this state, we can accept user data if IP TX
rdy
if ip_tx_data_out_ready = '1' then
if udp_txi.data.data_out_valid = '1' or tx_count = x"000" then
-- only increment if
ready and valid has been subsequently established, otherwise data count moves on too
fast
if unsigned(tx_count) = unsigned(udp_txi.hdr.data_length) then
-- TX terminated due to count - end normally
set_last <= '1';
tx_data <= udp_txi.data.data_out;
next_tx_result <= UDPTX_RESULT_SENT;
set_ip_tx_start <= CLR;
set_tx_result <= '1';
next_tx_state <= IDLE;
else
-- TX continues
tx_count_mode <= INCR;
tx_data <= udp_txi.data.data_out;
end if;
end if;
end if;
end case;
end process;
------------------------------------------------------------------------------ sequential process to action control signals and change states and outputs
----------------------------------------------------------------------------tx_sequential : process (clk,reset,data_out_ready_reg)
begin
if rising_edge(clk) then
data_out_ready_reg <= ip_tx_data_out_ready;
else
data_out_ready_reg <= data_out_ready_reg;
end if;
if rising_edge(clk) then
if reset = '1' then
-- reset state variables
udp_tx_state <= IDLE;
tx_count <= x"0000";
tx_result_reg <= IPTX_RESULT_NONE;
ip_tx_start_reg <= '0';
else
-- Next udp_tx_state processing
if set_tx_state = '1' then
udp_tx_state <= next_tx_state;
else
udp_tx_state <= udp_tx_state;
end if;
-- ip_tx_start_reg processing
case set_ip_tx_start is
when SET => ip_tx_start_reg <= '1';
when CLR => ip_tx_start_reg <= '0';
when HOLD => ip_tx_start_reg <= ip_tx_start_reg;
end case;
-- tx result processing
if set_tx_result = '1' then
tx_result_reg <= next_tx_result;
else